[limb-svn] r5493 - cli
svn at limb-project.com
svn at limb-project.com
Mon Apr 2 17:04:24 MSD 2007
Author: pachanga
Date: 2007-04-02 17:04:24 +0400 (Mon, 02 Apr 2007)
New Revision: 5493
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5493
Added:
cli/create_package_release.php
Modified:
cli/
Log:
-- create_package_release.php added
Property changes on: cli
___________________________________________________________________
Name: svn:ignore
+ cookie.txt
Added: cli/create_package_release.php
===================================================================
--- cli/create_package_release.php (rev 0)
+++ cli/create_package_release.php 2007-04-02 13:04:24 UTC (rev 5493)
@@ -0,0 +1,169 @@
+<?php
+set_time_limit(0);
+
+$PEAR = 'http://pear.limb-project.com/back.php';
+
+if($argc < 4)
+{
+ echo "Usage: create_package_release <dir> <user> <password>";
+ exit(1);
+}
+
+$pkg = $argv[1];
+$user = $argv[2];
+$password = $argv[3];
+
+$file = create_archive($pkg);
+login($user, $password);
+upload($file);
+unlink($file);
+
+echo "File '$file' uploaded\n";
+
+function create_archive($dir)
+{
+ $old = getcwd();
+ chdir($dir);
+
+ list($name, $version) = explode('-', trim(file_get_contents("./VERSION")));
+
+ system("php package.php", $res);
+
+ if($res != 0)
+ fatal("Package XML creation error");
+
+ system("pear package", $res);
+
+ if($res != 0)
+ fatal("'pear package' failed");
+
+ unlink("package.xml");
+ chdir($old);
+
+ return "$dir/$name-$version.tgz";
+}
+
+function login($user, $password)
+{
+ global $PEAR;
+
+ $login_form = array("user" => $user,
+ "password" => $password,
+ "login" => "Login");
+ $curl = new CURL();
+ $page = $curl->post($PEAR, $login_form);
+
+ if(preg_match('~Invalid\s+Login~', $page))
+ fatal("Could not login to admin page");
+}
+
+function upload($file)
+{
+ global $PEAR;
+
+ $upload_form = array("MAX_FILE_SIZE" => "2097152",
+ "submitted" => '1',
+ "release" => "@$file",
+ "Submit" => 'Submit',
+ "f" => "0");
+ $curl = new CURL();
+
+ $page = $curl->post($PEAR, $upload_form);
+
+ if(!preg_match('~Release\s+successfully\s+saved~', $page))
+ fatal("Could not upload release '$file'");
+}
+
+class CURL
+{
+ protected $handle;
+ protected $opts = array();
+
+ function __construct()
+ {
+ $this->verbose(false);
+ }
+
+ protected function _ensureCurl()
+ {
+ if(!is_resource($this->handle))
+ $this->handle = curl_init();
+ }
+
+ protected function _resetCurl()
+ {
+ if(is_resource($this->handle))
+ curl_close($this->handle);
+ $this->opts = array();
+ }
+
+ protected function _browserInit()
+ {
+ $this->setOpt(CURLOPT_HEADER, 1);
+ $this->setOpt(CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322;)");
+ $this->setOpt(CURLOPT_FOLLOWLOCATION, 1);
+ $this->setOpt(CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt');
+ $this->setOpt(CURLOPT_COOKIEFILE, dirname(__FILE__) . '/cookie.txt');
+ $this->setOpt(CURLOPT_SSL_VERIFYHOST, 0);
+ $this->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
+ if($proxy = getenv('http_proxy'))
+ $this->setOpt(CURLOPT_PROXY, $proxy);
+ }
+
+ function exec()
+ {
+ $this->_ensureCurl();
+
+ foreach($this->opts as $opt => $value)
+ curl_setopt($this->handle, $opt, $value);
+
+ $res = curl_exec($this->handle);
+ if (curl_errno($this->handle) == 0)
+ {
+ $this->_resetCurl();
+ return $res;
+ }
+ else
+ {
+ $error = curl_error($this->handle);
+ $this->_resetCurl();
+ fatal($error);
+ }
+ }
+
+ function get($url)
+ {
+ $this->_browserInit();
+ $this->setOpt(CURLOPT_URL, $url);
+ $this->setOpt(CURLOPT_RETURNTRANSFER, 1);
+ return $this->exec();
+ }
+
+ function post($url, $vars)
+ {
+ $this->_browserInit();
+ $this->setOpt(CURLOPT_URL, $url);
+ $this->setOpt(CURLOPT_POST, 1);
+ $this->setOpt(CURLOPT_RETURNTRANSFER, 1);
+ $this->setOpt(CURLOPT_POSTFIELDS, $vars);
+ return $this->exec();
+ }
+
+ function verbose($flag = true)
+ {
+ $this->setOpt(CURLOPT_VERBOSE, $flag ? 1 : 0);
+ }
+
+ function setOpt($opt, $value)
+ {
+ $this->opts[$opt] = $value;
+ }
+}
+
+function fatal($msg)
+{
+ echo $msg;
+ exit(1);
+}
+
+?>
\ No newline at end of file
More information about the limb-svn
mailing list