Class: Drupal::Install
- Inherits:
-
Object
- Object
- Drupal::Install
- Defined in:
- lib/drupal/install.rb
Instance Method Summary collapse
-
#check_core ⇒ Object
Allow users to type ‘core’ instead of ‘drupal install drupal’.
- #debug(message) ⇒ Object
-
#destination_empty? ⇒ Boolean
Check if the destination is empty.
-
#install_project ⇒ Object
Install project.
-
#install_projects ⇒ Object
Install single project or iterate lists.
-
#run(arguments) ⇒ Object
Attempt to download core installation or module.
-
#uri_available?(uri) ⇒ Boolean
Check if a uri is available.
Instance Method Details
#check_core ⇒ Object
Allow users to type ‘core’ instead of ‘drupal install drupal’
43 44 45 |
# File 'lib/drupal/install.rb', line 43 def check_core @project = 'drupal' if @project =~ /^core|drupal$/ end |
#debug(message) ⇒ Object
17 18 19 |
# File 'lib/drupal/install.rb', line 17 def debug() puts '... ' + end |
#destination_empty? ⇒ Boolean
Check if the destination is empty.
38 39 40 |
# File 'lib/drupal/install.rb', line 38 def destination_empty? Dir['*'].length == 0 end |
#install_project ⇒ Object
Install project.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/drupal/install.rb', line 53 def install_project debug "Locating #{@project} page" # Locate tarball from project page begin response = Net::HTTP.get_response(URI.parse("http://drupal.org/project/#{@project}")) @markup = response.body # TODO: check 404 debug 'Located the project page' rescue puts 'Failed to request page' end @markup.match /(#{@project}-6(?:.*?)\.gz)/ @tarball = $1 @tarpath = File.("#{@dest}/#{@tarball}") abort "Failed to find Drupal 6 tar of #{@project}" if @tarball.nil? debug "Found tarball #{@tarball}" # Fetch tarball begin response = Net::HTTP.get_response(URI.parse("http://ftp.drupal.org/files/projects/#{@tarball}")) File.open(@tarpath, 'w') do |f| f.write response.body end debug "Copied tarball to #{@tarpath}" rescue abort "Failed to copy remote tarball #{@tarball}" end # Extract tarball @pwd = Dir.getwd Dir.chdir File.dirname(@tarpath) and debug "Changed cwd to #{File.dirname(@tarpath)}" unless @dest == '.' Kernel.system "tar -xf #{@tarpath}" rescue abort "Failed to extract #{@tarpath}" Dir.chdir @pwd and debug "Reverted cwd back to #{@pwd}" unless @dest == '.' # Remove tarball Kernel.system "rm #{@tarpath}" rescue abort "Failed to remove #{@tarpath}" # Installation complete debug "Project installed to #{File.dirname(@tarpath)}" unless @dest == '.' debug 'Installation complete' end |
#install_projects ⇒ Object
Install single project or iterate lists.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/drupal/install.rb', line 22 def install_projects if @project.include? ',' projects = @project.split ',' projects.each do |p| @project = p check_core install_project puts end else check_core install_project end end |
#run(arguments) ⇒ Object
Attempt to download core installation or module.
9 10 11 12 13 14 15 |
# File 'lib/drupal/install.rb', line 9 def run(arguments) @project = arguments[0] @dest = arguments[1] || '.' abort "Destination #{@dest} is not a directory." unless File.directory?(@dest) abort 'Project name required (core | <project>).' if arguments.empty? install_projects end |
#uri_available?(uri) ⇒ Boolean
Check if a uri is available.
48 49 50 |
# File 'lib/drupal/install.rb', line 48 def uri_available?(uri) open(uri) rescue false end |