示例#1
0
 protected function _import()
 {
     if (!$this->_obligateFileParam()) {
         return;
     }
     $path = $this->_args[1];
     $content = file_get_contents($path);
     $size = round(strlen($content) / 1024 / 1024);
     Garp_Cli::lineOut("Thanks for feeding me {$size} MB of data.");
     $zipSet = new Garp_Service_PostcodeNl_Zipcode_Set($content);
     $this->_totalZips = count($zipSet);
     $linesCountLabel = $this->_formatBigNumber($this->_totalZips);
     Garp_Cli::lineOut("Parsing {$linesCountLabel} lines.");
     $question = "Do you want this data to overwrite\n" . "existing entries for matching zip codes?\n" . "Warning: this can remove richer data.";
     $overwrite = Garp_Cli::confirm($question);
     $this->_storeZipSet($zipSet, $overwrite);
     $stored = $this->_formatBigNumber($this->_storedZips);
     Garp_Cli::lineOut("\nStored {$stored} zipcodes.");
 }
示例#2
0
 public function rm(array $args = array())
 {
     if (empty(Zend_Registry::get('config')->cdn->s3->bucket)) {
         Garp_Cli::errorOut('No bucket configured');
         return false;
     }
     if (empty($args)) {
         Garp_Cli::errorOut('No path given.');
         return false;
     }
     $path = rtrim('s3://' . Zend_Registry::get('config')->cdn->s3->bucket, DIRECTORY_SEPARATOR);
     if (isset($args[0])) {
         $path .= DIRECTORY_SEPARATOR . $args[0];
     }
     if (!Garp_Cli::confirm('Are you sure you want to permanently remove ' . $path . '?')) {
         Garp_Cli::lineOut('Changed your mind, huh? Not deleting.');
         return true;
     }
     $args = array($path);
     return $this->s3('rm', $args);
 }
示例#3
0
 public function make($args = array())
 {
     $mem = new Garp_Util_Memory();
     $mem->useHighMemory();
     // @todo Superduperbonusmode: would be cool if you could go back in time and generate a
     // gumball for a given semver (using Git to grab the correct tag).
     // There would be no way to include that moment's data though.
     $version = new Garp_Semver();
     Garp_Cli::lineOut('Creating gumball ' . $version, Garp_Cli::PURPLE);
     $fromEnv = null;
     if ($useDb = Garp_Cli::confirm(self::PROMPT_INCLUDE_DATABASE)) {
         $fromEnv = Garp_Cli::prompt(self::PROMPT_SOURCE_DATABASE_ENVIRONMENT) ?: self::DEFAULT_SOURCE_DATABASE_ENVIRONMENT;
     }
     $gumball = new Garp_Gumball($version, array('useDatabase' => $useDb, 'databaseSourceEnvironment' => $fromEnv));
     if ($gumball->exists() && !Garp_Cli::confirm(sprintf(self::PROMPT_OVERWRITE, $version))) {
         Garp_Cli::lineOut(self::ABORT_NO_OVERWRITE, Garp_Cli::YELLOW);
         return false;
     }
     $gumball->exists() && $gumball->remove();
     if (!$this->_createGumballDirectory()) {
         Garp_Cli::errorOut(self::ABORT_CANT_MKDIR_GUMBALLS);
         return false;
     }
     try {
         $gumball->make();
     } catch (Garp_Gumball_Exception_CannotWriteTargetDirectory $e) {
         Garp_Cli::errorOut(self::ABORT_CANT_MKDIR_TARGET_DIRECTORY);
         return false;
     } catch (Garp_Gumball_Exception_CannotCopySourceFiles $e) {
         Garp_Cli::errorOut(self::ABORT_CANT_COPY_SOURCEFILES);
         return false;
     } catch (Garp_Gumball_Exception_CannotCreateZip $e) {
         Garp_Cli::errorOut(self::ABORT_CANT_WRITE_ZIP);
         return false;
     } catch (Garp_Gumball_Exception_DatadumpFailed $e) {
         Garp_Cli::errorOut(self::ABORT_DATADUMP_FAILED);
         return false;
     }
     return true;
 }