Class: Melai::CommandHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/melai.rb

Overview

This module is the main module. Creates a class of CommandHandler. Not entirely sure if the code is structured correctly. Might have to rethink module vs class locations, based on inheritance.

Instance Method Summary collapse

Instance Method Details

#create(repositories_path, packages_path, url_root) ⇒ Object

Creates/updates a symlink-based repository structure

Parameters:

  • a (String)

    directory to build into

  • a (String)

    directory containing the source packages



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/melai.rb', line 19

def create(repositories_path, packages_path, url_root)
  puts "Creating a repository at #{repositories_path}."
  ensure_directory(repositories_path)

  # Accumulate a Hash keyed by repository filesystem path
  # whose values are hashes of {:needs_update => bool, 
  # :arch => String, :variant => String }
  repositories = Hash.new

  find_packages(packages_path).each do |package_path|
    (package_path, repositories_path).each do ||
      repository_path = [:repository_path]
      needs_update = ensure_symlink([:symlink_path], [:package_path])

      if repositories.include?(repository_path)
        repositories[repository_path][:needs_update] ||= needs_update
      else
        repositories[repository_path] = {
          :needs_update => needs_update,
          :variant => [:variant],
          :arch => [:arch],
          :repository_path => [:repository_path],
          :repository_prefix => [:repository_prefix]
        }
      end
    end
  end

  # Now we have a Hash of all the repo directories that need updating by a value of 'true'
  repositories.each do |repository_path, |
    next unless [:needs_update]

    repo_template(, repositories_path, url_root)
    (, repositories_path, packages_path)
  end
end

#destroy(repositories_path) ⇒ Object

Destroy the repository directory completely. This is a glorified ‘rm -fr repo/` command, with a simple guard.

Parameters:

  • the (String)

    root of repository directory



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/melai.rb', line 68

def destroy(repositories_path)
  if repositories_path == "/"
    exit_now!("WTF are you trying to do?", 1)
  elsif Dir.exists?(repositories_path)
    puts "Removing the entire #{repositories_path}"
    FileUtils.remove_dir repositories_path
    puts "It's gone!"
  else
    puts "Nothing there... idiot."
  end
end

#list(packages_path) ⇒ Array

List all package files found

Parameters:

  • a (String)

    directory containing the source packages

Returns:

  • (Array)

    an array of filenames



60
61
62
# File 'lib/melai.rb', line 60

def list(packages_path)
  find_packages(packages_path)
end