Class: Debci::Data::Import
- Inherits:
-
Object
- Object
- Debci::Data::Import
- Defined in:
- lib/debci/data.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#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
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
61 62 63 |
# File 'lib/debci/data.rb', line 61 def root @root end |
#tarball ⇒ Object (readonly)
Returns the value of attribute tarball.
61 62 63 |
# File 'lib/debci/data.rb', line 61 def tarball @tarball end |
Instance Method Details
#import! ⇒ Object
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 |
# File 'lib/debci/data.rb', line 68 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}" rename_files(job, orig_run_id) 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.write(history, JSON.pretty_generate(data)) puts "# rewrite #{history}" end end puts('# copying data files ...') cmd = ['rsync', '-apq', '--exclude=/export', "#{tmpdir}/", "#{root}/"] puts cmd.join(' ') system(*cmd) end update_html(pkgs.to_a) end |
#load_job(data) ⇒ Object
111 112 113 114 115 116 117 118 119 |
# File 'lib/debci/data.rb', line 111 def load_job(data) job = Debci::Job.new job.package = Debci::Package.find_or_create_by!(name: data.delete("package")) data.each do |attr, value| job[attr] = value if job.attributes.key?(attr) end job.save! job end |