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