示例#1
0
function run_init_app($task, $args)
{
    if (!count($args)) {
        throw new Exception('You must provide your application name.');
    }
    $app = $args[0];
    $sf_root_dir = sfConfig::get('sf_root_dir');
    $app_dir = $sf_root_dir . '/' . sfConfig::get('sf_apps_dir_name') . '/' . $app;
    if (is_dir($app_dir)) {
        throw new Exception(sprintf('The directory "%s" already exists.', $app_dir));
    }
    // create basic application structure
    $finder = pakeFinder::type('any')->ignore_version_control()->discard('.sf');
    pake_mirror($finder, sfConfig::get('sf_symfony_data_dir') . '/skeleton/app/app', $app_dir);
    // create $app.php or index.php if it is our first app
    $index_name = 'index';
    $first_app = file_exists(sfConfig::get('sf_web_dir') . '/index.php') ? false : true;
    if (!$first_app) {
        $index_name = $app;
    }
    // set no_script_name value in settings.yml for production environment
    $finder = pakeFinder::type('file')->name('settings.yml');
    pake_replace_tokens($finder, $app_dir . '/' . sfConfig::get('sf_app_config_dir_name'), '##', '##', array('NO_SCRIPT_NAME' => $first_app ? 'on' : 'off'));
    pake_copy(sfConfig::get('sf_symfony_data_dir') . '/skeleton/app/web/index.php', sfConfig::get('sf_web_dir') . '/' . $index_name . '.php');
    pake_copy(sfConfig::get('sf_symfony_data_dir') . '/skeleton/app/web/index_dev.php', sfConfig::get('sf_web_dir') . '/' . $app . '_dev.php');
    $finder = pakeFinder::type('file')->name($index_name . '.php', $app . '_dev.php');
    pake_replace_tokens($finder, sfConfig::get('sf_web_dir'), '##', '##', array('APP_NAME' => $app));
    run_fix_perms($task, $args);
    // create test dir
    pake_mkdirs($sf_root_dir . '/test/functional/' . $app);
}
示例#2
0
 public static function emitFile($data, $file)
 {
     if (file_exists($file) and !is_writable($file)) {
         throw new pakeException('Not enough rights to overwrite "' . $file . '"');
     }
     $dir = dirname($file);
     pake_mkdirs($dir);
     if (!is_writable($dir)) {
         throw new pakeException('Not enough rights to create file in "' . $dir . '"');
     }
     if (extension_loaded('yaml')) {
         // not yet implemented:
         // yaml_emit_file($file, $data);
         // so using this instead:
         if (false === file_put_contents($file, yaml_emit($data))) {
             throw new pakeException("Couldn't create file");
         }
     } else {
         sfYaml::setSpecVersion('1.1');
         // more compatible
         $dumper = new sfYamlDumper();
         if (false === file_put_contents($file, $dumper->dump($data, 1))) {
             throw new pakeException("Couldn't create file");
         }
     }
     pake_echo_action('file+', $file);
 }
示例#3
0
文件: alba.php 项目: mediasadc/alba
/**
 * La funcion original en dist/symfony/data/tasks/sfPakePropel.php 
 * NO FUNCIONA
 * porque a la funcion dumpData() no se le pasan los parametros correctos 
 * 
 *
 * Dumps yml database data to fixtures directory.
 *
 * @example symfony dump-data frontend data.yml
 * @example symfony dump-data frontend data.yml dev
 *
 * @param object $task
 * @param array $args
 */
function run_alba_dump_data($task, $args)
{
    if (!count($args)) {
        throw new Exception('You must provide the app.');
    }
    $app = $args[0];
    if (!is_dir(sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . $app)) {
        throw new Exception('The app "' . $app . '" does not exist.');
    }
    if (!isset($args[1])) {
        throw new Exception('You must provide a filename.');
    }
    $filename = $args[1];
    $env = empty($args[2]) ? 'dev' : $args[2];
    // define constants
    define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
    define('SF_APP', $app);
    define('SF_ENVIRONMENT', $env);
    define('SF_DEBUG', true);
    // get configuration
    require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
    $databaseManager = new sfDatabaseManager();
    $databaseManager->initialize();
    if (!sfToolkit::isPathAbsolute($filename)) {
        $dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'fixtures';
        pake_mkdirs($dir);
        $filename = $dir . DIRECTORY_SEPARATOR . $filename;
    }
    pake_echo_action('propel', sprintf('dumping data to "%s"', $filename));
    $data = new sfPropelData();
    // FIX de parametros
    $data->dumpData($filename, 'all', 'alba');
}
示例#4
0
 /**
  * Returns true if the lock is acquired for the given token (no waiting here).
  * A Write lock can only be acquired as long as there are no W or R locks.
  * A Read lock can be acquired as long as there are no W locks.
  * Does not not complain if 2 Read locks are taken on the same token by the same php script.
  *
  * @param string $token
  * @param int $mode LOCK_SH (reader) or LOCK_EX (writer)
  * @param array $opts
  * @param bool $autoCleanup when true, on first lock acquired we remove any stale locks found
  * @return bool
  */
 public static function acquire($token, $mode, $opts = array(), $autoCleanup = true)
 {
     // just in case (is_file results might be cached!)...
     clearstatcache();
     if ($autoCleanup && !self::$cleanedUp) {
         self::cleanup($opts);
         self::$cleanedUp = true;
     }
     $lockDir = self::lockDir($opts);
     $wLockFile = "{$lockDir}/{$token}_W.lock";
     if (file_exists($wLockFile)) {
         return false;
     }
     if ($mode == LOCK_EX && count(glob($lockDir . "/{$token}_R/*.lock"))) {
         return false;
     }
     if ($mode == LOCK_EX) {
         pake_mkdirs($lockDir);
         if (!file_put_contents($wLockFile, getmypid(), LOCK_EX)) {
             pake_echo_error("Could not create W lock file '{$wLockFile}'");
             return false;
         }
         return true;
     }
     // assume a read lock
     $rLockFile = "{$lockDir}/{$token}_R/" . getmypid() . ".lock";
     pake_mkdirs("{$lockDir}/{$token}_R/");
     // we assume to be running in single-thread mode: do not lock the file for writing
     if (!file_put_contents($rLockFile, getmypid())) {
         // log some error?
         pake_echo_error("Could not create R lock file '{$wLockFile}'");
         return false;
     }
     return true;
 }
function run_freeze($task, $args)
{
    // check that the symfony librairies are not already freeze for this project
    if (is_readable(sfConfig::get('sf_lib_dir') . '/symfony')) {
        throw new Exception('You can only freeze when lib/symfony is empty.');
    }
    if (is_readable(sfConfig::get('sf_data_dir') . '/symfony')) {
        throw new Exception('You can only freeze when data/symfony is empty.');
    }
    if (is_readable(sfConfig::get('sf_web_dir') . '/sf')) {
        throw new Exception('You can only freeze when web/sf is empty.');
    }
    if (is_link(sfConfig::get('sf_web_dir') . '/sf')) {
        pake_remove(sfConfig::get('sf_web_dir') . '/sf', '');
    }
    $symfony_lib_dir = sfConfig::get('sf_symfony_lib_dir');
    $symfony_data_dir = sfConfig::get('sf_symfony_data_dir');
    pake_echo_action('freeze', 'freezing lib found in "' . $symfony_lib_dir . '"');
    pake_echo_action('freeze', 'freezing data found in "' . $symfony_data_dir . '"');
    pake_mkdirs(sfConfig::get('sf_lib_dir') . DIRECTORY_SEPARATOR . 'symfony');
    pake_mkdirs(sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'symfony');
    $finder = pakeFinder::type('any')->ignore_version_control();
    pake_mirror($finder, $symfony_lib_dir, sfConfig::get('sf_lib_dir') . '/symfony');
    pake_mirror($finder, $symfony_data_dir, sfConfig::get('sf_data_dir') . '/symfony');
    pake_rename(sfConfig::get('sf_data_dir') . '/symfony/web/sf', sfConfig::get('sf_web_dir') . '/sf');
    // change symfony paths in config/config.php
    file_put_contents('config/config.php.bak', "{$symfony_lib_dir}#{$symfony_data_dir}");
    _change_symfony_dirs("dirname(__FILE__).'/../lib/symfony'", "dirname(__FILE__).'/../data/symfony'");
    // install the command line
    pake_copy($symfony_data_dir . '/bin/symfony.php', 'symfony.php');
}
示例#6
0
 public static function package_pear_package($package_xml_path, $target_dir)
 {
     if (!file_exists($package_xml_path)) {
         throw new pakeException('"' . $package_xml_path . '" file does not exist');
     }
     pake_mkdirs($target_dir);
     $current = getcwd();
     chdir($target_dir);
     if (!class_exists('PEAR_Packager')) {
         @(include 'PEAR/Packager.php');
         if (!class_exists('PEAR_Packager')) {
             // falling back to cli-call
             $results = pake_sh('pear package ' . escapeshellarg($package_xml_path));
             if ($task->is_verbose()) {
                 echo $results;
             }
             chdir($current);
             return;
         }
     }
     $packager = new PEAR_Packager();
     $packager->debug = 0;
     // silence output
     $archive = $packager->package($package_xml_path, true);
     pake_echo_action('file+', $target_dir . '/' . $archive);
     chdir($current);
 }
 public function copy_from_server($src, $local_path)
 {
     if (is_string($src)) {
         $src = array($src);
     }
     pake_mkdirs($local_path);
     foreach ($src as &$remote_path) {
         $remote_path = $this->login . '@' . $this->host . ':' . $remote_path;
     }
     pake_sh(escapeshellarg(pake_which('scp')) . ' -rC ' . implode(' ', array_map('escapeshellarg', $src)) . ' ' . escapeshellarg($local_path));
 }
function run_init_migration($task, $args)
{
    if (count($args) == 0) {
        throw new Exception('You must provide a migration name.');
    }
    if ($args[0]) {
        $migrator = new sfMigrator();
        if (!is_dir($migrator->getMigrationsDir())) {
            pake_mkdirs($migrator->getMigrationsDir());
        }
        pake_echo_action('migrations', 'generating new migration stub');
        $filename = $migrator->generateMigration($args[0]);
        pake_echo_action('file+', $filename);
    }
}
示例#9
0
function run_phpunit()
{
    $cc_token = getenv('CODECLIMATE_REPO_TOKEN');
    $cc = !empty($cc_token);
    $clover = $cc ? ' --coverage-clover build/logs/clover.xml' : '';
    $circle_test_reports = getenv('CIRCLE_TEST_REPORTS');
    if (!empty($circle_test_reports)) {
        pake_mkdirs($circle_test_reports);
        $junit = " --log-junit {$circle_test_reports}/phpunit/junit.xml";
    } else {
        $junit = '';
    }
    print pake_sh('vendor/bin/phpunit' . $clover . $junit);
    if ($cc && file_exists('build/logs/clover.xml')) {
        print pake_sh('vendor/bin/test-reporter');
    }
}
示例#10
0
文件: pakefile.php 项目: umonkey/pake
/**
 * 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
 */
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 .= file_get_contents($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);
}
 public static function checkout($src_url, $target_path)
 {
     pake_mkdirs($target_path);
     if (self::isRepository($target_path)) {
         throw new pakeException('"' . $target_path . '" directory is a Subversion repository already');
     }
     if (count(pakeFinder::type('any')->in($target_path)) > 0) {
         throw new pakeException('"' . $target_path . '" directory is not empty. Can not checkout there');
     }
     pake_echo_action('svn checkout', $target_path);
     if (extension_loaded('svn')) {
         $result = svn_checkout($src_url, $target_path);
         if (false === $result) {
             throw new pakeException('Couldn\'t checkout "' . $src_url . '" repository');
         }
     } else {
         pake_sh(escapeshellarg(pake_which('svn')) . ' checkout ' . escapeshellarg($src_url) . ' ' . escapeshellarg($target_path));
     }
 }
示例#12
0
 public static function clone_repository($src_url, $target_path = null)
 {
     if (null === $target_path) {
         // trying to "guess" path
         $target_path = basename($src_url);
         // removing suffix
         if (substr($target_path, -3) === '.hg') {
             $target_path = substr($target_path, 0, -3);
         }
     }
     if (self::isRepository($target_path)) {
         throw new pakeException('"' . $target_path . '" directory is a Mercurial repository already');
     }
     if (file_exists($target_path)) {
         throw new pakeException('"' . $target_path . '" directory already exists. Can not clone Mercurial-repository there');
     }
     pake_mkdirs($target_path);
     pake_sh('hg clone -q ' . escapeshellarg($src_url) . ' ' . escapeshellarg($target_path));
     return new pakeMercurial($target_path);
 }
示例#13
0
 /**
  * Creates the MS WPI
  */
 public static function run_dist_wpi($task = null, $args = array(), $cliopts = array())
 {
     $opts = self::getOpts($args, $cliopts);
     if ($opts['create']['mswpipackage']) {
         pake_mkdirs($opts['dist']['dir']);
         $toppath = $opts['build']['dir'] . '/release';
         $rootpath = $toppath . '/' . self::getProjName();
         if ($opts['create']['mswpipackage']) {
             // add extra files to build
             /// @todo move this to another phase/task... ?
             /// @todo shall we check that there's no spurious file in $toppath?
             $resourcesPath = self::getResourceDir();
             pake_copy($resourcesPath . '/wpifiles/install.sql', $toppath . '/install.sql', array('override' => true));
             /// @todo: if the $rootpath is different from "ezpublish", the manifest and parameters files need to be altered accordingly
             /// after copying them to their location
             pake_copy($resourcesPath . '/wpifiles/manifest.xml', $toppath . '/manifest.xml', array('override' => true));
             pake_copy($resourcesPath . '/wpifiles/parameters.xml', $toppath . '/parameters.xml', array('override' => true));
             // this one is overwritten
             pake_copy($resourcesPath . '/wpifiles/kickstart.ini', $rootpath . '/kickstart.ini', array('override' => true));
             if (is_file($rootpath . '/web.config-RECOMMENDED')) {
                 pake_copy($rootpath . '/web.config-RECOMMENDED', $rootpath . '/web.config', array('override' => true));
             } else {
                 if (!is_file($rootpath . '/web.config')) {
                     pake_copy($resourcesPath . '/wpifiles/web.config', $rootpath . '/web.config', array('override' => true));
                 }
             }
             // create zip
             /// @todo if name is empty do not add an extra hyphen
             $filename = self::getProjFileName() . '-wpi.zip';
             $target = $opts['dist']['dir'] . '/' . $filename;
             self::archiveDir($toppath, $target, true);
             // update feed file
             $feedfile = 'ezpcpmswpifeed.xml';
             pake_copy($resourcesPath . '/wpifiles/' . $feedfile, $opts['dist']['dir'] . '/' . $feedfile);
             $files = pakeFinder::type('file')->name($feedfile)->maxdepth(0)->in($opts['dist']['dir']);
             //pake_replace_regexp( $files, $opts['dist']['dir'], array(
             //) );
             pake_replace_tokens($files, $opts['dist']['dir'], '{', '}', array('$update_date' => gmdate('c'), '$version' => $opts['version']['alias'], '$sha1' => sha1_file($target), '$filename' => $filename, '$filesizeKB' => round(filesize($target) / 1024)));
         }
     }
 }
示例#14
0
 public static function sync_from_server($local_path, $server_host, $remote_paths, $rsync_login = '', $transport = 'ssh')
 {
     if (strlen($rsync_login) > 0) {
         $rsync_login .= '@';
     }
     pake_mkdirs($local_path);
     if (is_string($remote_paths)) {
         // sync contents of dir, so adding trailing slash
         if ($remote_paths[strlen($remote_paths) - 1] != '/') {
             $remote_paths .= '/';
         }
         $remote_paths = array($remote_paths);
     } elseif (is_array($remote_paths)) {
         // syncing multiple objects, so removing trailing slashes
         $remote_paths = array_map(create_function('$path', 'return rtrim($path, "/");'), $remote_paths);
     }
     foreach ($remote_paths as &$remote_path) {
         $remote_path = $rsync_login . $server_host . ':' . $remote_path;
     }
     pake_sh('rsync -az -e ' . escapeshellarg($transport) . ' ' . implode(' ', array_map('escapeshellarg', $remote_paths)) . ' ' . escapeshellarg($local_path));
 }
示例#15
0
 public static function init($path, $template_path = null, $shared = false)
 {
     pake_mkdirs($path);
     if (false === $shared) {
         $shared = 'false';
     } elseif (true === $shared) {
         $shared = 'true';
     } elseif (is_int($shared)) {
         $shared = sprintf("%o", $shared);
     }
     $cmd = escapeshellarg(pake_which('git')) . ' init -q';
     if (null !== $template_path) {
         $cmd .= ' ' . escapeshellarg('--template=' . $template_path);
     }
     $cmd .= ' ' . escapeshellarg('--shared=' . $shared);
     $cwd = getcwd();
     chdir($path);
     chdir('.');
     // hack for windows. see http://docs.php.net/manual/en/function.chdir.php#88617
     pake_sh($cmd);
     chdir($cwd);
     return new pakeGit($path);
 }
示例#16
0
function _pear_init()
{
    // Remove E_STRICT from error_reporting
    error_reporting(error_reporting() & ~E_STRICT);
    require_once 'PEAR.php';
    require_once 'PEAR/Frontend.php';
    require_once 'PEAR/Config.php';
    require_once 'PEAR/Registry.php';
    require_once 'PEAR/Command.php';
    require_once 'PEAR/Remote.php';
    // current symfony release
    $sf_version = preg_replace('/\\-\\w+$/', '', file_get_contents(sfConfig::get('sf_symfony_lib_dir') . '/VERSION'));
    // PEAR
    PEAR_Command::setFrontendType('CLI');
    $ui =& PEAR_Command::getFrontendObject();
    // read user/system configuration (don't use the singleton)
    $config = new PEAR_Config();
    $config_file = sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR . '.pearrc';
    // change the configuration for symfony use
    $config->set('php_dir', sfConfig::get('sf_plugins_dir'));
    $config->set('data_dir', sfConfig::get('sf_plugins_dir'));
    $config->set('test_dir', sfConfig::get('sf_plugins_dir'));
    $config->set('doc_dir', sfConfig::get('sf_plugins_dir'));
    $config->set('bin_dir', sfConfig::get('sf_plugins_dir'));
    // change the PEAR temp dir
    $config->set('cache_dir', sfConfig::get('sf_cache_dir'));
    $config->set('download_dir', sfConfig::get('sf_cache_dir'));
    $config->set('tmp_dir', sfConfig::get('sf_cache_dir'));
    // save out configuration file
    $config->writeConfigFile($config_file, 'user');
    // use our configuration file
    $config =& PEAR_Config::singleton($config_file);
    $config->set('verbose', 1);
    $ui->setConfig($config);
    date_default_timezone_set('UTC');
    // register our channel
    $symfony_channel = array('attribs' => array('version' => '1.0', 'xmlns' => 'http://pear.php.net/channel-1.0', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation' => 'http://pear.php.net/dtd/channel-1.0 http://pear.php.net/dtd/channel-1.0.xsd'), 'name' => 'pear.symfony-project.com', 'summary' => 'symfony project PEAR channel', 'suggestedalias' => 'symfony', 'servers' => array('primary' => array('rest' => array('baseurl' => array(array('attribs' => array('type' => 'REST1.0'), '_content' => 'http://pear.symfony-project.com/Chiara_PEAR_Server_REST/'), array('attribs' => array('type' => 'REST1.1'), '_content' => 'http://pear.symfony-project.com/Chiara_PEAR_Server_REST/'))))), '_lastmodified' => array('ETag' => "113845-297-dc93f000", 'Last-Modified' => date('r')));
    pake_mkdirs(sfConfig::get('sf_plugins_dir') . '/.channels/.alias');
    file_put_contents(sfConfig::get('sf_plugins_dir') . '/.channels/pear.symfony-project.com.reg', serialize($symfony_channel));
    file_put_contents(sfConfig::get('sf_plugins_dir') . '/.channels/.alias/symfony.txt', 'pear.symfony-project.com');
    // register symfony for dependencies
    $symfony = array('name' => 'symfony', 'channel' => 'pear.symfony-project.com', 'date' => date('Y-m-d'), 'time' => date('H:i:s'), 'version' => array('release' => $sf_version, 'api' => '1.0.0'), 'stability' => array('release' => 'stable', 'api' => 'stable'), 'xsdversion' => '2.0', '_lastmodified' => time(), 'old' => array('version' => $sf_version, 'release_state' => 'stable'));
    $dir = sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR . '.registry' . DIRECTORY_SEPARATOR . '.channel.pear.symfony-project.com';
    pake_mkdirs($dir);
    file_put_contents($dir . DIRECTORY_SEPARATOR . 'symfony.reg', serialize($symfony));
    return $config;
}
示例#17
0
 /**
  * Creates the tarballs for a release
  */
 function run_dist($task = null, $args = array(), $cliOpts = array())
 {
     // copy workspace dir into dist dir, without git
     pake_mkdirs(Builder::distDir());
     $finder = pakeFinder::type('any')->ignore_version_control();
     pake_mirror($finder, realpath(Builder::workspaceDir()), realpath(Builder::distDir()));
     // remove unwanted files from dist dir
     // also: do we still need to run dos2unix?
     // create tarballs
     $cwd = getcwd();
     chdir(dirname(Builder::distDir()));
     foreach (Builder::distFiles() as $distFile) {
         // php can not really create good zip files via phar: they are not compressed!
         if (substr($distFile, -4) == '.zip') {
             $cmd = Builder::tool('zip');
             $extra = '-9 -r';
             pake_sh("{$cmd} {$distFile} {$extra} " . basename(Builder::distDir()));
         } else {
             $finder = pakeFinder::type('any')->pattern(basename(Builder::distDir()) . '/**');
             // see https://bugs.php.net/bug.php?id=58852
             $pharFile = str_replace(Builder::libVersion(), '_LIBVERSION_', $distFile);
             pakeArchive::createArchive($finder, '.', $pharFile);
             rename($pharFile, $distFile);
         }
     }
     chdir($cwd);
 }
示例#18
0
 /**
  * Downloads the build tarballs from Jenkins for further repackaging; options: --build=<buildnr>
  */
 public static function run_dist_init($task = null, $args = array(), $cliopts = array())
 {
     $opts = self::getOpts($args, $cliopts);
     $buildnr = @$cliopts['build'];
     if ($buildnr == '') {
         pake_echo('Fetching latest available build');
         $buildnr = 'lastBuild';
     }
     // get list of files from the build
     $out = self::jenkinsCall('job/' . $opts['jenkins']['jobs']['community'] . '/' . $buildnr . '/api/json', $opts);
     if (!is_array($out) || !is_array(@$out['artifacts'])) {
         pake_echo('Error in retrieving build description from Jenkins or no artifacts in build');
         return;
     } else {
         if ($buildnr == 'lastBuild') {
             pake_echo('Found build ' . $out['number']);
         }
     }
     // find the correct variant
     //$buildurl = self::jenkinsUrl( 'job/' . $opts['jenkins']['jobs']['community'] . '/' . $buildnr, $opts );
     $fileurl = '';
     foreach ($out['artifacts'] as $artifact) {
         if (substr($artifact['fileName'], -4) == '.bz2') {
             $fileurl = 'job/' . $opts['jenkins']['jobs']['community'] . '/' . $buildnr . '/artifact/' . $artifact['relativePath'];
             break;
         }
     }
     if ($fileurl == '') {
         pake_echo("No artifacts available for build {$buildnr}");
         return;
     }
     // clean up the 'release' dir
     $rootpath = $opts['build']['dir'] . '/release';
     /// @todo this method is a bit slow, should find a faster one
     pake_remove_dir($rootpath);
     // download and unzip the file
     pake_mkdirs($rootpath);
     $filename = $rootpath . '/' . $artifact['fileName'];
     pake_write_file($filename, self::jenkinsCall($fileurl, $opts, 'GET', null, false), 'cpb');
     // and unzip eZ into it - in a folder with a specific name
     $tar = self::getTool('tar', $opts);
     pake_sh(self::getCdCmd($rootpath) . " && {$tar} -xjf " . escapeshellarg($artifact['fileName']));
     $currdir = pakeFinder::type('directory')->in($rootpath);
     $currdir = $currdir[0];
     $finaldir = $rootpath . '/' . self::getProjName();
     pake_rename($currdir, $finaldir);
     pake_echo("dir+         " . $finaldir);
 }
示例#19
0
 /**
  * Creates a share/filelist.md5 file, with the checksum of all files in the build.
  *
  * This task is only run if in the configuration file md5 creation is specified.
  */
 static function run_generate_md5sums($task = null, $args = array(), $cliopts = array())
 {
     $opts = self::getOpts(@$args[0], @$args[1], $cliopts);
     if ($opts['create']['filelist_md5']) {
         if (!SharedLock::acquire($opts['extension']['name'], LOCK_EX, $opts)) {
             throw new PakeException("Source code locked by another process");
         }
         $destdir = self::getBuildDir($opts) . '/' . $opts['extension']['name'];
         // make sure we do not add to checksum file the file itself
         @unlink($destdir . '/share/filelist.md5');
         $files = pakeFinder::type('file')->in($destdir);
         $out = array();
         $rootpath = pakeFinder::type('directory')->name($opts['extension']['name'])->in(self::getBuildDir($opts));
         foreach ($files as $file) {
             $out[] = md5_file($file) . '  ' . ltrim(str_replace(array($rootpath[0], '\\'), array('', '/'), $file), '/');
         }
         pake_mkdirs($destdir . '/share');
         file_put_contents($destdir . '/share/filelist.md5', implode("\n", $out));
         pake_echo_action('file+', $destdir . '/share/filelist.md5');
         SharedLock::release($opts['extension']['name'], LOCK_EX, $opts);
     }
 }
示例#20
0
 public static function extractArchive($archive_file, $target_dir, $overwrite = false, $files = null)
 {
     if (!extension_loaded('phar')) {
         throw new pakeException(__CLASS__ . ' module requires "phar" extension');
     }
     pake_mkdirs($target_dir);
     pake_echo_action('extract', $archive_file);
     $arc = new PharData($archive_file);
     $arc->extractTo($target_dir, $files, $overwrite);
 }
示例#21
0
/**
 * run_doctrine_dump_data 
 * 
 * @param mixed $task 
 * @param mixed $args 
 * @access public
 * @return void
 */
function run_doctrine_dump_data($task, $args)
{
    if (!count($args)) {
        throw new Exception('You must provide the app.');
    }
    $app = $args[0];
    if (!is_dir(sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . $app)) {
        throw new Exception('The app "' . $app . '" does not exist.');
    }
    if (!isset($args[1])) {
        throw new Exception('You must provide a filename.');
    }
    $filename = $args[1];
    $env = empty($args[2]) ? 'dev' : $args[2];
    _load_application_environment($app, $env);
    if (!sfToolkit::isPathAbsolute($filename)) {
        $dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'fixtures';
        pake_mkdirs($dir);
        $filename = $dir . DIRECTORY_SEPARATOR . $filename;
    }
    pake_echo_action('doctrine', sprintf('dumping data to "%s"', $filename));
    $data = new sfDoctrineData();
    $data->dumpData($filename);
}
示例#22
0
function pake_mirror($arg, $origin_dir, $target_dir, $options = array())
{
    $files = pakeApp::get_files_from_argument($arg, $origin_dir, true);
    foreach ($files as $file) {
        if (is_dir($origin_dir . DIRECTORY_SEPARATOR . $file)) {
            pake_mkdirs($target_dir . DIRECTORY_SEPARATOR . $file);
        } else {
            if (is_file($origin_dir . DIRECTORY_SEPARATOR . $file)) {
                pake_copy($origin_dir . DIRECTORY_SEPARATOR . $file, $target_dir . DIRECTORY_SEPARATOR . $file, $options);
            } else {
                if (is_link($origin_dir . DIRECTORY_SEPARATOR . $file)) {
                    pake_symlink($origin_dir . DIRECTORY_SEPARATOR . $file, $target_dir . DIRECTORY_SEPARATOR . $file);
                } else {
                    throw new pakeException(sprintf('Unable to determine "%s" type', $file));
                }
            }
        }
    }
}
示例#23
0
function _add_1_0_test_bootstraps()
{
    pake_echo_action('upgrade 1.0', 'add test bootstrap files');
    pake_mkdirs(sfConfig::get('sf_root_dir') . '/test/bootstrap');
    pake_copy(sfConfig::get('sf_symfony_data_dir') . '/skeleton/project/test/bootstrap/functional.php', sfConfig::get('sf_root_dir') . '/test/bootstrap/functional.php');
    pake_copy(sfConfig::get('sf_symfony_data_dir') . '/skeleton/project/test/bootstrap/unit.php', sfConfig::get('sf_root_dir') . '/test/bootstrap/unit.php');
}
示例#24
0
 /**
  * Converts a property file into a yaml file
  * @param array $transform an array of transformation rules such as eg. 'sourcetag' => 'desttag' (desttag can be empty for tag removal or an array for tag expansion)
  * @todo move to a separate class to slim down base class?
  * @todo make it capable to remove complete $ext.version.alias property
  */
 static function convertPropertyFileToYamlFile($infile, $outfile = '', $transform = array(), $prepend = '')
 {
     if ($outfile == '') {
         $outfile = self::getOptionsDir() . '/options.yaml';
     }
     $current = array();
     $out = array();
     foreach (file($infile) as $line) {
         $line = trim($line);
         if ($line == '') {
             $out[] = '';
         } else {
             if (strpos($line, '<!--') === 0) {
                 $out[] .= preg_replace('/^<!-- *(.*) *-->$/', '# $1', $line);
             } else {
                 if (strpos($line, '=') != 0) {
                     $line = explode('=', $line, 2);
                     $path = explode('.', trim($line[0]));
                     foreach ($transform as $src => $dst) {
                         foreach ($path as $i => $element) {
                             if ($element == $src) {
                                 if ($dst == '') {
                                     unset($path[$i]);
                                 } else {
                                     if (is_array($dst)) {
                                         array_splice($path, $i - 1, 1, $dst);
                                     } else {
                                         $path[$i] = $dst;
                                     }
                                 }
                             }
                         }
                     }
                     // elements index can have holes here, cannot trust them => reorder
                     $path = array_values($path);
                     $value = $line[1];
                     $token = array_pop($path);
                     if ($path != $current) {
                         $skip = 0;
                         foreach ($path as $j => $element) {
                             if ($element == @$current[$j]) {
                                 $skip++;
                             } else {
                                 break;
                             }
                         }
                         for ($j = $skip; $j < count($path); $j++) {
                             $line = '';
                             for ($i = 0; $i < $j; $i++) {
                                 $line .= '    ';
                             }
                             $line .= $path[$j] . ':';
                             $out[] = $line;
                         }
                     }
                     $line = '';
                     for ($i = 0; $i < count($path); $i++) {
                         $line .= '    ';
                     }
                     $line .= $token . ': ' . $value;
                     $out[] = $line;
                     $current = $path;
                 } else {
                     /// @todo log warning?
                 }
             }
         }
     }
     pake_mkdirs('pake');
     // ask confirmation if file exists
     $ok = !file_exists($outfile) || pake_input("Destionation file {$outfile} exists. Overwrite? [y/n]", 'n') == 'y';
     if ($ok) {
         file_put_contents($outfile, $prepend . implode($out, "\n"));
         pake_echo_action('file+', $outfile);
     }
 }
示例#25
0
 /**
  * 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);
 }