Commit b3d93f35 authored by Adrian Rossouw's avatar Adrian Rossouw Committed by adrian

#368294 - Modules are now correctly retrieved, still need to tackle themes....

#368294 - Modules are now correctly retrieved, still need to tackle themes. Also integrated cvs_deploy (#406796)
parent 9b4a6be9
<?php
// $Id$
/**
* @file
*
* This include file is based on the cvs_deploy module by Derek Wright.
* @author Derek Wright ("dww") http://drupal.org/user/46549
*/
/**
* Used by provision to hook into the cvs_deploy system.
*/
function _provision_cvs_deploy(&$file) {
$project = $file->info['project'];
$project = ($project) ? $project : _provision_cvs_deploy_get_project_name($file);
$file->project = $project;
_provision_cvs_deploy_version_alter($file->info['version'], $file);
$file->version = $file->info['version'];
}
/**
* Private helper to alter the 'project' of a module based on what directory
* in the CVS repository the module has been checked out from.
*/
function _provision_cvs_deploy_get_project_name($file) {
static $projects = array();
$name = $file->name;
if (empty($projects[$name])) {
// TODO: cache this in {cache}, too?
$cvs_dir = dirname($file->filename) .'/CVS';
if (is_dir($cvs_dir)) {
$repository = '';
if (file_exists($cvs_dir .'/Repository')) {
$repo_file = trim(file_get_contents($cvs_dir .'/Repository'));
if ($repo_file) {
$parts = explode('/', $repo_file);
if ($parts[0] == 'drupal') {
$projects[$name] = $parts[0];
}
else {
$projects[$name] = $parts[2];
}
}
}
}
}
return (isset($projects[$name]) ? $projects[$name] : '');
}
/**
* Private helper to alter the version of a module based on what we can figure
* out about the CVS tag in use.
*/
function _provision_cvs_deploy_version_alter(&$version, $file) {
static $available = array();
$match = array();
if (empty($version)) {
// The .info file contains no version data. Find the version based
// on the sticky tag in the local workspace (the CVS/Tag file).
$cvs_dir = dirname($file->filename) .'/CVS';
if (is_dir($cvs_dir)) {
$tag = ''; // If there's no Tag file, there's no tag, a.k.a. HEAD.
if (file_exists($cvs_dir .'/Tag')) {
$tag_file = trim(file_get_contents($cvs_dir .'/Tag'));
if ($tag_file) {
// Get the sticky tag for this workspace: strip off the leading 'T'.
$tag = preg_replace('@^(T|N)@', '', $tag_file);
}
}
$version = _provision_cvs_deploy_version_from_tag($tag);
}
}
// The weird concatenation prevents CVS from 'expanding' this $Name.
elseif (preg_match('/\$'.'Name: (.*?)\$/', $version, $match)) {
$version = _provision_cvs_deploy_version_from_tag(trim($match[1]));
}
}
/**
* Returns the human-readable version string from a given CVS tag.
*/
function _provision_cvs_deploy_version_from_tag($tag) {
// If there's nothing, it must be a HEAD checkout, and therefore,
// we have no idea what the version is.
if (!$tag || $tag == 'HEAD') {
$version = 'HEAD';
}
// See if it's a full, official release from a tag:
elseif (preg_match('@^DRUPAL-(\d+)--(\d+)-(\d+)(-.+)?@', $tag, $match)) {
$version = $match[1] .'.x-'. $match[2] .'.'. $match[3];
if (isset($match[4])) {
// This version's tag has 'extra', so clean that up.
$version .= '-'. preg_replace('/[_-]/', '', strtolower($match[4]));
}
}
// If not, see if it's from a branch (like a development snapshot).
elseif (preg_match('@^DRUPAL-(\d+)(--(\d+))?@', $tag, $match)) {
$version = $match[1] .'.x-'. (isset($match[3]) ? $match[3] : '1') .'.x-dev';
}
return $version;
}
......@@ -377,3 +377,143 @@ function provision_drupal_install_log($ret) {
}
}
require_once('cvs_deploy.inc');
function provision_find_packages() {
$drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT');
$searchpaths[] = sprintf("%s/modules", $drupal_root);
$searchpaths[] = sprintf("%s/sites/all/modules", $drupal_root);
$packages['core']['modules'] = provision_parse_packages($searchpaths);
$profiles = drush_get_option('profiles', array());
foreach ($profiles as $profile => $info) {
$searchpaths = array();
$searchpaths[] = sprintf("%s/profiles/%s/modules", $drupal_root, $profile);
$packages['profiles'][$profile]['modules'] = provision_parse_packages($searchpaths);
}
$sites = drush_get_option('sites', array());
foreach ($sites as $site) {
$searchpaths = array();
$searchpaths[] = sprintf("%s/sites/%s/modules", $drupal_root, $site);
$packages['sites'][$site]['modules'] = provision_parse_packages($searchpaths);
}
return $packages;
}
function provision_parse_packages($paths, $type = 'module') {
$files = array();
foreach ($paths as $path) {
$files = array_merge($files, drush_scan_directory($path, ".module$", array('.', '..', 'CVS', '.svn'), 0, true, 'name'));
}
foreach ($files as $name => $info) {
$install_file = sprintf("%s/%s.install", dirname($info->filename), $name);
$schema_version = 1;
if (file_exists($install_file)) {
$source = file_get_contents(trim($install_file));
$source = str_replace("\r\n", "\n", $source);
$source = str_replace("\r", "\n", $source);
$function_matches = array();
preg_match_all('!function\s*&?([a-zA-Z0-9_]+)_update_([0-9]+)\(.*?\s*\{!', $source, $function_matches);
if (sizeof($function_matches[0])) {
$schema_version = max($function_matches[2]) + 1;
}
}
$info_file = sprintf("%s/%s.info", dirname($info->filename), $name);
$files[$name]->info = provision_parse_info_file($info_file);
$files[$name]->schema_version = $schema_version;
_provision_cvs_deploy($files[$name]);
}
return $files;
}
function provision_parse_info_file($filename) {
$info = array();
$defaults = array(
'dependencies' => array(),
'description' => '',
'version' => NULL,
'php' => DRUPAL_MINIMUM_PHP,
);
if (file_exists($filename)) {
switch (drush_drupal_major_version()) {
case 5 :
$info = parse_ini_file($filename);
break;
default :
$info = _provision_drupal_parse_info_file($filename);
break;
}
}
// Merge in defaults and return
return $info + $defaults;
}
/**
* This code is based on the Drupal 6 and Drupal 7 drupal_parse_info_file
*/
function _provision_drupal_parse_info_file($filename) {
$info = array();
if (!file_exists($filename)) {
return $info;
}
$data = file_get_contents($filename);
if (preg_match_all('
@^\s* # Start at the beginning of a line, ignoring leading whitespace
((?:
[^=;\[\]]| # Key names cannot contain equal signs, semi-colons or square brackets,
\[[^\[\]]*\] # unless they are balanced and not nested
)+?)
\s*=\s* # Key/value pairs are separated by equal signs (ignoring white-space)
(?:
("(?:[^"]|(?<=\\\\)")*")| # Double-quoted string, which may contain slash-escaped quotes/slashes
(\'(?:[^\']|(?<=\\\\)\')*\')| # Single-quoted string, which may contain slash-escaped quotes/slashes
([^\r\n]*?) # Non-quoted string
)\s*$ # Stop at the next end of a line, ignoring trailing whitespace
@msx', $data, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
// Fetch the key and value string
$i = 0;
foreach (array('key', 'value1', 'value2', 'value3') as $var) {
$$var = isset($match[++$i]) ? $match[$i] : '';
}
$value = stripslashes(substr($value1, 1, -1)) . stripslashes(substr($value2, 1, -1)) . $value3;
// Parse array syntax
$keys = preg_split('/\]?\[/', rtrim($key, ']'));
$last = array_pop($keys);
$parent = &$info;
// Create nested arrays
foreach ($keys as $key) {
if ($key == '') {
$key = count($parent);
}
if (!isset($parent[$key]) || !is_array($parent[$key])) {
$parent[$key] = array();
}
$parent = &$parent[$key];
}
// Handle PHP constants
if (defined($value)) {
$value = constant($value);
}
// Insert actual value
if ($last == '') {
$last = count($parent);
}
$parent[$last] = $value;
}
}
return $info;
}
......@@ -30,6 +30,8 @@ function provision_drupal_provision_verify($url = null) {
drush_log(dt("This platform is running @short_name @version",
array('@short_name' => 'drupal', '@version' => VERSION)));
drush_set_option('profiles', _scrub_object(_provision_find_profiles()), 'drupal');
drush_set_option('packages', _scrub_object(provision_find_packages()), 'drupal');
}
else {
......@@ -150,4 +152,4 @@ DirectoryIndex index.php
AllowOverride none
EOF;
}
\ No newline at end of file
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment