File: fix-dates.rb

package info (click to toggle)
debci 0.10.3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 904 kB
  • ctags: 310
  • sloc: sh: 1,662; ruby: 1,007; makefile: 35
file content (33 lines) | stat: -rw-r--r-- 805 bytes parent folder | download
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
require 'json'

def fix(entry)
  if entry['date'] =~ /^[0-9][0-9]:[0-9][0-9]:[0-9][0-9]$/ && entry['run_id']
    entry['date'] = entry['run_id'].sub(/([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])_([0-9][0-9])([0-9][0-9])([0-9][0-9])/, '\1-\2-\3 \4:\5:\6')
  end
end

to_fix = IO.popen(['grep', '-rl', '"date": "[0-9][0-9]:[0-9][0-9]:[0-9][0-9]"', 'data/packages/'])
to_fix.each_line do |line|
  file = line.strip

  begin
    data = JSON.load(File.read(file))
  rescue JSON::ParserError
    puts "Could't parse JSON in #{file}, please fix manually"
    next
  end

  if File.basename(file) == 'history.json'
    data.each do |entry|
      fix(entry)
    end
  else
    fix(data)
  end

  File.open(file, 'w') do |f|
    f.write(JSON.pretty_generate(data))
  end
end

system('./bin/debci generate-index')