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



22
23
24
25
26
27
# File 'lib/debci/data.rb', line 22

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

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries



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

def entries
  @entries
end

#repoObject (readonly)

Returns the value of attribute repo



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

def repo
  @repo
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



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

def tarball
  @tarball
end

Instance Method Details

#add(pkgname) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/debci/data.rb', line 29

def add(pkgname)
  pkg = @repo.find_package(pkgname)

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

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

#saveObject



53
54
55
56
57
58
59
60
61
# File 'lib/debci/data.rb', line 53

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