function pake_replace_tokens_to_dir($arg, $src_dir, $target_dir, $begin_token, $end_token, $tokens) { $files = pakeFinder::get_files_from_argument($arg, $src_dir, true); foreach ($files as $file) { $src_file = $src_dir . DIRECTORY_SEPARATOR . $file; $target_file = $target_dir . DIRECTORY_SEPARATOR . $file; pake_echo_action('tokens <-', $src_file); $content = pake_read_file($src_file); foreach ($tokens as $key => $value) { $content = str_replace($begin_token . $key . $end_token, $value, $content, $count); } pake_write_file($target_file, $content, true); } }
/** * 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); }
/** * 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); }