Class: RepoMate::Component

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

Overview

Class for the component layer of the directory structure

Class Method Summary collapse

Instance Method Summary collapse

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

.allObject

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

.allowedObject

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

#createObject

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

#destroyObject

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

#directoryObject

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

Returns:

  • (Boolean)


25
26
27
# File 'lib/repomate/component.rb', line 25

def exist?
  Dir.exist?(directory)
end

#filesObject

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)

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

#nameObject

Returns the given architecture name (eg. main, contrib, non-free)



15
16
17
# File 'lib/repomate/component.rb', line 15

def name
  @component
end