cvs.inc

  1. 3.x commands/pm/package_handler/cvs.inc
  2. 4.x commands/pm/package_handler/cvs.inc

Drush PM CVS extension

Functions

Namesort descending Description
drush_pm_cvs General CVS helper function.
package_handler_download_project Install a project.
package_handler_post_download Post download action.
package_handler_update_project Update a project (so far, only modules are supported).
package_handler_validate Validate this package handler can run.

File

commands/pm/package_handler/cvs.inc
View source
  1. <?php
  2. /**
  3. * @file Drush PM CVS extension
  4. */
  5. /**
  6. * Validate this package handler can run.
  7. */
  8. function package_handler_validate() {
  9. // Check cvs command exists. Disable possible output.
  10. $debug = drush_get_context('DRUSH_DEBUG');
  11. drush_set_context('DRUSH_DEBUG', FALSE);
  12. $success = drush_shell_exec('cvs --version');
  13. drush_set_context('DRUSH_DEBUG', $debug);
  14. if (!$success) {
  15. return drush_set_error('DRUSH_SHELL_COMMAND_NOT_FOUND', dt('cvs executable not found.'));
  16. }
  17. // Check cvs_deploy is enabled. Only for bootstrapped sites.
  18. if (drush_get_context('DRUSH_BOOTSTRAP_PHASE') >= DRUSH_BOOTSTRAP_DRUPAL_FULL) {
  19. if (!module_exists('cvs_deploy')) {
  20. drush_log(dt('cvs package handler needs cvs_deploy module enabled to work properly.'), 'warning');
  21. }
  22. }
  23. }
  24. /**
  25. * Install a project.
  26. *
  27. * @param $project The project array with name, base and full (final) paths.
  28. * @param $release The release details array from drupal.org
  29. */
  30. function package_handler_download_project(&$project, $release) {
  31. // Check it out.
  32. drush_pm_cvs($project, $release);
  33. if (!drush_get_context('DRUSH_SIMULATE')) {
  34. if (is_dir($project['full_project_path'])) {
  35. drush_log("Checking out " . $project['name'] . " was successful.");
  36. return TRUE;
  37. }
  38. else {
  39. 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'])));
  40. }
  41. }
  42. }
  43. /**
  44. * Update a project (so far, only modules are supported).
  45. *
  46. * @param $project The project array with name, base and full (final) paths.
  47. * @param $release The release details array from drupal.org
  48. */
  49. function package_handler_update_project(&$project, $release) {
  50. drush_log('Updating project ' . $project['name'] . ' ...');
  51. // Check out a fresh copy, or update an existing one.
  52. drush_pm_cvs($project, $release);
  53. if (is_dir($project['full_project_path']) && !drush_get_context('DRUSH_SIMULATE')) {
  54. drush_log("Updating of " . $project['name'] . " was successful.");
  55. return TRUE;
  56. }
  57. else {
  58. return drush_set_error('DRUSH_PM_CVS_UPDATE_PROBLEMS', dt("Unable to update !project from cvs.drupal.org", array('!project' => $project['name'])));
  59. }
  60. }
  61. /**
  62. * General CVS helper function.
  63. *
  64. * @param $project The project array with name, base and full (final) paths.
  65. * @param $release The release details array from drupal.org
  66. */
  67. function drush_pm_cvs(&$project, $release) {
  68. // Build the cvs command to execute.
  69. $command = array('cvs');
  70. // Global options.
  71. $command[] = '-z6';
  72. // cvs root.
  73. $cvsroot = '-d:pserver:' . drush_get_option('cvscredentials', 'anonymous:anonymous') . '@cvs.drupal.org:/cvs/';
  74. $cvsroot .= ($project['project_type'] == 'core')?'drupal':'drupal-contrib';
  75. $command[] = $cvsroot;
  76. // CVS command ("cvs method").
  77. $cvsmethod = drush_get_option('cvsmethod', FALSE);
  78. if (empty($cvsmethod)) {
  79. $cvsmethod = 'checkout';
  80. // If we have an existing working copy we update.
  81. if (is_dir($project['full_project_path'] . '/CVS')) {
  82. $cvsmethod = 'update';
  83. }
  84. }
  85. $command[] = $cvsmethod;
  86. // CVS command options.
  87. $cvsparams = drush_get_option('cvsparams', FALSE);
  88. // common options for any command.
  89. $command[] = '-r '. $release['tag'];
  90. // command specific options.
  91. if ($cvsmethod == 'checkout') {
  92. // checkout dir.
  93. $command[] = '-d ' . $project['project_dir'];
  94. // path to cvs 'module' to check out.
  95. if ($project['project_type'] == 'core') {
  96. $command[] = $project['name']; // drupal
  97. }
  98. else {
  99. // strtr for 'theme engine' type.
  100. $command[] = 'contributions/' . strtr($project['project_type'], ' ' ,'-') . 's/' . $project['name'];
  101. }
  102. }
  103. else {
  104. if ($cvsparams === FALSE) {
  105. // By default we update overwriting changes, however if we have an
  106. // existing CVS checkout that is version controlled then the default is
  107. // to update in place, which will attempt to merge changes but we assume
  108. // anyone using a VCS is competent enough to deal with this!
  109. $reserved_files = drush_version_control_reserved_files();
  110. $overwrite = TRUE;
  111. foreach ($reserved_files as $file) {
  112. if (file_exists($project['full_project_path'] . '/' . $file)) {
  113. $overwrite = FALSE;
  114. break;
  115. }
  116. }
  117. $command[] = $overwrite?'-dPC':'-dP';
  118. }
  119. // Directory to work on.
  120. $command[] = $project['project_dir'];
  121. }
  122. // CVS only accepts relative paths. We will cd in the checkout path right
  123. // before running the cvs command.
  124. if (!drush_shell_cd_and_exec($project['base_project_path'], implode(' ', $command))) {
  125. return drush_set_error('DRUSH_PM_UNABLE_CHECKOUT', dt('Unable to !op !project from cvs.drupal.org.', array('!op' => $cvsmethod, '!project' => $project['name'])));
  126. }
  127. }
  128. /**
  129. * Post download action.
  130. *
  131. * This action take place once the project is placed in its final location.
  132. */
  133. function package_handler_post_download($project) {
  134. }