Class: RepoMate::Metafile

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

Overview

Class that can create and delete all metafiles like Packages, Packages.gz, Release and Release.gpg

Instance Method Summary collapse

Constructor Details

#initializeMetafile

Init



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

def initialize
  @repository = Repository.new
end

Instance Method Details

#allObject

Returns a list of all existing metafiles as array



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/repomate/metafile.rb', line 21

def all
  rootdir  = Cfg.rootdir
  dirlist  = ["#{rootdir}/*/*", "#{rootdir}/*/*/*/*"]
  filelist = ["Packages", "Packages.gz", "Release", "Release.gpg" ]
  files = []

  dirlist.each do |dirs|
    Dir.glob(dirs).each do |dir|
      filelist.each do |file|
        fullname = File.join(dir, file)
        files << fullname if File.exists? fullname
      end
    end
  end
  return files
end

#createObject

Creates all metafiles



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/repomate/metafile.rb', line 44

def create
  puts "Creating Metafiles..."
  
  destroy
  create_packages

  if Cfg.gpg
    if Cfg.gpg_password.nil? || Cfg.gpg_email.nil?
      puts "Configure password and email for GPG!"
      exit 1
    else
      create_release
    end
  end
end

#create_packagesObject

Create Packages* files



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
# File 'lib/repomate/metafile.rb', line 61

def create_packages
  source_category = "dists"

  packages_template = ERB.new File.new(File.join(File.dirname(__FILE__), "templates/packages.erb")).read, nil, "%"
  
  Architecture.dataset(source_category).each do |entry|
    
    source  = Architecture.new(entry[:architecture], entry[:component], entry[:suitename], source_category)
    source.files.each do |fullname|
      package = Package.new(fullname, entry[:suitename], entry[:component])

      checksums = package.load_checksums

      packagesfile = File.join(entry[:fullpath], "Packages")
      size         = File.size(fullname)
      path         = File.join("dists", entry[:suitename], entry[:component], entry[:architecture_dir], package.newbasename)

      File.open(packagesfile, 'a') do |file|
        package.controlfile.each { |key, value| file.puts "#{key}: #{value}" unless value.to_s.empty? }
        file.puts packages_template.result(binding)
      end
      raise "Could not gzip" unless system "gzip -9 -c #{packagesfile} > #{packagesfile}.gz"
    end
  end
end

#create_releaseObject

Create Release* files



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
119
120
121
122
123
124
125
126
127
# File 'lib/repomate/metafile.rb', line 88

def create_release
  source_category = "dists"
  suites          = []
  archrelease_template  = ERB.new File.new(File.join(File.dirname(__FILE__), "templates/archrelease.erb")).read, nil, "%"
  suiterelease_template = ERB.new File.new(File.join(File.dirname(__FILE__), "templates/suiterelease.erb")).read, nil, "%"

  now = Time.new.strftime("%a, %d %b %Y %H:%M:%S %Z")

  Architecture.dataset(source_category).each do |entry|
    releasefile = File.join(entry[:fullpath], "Release")

    suites << entry[:suitename] unless suites.include?(entry[:suitename])

    File.open(releasefile, 'w') { |file| file.puts archrelease_template.result(binding) }
  end

  suites.each do |suite|
    architecture = []
    component    = []

    Architecture.dataset(source_category).each do |entry|
      if entry[:suitename].eql?(suite)
        architecture << entry[:architecture] unless architecture.include?(entry[:architecture])
        component << entry[:component] unless component.include?(entry[:component])
      end
    end

    releasefile = File.join(Cfg.rootdir, source_category, suite, "Release")
    File.open(releasefile, 'w') { |file| file.puts suiterelease_template.result(binding).gsub(/^\s+\n|^\n|^\s{3}/, '') }
    
    begin
      sign(releasefile)
    rescue
      destroy
      create_packages
      puts "GPG email/password incorrect or gpg is not installed!"
      return
    end
  end
end

#destroyObject

Deletes all existing metafiles



39
40
41
# File 'lib/repomate/metafile.rb', line 39

def destroy
  all.each { |file| FileUtils.rm_f(file) }
end

#sign(file) ⇒ Object

Sign a file



130
131
132
133
134
135
# File 'lib/repomate/metafile.rb', line 130

def sign(file)
  crypto = GPGME::Crypto.new :password => Cfg.gpg_password
  outfile = "#{file}.gpg"
  output = File.open(outfile, 'w')
  crypto.sign File.open(file, 'r'), :symmetric => false, :output => output, :signer => Cfg.gpg_email, :mode => GPGME::SIG_MODE_DETACH
end