Class: Debci::Data::Import

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tarball) ⇒ Import

Returns a new instance of Import



68
69
70
71
# File 'lib/debci/data.rb', line 68

def initialize(tarball)
  @repo = Debci::Repository.new
  @tarball = tarball
end

Instance Attribute Details

#repoObject (readonly)

Returns the value of attribute repo



66
67
68
# File 'lib/debci/data.rb', line 66

def repo
  @repo
end

#tarballObject (readonly)

Returns the value of attribute tarball



65
66
67
# File 'lib/debci/data.rb', line 65

def tarball
  @tarball
end

Instance Method Details

#import!Object



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
110
111
112
113
114
115
116
117
# File 'lib/debci/data.rb', line 73

def import!
  pkgs = Set.new

  Dir.mktmpdir do |tmpdir|
    Archive::Tar::Minitar.unpack(tarball, tmpdir)
    Dir.chdir(tmpdir) do
      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 = Debci::Job.create!(data)

          pkgs.add(job.package)

          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
    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

#update_html(pkgs) ⇒ Object



119
120
121
122
123
124
125
126
# File 'lib/debci/data.rb', line 119

def update_html(pkgs)
  if !pkgs.empty?
    puts '# updating HTML pages ...'
    cmd = ['debci-generate-html'] + pkgs
    puts cmd.join(' ')
    system(*cmd)
  end
end