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 ascending Description
package_handler_validate Validate this package handler can run.
package_handler_update_project Update a project.
package_handler_post_download Post download action.
package_handler_download_project Download a project.

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. $variant = drush_get_option('variant', 'full');
  38. foreach ($release['files'] as $file) {
  39. if ($file['variant'] == $variant && $file['archive_type'] == 'tar.gz') {
  40. $release = array_merge($release, $file);
  41. break;
  42. }
  43. }
  44. }
  45. // Add <date> to download link, so it is part of the cache key. Dev snapshots can then be cached forever.
  46. $download_link = $release['download_link'];
  47. if (strpos($release['download_link'], '-dev') !== FALSE) {
  48. $download_link .= '?date=' . $release['date'];
  49. }
  50. // Cache for a year by default.
  51. $cache_duration = (drush_get_option('cache', TRUE)) ? 86400*365 : 0;
  52. // Prepare download path. On Windows file name cannot contain '?'.
  53. // See http://drupal.org/node/1782444
  54. $filename = str_replace('?', '_', basename($download_link));
  55. $download_path = drush_tempdir() . '/' . $filename;
  56. // Download the tarball.
  57. $download_path = drush_download_file($download_link, $download_path, $cache_duration);
  58. if ($download_path || drush_get_context('DRUSH_SIMULATE')) {
  59. drush_log(dt('Downloading !filename was successful.', array('!filename' => $filename)));
  60. }
  61. else {
  62. return drush_set_error('DRUSH_PM_DOWNLOAD_FAILED', dt('Unable to download !project to !path from !url.', array('!project' => $request['name'], '!path' => $download_path, '!url' => $download_link)));
  63. }
  64. // Check Md5 hash.
  65. if (!drush_get_option('no-md5')) {
  66. if (drush_op('md5_file', $download_path) != $release['mdhash'] && !drush_get_context('DRUSH_SIMULATE')) {
  67. drush_delete_dir(drush_download_file_name($download_link, TRUE));
  68. return drush_set_error('DRUSH_PM_FILE_CORRUPT', dt('File !filename is corrupt (wrong md5 checksum).', array('!filename' => $filename)));
  69. }
  70. else {
  71. drush_log(dt('Md5 checksum of !filename verified.', array('!filename' => $filename)));
  72. }
  73. }
  74. // Extract the tarball in place and return the full path to the untarred directory.
  75. $download_base = dirname($download_path);
  76. $tar_file_list = drush_tarball_extract($download_path, $download_base, TRUE);
  77. $tar_directory = drush_trim_path($tar_file_list[0]);
  78. return $download_base . '/' . $tar_directory;
  79. }
  80. /**
  81. * Update a project.
  82. */
  83. function package_handler_update_project(&$request, $release) {
  84. $download_path = package_handler_download_project($request, $release);
  85. if ($download_path) {
  86. return drush_move_dir($download_path, $request['full_project_path']);
  87. }
  88. }
  89. /**
  90. * Post download action.
  91. *
  92. * This action take place once the project is placed in its final location.
  93. */
  94. function package_handler_post_download($project) {
  95. }