File: debci-enqueue

package info (click to toggle)
debci 3.13
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,656 kB
  • sloc: ruby: 6,516; sh: 2,437; javascript: 100; makefile: 92; perl: 11
file content (84 lines) | stat: -rwxr-xr-x 1,990 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/ruby

require 'optparse'

require 'debci'
require 'debci/job'

# defaults
trigger = nil
extra_apt_sources = []
pin_packages = []
run_id = nil
requestor = ENV['USER'] || 'nobody'
arch = Debci.config.arch
suite = Debci.config.suite
priority = 5

# parse command line
optparse = OptionParser.new do |opts|
  opts.banner = 'Usage: debci enqueue [OPTIONS] PKG [PKG ...]'
  opts.separator 'Options:'

  opts.on('-s', '--suite SUITE', 'sets the suite to test') do |s|
    suite = s
  end

  opts.on('-a', '--arch ARCH', 'sets architecture to test') do |a|
    arch = a
  end

  opts.on('-b', '--backend BACKEND', 'sets the test backend') do |b|
    Debci.config.backend = b
  end

  opts.on('-t', '--trigger TRIGGER', 'associate TRIGGER as the trigger for this test run') do |t|
    trigger = t
  end

  opts.on('-e', '--extra-apt-sources ', Array, 'comma-separated list of extra apt sources') do |e|
    extra_apt_sources = e
  end

  opts.on('-p', '--pin-packages PIN', 'sets package pinning for the test') do |p|
    pin_suite, pin_pkg = p.split('=')
    pin_packages << [pin_pkg, pin_suite]
  end

  opts.on('-r', '--requestor REQUESTOR', 'sets the test requestor') do |r|
    requestor = r
  end

  opts.on('-P', '--priority N', 'sets priority for the test (0-10)') do |p|
    priority = Integer(p)
    unless (0..10).cover?(priority)
      warn 'E: priority must be a number between 0 and 10'
      exit 1
    end
  end

  opts.on('-i', '--run-id RUNID') do |id|
    run_id = id
  end
end
optparse.parse!

user = Debci::User.find_or_create_by!(username: requestor)

ARGV.each do |pkg|
  package = Debci::Package.find_or_create_by!(name: pkg)
  job = Debci::Job.new(
    package: package,
    arch: arch,
    suite: suite,
    requestor: user,
    status: nil,
    trigger: trigger,
    extra_apt_sources: extra_apt_sources,
    pin_packages: pin_packages,
  )
  job.run_id = run_id if run_id
  job.save!
  job.enqueue(priority)
  Debci.log "#{pkg} #{suite}/#{arch} requested"
end