Class: Debci::Data::Import
- Inherits:
-
Object
- Object
- Debci::Data::Import
- Defined in:
- lib/debci/data.rb
Instance Attribute Summary collapse
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#tarball ⇒ Object
readonly
Returns the value of attribute tarball.
Instance Method Summary collapse
- #import! ⇒ Object
-
#initialize(tarball) ⇒ Import
constructor
A new instance of Import.
- #load_job(data) ⇒ Object
- #update_html(pkgs) ⇒ Object
Constructor Details
#initialize(tarball) ⇒ Import
Returns a new instance of Import.
71 72 73 74 |
# File 'lib/debci/data.rb', line 71 def initialize(tarball) @repo = Debci::Repository.new @tarball = tarball end |
Instance Attribute Details
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
69 70 71 |
# File 'lib/debci/data.rb', line 69 def repo @repo end |
#tarball ⇒ Object (readonly)
Returns the value of attribute tarball.
68 69 70 |
# File 'lib/debci/data.rb', line 68 def tarball @tarball end |
Instance Method Details
#import! ⇒ Object
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/debci/data.rb', line 76 def import! pkgs = Set.new Dir.mktmpdir do |tmpdir| system('tar', 'xaf', tarball, '-C', tmpdir) Dir.chdir(tmpdir) do mapping = {} Dir['export/*.json'].each do |json| jobs = JSON.parse(File.read(json)) jobs.each do |data| # load job to database orig_run_id = data.delete('run_id') job = load_job(data) pkgs.add(job.package) mapping[orig_run_id] = job.run_id puts"# loaded job: #{orig_run_id} -> #{job.run_id}" if orig_run_id != job.run_id # rename files to match database to_rename = Dir["autopkgtest/#{job.suite}/#{job.arch}/*/#{job.package}/#{orig_run_id}"] to_rename += Dir["packages/#{job.suite}/#{job.arch}/*/#{job.package}/#{orig_run_id}.*"] to_rename.each do |src| dest = src.sub("/#{orig_run_id}", "/#{job.run_id}") if File.basename(dest) =~ /\.json$/ # rewrite run_id File.open(dest, 'w') do |f| f.write(JSON.pretty_generate(data.merge({"run_id" => job.run_id.to_s}))) FileUtils.rm_f(src) puts "# rewrite #{src} -> #{dest}" end else puts "mv #{src} #{dest}" FileUtils.mv src, dest end end end end end Dir['packages/*/*/*/*/history.json'].each do |history| data = JSON.parse(File.read(history)) data.each do |entry| old_id = entry['run_id'].to_i new_id = mapping[old_id] if new_id entry['run_id'] = new_id end end File.open(history, 'w') do |f| f.write(JSON.pretty_generate(data)) end puts "# rewrite #{history}" end end puts('# copying data files ...') cmd = ['rsync', '-apq', '--exclude=/export', tmpdir + '/', repo.path + '/'] puts cmd.join(' ') system(*cmd) end update_html(pkgs.to_a) end |