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