function loadCache() { console::write("Reading database ... "); $fc = file_get_contents($this->cachefile); $fco = unserialize($fc); $this->cache = $fco; console::write("(%d files, %d packages) ", count($this->cache['special:files']), count($this->cache['special:installed'])); Console::writeLn("Done"); }
public function renderTimeline() { $frlast = $this->_duration; for ($fr = 0; $fr < $this->_duration; $fr++) { $frc = $fr + 1; $pc = 100 / $frlast * $frc; console::write(str_repeat(chr(8), 80) . "[%d%%] Rendering frame %d of %d (%d to go) ", $pc, $frc, $frlast, $frlast - $frc); $this->_scenes[0]->render($fr); } console::writeLn("\nDone!"); }
public function render($frame) { $props = $this->_properties; foreach ($this->_animators as $prop => $anims) { foreach ($anims as $anim) { // We aren't checking the framestart and frameend properties here $fi = $frame; $fe = 1000; $animator = $anim['animator']; $val = $animator->getValue($fi, $fe); console::write(" %s=%s ", $prop, $val); $props[$prop] = $val; } } $framedata = array('width' => $this->scene->width, 'height' => $this->scene->height, 'frame' => $frame); // TODO: Pass through blender return $this->_object->render($framedata, $props); }
static function readPass() { if (IS_LINUX) { system('stty -echo'); } $ld = fgets(STDIN); $ld = __strip_newline($ld); if (IS_LINUX) { system('stty echo'); } console::write("\n"); return $ld; }
public function spell($lang = null) { $this->openDatabase(); if (!$lang) { $lang = $this->db['db:defaultlang']; } if (!function_exists('pspell_new')) { console::fatal("strings spell requires the pspell extension"); exit(1); } $sp = pspell_new($lang); if (!$sp) { console::fatal("Couldn't load dictionary for %s", $lang); exit(1); } foreach ($this->db['lang:' . $lang] as $key => $str) { $strn = explode(' ', $str); foreach ($strn as $word) { if (!pspell_check($sp, $word)) { console::write("%s: ", $word); $suggestions = pspell_suggest($sp, $word); foreach ($suggestions as $suggestion) { console::write('%s ,', $suggestion); } console::writeLn(); } } } }
function test($username = null) { using('lepton.user.*'); using('lepton.mvc.request'); if ($username) { console::write("Password: "******"Success!"); } } else { console::writeLn("Use: user test username"); } }
/** * * * * */ public function alias() { $this->checkData(); console::writeLn("Generating geoalias table"); $db = new DatabaseConnection(); $db->exec('DROP TABLE IF EXISTS geoalias'); $db->exec('CREATE TABLE geoalias (id INT PRIMARY KEY AUTO_INCREMENT, geoid BIGINT, locname VARCHAR(64) CHARSET utf8, INDEX locname(locname(5))) CHARSET utf8'); $rows = $db->getRows("SELECT id,alternatenames FROM geonames WHERE alternatenames!=''"); console::write('%8d / %8d ', 0, count($rows)); foreach ($rows as $row) { $alt = explode(',', $row['alternatenames']); foreach ($alt as $altstr) { $db->insertRow("INSERT INTO geoalias (geoid,locname) VALUES (%d,%s)", $row['id'], $altstr); } $rc++; $rt++; if ($rt >= 100) { $rh++; if ($rh >= 50) { console::write("\n%8d / %8d ", $rc, count($rows)); $rh = 0; } else { console::write('.'); } $rt = 0; } } console::writeLn(' Done!'); }
public function initialize($rootuser = null) { console::writeLn(__astr('\\b{Initializing database}')); $db = config::get('lepton.db.default'); $dbc = config::get('lepton.db.default'); console::writeLn(" Database: %s", $dbc['database']); console::writeLn(" User: %s", $dbc['username']); console::writeLn(" Host: %s", $dbc['hostname']); switch ($db['driver']) { case 'pdo/mysql': case 'mysql': console::writeLn(" Driver: MySQL"); break; default: console::fatal('This version of the script does not support anything else than MySQL'); exit(1); } console::writeLn(__astr("\n\\b{Creating database and user}")); console::writeLn(" The script can create the database and the user. Hit enter to skip this step."); console::write(" Password for root user: "******"SHOW DATABASES LIKE %s", $dbc['database']); if (count($dblist) == 0) { console::writeLn("Creating database..."); try { $conn->exec(sprintf("CREATE DATABASE %s;", $dbc['database'])); } catch (Exception $e) { console::writeLn("Not successful, does the database already exist?"); } } console::writeLn("Creating user..."); $conn->exec(sprintf("GRANT ALL ON %s.* TO %s@localhost IDENTIFIED BY '%s';", $dbc['database'], $dbc['username'], $dbc['password'])); $conn->exec("USE " . $dbc['database']); } else { console::writeLn("No password specified, ignoring database and user creation."); $conn = new DatabaseConnection(); } console::writeLn(__astr("\n\\b{Importing tables}")); $f = glob(base::basePath() . '/dist/sql/*.sql'); foreach ($f as $fn) { $fc = file_get_contents($fn); console::writeLn(" [sys] %s", basename($fn)); $conn->exec($fc); } $f = glob(base::appPath() . '/sql/*.sql'); foreach ($f as $fn) { $fc = file_get_contents($fn); console::writeLn(" [app] %s", basename($fn)); $conn->exec($fc); } console::writeLn("All done."); }
} else { $pks = implode('\', \'', $pks); $modelBody .= ' protected $primaryKeys = array(\'' . $pks . '\');' . PHP_EOL . PHP_EOL; } $modelBody .= ' // fields:' . PHP_EOL; foreach ($fields as $uniqueField) { $modelBody .= ' public $' . $uniqueField . ' = null;' . PHP_EOL; } $modelBody .= PHP_EOL . '}'; console::write('[fields: ' . count($fields) . ']'); if (count($pks) == 0) { console::write('[!!!] Warning, table ' . $newModel . ' without Primary Key'); } file_put_contents($model_location . $file, $modelBody); } else { console::write('[!] File ' . $file . ' already exists.'); } } //var_dump(getTableFields('support_responses')); function getTableFields($table) { $out = array(); $pks = array(); foreach (DB::fetchAll(DB::query('describe ' . $table)) as $field) { $out[] = $field['Field']; if ($field['Key'] == 'PRI') { $pks[] = $field['Field']; } } return array('fields' => $out, 'pk' => $pks); }
public static function lines() { console::write(str_repeat('=', static::cols())); }
/** * * @return Option key */ function runMenu() { while (true) { $col = 0; console::writeLn($this->title); $keys = array(); foreach ($this->options as $key => $option) { if ($this->width) { console::write(' [%s] %-' . $this->width . 's', $option['state'] ? __astr('\\b{x}') : ' ', $key); } else { console::writeLn(' %s. [%s] %s', $key, $option['state'] ? __astr('\\b{x}') : ' ', $option['value']); } if ($this->columns) { $col++; if ($col > $this->columns) { $col = 0; console::writeLn(); } } $keys[] = $key; } if ($this->columns && $col > 0) { console::writeLn(); } if (count($keys) > 10) { $keys = array_merge(array_slice($keys, 0, 9), array('...')); } $keystr = join('/', $keys); $prompt = '[Y/n/help/all/none/invert/reset/' . $keystr . ']: '; $rl = readline::read($prompt); foreach (explode(' ', $rl) as $r) { foreach ($this->options as $key => $option) { if ($key == $r) { $this->options[$key]['state'] = !$this->options[$key]['state']; } } if (strtolower($r) == 'help') { console::writeLn("Type any of the alternatives listed above. They will be evaluated in the order they are provided."); console::writeLn("When you are done, hit enter on an empty line or enter 'y'. To cancel, enter 'n'."); } if (strtolower($r) == 'y' || $r == '') { return true; } if (strtolower($r) == 'n') { return false; } if (strtolower($r) == 'all') { foreach ($this->options as $key => $option) { $this->options[$key]['state'] = true; } } if (strtolower($r) == 'none') { foreach ($this->options as $key => $option) { $this->options[$key]['state'] = false; } } if (strtolower($r) == 'reset') { foreach ($this->options as $key => $option) { $this->options[$key]['state'] = $this->options[$key]['default']; } } if (strtolower($r) == 'invert') { foreach ($this->options as $key => $option) { $this->options[$key]['state'] = !$this->options[$key]['state']; } } } } }