Class: RepoMate::Base

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

Overview

Class containing the main logic

Instance Method Summary collapse

Constructor Details

#initializeBase

Init



12
13
14
15
16
17
18
19
# File 'lib/repomate/base.rb', line 12

def initialize
  FileUtils.mkdir_p(Cfg.rootdir) unless File.exists?(Cfg.rootdir)

  @repository = Repository.new
  @link       = Link.new
  @checkpoint = Checkpoint.new
  @metafile   = Metafile.new
end

Instance Method Details

#activate(entry) ⇒ Object

Activates a package



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/repomate/base.rb', line 162

def activate(entry)
  link_workload = []

  package        = Package.new(entry[:fullname], entry[:suitename], entry[:component])
  dists          = Architecture.new(package.architecture, entry[:component], entry[:suitename], "dists")
  dists_fullname = File.join(dists.directory, package.basename)

  link_workload << {
    :source_fullname      => entry[:fullname],
    :destination_fullname => dists_fullname,
    :suitename            => package.suitename,
    :component            => package.component,
    :architecture         => package.architecture
  }
  if File.exists?(dists_fullname)
    puts "Package already activated"
  else
    @link.create(link_workload)
    @metafile.create
  end
end

#deactivate(entry, mode) ⇒ Object

Deactivates a package



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/repomate/base.rb', line 185

def deactivate(entry, mode)
  unlink_workload = []

  @repository.categories.each do |category|
    next if mode.eql?("deactivate") && category.eql?("pool")

    path = Dir.glob(File.join(Cfg.rootdir, category, entry[:suitename], entry[:component], "*", entry[:basename]))

    Dir.glob(path).each do |fullname|
      unlink_workload << {
        :destination_fullname => fullname,
        :category             => category,
        :suitename            => entry[:suitename],
        :component            => entry[:component]
      }
    end
  end

  @checkpoint.delete_package(entry) if mode.eql?("remove")
  @link.destroy(unlink_workload)
  @metafile.create
end

#listpackagesObject

Returns a list of packages



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/repomate/base.rb', line 121

def listpackages
  packages = []

  @repository.categories.each do |category|
    Architecture.dataset(category).each do |entry|
      source = Architecture.new(entry[:architecture], entry[:component], entry[:suitename], category)
      source.files.each do |fullname|
        package = Package.new(fullname, entry[:suitename], entry[:component])
        packages << {
          :fullname    => fullname,
          :category    => category,
          :basename    => File.basename(fullname),
          :controlfile => package.controlfile,
          :component   => entry[:component],
          :suitename   => entry[:suitename],
          :architecture => entry[:architecture]
        }
      end
    end
    if category.eql? "stage"
      Component.dataset(category).each do |entry|
        source = Component.new(entry[:component], entry[:suitename], category)
        source.files.each do |fullname|
          package = Package.new(fullname, entry[:suitename], entry[:component])
          packages << {
            :fullname    => fullname,
            :category    => category,
            :basename    => File.basename(fullname),
            :controlfile => package.controlfile,
            :component   => entry[:component],
            :suitename   => entry[:suitename],
            :architecture => "unknown"
          }
        end
      end
    end
  end
  packages
end

#prepare_publishObject

Returns a list of staged packages for cli confirmation packed as array of hashes



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/repomate/base.rb', line 34

def prepare_publish
  workload = []

  source_category      = "stage"
  destination_category = "pool"

  Component.dataset(source_category).each do |entry|
    source = Component.new(entry[:component], entry[:suitename], source_category)
    source.files.each do |fullname|
      package     = Package.new(fullname, entry[:suitename], entry[:component])
      destination = Architecture.new(package.architecture, entry[:component], entry[:suitename], destination_category)

      workload << {
        :source_fullname      => fullname,
        :destination_fullname => File.join(destination.directory, package.newbasename),
        :component            => entry[:component],
        :suitename            => entry[:suitename],
        :architecture         => package.architecture
      }
    end
  end
  
  workload
end

#publish(workload) ⇒ Object

Publish all staged packages. Packages will be moved from stage to pool and linked to dists



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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/repomate/base.rb', line 60

def publish(workload)
  link_workload   = []
  unlink_workload = []

  workload.each do |entry|

    action = true

    @repository.create(entry[:suitename], entry[:component], entry[:architecture])

    package        = Package.new(entry[:source_fullname], entry[:suitename], entry[:component])
    pool           = Architecture.new(package.architecture, entry[:component], entry[:suitename], "pool")
    dists          = Architecture.new(package.architecture, entry[:component], entry[:suitename], "dists")
    pool_fullname  = File.join(pool.directory, package.basename)
    dists_fullname = File.join(dists.directory, package.basename)
    stage_fullname = package.fullname

    Dir.glob("#{pool.directory}/#{package.name}*.deb") do |pool_fullname|
      pool_package = Package.new(pool_fullname, entry[:suitename], entry[:component] )
      if system("#{Cfg.dpkg} --compare-versions #{package.version} gt #{pool_package.version}")
        puts "Package: #{pool_package.newbasename} will be replaced with #{package.newbasename}"
      elsif system("#{Cfg.dpkg} --compare-versions #{package.version} eq #{pool_package.version}")
        puts "Package: #{pool_package.newbasename} already exists with same version"
        action = false
        next
      elsif system("#{Cfg.dpkg} --compare-versions #{package.version} lt #{pool_package.version}")
        puts "Package: #{pool_package.newbasename} already exists with higher version"
        File.unlink(package.fullname)
        action = false
        next
      end
    end

    if action
      link_workload << {
        :source_fullname      => pool_fullname,
        :destination_fullname => dists_fullname,
        :suitename            => package.suitename,
        :component            => package.component,
        :architecture         => package.architecture
      }
                
      Dir.glob("#{dists.directory}/#{package.name}*.deb") do |fullname|
        unlink_workload << {
          :destination_fullname => fullname,
          :suitename            => package.suitename,
          :component            => package.component,
          :category             => 'dists'
        }
      end
      
      FileUtils.move(stage_fullname, pool_fullname) unless File.exists?(pool_fullname)
    end
  end
  
  @link.destroy(unlink_workload) unless unlink_workload.empty?
  @link.create(link_workload) unless link_workload.empty?
  @metafile.create unless link_workload.empty?
end

#stage(workload) ⇒ Object

Add’s a package to the staging area



22
23
24
25
26
27
28
29
30
31
# File 'lib/repomate/base.rb', line 22

def stage(workload)
  workload.each do |entry|
    @repository.create(entry[:suitename], entry[:component])

    package     = Package.new(entry[:package_fullname], entry[:suitename], entry[:component])
    destination = Component.new(entry[:component], entry[:suitename], "stage")

    FileUtils.move(entry[:package_fullname], File.join(destination.directory, package.newbasename))
  end
end