Exemple #1
0
 static function status($pos, $len)
 {
     if (self::$in_file != self::$source_name) {
         if (self::$in_file != "") {
             self::clear_progress();
         }
         self::verbose("Loading " . self::$source_name . "...\n");
         self::$in_file = self::$source_name;
     }
     if (!self::$progress) {
         return;
     }
     $progress_size = 2;
     $min_width = 8 + 2 + $progress_size + 2 + 5 + 1;
     # "%"
     $min_filename_length = 3;
     # if there's no way to fit the progress bar on this screen, just return
     if ($min_width + $min_filename_length >= self::$width) {
         self::$progress = false;
         return;
     }
     $filename = self::$source_name;
     # if we can fit the entire filename on the line then we size the progress bar
     if ($min_width + strlen(self::$source_name) < self::$width - 1) {
         $progress_size = self::$width - ($min_width + strlen($filename) + 1);
     } else {
         $filename = substr($filename, 0, self::$width - ($min_width + 1));
     }
     $percent_per_file = 1 / self::$source_count;
     $already_done = (self::$source_index - 1) * $percent_per_file;
     $in_file = $len == 0 ? 1 : $pos / $len;
     $overall = $already_done + $percent_per_file * $in_file;
     $fill_count = floor($overall * $progress_size);
     $blank_count = ceil($progress_size - $fill_count);
     $fill = str_repeat("*", $fill_count);
     $blank = str_repeat("-", $blank_count);
     self::warn(sprintf("\rLoading %s [%s%s] %2.1f%%", $filename, $fill, $blank, $overall * 100));
 }
Exemple #2
0
 static function get_args($arg_spec)
 {
     global $argv;
     if (in_array("--version", $argv)) {
         fputs(STDERR, "Modyllic Version: @VERSION@ @STATE@\n");
         exit;
     }
     $parser = self::get_parser();
     $parser->addOption('verbose', array('short_name' => '-v', 'long_name' => '--verbose', 'description' => 'report each stage of execution to stderr', 'action' => 'Counter', 'default' => 0));
     $parser->addOption('debug', array('long_name' => '--debug', 'description' => 'enables further diagnostic information for debugging the parser (useful for bug reports!)', 'action' => 'StoreTrue', 'default' => false));
     $parser->addOption('progress', array('long_name' => '--progress', 'description' => 'output a progress meter to stderr', 'action' => 'StoreTrue', 'default' => false));
     // This is only in here to be included in help... we short circuit above if it's found
     $parser->addOption('version', array('long_name' => '--version', 'description' => 'show the Modyllic version number', 'action' => 'StoreTrue', 'default' => false));
     $parser->addOption('modyllic', array('help_name' => 'path', 'long_name' => '--modyllic-path', 'action' => 'StoreString', 'description' => 'The path containing the modyllic binary'));
     if (isset($arg_spec['description'])) {
         $parser->description = $arg_spec['description'];
     }
     if (isset($arg_spec['options'])) {
         foreach ($arg_spec['options'] as $name => $opt) {
             $parser->addOption($name, $opt);
         }
     }
     if (isset($arg_spec['arguments'])) {
         foreach ($arg_spec['arguments'] as $name => $opt) {
             $parser->addArgument($name, $opt);
         }
     }
     try {
         $args = $parser->parse();
     } catch (Exception $e) {
         $parser->displayError($e->getMessage());
     }
     Modyllic_Status::$verbose = $args->options['verbose'];
     Modyllic_Status::$progress = $args->options['progress'];
     Modyllic_Status::$debug = $args->options['debug'];
     return $args;
 }