first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,148 @@
<?php
/**
* @file Drush PM CVS extension
*/
/**
* Validate this package handler can run.
*/
function package_handler_validate() {
// Check cvs command exists. Disable possible output.
$debug = drush_get_context('DRUSH_DEBUG');
drush_set_context('DRUSH_DEBUG', FALSE);
$success = drush_shell_exec('cvs --version');
drush_set_context('DRUSH_DEBUG', $debug);
if (!$success) {
return drush_set_error('DRUSH_SHELL_COMMAND_NOT_FOUND', dt('cvs executable not found.'));
}
// Check cvs_deploy is enabled. Only for bootstrapped sites.
if (drush_get_context('DRUSH_BOOTSTRAP_PHASE') >= DRUSH_BOOTSTRAP_DRUPAL_FULL) {
if (!module_exists('cvs_deploy')) {
drush_log(dt('cvs package handler needs cvs_deploy module enabled to work properly.'), 'warning');
}
}
}
/**
* Install a project.
*
* @param $project The project array with name, base and full (final) paths.
* @param $release The release details array from drupal.org
*/
function package_handler_download_project(&$project, $release) {
// Check it out.
drush_pm_cvs($project, $release);
if (!drush_get_context('DRUSH_SIMULATE')) {
if (is_dir($project['full_project_path'])) {
drush_log("Checking out " . $project['name'] . " was successful.");
return TRUE;
}
else {
return drush_set_error('DRUSH_PM_CVS_CHECKOUT_PROBLEMS', dt("Unable to check out !project to !destination from cvs.drupal.org", array('!project' => $project['name'], '!destination' => $project['full_project_path'])));
}
}
}
/**
* Update a project (so far, only modules are supported).
*
* @param $project The project array with name, base and full (final) paths.
* @param $release The release details array from drupal.org
*/
function package_handler_update_project(&$project, $release) {
drush_log('Updating project ' . $project['name'] . ' ...');
// Check out a fresh copy, or update an existing one.
drush_pm_cvs($project, $release);
if (is_dir($project['full_project_path']) && !drush_get_context('DRUSH_SIMULATE')) {
drush_log("Updating of " . $project['name'] . " was successful.");
return TRUE;
}
else {
return drush_set_error('DRUSH_PM_CVS_UPDATE_PROBLEMS', dt("Unable to update !project from cvs.drupal.org", array('!project' => $project['name'])));
}
}
/**
* General CVS helper function.
*
* @param $project The project array with name, base and full (final) paths.
* @param $release The release details array from drupal.org
*/
function drush_pm_cvs(&$project, $release) {
// Build the cvs command to execute.
$command = array('cvs');
// Global options.
$command[] = '-z6';
// cvs root.
$cvsroot = '-d:pserver:' . drush_get_option('cvscredentials', 'anonymous:anonymous') . '@cvs.drupal.org:/cvs/';
$cvsroot .= ($project['project_type'] == 'core')?'drupal':'drupal-contrib';
$command[] = $cvsroot;
// CVS command ("cvs method").
$cvsmethod = drush_get_option('cvsmethod', FALSE);
if (empty($cvsmethod)) {
$cvsmethod = 'checkout';
// If we have an existing working copy we update.
if (is_dir($project['full_project_path'] . '/CVS')) {
$cvsmethod = 'update';
}
}
$command[] = $cvsmethod;
// CVS command options.
$cvsparams = drush_get_option('cvsparams', FALSE);
// common options for any command.
$command[] = '-r '. $release['tag'];
// command specific options.
if ($cvsmethod == 'checkout') {
// checkout dir.
$command[] = '-d ' . $project['project_dir'];
// path to cvs 'module' to check out.
if ($project['project_type'] == 'core') {
$command[] = $project['name']; // drupal
}
else {
// strtr for 'theme engine' type.
$command[] = 'contributions/' . strtr($project['project_type'], ' ' ,'-') . 's/' . $project['name'];
}
}
else {
if ($cvsparams === FALSE) {
// By default we update overwriting changes, however if we have an
// existing CVS checkout that is version controlled then the default is
// to update in place, which will attempt to merge changes but we assume
// anyone using a VCS is competent enough to deal with this!
$reserved_files = drush_version_control_reserved_files();
$overwrite = TRUE;
foreach ($reserved_files as $file) {
if (file_exists($project['full_project_path'] . '/' . $file)) {
$overwrite = FALSE;
break;
}
}
$command[] = $overwrite?'-dPC':'-dP';
}
// Directory to work on.
$command[] = $project['project_dir'];
}
// CVS only accepts relative paths. We will cd in the checkout path right
// before running the cvs command.
if (!drush_shell_cd_and_exec($project['base_project_path'], implode(' ', $command))) {
return drush_set_error('DRUSH_PM_UNABLE_CHECKOUT', dt('Unable to !op !project from cvs.drupal.org.', array('!op' => $cvsmethod, '!project' => $project['name'])));
}
}
/**
* Post download action.
*
* This action take place once the project is placed in its final location.
*/
function package_handler_post_download($project) {
}

View File

@@ -0,0 +1,191 @@
<?php
/**
* @file Drush PM drupal.org Git extension.
*/
/**
* Validate this package handler can run.
*/
function package_handler_validate() {
// Check git command exists. Disable possible output.
$debug = drush_get_context('DRUSH_DEBUG');
drush_set_context('DRUSH_DEBUG', FALSE);
$success = drush_shell_exec('git --version');
drush_set_context('DRUSH_DEBUG', $debug);
if (!$success) {
return drush_set_error('DRUSH_SHELL_COMMAND_NOT_FOUND', dt('git executable not found.'));
}
// Check git_deploy is enabled. Only for bootstrapped sites.
if (drush_get_context('DRUSH_BOOTSTRAP_PHASE') >= DRUSH_BOOTSTRAP_DRUPAL_FULL) {
if (!module_exists('git_deploy')) {
drush_log(dt('git package handler needs git_deploy module enabled to work properly.'), 'warning');
}
}
}
/**
* Download a project.
*
* @param $request
* The project array with name, base and full (final) paths.
* @param $release
* The release details array from drupal.org.
*/
function package_handler_download_project(&$request, $release) {
if ($username = drush_get_option('gitusername')) {
// Uses SSH, which enables pushing changes back to git.drupal.org.
$repository = $username . '@git.drupal.org:project/' . $request['name'] . '.git';
}
else {
$repository = 'git://git.drupal.org/project/' . $request['name'] . '.git';
}
$request['repository'] = $repository;
$tag = $release['tag'];
// If the --cache option was given, create a new git reference cache of the
// remote repository, or update the existing cache to fetch recent changes.
if (drush_get_option('cache') && ($cachedir = drush_directory_cache())) {
$gitcache = $cachedir . '/git';
$projectcache = $gitcache . '/' . $request['name'] . '.git';
drush_mkdir($gitcache);
// Setup a new cache, if we don't have this project yet.
if (!file_exists($projectcache)) {
// --mirror works similar to --bare, but retrieves all tags, local
// branches, remote branches, and any other refs (notes, stashes, etc).
// @see http://stackoverflow.com/questions/3959924
$command = 'git clone --mirror';
if (drush_get_context('DRUSH_VERBOSE')) {
$command .= ' --verbose --progress';
}
$command .= ' %s %s';
drush_shell_cd_and_exec($gitcache, $command, $repository, $request['name'] . '.git');
}
// If we already have this project, update it to speed up subsequent clones.
else {
// A --mirror clone is fully synchronized with `git remote update` instead
// of `git fetch --all`.
// @see http://stackoverflow.com/questions/6150188
drush_shell_cd_and_exec($projectcache, 'git remote update');
}
$gitcache = $projectcache;
}
// Clone the repo into its appropriate target location.
$command = 'git clone';
$command .= ' ' . drush_get_option('gitcloneparams');
if (drush_get_option('cache')) {
$command .= ' --reference ' . drush_escapeshellarg($gitcache);
}
if (drush_get_context('DRUSH_VERBOSE')) {
$command .= ' --verbose --progress';
}
$command .= ' ' . drush_escapeshellarg($repository);
$command .= ' ' . drush_escapeshellarg($request['full_project_path']);
if (!drush_shell_exec($command)) {
return drush_set_error('DRUSH_PM_GIT_CHECKOUT_PROBLEMS', dt('Unable to clone project !name from git.drupal.org.', array('!name' => $request['name'])));
}
// Check if the 'tag' from the release feed is a tag or a branch.
// If the tag exists, git will return it
if (!drush_shell_cd_and_exec($request['full_project_path'], 'git tag -l ' . drush_escapeshellarg($tag))) {
return drush_set_error('DRUSH_PM_GIT_CHECKOUT_PROBLEMS', dt('Unable to clone project !name from git.drupal.org.', array('!name' => $request['name'])));
}
$output = drush_shell_exec_output();
if (isset($output[0]) && ($output[0] == $tag)) {
// If we want a tag, simply checkout it. The checkout will end up in
// "detached head" state.
$command = 'git checkout ' . drush_get_option('gitcheckoutparams');
$command .= ' ' . drush_escapeshellarg($tag);
if (!drush_shell_cd_and_exec($request['full_project_path'], $command)) {
return drush_set_error('DRUSH_PM_UNABLE_CHECKOUT', 'Unable to retrieve ' . $request['name'] . ' from git.drupal.org.');
}
}
else {
// Else, we want to checkout a branch.
// First check if we are not already in the correct branch.
if (!drush_shell_cd_and_exec($request['full_project_path'], 'git symbolic-ref HEAD')) {
return drush_set_error('DRUSH_PM_UNABLE_CHECKOUT', 'Unable to retrieve ' . $request['name'] . ' from git.drupal.org.');
}
$output = drush_shell_exec_output();
$current_branch = preg_replace('@^refs/heads/@', '', $output[0]);
// If we are not on the correct branch already, switch to the correct one.
if ($current_branch != $tag) {
$command = 'git checkout';
$command .= ' ' . drush_get_option('gitcheckoutparams');
$command .= ' --track ' . drush_escapeshellarg('origin/' . $tag) . ' -b ' . drush_escapeshellarg($tag);
if (!drush_shell_cd_and_exec($request['full_project_path'], $command)) {
return drush_set_error('DRUSH_PM_UNABLE_CHECKOUT', 'Unable to retrieve ' . $request['name'] . ' from git.drupal.org.');
}
}
}
return TRUE;
}
/**
* Update a project (so far, only modules are supported).
*
* @param $request
* The project array with name, base and full (final) paths.
* @param $release
* The release details array from drupal.org.
*/
function package_handler_update_project($request, $release) {
drush_log('Updating project ' . $request['name'] . ' ...');
$commands = array();
if ($release['version_extra'] == 'dev') {
// Update the branch of the development repository.
$commands[] = 'git pull';
$commands[] = drush_get_option('gitpullparams');
}
else {
// Use a stable repository.
$commands[] = 'git fetch';
$commands[] = drush_get_option('gitfetchparams');
$commands[] = ';';
$commands[] = 'git checkout';
$commands[] = drush_get_option('gitcheckoutparams');
$commands[] = $release['version'];
}
if (!drush_shell_cd_and_exec($request['full_project_path'], implode(' ', $commands))) {
return drush_set_error('DRUSH_PM_UNABLE_CHECKOUT', 'Unable to update ' . $request['name'] . ' from git.drupal.org.');
}
return TRUE;
}
/**
* Post download action.
*
* This action take place once the project is placed in its final location.
*
* Here we add the project as a git submodule.
*/
function package_handler_post_download($project) {
if (drush_get_option('gitsubmodule', FALSE)) {
// Obtain the superproject path, then add as submodule.
if (drush_shell_cd_and_exec(dirname($project['full_project_path']), 'git rev-parse --show-toplevel')) {
$output = drush_shell_exec_output();
$superproject = $output[0];
// Add the downloaded project as a submodule of its git superproject.
$command = array();
$command[] = 'git submodule add';
$command[] = drush_get_option('gitsubmoduleaddparams');
$command[] = $project['repository'];
// We need the submodule relative path.
$command[] = substr($project['full_project_path'], strlen($superproject) + 1);
if (!drush_shell_cd_and_exec($superproject, implode(' ', $command))) {
return drush_set_error('DRUSH_PM_GIT_CHECKOUT_PROBLEMS', dt('Unable to add !name as a git submodule of !super.', array('!name' => $project['name'], '!super' => $superproject)));
}
}
else {
return drush_set_error('DRUSH_PM_GIT_SUBMODULE_PROBLEMS', dt('Unable to create !project as a git submodule: !dir is not in a Git repository.', array('!project' => $project['name'], '!dir' => dirname($project['full_project_path']))));
}
}
}

View File

@@ -0,0 +1,104 @@
<?php
/**
* @file Drush PM Wget extension
*/
/**
* Validate this package handler can run.
*/
function package_handler_validate() {
// Check wget or curl command exists. Disable possible output.
$debug = drush_get_context('DRUSH_DEBUG');
drush_set_context('DRUSH_DEBUG', FALSE);
$success = drush_shell_exec('wget --version');
if (!$success) {
$success = drush_shell_exec('curl --version');
// Old version of curl shipped in darwin returns error status for --version
// and --help. Give the chance to use it.
if (!$success) {
$success = drush_shell_exec('which curl');
}
}
drush_set_context('DRUSH_DEBUG', $debug);
if (!$success) {
return drush_set_error('DRUSH_SHELL_COMMAND_NOT_FOUND', dt('wget nor curl executables found.'));
}
}
/**
* Download a project.
*
* @param $request Array with information on the request to download.
* @param $release The release details array from drupal.org.
*/
function package_handler_download_project(&$request, $release) {
// Install profiles come in several variants. User may specify which one she wants.
if ($request['project_type'] == 'profile') {
// @todo Use xpath to get the right file url.
$files = $release['files'];
foreach ($files as $key => $file) {
if ((string)$file->variant == drush_get_option('variant', 'full') && (string)$file->archive_type == 'tar.gz') {
$release['download_link'] = (string)$file->url;
$release['mdhash'] = (string)$file->md5;
break;
}
}
}
$filename = explode('/', $release['download_link']);
$filename = array_pop($filename);
// Download the project.
if (!drush_shell_exec("wget -P . %s", $release['download_link'])) {
drush_shell_exec("curl -O %s", $release['download_link']);
}
if (file_exists($filename) || drush_get_context('DRUSH_SIMULATE')) {
drush_log("Downloading " . $filename . " was successful.");
}
else {
return drush_set_error('DRUSH_PM_DOWNLOAD_FAILED', 'Unable to download ' . $filename . ' to ' . $request['base_project_path'] . ' from '. $release['download_link']);
}
// Check Md5 hash.
if (drush_op('md5_file', $filename) != $release['mdhash'] && !drush_get_context('DRUSH_SIMULATE')) {
drush_set_error('DRUSH_PM_FILE_CORRUPT', "File $filename is corrupt (wrong md5 checksum).");
drush_op('unlink', $filename);
return FALSE;
}
else {
drush_log("Md5 checksum of $filename verified.");
}
// Extract the tarball.
$file_list = drush_tarball_extract($filename, $request['base_project_path'], TRUE);
drush_op('unlink', $filename);
// Move untarred directory to project_dir, if distinct.
if (($request['project_type'] == 'core') || (($request['project_type'] == 'profile') && (drush_get_option('variant', 'core') == 'core'))) {
// Obtain the dodgy project_dir for drupal core.
$project_dir = rtrim($file_list[0], DIRECTORY_SEPARATOR);
if ($request['project_dir'] != $project_dir) {
$path = $request['base_project_path'];
drush_move_dir($path . '/'. $project_dir, $path . '/' . $request['project_dir']);
}
}
return TRUE;
}
/**
* This is an alias of the download function, since they are identical
*/
function package_handler_update_project(&$request, $release) {
return package_handler_download_project($request, $release);
}
/**
* Post download action.
*
* This action take place once the project is placed in its final location.
*/
function package_handler_post_download($project) {
}