com web/rmtools: start to move away from sqlite: client/include/PickleWeb.php client/script/pickle_ctl.php

From: Date: Tue, 12 May 2015 09:20:43 +0000
Subject: com web/rmtools: start to move away from sqlite: client/include/PickleWeb.php client/script/pickle_ctl.php
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-25971@lists.php.net to get a copy of this message
Commit: 4a8b33dbc3b054bc8572ad71b7230fbc71af39c6 Author: Anatol Belski <ab@php.net> Tue, 12 May 2015 11:20:43 +0200 Parents: e8c45281bb21303e213e91150b2ec6c2823c97fc Branches: master pecl_legacy Link: http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=4a8b33dbc3b054bc8572ad71b7230fbc71af39c6 Log: start to move away from sqlite Changed paths: M client/include/PickleWeb.php M client/script/pickle_ctl.php Diff: diff --git a/client/include/PickleWeb.php b/client/include/PickleWeb.php index 41a62b2..88c474d 100644 --- a/client/include/PickleWeb.php +++ b/client/include/PickleWeb.php @@ -4,14 +4,25 @@ namespace rmtools; class PickleWeb { + protected $db_path; protected $host; protected $info; - public function __construct($host) + protected $updatesAvailableFlag = false; + + public function __construct($host, $db_path) { $this->host = $host; + if (!is_dir($db_path)) { + if (!mkdir($db_path)) { + throw new \Exception("failed to create '$db_path'"); + } + } + + $this->db_path = $db_path; + $this->init(); } @@ -31,6 +42,28 @@ class PickleWeb if (!isset($this->info["provider-includes"])) { throw new \Exception("No provider includes found"); } + + $packages_json = $this->db_path . DIRECTORY_SEPARATOR . "packages.json"; + if (!file_exists($packages_json)) { + $this->updatesAvailableFlag = true; + } else { + $packages_info = json_decode(file_get_contents($packages_json), true); + foreach ($this->info["provider-includes"] as $uri => $hash) { + if (!isset($packages_info["provider-includes"][$uri]) || + $packages_info["provider-includes"][$uri] != $hash) { + $this->updatesAvailableFlag = true; + break; + } + } + } + if ($this->updatesAvailableFlag && strlen($__tmp) != file_put_contents($packages_json, $__tmp)) { + throw new \Exception("Couldn't save '$packages_json'"); + } + } + + public function updatesAvailable() + { + return $this->updatesAvailableFlag; } public function fetchProviders() @@ -64,6 +97,11 @@ class PickleWeb return $ret; } + public function pingBack($data) + { + // TODO send the build data to pickle web + } + public function updateDb() { diff --git a/client/script/pickle_ctl.php b/client/script/pickle_ctl.php index 40c1c28..b9ff884 100644 --- a/client/script/pickle_ctl.php +++ b/client/script/pickle_ctl.php @@ -1,13 +1,14 @@ <?php include __DIR__ . '/../data/config.php'; -include __DIR__ . '/../include/PickleDb.php'; include __DIR__ . '/../include/PickleWeb.php'; +include __DIR__ . '/../include/PickleJob.php'; use rmtools as rm; -$sync_host = "http://16e0a43d.ngrok.io"; -$db_path = realpath(__DIR__ . '/../data/pickle.sqlite'); +$sync_host = "http://aa382bdf.ngrok.io"; +$db_dir = __DIR__ . '/../data/pickle_db'; +$job_dir = 'c:\pickle-in-pkg'; $longopts = array("help", "sync", "init-db"); @@ -15,7 +16,6 @@ $options = getopt(NULL, $longopts); $help_cmd = isset($options['help']); $sync_cmd = isset($options['sync']); -$init_cmd = isset($options['init-db']); /* --help */ if ($_SERVER['argc'] <= 1 || $help_cmd) { @@ -30,40 +30,28 @@ if ($_SERVER['argc'] <= 1 || $help_cmd) { exit(0); } -if ($init_cmd) { - echo "Warning: the original DB will be overwritten! Press c^C to abort.\n"; - for ($i = 0; $i < 8; $i++) { - echo "."; - sleep(1); - } - echo "\n"; - try { - if (file_exists($db_path)) { - unlink($db_path); - } - $db = new rm\PickleDb($db_path, true); - echo "Pickle DB initialized"; - exit(0); - } catch (Exception $e) { - echo "Error: " . $e->getMessage(); - exit(3); - } -} if ($sync_cmd) { + $jobs = new rm\PickleJob($job_dir); + + /* XXX handle the finished jobs first. */ + + try { - $pw = new rm\PickleWeb($sync_host); + $pw = new rm\PickleWeb($sync_host, $db_dir); + + if (!$pw->updatesAvailable()) { + echo "No updates available"; + exit(0); + } + $news = (array)$pw->fetchProviders(); } catch (Exception $e) { echo $e->getMessage() . "\n"; exit(3); } - $db = new rm\PickleDb($db_path); - foreach ($news as $name => $sha) { - $db->add($name, $sha); - } }

« previous php.webmaster (#25971) next »