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_install_project Install a project.
package_handler_update_project Update a project (so far, only modules are supported).

File

commands/pm/package_handler/cvs.inc
View source
  1. <?php
  2. /**
  3. * @file Drush PM CVS extension
  4. */
  5. /**
  6. * Install a project.
  7. *
  8. * @param $project The project array with name, base and full (final) paths.
  9. * @param $release The release details array from drupal.org
  10. */
  11. function package_handler_install_project($project, $release) {
  12. drush_log('Downloading project ' . $project['name'] . ' ...');
  13. // Check it out.
  14. drush_pm_cvs($project, $release);
  15. if (!drush_get_context('DRUSH_SIMULATE')) {
  16. if (is_dir($project['full_project_path'])) {
  17. drush_log("Checking out " . $project['name'] . " was successful.");
  18. return TRUE;
  19. }
  20. else {
  21. 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'])));
  22. return FALSE;
  23. }
  24. }
  25. }
  26. /**
  27. * Update a project (so far, only modules are supported).
  28. *
  29. * @param $project The project array with name, base and full (final) paths.
  30. * @param $release The release details array from drupal.org
  31. */
  32. function package_handler_update_project($project, $release) {
  33. drush_log('Updating project ' . $project['name'] . ' ...');
  34. // Check out a fresh copy, or update an existing one.
  35. drush_pm_cvs($project, $release);
  36. if (is_dir($project['full_project_path']) && !drush_get_context('DRUSH_SIMULATE')) {
  37. drush_log("Updating of " . $project['name'] . " was successful.");
  38. return TRUE;
  39. }
  40. else {
  41. return drush_set_error('DRUSH_PM_CVS_UPDATE_PROBLEMS', dt("Unable to update !project from cvs.drupal.org", array('!project' => $project['name'])));
  42. }
  43. }
  44. /**
  45. * General CVS helper function
  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 drush_pm_cvs($project, $release) {
  50. // By default we assume a module
  51. $repos = 'drupal-contrib';
  52. $cvsdir = 'contributions/modules/';
  53. switch ($project['project_type']) {
  54. case 'theme':
  55. $cvsdir = 'contributions/themes/';
  56. break;
  57. case 'theme engine':
  58. $cvsdir = 'contributions/theme-engines/';
  59. break;
  60. case 'translation':
  61. drush_set_error('DRUSH_PM_CVS_NO_TRANSLATIONS', 'You cannot install translations with CVS, because they require processing (normally done on drupal.org to produce the tar.gz files).');
  62. exit();
  63. case 'profile':
  64. $cvsdir = 'contributions/profiles/';
  65. break;
  66. case 'core':
  67. $cvsdir = '';
  68. $repos = 'drupal';
  69. }
  70. $cvsmethod = drush_get_option('cvsmethod', FALSE);
  71. $cvsparams = drush_get_option('cvsparams', FALSE);
  72. // Determine reasonable defaults, based on context.
  73. if (empty($cvsmethod)) {
  74. $cvsmethod = 'checkout';
  75. // If we have an existing working copy we update.
  76. if (is_dir($project['full_project_path'] . '/CVS')) {
  77. $cvsmethod = 'update';
  78. // By default we update overwriting changes, however if we have
  79. // an existing CVS checkout that is version controlled then the
  80. // default is to update in place, which will attempt to merge changes
  81. // but we assume anyone using SVN is competent enough to deal with this!
  82. // TODO: Make this work with BZR etc.
  83. if (!file_exists($path . '/.svn') && $cvsparams === FALSE) {
  84. $cvsparams = '-dPC';
  85. }
  86. }
  87. }
  88. if ($cvsparams === FALSE) {
  89. $cvsparams = '-dP';
  90. }
  91. // CVS only accepts relative paths. We will cd in the checkout path right
  92. // before running the cvs command.
  93. $checkout_path = $project['base_project_path'];
  94. $cvsparts = array();
  95. $cvsparts[] = '-z6';
  96. $cvsparts[] = $cvsparams;
  97. $cvsparts[] = '-d:pserver:' . drush_get_option('cvscredentials', 'anonymous:anonymous') . '@cvs.drupal.org:/cvs/' . $repos;
  98. $cvsparts[] = $cvsmethod;
  99. $cvsparts[] = '-r '. $release['tag'];
  100. if ($cvsmethod == 'checkout') {
  101. $cvsparts[] = '-d ' . $project['name'];
  102. $cvsparts[] = $cvsdir . $project['name'];
  103. }
  104. else {
  105. $cvsparts[] = $project['name'];
  106. }
  107. if (!drush_shell_exec('cd ' . $checkout_path . ' ; cvs ' . implode(' ', $cvsparts))) {
  108. drush_set_error('DRUSH_PM_UNABLE_CHECKOUT', 'Unable to checkout ' . $project['name'] . ' from cvs.drupal.org.');
  109. }
  110. }