Class: Debci::HTML

Inherits:
Object
  • Object
show all
Includes:
HTMLHelpers, ERB::Util
Defined in:
lib/debci/html.rb,
lib/debci/html_cli.rb

Defined Under Namespace

Classes: Autopkgtest, CLI, Feed, JSON, PackageJSON, Rooted

Constant Summary

Constants included from HTMLHelpers

Debci::HTMLHelpers::ICONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HTMLHelpers

#filesize, #icon

Constructor Details

#initialize(root_directory = Debci.config.html_dir) ⇒ HTML

Returns a new instance of HTML.



241
242
243
244
245
246
247
248
# File 'lib/debci/html.rb', line 241

def initialize(root_directory=Debci.config.html_dir)
  @root_directory = root_directory
  @repository = Debci::Repository.new
  @package_prefixes = @repository.prefixes

  @head = read_config_file('head.html')
  @footer = read_config_file('footer.html')
end

Instance Attribute Details

#root_directoryObject (readonly)

Returns the value of attribute root_directory.



239
240
241
# File 'lib/debci/html.rb', line 239

def root_directory
  @root_directory
end

Class Method Details

.updateObject



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
# File 'lib/debci/html.rb', line 20

def update
  html = Debci::HTML.new
  feed = Debci::HTML::Feed.new

  Debci.config.suite_list.each do |suite|
    Debci.config.arch_list.each do |arch|
      json = Debci::HTML::JSON.new(suite, arch)
      json.status
      json.history
      json.packages
    end
  end

  feed.global

  html.index('index.html')
  html.obsolete_packages_page('packages/index.html')
  html.status('status/index.html')
  html.status_alerts('status/alerts/index.html')
  html.status_slow('status/slow/index.html')
  html.status_pending_jobs('status/pending')
  html.status_failing('status/failing')
  html.blacklist('status/blacklist/index.html')
  html.platform_specific_issues('status/platform-specific-issues')
end

.update_package(pkg, suite = nil, arch = nil) ⇒ Object



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
# File 'lib/debci/html.rb', line 46

def update_package(pkg, suite = nil, arch = nil)
  html = new
  pkgjson = Debci::HTML::PackageJSON.new
  autopkgtest = Debci::HTML::Autopkgtest.new
  feed = Debci::HTML::Feed.new
  repository = Debci::Repository.new
  package = Debci::Package.new(pkg, repository)

  suites = suite && [suite] || Debci.config.suite_list
  archs = arch && [arch] || Debci.config.arch_list
  suites.each do |s|
    archs.each do |a|
      pkgjson.history(package, s, a)
      pkgjson.latest(package, s, a)
      autopkgtest.link_latest(package, s, a)
      html.history(package, s, a)
    end
  end

  feed.package(package)

  # reload data from disk
  # #
  # FIXME this should not be necessary but it fixes a design flaw:
  # Repository reads from disk, but HTML writes new data based on it.
  html = new
  repository = Debci::Repository.new
  package = Debci::Package.new(pkg, repository)

  html.package(package)
  html.prefix(package.prefix)
end

Instance Method Details

#blacklist(filename) ⇒ Object



314
315
316
317
# File 'lib/debci/html.rb', line 314

def blacklist(filename)
  @status_nav = load_template(:status_nav)
  expand_template(:blacklist, filename)
end

#expand_url(url, suite) ⇒ Object

expand { SUITE } macro in URLs



340
341
342
# File 'lib/debci/html.rb', line 340

def expand_url(url, suite)
  url && url.gsub('{SUITE}', suite)
end

#history(package, suite, architecture) ⇒ Object



344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/debci/html.rb', line 344

def history(package, suite, architecture)
  @package = package
  @suite = suite
  @architecture = architecture
  @packages_dir = 'data/packages'
  @package_dir = File.join(suite, architecture, package.prefix, package.name)
  @site_url = expand_url(Debci.config.url_base, @suite)
  @artifacts_url_base = expand_url(Debci.config.artifacts_url_base, @suite)
  @moretitle = "#{package.name}/#{suite}/#{architecture}"
  history = package.history(@suite, @architecture)
  @latest = history && history.first
  @history = package.history(@suite, @architecture)
  @latest = @history && @history.first
  @package_links = load_template(:package_links)

  filename = "packages/#{package.prefix}/#{package.name}/#{suite}/#{architecture}/index.html"
  expand_template(:history, filename)
end

#index(filename) ⇒ Object



250
251
252
253
# File 'lib/debci/html.rb', line 250

def index(filename)
  @news = @repository.global_news
  expand_template(:index, filename)
end

#obsolete_packages_page(filename) ⇒ Object



335
336
337
# File 'lib/debci/html.rb', line 335

def obsolete_packages_page(filename)
  expand_template(:packages, filename)
end

#package(package) ⇒ Object



319
320
321
322
323
324
325
326
# File 'lib/debci/html.rb', line 319

def package(package)
  @package = package
  @moretitle = package.name
  @package_links = load_template(:package_links)

  filename = "packages/#{package.prefix}/#{package.name}/index.html"
  expand_template(:package, filename)
end

#platform_specific_issues(dirname) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/debci/html.rb', line 299

def platform_specific_issues(dirname)
  @status_nav = load_template(:status_nav)

  @filters = {
    "#{dirname}": ["All", -1],
    "#{dirname}/last_thirty_days": ["Last 30 Days", 30],
    "#{dirname}/last_one_eighty_days": ["Last 180 Days", 180],
    "#{dirname}/last_year": ["Last Year", 365]
  }

  @filters.each do |target, filter|
    generate_platform_specific_issues(target, filter)
  end
end

#prefix(prefix) ⇒ Object



328
329
330
331
332
333
# File 'lib/debci/html.rb', line 328

def prefix(prefix)
  @prefix = prefix
  @moretitle = prefix
  filename = "packages/#{prefix}/index.html"
  expand_template(:packagelist, filename)
end

#status(filename) ⇒ Object



255
256
257
258
# File 'lib/debci/html.rb', line 255

def status(filename)
  @status_nav = load_template(:status_nav)
  expand_template(:status, filename)
end

#status_alerts(filename) ⇒ Object



260
261
262
263
264
265
266
# File 'lib/debci/html.rb', line 260

def status_alerts(filename)
  # Packages with atleast one visible tmpfail status
  @tmpfail = @repository.tmpfail_packages.select { |package| package.tmpfail.any?(&:visible?) }

  @alert_number = @tmpfail.length
  expand_template(:status_alerts, filename)
end

#status_failing(dirname) ⇒ Object



286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/debci/html.rb', line 286

def status_failing(dirname)
  @status_nav = load_template(:status_nav)

  packages = @repository.failing_packages
  @packages_per_page = Debci.config.failing_packages_per_page.to_i

  generate_status_failing(dirname, packages)

  @repository.suites.map do |suite|
    generate_status_failing(dirname, packages, suite)
  end
end

#status_pending_jobs(dirname) ⇒ Object



273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/debci/html.rb', line 273

def status_pending_jobs(dirname)
  @status_nav = load_template(:status_nav)
  @status_per_page = Debci.config.pending_status_per_page.to_i
  @pending_jobs = Debci::Job.pending.length

  @suites_jobs = Hash[@repository.suites.map do |x|
    [x, Debci::Job.pending.where(suite: x).count]
  end
  ]
  generate_status_pending(dirname, nil) # For 'All suites'
  @suites_jobs.each_key { |suite| generate_status_pending(dirname, suite) }
end

#status_slow(filename) ⇒ Object



268
269
270
271
# File 'lib/debci/html.rb', line 268

def status_slow(filename)
  @slow = @repository.slow_statuses.select(&:visible?)
  expand_template(:status_slow, filename)
end