Class: RepoMate::Architecture

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

Overview

Class for the architecture layer of the directory structure

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(architecture, component, suitename, category) ⇒ Architecture

Init



8
9
10
11
12
13
# File 'lib/repomate/architecture.rb', line 8

def initialize(architecture, component, suitename, category)
  @architecture = architecture
  @component    = component
  @suitename    = suitename
  @category     = category
end

Class Method Details

.allObject

Returns all directories without @rootdir



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/repomate/architecture.rb', line 85

def self.all
  components  = Component.all
  dirs        = []
  rootdir     = Cfg.rootdir
  components.each do |component|
    architectures = Dir.glob(File.join(rootdir, component, "*"))
    architectures.each do |architecture|
      dirs.push architecture.gsub(/#{rootdir}\//, '') if File.directory? architecture
    end
  end
  return dirs
end

.allowedObject

Gets all configured architectures



99
100
101
# File 'lib/repomate/architecture.rb', line 99

def self.allowed
  Cfg.architectures.uniq
end

.dataset(category = nil) ⇒ Object

Returns a dataset including the name of the architecture and the fullpath recursive through all lower layers



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/repomate/architecture.rb', line 64

def self.dataset(category=nil)
  data   = []
  self.all.each do |entry|
    parts = entry.split(/\//)
    unless parts.length < 4
      next unless parts[0].eql?(category) || category.eql?("all")
      architecture = parts[3].split(/-/)
      data << {
        :category         => parts[0],
        :suitename        => parts[1],
        :component        => parts[2],
        :architecture_dir => parts[3],
        :architecture     => architecture[1],
        :fullpath         => File.join(Cfg.rootdir, entry)
      }
    end
  end
  data
end

Instance Method Details

#createObject

Creates the directory strcuture of the architecture including all lower layers



49
50
51
# File 'lib/repomate/architecture.rb', line 49

def create
  FileUtils.mkdir_p(directory) unless exist?
end

#destroyObject

Deletes the architecture directory including all lower layers



54
55
56
# File 'lib/repomate/architecture.rb', line 54

def destroy
  FileUtils.rm_r(directory) if exist?
end

#directoryObject

Returns the directory strcuture of the architecture including all lower layers



21
22
23
# File 'lib/repomate/architecture.rb', line 21

def directory
  File.join(Cfg.rootdir, @category, @suitename, @component, "binary-#{name}")
end

#exist?Boolean

Checks if the architecture directory exists

Returns:

  • (Boolean)


26
27
28
# File 'lib/repomate/architecture.rb', line 26

def exist?
  Dir.exist?(directory)
end

#filesObject

Returns a list of all debian files in the architecture directory



59
60
61
# File 'lib/repomate/architecture.rb', line 59

def files
  Dir.glob(File.join(directory, "*.deb"))
end

#is_allowed?Boolean

Checks if the architecture is allowed (See: configurationfile)

Returns:

  • (Boolean)


31
32
33
# File 'lib/repomate/architecture.rb', line 31

def is_allowed?
  self.allowed.include?(@architecture)
end

#is_unused?(dir) ⇒ Boolean

Checks if directory is unused

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
45
46
# File 'lib/repomate/architecture.rb', line 36

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. all, amd64)



16
17
18
# File 'lib/repomate/architecture.rb', line 16

def name
  @architecture
end