wget.inc

  1. 8.0.x commands/pm/package_handler/wget.inc
  2. 6.x commands/pm/package_handler/wget.inc
  3. 7.x commands/pm/package_handler/wget.inc
  4. 3.x commands/pm/package_handler/wget.inc
  5. 4.x commands/pm/package_handler/wget.inc
  6. 5.x commands/pm/package_handler/wget.inc
  7. master commands/pm/package_handler/wget.inc

Drush PM Wget extension

Functions

Namesort descending Description
package_handler_download_project Download a project.
package_handler_post_download Post download action.
package_handler_update_project This is an alias of the download function, since they are identical
package_handler_validate Validate this package handler can run.

File

commands/pm/package_handler/wget.inc
View source
  1. <?php
  2. /**
  3. * @file Drush PM Wget extension
  4. */
  5. /**
  6. * Validate this package handler can run.
  7. */
  8. function package_handler_validate() {
  9. // Check wget or curl command exists. Disable possible output.
  10. $debug = drush_get_context('DRUSH_DEBUG');
  11. drush_set_context('DRUSH_DEBUG', FALSE);
  12. $success = drush_shell_exec('wget --version');
  13. if (!$success) {
  14. $success = drush_shell_exec('curl --version');
  15. // Old version of curl shipped in darwin returns error status for --version
  16. // and --help. Give the chance to use it.
  17. if (!$success) {
  18. $success = drush_shell_exec('which curl');
  19. }
  20. }
  21. drush_set_context('DRUSH_DEBUG', $debug);
  22. if (!$success) {
  23. return drush_set_error('DRUSH_SHELL_COMMAND_NOT_FOUND', dt('wget nor curl executables found.'));
  24. }
  25. }
  26. /**
  27. * Download a project.
  28. *
  29. * @param $request Array with information on the request to download.
  30. * @param $release The release details array from drupal.org.
  31. */
  32. function package_handler_download_project(&$request, $release) {
  33. // Install profiles come in several variants. User may specify which one she wants.
  34. if ($request['project_type'] == 'profile') {
  35. // @todo Use xpath to get the right file url.
  36. $files = $release['files'];
  37. foreach ($files as $key => $file) {
  38. if ((string)$file->variant == drush_get_option('variant', 'full') && (string)$file->archive_type == 'tar.gz') {
  39. $release['download_link'] = (string)$file->url;
  40. $release['mdhash'] = (string)$file->md5;
  41. break;
  42. }
  43. }
  44. }
  45. $filename = explode('/', $release['download_link']);
  46. $filename = array_pop($filename);
  47. // Chdir to the download location.
  48. $olddir = getcwd();
  49. drush_op('chdir', $request['base_project_path']);
  50. // Download the project.
  51. if (!drush_shell_exec("wget -P . %s", $release['download_link'])) {
  52. drush_shell_exec("curl -O %s", $release['download_link']);
  53. }
  54. if (file_exists($filename) || drush_get_context('DRUSH_SIMULATE')) {
  55. drush_log("Downloading " . $filename . " was successful.");
  56. }
  57. else {
  58. drush_op('chdir', $olddir);
  59. return drush_set_error('DRUSH_PM_DOWNLOAD_FAILED', 'Unable to download ' . $filename . ' to ' . $request['base_project_path'] . ' from '. $release['download_link']);
  60. }
  61. // Check Md5 hash.
  62. if (drush_op('md5_file', $filename) != $release['mdhash'] && !drush_get_context('DRUSH_SIMULATE')) {
  63. drush_set_error('DRUSH_PM_FILE_CORRUPT', "File $filename is corrupt (wrong md5 checksum).");
  64. drush_op('unlink', $filename);
  65. return FALSE;
  66. }
  67. else {
  68. drush_log("Md5 checksum of $filename verified.");
  69. }
  70. // Extract the tarball.
  71. $file_list = drush_tarball_extract($filename, $request['base_project_path'], TRUE);
  72. drush_op('unlink', $filename);
  73. drush_op('chdir', $olddir);
  74. // Move untarred directory to project_dir, if distinct.
  75. if (($request['project_type'] == 'core') || (($request['project_type'] == 'profile') && (drush_get_option('variant', 'core') == 'core'))) {
  76. // Obtain the dodgy project_dir for drupal core.
  77. $project_dir = rtrim($file_list[0], DIRECTORY_SEPARATOR);
  78. if ($request['project_dir'] != $project_dir) {
  79. $path = $request['base_project_path'];
  80. drush_move_dir($path . '/'. $project_dir, $path . '/' . $request['project_dir']);
  81. }
  82. }
  83. // Cleanup. Set previous working directory.
  84. drush_op('chdir', $olddir);
  85. return TRUE;
  86. }
  87. /**
  88. * This is an alias of the download function, since they are identical
  89. */
  90. function package_handler_update_project(&$request, $release) {
  91. return package_handler_download_project($request, $release);
  92. }
  93. /**
  94. * Post download action.
  95. *
  96. * This action take place once the project is placed in its final location.
  97. */
  98. function package_handler_post_download($project) {
  99. }