Class: Debci::Data::Export

Inherits:
Object
  • Object
show all
Defined in:
lib/debci/data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tarball) ⇒ Export

Returns a new instance of Export.



20
21
22
23
24
# File 'lib/debci/data.rb', line 20

def initialize(tarball)
  @tarball = tarball
  @root = Debci.config.data_basedir
  @entries = []
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



18
19
20
# File 'lib/debci/data.rb', line 18

def entries
  @entries
end

#rootObject (readonly)

Returns the value of attribute root.



18
19
20
# File 'lib/debci/data.rb', line 18

def root
  @root
end

#tarballObject (readonly)

Returns the value of attribute tarball.



18
19
20
# File 'lib/debci/data.rb', line 18

def tarball
  @tarball
end

Instance Method Details

#add(pkgname) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/debci/data.rb', line 26

def add(pkgname)
  pkg = Debci::Package.find_by!(name: pkgname)

  # add data files
  suites = Debci.config.suite_list
  architectures = Debci.config.arch_list
  glob = "{packages,autopkgtest}/{#{suites.join(',')}}/{#{architectures.join(',')}}/#{pkg.prefix}/#{pkg.name}"
  Dir.chdir(root) do
    Dir[glob].each do |d|
      entries << d
    end
  end

  # add database data
  # FIXME make directory unique
  Dir.chdir(root) do
    FileUtils.mkdir_p('export')
    File.write("export/#{pkg.name}.json", Debci::Job.where(package: pkg).to_json)
  end
  entries << "export/#{pkg.name}.json"
end

#saveObject



48
49
50
51
52
53
54
55
56
# File 'lib/debci/data.rb', line 48

def save
  files_from = Tempfile.new
  files_from.puts(entries.sort)
  files_from.close
  target = File.expand_path(tarball)
  Dir.chdir(root) do
    system('tar', 'caf', target, "--files-from=#{files_from.path}")
  end
end