com web/rmtools: added PickleWeb class and reworked the current pickle fetching stuff: client/include/PickleDb.php client/include/PickleWeb.php
client/script/pickle_ctl.php

From: Date: Mon, 11 May 2015 13:42:13 +0000
Subject: com web/rmtools: added PickleWeb class and reworked the current pickle fetching stuff: client/include/PickleDb.php client/include/PickleWeb.php
client/script/pickle_ctl.php
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-25976@lists.php.net to get a copy of this message
Commit: eff42ec4aa1058e2ce70f9b9cd27ce096d2d0678 Author: Anatol Belski <ab@php.net> Mon, 11 May 2015 15:42:13 +0200 Parents: c55b9f29e14955a532c279fe7629a2e1e0521170 Branches: master pecl_legacy Link: http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=eff42ec4aa1058e2ce70f9b9cd27ce096d2d0678 Log: added PickleWeb class and reworked the current pickle fetching stuff Changed paths: M client/include/PickleDb.php A client/include/PickleWeb.php M client/script/pickle_ctl.php Diff: diff --git a/client/include/PickleDb.php b/client/include/PickleDb.php index decb1c0..d898fb4 100644 --- a/client/include/PickleDb.php +++ b/client/include/PickleDb.php @@ -2,8 +2,9 @@ namespace rmtools; +/* This is one model for all, could be split somewhen to improve. Only can work */ -class PDb extends \SQLite3 { +class PickleDb extends \SQLite3 { public function __construct($db_path, $autoinit = true) { @@ -23,10 +24,15 @@ class PDb extends \SQLite3 { public function initDb() { - $sql = "CREATE TABLE package_release (package_release_id INTEGER PRIMARY KEY, package_hash STRING, package_name STRING);"; + /*status: new, */ + $sql = "CREATE TABLE package_release (package_release_id INTEGER PRIMARY KEY, package_hash STRING, package_name STRING, package_status TEXT);"; $this->exec($sql); - $sql = "CREATE TABLE package_build (package_build_id INTEGER PRIMARY KEY, package_hash STRING, build_status INTEGER, ts_last_build INTEGER, ts_last_);"; + /* status: */ + $sql = "CREATE TABLE package_build (package_build_id INTEGER PRIMARY KEY, package_hash STRING, build_status TEXT, ts_last_build INTEGER);"; + $this->exec($sql); + + $sql = "CREATE TABLE package_build_job (package_build_job_id INTEGER PRIMARY KEY, package_hash STRING, build_status INTEGER, ts_last_build INTEGER);"; $this->exec($sql); } diff --git a/client/include/PickleWeb.php b/client/include/PickleWeb.php new file mode 100644 index 0000000..f2fd4be --- /dev/null +++ b/client/include/PickleWeb.php @@ -0,0 +1,70 @@ +<?php + +class PickleWeb +{ + protected $host; + + protected $info; + + public function __construct($host) + { + $this->host = $host; + + $this->init(); + } + + public function init() + { + $uri = "{$this->host}/packages.json"; + $__tmp = file_get_contents($uri); + if (!$__tmp) { + throw new \Exception("Empty content received from '$url'"); + } + + $this->info = json_decode($__tmp, true); + if (!$this->info) { + throw new \Exception("Couldn't decode JSON from '$url'"); + } + + if (!isset($this->info["provider-includes"])) { + throw new \Exception("No provider includes found"); + } + } + + public function fetchProviders() + { + $ret = array(); + + /* XXX What meaning does the $hash have? */ + foreach ($this->info["provider-includes"] as $uri => $hash) { + $url = "{$this->host}$uri"; + $__tmp = file_get_contents($url); + + if (!$__tmp) { + //echo "Empty content received from '$url'"; + continue; + } + + $pkgs = json_decode($__tmp, true); + if (!is_array($pkgs) || !isset($pkgs["providers"]) || !is_array($pkgs["providers"]) || empty($pkgs["providers"])) { + //echo "No packages provided from '$url'"; + continue; + } + $pkgs = $pkgs["providers"]; + + foreach ($pkgs as $pkg => $phash) { + + } + + $ret = array_merge($ret, $pkgs); + } + + return $ret; + } + + public function updateDb() + { + + } +} + diff --git a/client/script/pickle_ctl.php b/client/script/pickle_ctl..php index cee2849..0c1e344 100644 --- a/client/script/pickle_ctl.php +++ b/client/script/pickle_ctl.php @@ -2,12 +2,11 @@ include __DIR__ . '/../data/config.php'; include __DIR__ . '/../include/PickleDb.php'; -include __DIR__ . '/../include/PickleJob.php'; +include __DIR__ . '/../include/PickleWeb.php'; use rmtools as rm; -$sync_host = "http://9fe756ee.ngrok.io"; -$base_uri = "/packages.json"; +$sync_host = "http://16e0a43d.ngrok.io"; $db_path = __DIR__ . '/../data/pickle.sqlite'; $longopts = array("help", "sync", "init-db"); @@ -16,7 +15,7 @@ $options = getopt(NULL, $longopts); $help_cmd = isset($options['help']); $sync_cmd = isset($options['sync']); -$init_cmd = isset($options['sync']); +$init_cmd = isset($options['init-db']); /* --help */ if ($_SERVER['argc'] <= 1 || $help_cmd) { @@ -32,6 +31,12 @@ if ($_SERVER['argc'] <= 1 || $help_cmd) { } 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 { $db = new rm\PickleDb($db_path, true); echo "Pickle DB initialized"; @@ -43,52 +48,20 @@ if ($init_cmd) { } if ($sync_cmd) { - $url = "$sync_host$base_uri"; - $__tmp = file_get_contents($url); - - if (!$__tmp) { - echo "Empty content received from '$url'"; - exit(3); - } - $info = json_decode($__tmp, true); - if (!$info) { - echo "Couldn't decode JSON from '$url'"; + try { + $pw = new PickleWeb($sync_host); + $info = $pw->fetchProviders(); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; exit(3); } - if (!isset($info["provider-includes"])) { - echo "No provider includes found"; - exit(3); - } + var_dump($info); $db = new rm\PickleDb($db_path); - /* XXX What meaning does the $hash have? */ - foreach ($info["provider-includes"] as $uri => $hash) { - $url = "$sync_host$uri"; - $__tmp = file_get_contents($url); - - if (!$__tmp) { - echo "Empty content received from '$url'"; - continue; - } - - $pkgs = json_decode($__tmp, true); - if (!is_array($pkgs) || !isset($pkgs["providers"]) || !is_array($pkgs["providers"]) || empty($pkgs["providers"])) { - echo "No packages provided from '$url'"; - continue; - } - $pkgs = $pkgs["providers"]; - - foreach ($pkgs as $pkg => $phash) { - } - - var_dump($pkgs); - } - - var_dump($info); }

« previous php.webmaster (#25976) next »