[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/getid3/ -> getid3.drush.inc (source)

   1  <?php
   2  // $Id: getid3.drush.inc,v 1.1.2.2 2010/07/25 03:40:32 drewish Exp $
   3  
   4  /**
   5   * @file
   6   * Drush integration for getID3.
   7   */
   8  
   9  /**
  10   * Implements hook_drush_command().
  11   */
  12  function getid3_drush_command() {
  13    $items['getid3-download'] = array(
  14      'callback' => 'drush_getid3_download',
  15      'description' => dt('Downloads the required getID3 library from SourceForge.net.'),
  16      'arguments' => array(
  17        'path' => dt('Optional. A path to the download folder. If omitted Drush will use the default location (sites/all/libraries/getid3).'),
  18      ),
  19    );
  20    return $items;
  21  }
  22  
  23  /**
  24   * Implements drush_MODULE_pre_COMMAND().
  25   * 
  26   * This automatically downloads the library when the module is being installed.
  27   */
  28  function drush_getid3_pre_pm_enable() {
  29    $modules = func_get_args();
  30    if (in_array('getid3', $modules)) {
  31      drush_getid3_download();
  32    }
  33  }
  34  /**
  35   * Download the getID3 library from SourceForge.
  36   */
  37  function drush_getid3_download() {
  38    $args = func_get_args();
  39    if (!empty($args[0])) {
  40      $library_path = $args[0];
  41    }
  42    else {
  43      $library_path = drush_get_context('DRUSH_DRUPAL_ROOT') . '/sites/all/libraries/getid3';
  44    }
  45  
  46    $url = "http://downloads.sourceforge.net/project/getid3/getID3%28%29%201.x/1.7.9/getid3-1.7.9.zip";
  47    $md5 = "76fe6d1213b20d59ae8a5c389d3a44e1";
  48  
  49    // Create the directory.
  50    if (!drush_shell_exec('mkdir -p  %s', $library_path)) {
  51      return drush_set_error('GETID3_MKDIR', dt('Drush was unable to create the getID3 directory at @path.', array('@path' => $library_path)));
  52    }
  53    $zipfile_path = $library_path ."/getid3-1.7.9.zip";
  54    drush_register_file_for_deletion($zipfile_path);
  55    // Download the file.
  56    if (!drush_shell_exec('wget -O %s %s', $zipfile_path, $url)) {
  57      return drush_set_error('GETID3_FETCH', dt('Drush was unable to download the getID3 library to @path.', array('@path' => $zipfile_path)));
  58    }
  59    // Check MD5 hash.
  60    if (md5_file($zipfile_path) != $md5) {
  61      return drush_set_error('GETID3_MD5', dt('The downloaded file @path was corrupted. Expected MD5 checksum: @md5.', array('@path' => $zipfile_path, '@md5' => $md5)));
  62    }
  63    // Unzip it the file -- using the "update" option to avoid being prompted
  64    // about overwriting files.
  65    if (!drush_shell_exec('unzip -u %s -d %s', $zipfile_path, $library_path)) {
  66      return drush_set_error('GETID3_UNZIP', dt('Drush was unable to unzip the archive @path.', array('@path' => $zipfile_path)));
  67    }
  68    // Delete the demos. They're a security risk.
  69    $demos_path = $library_path . '/demos';
  70    if (!drush_shell_exec('rm -r %s', $demos_path)) {
  71      return drush_set_error('GETID3_RM', dt("Drush was unable to remove getID3's demos directory. You should do so manually.", array('@path' => $demos_path)));
  72    }
  73    drush_log(dt('getID3 has been installed to @path.', array('@path' => $library_path)), 'success');
  74  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7