/** * create a single file with all pake classes; usage: pake compact [plugin1 [plugin2 […]]] * * To be able to include a plugin in pake_runtime.php, you have to use include_once for external dependencies * and require_once for internal dependencies (for other included PI or pake classes) because we strip * all require_once statements * * @return bool * @author Alexey Zakhlestin */ function run_compact($task, $args) { $_root = dirname(__FILE__); $options = pakeYaml::loadFile($_root . '/options.yaml'); $version = $options['version']; pake_replace_tokens('lib/pake/pakeApp.class.php', $_root, 'const VERSION = \'', '\';', array('1.1.DEV' => "const VERSION = '{$version}';")); // core-files $files = array($_root . '/lib/pake/init.php', $_root . '/lib/pake/pakeFunction.php'); // adding pake-classes library $files = array_merge($files, pakeFinder::type('file')->name('*.class.php')->maxdepth(0)->in($_root . '/lib/pake')); // adding sfYaml library $files = array_merge($files, pakeFinder::type('file')->name('*.php')->in($_root . '/lib/pake/sfYaml')); $plugins = $args; foreach ($plugins as $plugin_name) { $files[] = $_root . '/lib/pake/tasks/pake' . $plugin_name . 'Task.class.php'; } // starter $files[] = $_root . '/bin/pake.php'; // merge all files $content = ''; foreach ($files as $file) { $content .= pake_read_file($file); } pake_replace_tokens('lib/pake/pakeApp.class.php', $_root, "const VERSION = '", "';", array($version => "const VERSION = '1.1.DEV';")); // strip require_once statements $content = preg_replace('/^\\s*require(?:_once)?[^$;]+;/m', '', $content); // replace windows and mac format with unix format $content = str_replace(array("\r\n"), "\n", $content); // strip php tags $content = preg_replace(array("/<\\?php/", "/<\\?/", "/\\?>/"), '', $content); // replace multiple new lines with a single newline $content = preg_replace(array("/\n\\s+\n/s", "/\n+/s"), "\n", $content); $content = "#!/usr/bin/env php\n<?php\n" . trim($content) . "\n"; $target_dir = $_root . '/target'; pake_mkdirs($target_dir); $target = $target_dir . '/pake'; if (!file_put_contents($target, $content)) { throw new pakeException('Failed to write to "' . $target . '"'); } pake_echo_action('file+', $target); // strip all comments pake_strip_php_comments($target); pake_chmod('pake', $target_dir, 0755); }
/** * Downloads the yaml file used to drive the build for a given extension, from projects.ez.no/github/some random url. * You have to provide the url to the config file as 2nd parameter, unless your extension is set up on projects.ez.no, * in which case we try to figure it out automatically. * Will ask to overwrite an existing config file if found, unless option overwrite-existing is given */ static function run_download_extension_config($task = null, $args = array(), $cliopts = array()) { self::setConfigDir($cliopts); $overwrite = @$cliopts['overwrite-existing']; if (count($args) == 0) { throw new pakeException("Missing extension name"); } $extname = $args[0]; if (count($args) > 1) { $exturl = $args[1]; } else { /// @todo add support for custom branches $page = pake_read_file('http://projects.ez.no/' . $extname); if (!preg_match('#<a +href *= *"([^"]+)" [^>]+>Source</a>#', $page, $matches)) { throw new pakeException("Can not download or parse http://projects.ez.no/{$extname}"); } /// @todo we should test that $matches[1] is not an absolute url $exturl = 'http://projects.ez.no' . $matches[1]; $extpage = pake_read_file($exturl); if (preg_match('#<code>svn checkout <a href="([^"]+)">#', $extpage, $matches)) { $source = 'svn'; //$exturl = $matches[1]; } else { if (preg_match('#<a +href *= *"https://github.com/([^/]+)/([^"]+)"#', $extpage, $matches)) { $source = 'github'; $username = $matches[1]; $gitext = rtrim($matches[2], '/'); } else { throw new pakeException("Can not download or parse {$exturl}"); } } pake_echo("Scm system found: {$source}"); $targetfile = self::getOptionsDir() . "/options-{$extname}.yaml"; if ($source == 'github') { $branch = 'master'; $exturl = "https://github.com/{$username}/{$gitext}/raw/{$branch}/{$targetfile}"; } elseif ($source == 'svn') { $extpage = pake_read_file("http://svn.projects.ez.no/{$extname}"); if (preg_match('#<li><a href="([tT]runk)">[tT]runk</a></li>>#', $extpage, $matches)) { $branch = $matches[1]; } else { /// @todo what if there is no 'trunk' but there are branches? $branch = ''; } pake_echo("Branch found: {$branch}"); // for extensions still on projects.ez.no svn, try different possibilities $exturl = "http://svn.projects.ez.no/{$extname}/{$branch}/extension/{$extname}/{$targetfile}"; if (!file_exists($exturl)) { $exturl = "http://svn.projects.ez.no/{$extname}/{$branch}/{$targetfile}"; } if (!file_exists($exturl)) { $exturl = "http://svn.projects.ez.no/{$extname}/{$branch}/packages/{$extname}_extension/ezextension/{$extname}/{$targetfile}"; } if (!file_exists($exturl)) { throw new pakeException("Can not download from {$source} build config file {$targetfile}"); } } else { throw new pakeException("Can not download from scm build config file for {$extname}"); } } /// @todo check that $extconf is a valid yaml file with minimal params $extconf = pake_read_file($exturl); $configfile = self::getOptionsDir() . "/options-{$extname}.yaml"; if (file_exists($configfile) && !$overwrite) { pake_echo("File {$configfile} already exists. Must overwrite it to continue"); $ok = pake_input("Do you want to overwrite it them? [y/n]", 'n'); if ($ok != 'y') { return; } } pake_mkdirs(self::getOptionsDir()); pake_write_file($configfile, $extconf, true); }
public static function loadFile($file) { return self::loadString(pake_read_file($file)); }
function pake_strip_php_comments($arg, $target_dir = '') { /* T_ML_COMMENT does not exist in PHP 5. * The following three lines define it in order to * preserve backwards compatibility. * * The next two lines define the PHP 5-only T_DOC_COMMENT, * which we will mask as T_ML_COMMENT for PHP 4. */ if (!defined('T_ML_COMMENT')) { define('T_ML_COMMENT', T_COMMENT); } else { if (!defined('T_DOC_COMMENT')) { define('T_DOC_COMMENT', T_ML_COMMENT); } } $files = pakeFinder::get_files_from_argument($arg, $target_dir); foreach ($files as $file) { if (!is_file($file)) { continue; } $source = pake_read_file($file); $output = ''; $tokens = token_get_all($source); foreach ($tokens as $token) { if (is_string($token)) { // simple 1-character token $output .= $token; } else { // token array list($id, $text) = $token; switch ($id) { case T_COMMENT: case T_ML_COMMENT: // we've defined this // we've defined this case T_DOC_COMMENT: // and this // no action on comments break; default: // anything else -> output "as is" $output .= $text; break; } } } file_put_contents($file, $output); } }
/** * Updates the "eZ CP version history" document, currently hosted on pubsvn.ez.no. * * Options: --public-keyfile=<...> --private-keyfile=<...> --user=<...> --private-keypasswd=<...> * * @todo add support for getting ssl certs options in config settings */ public static function run_update_version_history($task = null, $args = array(), $cliopts = array()) { $opts = self::getOpts($args, $cliopts); $public_keyfile = @$cliopts['public-keyfile']; $private_keyfile = @$cliopts['private-keyfile']; $private_keypasswd = @$cliopts['private-keypasswd']; $user = @$cliopts['user']; // get file $srv = "http://pubsvn.ez.no"; $filename = "/ezpublish_version_history/ez_history.csv"; $fullfilename = $srv . $filename; $remotefilename = '/mnt/pubsvn.ez.no/www/' . $filename; $file = pake_read_file($fullfilename); if ("" == $file) { throw new pakeException("Couldn't download {$fullfilename} file"); } // patch it /// @todo test that what we got looks at least a bit like what we expect $lines = preg_split("/\r?\n/", $file); $lines[0] .= $opts['version']['alias'] . ','; $lines[1] .= strftime('%Y/%m/%d') . ','; $file = implode("\n", $lines); /// @todo: back up the original as well (upload 1st to srv the unpatched version with a different name, then the new version) // upload it: we use curl for sftp $randfile = tempnam(sys_get_temp_dir(), 'EZP'); pake_write_file($randfile, $file, true); $fp = fopen($randfile, 'rb'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, str_replace('http://', 'sftp://@', $srv) . $remotefilename); if ($user != "") { curl_setopt($ch, CURLOPT_USERPWD, $user); } if ($public_keyfile != "") { curl_setopt($ch, CURLOPT_SSH_PUBLIC_KEYFILE, $public_keyfile); } if ($private_keyfile != "") { curl_setopt($ch, CURLOPT_SSH_PRIVATE_KEYFILE, $private_keyfile); } if ($private_keypasswd != "") { curl_setopt($ch, CURLOPT_KEYPASSWD, $private_keypasswd); } curl_setopt($ch, CURLOPT_UPLOAD, 1); curl_setopt($ch, CURLOPT_INFILE, $fp); // set size of the file, which isn't _mandatory_ but helps libcurl to do // extra error checking on the upload. curl_setopt($ch, CURLOPT_INFILESIZE, filesize($randfile)); $ok = curl_exec($ch); $errinfo = curl_error($ch); curl_close($ch); fclose($fp); pake_unlink($randfile); if (!$ok) { throw new pakeException("Couldn't write {$fullfilename} file: " . $errinfo); } pake_echo_action("file+", $filename); }