Class: RepoMate::Component
- Inherits:
-
Object
- Object
- RepoMate::Component
- Defined in:
- lib/repomate/component.rb
Overview
Class for the component layer of the directory structure
Class Method Summary collapse
-
.all ⇒ Object
Returns all directories without @rootdir.
-
.allowed ⇒ Object
Gets all configured architectures.
-
.dataset(category = nil) ⇒ Object
Returns a dataset including the name of the component, the fullpath recursive through all lower layers.
Instance Method Summary collapse
-
#create ⇒ Object
Creates the directory strcuture of the component including all lower layers.
-
#destroy ⇒ Object
Deletes the components directory including all lower layers.
-
#directory ⇒ Object
Returns the directory strcuture of the component including all lower layers.
-
#exist? ⇒ Boolean
Checks if the component directory exists.
-
#files ⇒ Object
Returns a list of all debian files in the component directory.
-
#initialize(component, suitename, category) ⇒ Component
constructor
Init.
-
#is_allowed? ⇒ Boolean
Checks if the component is allowed (See: configurationfile).
-
#is_unused?(dir) ⇒ Boolean
Checks if directory is unused.
-
#name ⇒ Object
Returns the given architecture name (eg. main, contrib, non-free).
Constructor Details
#initialize(component, suitename, category) ⇒ Component
Init
8 9 10 11 12 |
# File 'lib/repomate/component.rb', line 8 def initialize(component, suitename, category) @component = component @suitename = suitename @category = category end |
Class Method Details
.all ⇒ Object
Returns all directories without @rootdir
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/repomate/component.rb', line 81 def self.all config = Configuration.new suites = Suite.all dirs = [] rootdir = Cfg.rootdir suites.each do |suite| components = Dir.glob(File.join(rootdir, suite, "*")) components.each do |component| dirs.push component.gsub(/#{rootdir}\//, '') if File.directory? component end end return dirs end |
.allowed ⇒ Object
Gets all configured architectures
96 97 98 |
# File 'lib/repomate/component.rb', line 96 def self.allowed Cfg.components.uniq end |
.dataset(category = nil) ⇒ Object
Returns a dataset including the name of the component, the fullpath recursive through all lower layers
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/repomate/component.rb', line 63 def self.dataset(category=nil) data = [] self.all.each do |entry| parts = entry.split(/\//) unless parts.length < 3 next unless parts[0].eql?(category) || category.eql?("all") data << { :category => parts[0], :suitename => parts[1], :component => parts[2], :fullpath => File.join(Cfg.rootdir, entry) } end end data end |
Instance Method Details
#create ⇒ Object
Creates the directory strcuture of the component including all lower layers
48 49 50 |
# File 'lib/repomate/component.rb', line 48 def create FileUtils.mkdir_p(directory) unless exist? end |
#destroy ⇒ Object
Deletes the components directory including all lower layers
53 54 55 |
# File 'lib/repomate/component.rb', line 53 def destroy FileUtils.rm_r(directory) if exist? end |
#directory ⇒ Object
Returns the directory strcuture of the component including all lower layers
20 21 22 |
# File 'lib/repomate/component.rb', line 20 def directory File.join(Cfg.rootdir, @category, @suitename, @component) end |
#exist? ⇒ Boolean
Checks if the component directory exists
25 26 27 |
# File 'lib/repomate/component.rb', line 25 def exist? Dir.exist?(directory) end |
#files ⇒ Object
Returns a list of all debian files in the component directory
58 59 60 |
# File 'lib/repomate/component.rb', line 58 def files Dir.glob(File.join(directory, "*.deb")) end |
#is_allowed? ⇒ Boolean
Checks if the component is allowed (See: configurationfile)
30 31 32 |
# File 'lib/repomate/component.rb', line 30 def is_allowed? self.allowed.include?(@component) end |
#is_unused?(dir) ⇒ Boolean
Checks if directory is unused
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/repomate/component.rb', line 35 def is_unused?(dir) status = true path = Dir.glob(File.join(dir, "*")) path.each do |dirorfile| status = false if File.directory?(dirorfile) status = false if File.basename(dirorfile) =~ /\.deb$/ end status end |
#name ⇒ Object
Returns the given architecture name (eg. main, contrib, non-free)
15 16 17 |
# File 'lib/repomate/component.rb', line 15 def name @component end |