function retrieve() {
     // check out the right tag
     `git clone $this->base_location $this->temp_path`;
     `cd $this->temp_path; git checkout $this->tag -b $this->temp_token`;
     // remove the git directory
     SparkUtils::remove_full_directory("$this->temp_path/.git");
     return file_exists($this->temp_path);
 }
 function search($term) {
     $json_data = @file_get_contents("http://$this->url/api/packages/search?q=" . urlencode($term)); 
     $data = json_decode($json_data);
     // if the data isn't around of success is false, return a warning for this source
     if ($data == null || !$data->success) {
         $message = "Error searching source: $this->url";
         if ($data != null) $message .= " ($data->message)";
         SparkUtils::warning($message);
         return array();
     }
     // Get sparks for each one
     $results = array();
     foreach($data->results as $data) $results[] = $this->get_spark($data);
     return $results;
 }
 function verify() {
     // see if this is deactivated
     if ($this->data->is_deactivated) {
         $msg = 'Woah there - it seems the spark you want has been deactivated';
         if ($this->data->spark_home) $msg .= "\nLook for different versions at: " . $this->data->spark_home;
         throw new SparkException($msg);
     }
     // see if this is unsupported
     if ($this->data->is_unsupported) {
         SparkUtils::warning('This spark is no longer supported.');
         SparkUtils::warning('You can keep using it, or look for an alternate');
     }
     // tell the user if its already installed and throw an error
     $this->installation_path = SPARK_PATH . "/$this->name/$this->version";
     if (is_dir($this->installation_path)) {
         throw new SparkException("Already installed.  Try `php tools/spark remove $this->name`");
     }
 }
   private function install($args) {

        $flats = array();
        $flags = array();
        foreach($args as $arg) {
            preg_match('/^(\-?[a-zA-Z])([^\s]+)$/', $arg, $matches);
            if (count($matches) != 3) continue;
            $matches[0][0] == '-' ? $flags[$matches[1][1]] = $matches[2] : $flats[] = $matches[0];
        }

        if (count($flats) != 1) return $this->failtown('format: `spark install -v1.0.0 name`');
        $spark_name = $flats[0];
        $version = array_key_exists('v', $flags) ? $flags['v'] : 'HEAD';

        // retrieve the spark details
        foreach ($this->spark_sources as $source) {
            SparkUtils::notice("Retrieving spark detail from " . $source->get_url());
            $spark = $source->get_spark_detail($spark_name, $version);
            if ($spark != null) break;
        }

        // did we find the details?
        if ($spark == null) throw new SparkException("Unable to find spark: $spark_name ($version) in any sources");

        // verify the spark, and put out warnings if needed
        $spark->verify();

        // retrieve the spark
        SparkUtils::notice("From Downtown! Retrieving spark from " . $spark->location_detail());
        if (!$spark->retrieve()) throw new SparkException('Failed to retrieve the spark ;(');

        SparkUtils::notice('Installing spark');
        $spark->install();
        SparkUtils::notice('Spark installed to ' . $spark->installed_path() . ' - You\'re on fire!');
    }
 function retrieve() {
     `hg clone -r$this->tag $this->base_location $this->temp_path`;
     // remove the mercurial directory
     SparkUtils::remove_full_directory("$this->temp_path/.hg");
     return file_exists($this->temp_path);
 }