Skip to content

Commit

Permalink
Update rubocop and fix findings
Browse files Browse the repository at this point in the history
  • Loading branch information
m-bucher committed Jun 25, 2024
1 parent cc8dae2 commit ccb700a
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 156 deletions.
20 changes: 12 additions & 8 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 3.3
NewCops: enable


Style/WordArray:
EnforcedStyle: brackets
Expand All @@ -10,6 +12,9 @@ Style/MutableConstant:
Style/MixinUsage:
Enabled: False

Layout/LineLength:
Max: 159

# not my style ;-)
Layout/SpaceAroundEqualsInParameterDefault:
Enabled: False
Expand All @@ -22,16 +27,15 @@ Style/StringLiterals:
Exclude:
- 'Gemfile'

Style/OptionalBooleanParameter:
Enabled: False

# we want that for better
Style/TrailingCommaInHashLiteral:
Enabled: False


Metrics/CyclomaticComplexity:
Max: 20

Metrics/LineLength:
Max: 159
Max: 22

Metrics/ClassLength:
Max: 300
Expand All @@ -43,13 +47,13 @@ Metrics/BlockLength:
Max: 65

Metrics/AbcSize:
Max: 60
Max: 70

Metrics/BlockNesting:
Max: 5

Metrics/PerceivedComplexity:
Max: 20
Max: 22

Style/ClassVars:
Exclude:
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ gem "ruby-xz", "~> 1.0", group: %i[build test]
gem "bzip2-ffi", "~> 1.0", group: %i[build test]

# Added at 2018-09-07 16:41:14 +0200 by markus:
gem "test-unit", "~> 3.2", group: [:test]
gem "test-unit", "~> 3.5", group: [:test]

# Added at 2021-11-12 17:19:23 +0200 by bernhard:
gem 'parallel', '~> 1.20', '< 1.21', group: %i[build test]

# Added at 2018-12-05 19:28:10 +0100 by markus:
group :rubocop, optional: true do
gem "rubocop", "~> 0.61.0"
gem "rubocop", "~> 1.51.0"
end

group :development, optional: true do
Expand Down
25 changes: 15 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,34 @@ GEM
bzip2-ffi (1.1.1)
ffi (~> 1.0)
ffi (1.16.3)
jaro_winkler (1.5.6)
json (2.7.2)
parallel (1.20.1)
parser (3.3.1.0)
ast (~> 2.4.1)
racc
power_assert (2.0.3)
powerpack (0.1.3)
racc (1.7.3)
rainbow (3.1.1)
rubocop (0.61.1)
jaro_winkler (~> 1.5.1)
regexp_parser (2.9.1)
rexml (3.2.6)
rubocop (1.51.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.4.0)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
ruby-debian (0.3.8)
ruby-progressbar (1.13.0)
ruby-xz (1.0.3)
test-unit (3.6.2)
power_assert
unicode-display_width (1.4.1)
unicode-display_width (2.5.0)

PLATFORMS
x86_64-linux
Expand All @@ -37,10 +42,10 @@ DEPENDENCIES
byebug (~> 11.1)
bzip2-ffi (~> 1.0)
parallel (~> 1.20, < 1.21)
rubocop (~> 0.61.0)
rubocop (~> 1.51.0)
ruby-debian (~> 0.3.8)
ruby-xz (~> 1.0)
test-unit (~> 3.2)
test-unit (~> 3.5)

BUNDLED WITH
2.5.9
44 changes: 24 additions & 20 deletions debRelease.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class DebRelease
@@tempdir = '/tmp/errata_parser_cache/debian'

attr_reader :data, :files
attr_accessor :suite, :base_url
attr_accessor :suite, :base_url, :whitelist_arch, :whitelist_comp
attr_writer :release_name
attr_accessor :whitelist_arch, :whitelist_comp
RE_FILES = /^\s*(?<digest>[0-9a-f]+)\s+(?<size>\d+)\s*(?<path>\S.*)$/.freeze

RE_FILES = /^\s*(?<digest>[0-9a-f]+)\s+(?<size>\d+)\s*(?<path>\S.*)$/

def initialize(uri=nil, suite='stable')
init
Expand Down Expand Up @@ -58,7 +58,7 @@ def parse(release_text)
when 'date', 'valid-until'
Time.parse value
when 'architectures', 'components'
value.split ' '
value.split
when 'md5sum', 'sha1', 'sha256'
state = key
next
Expand Down Expand Up @@ -93,22 +93,20 @@ def get_package(component, architecture)
paths = paths_exist + (paths - paths_exist)

paths.each do |p|
begin
basefilename = p.split('/').last
path = "#{cache_dir}/#{basefilename}"
data = download_file_cached "#{release_base_url}/#{p}", path
plainfile = "#{cache_dir}/Packages.plain"
File.open(plainfile, 'w') do |f|
case basefilename.downcase
when 'packages.xz'
require 'xz'
f << XZ.decompress(data)
when 'packages.gz'
require 'zlib'
f << Zlib.gunzip(data)
else
f << data
end
basefilename = p.split('/').last
path = "#{cache_dir}/#{basefilename}"
data = download_file_cached "#{release_base_url}/#{p}", path
plainfile = "#{cache_dir}/Packages.plain"
File.open(plainfile, 'w') do |f|
case basefilename.downcase
when 'packages.xz'
require 'xz'
f << XZ.decompress(data)
when 'packages.gz'
require 'zlib'
f << Zlib.gunzip(data)
else
f << data
end
return Debian::Packages.new(plainfile)
rescue StandardError => e
Expand All @@ -117,6 +115,12 @@ def get_package(component, architecture)
ensure
File.unlink plainfile if plainfile && File.exist?(plainfile)
end
return Debian::Packages.new(plainfile)
rescue StandardError => e
warn "#{e} for #{p.inspect}"
FileUtils.rm_f path
ensure
File.unlink plainfile if plainfile && File.exist?(plainfile)
end
end

Expand Down
11 changes: 6 additions & 5 deletions downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def download_file_cached(url, path = nil, force = false, maxhop = MAXREDIRECTHOP
end
end

if res.is_a? Net::HTTPSuccess
case res
when Net::HTTPSuccess
mode = 'wb'
body = res.body
# check for content type; use 'wb' for images
Expand All @@ -53,11 +54,11 @@ def download_file_cached(url, path = nil, force = false, maxhop = MAXREDIRECTHOP
io.write body
end
end
return body
elsif res.is_a? Net::HTTPNotModified
body
when Net::HTTPNotModified
# Use already downloaded version
return File.read path
elsif res.is_a? Net::HTTPFound
File.read path
when Net::HTTPFound
# Redirect!
warn "REDIRECTed to #{res['location'].inspect}"
raise "Max redirect-depth reached (#{MAXREDIRECTHOPS} hops)" if maxhop.zero?
Expand Down
102 changes: 49 additions & 53 deletions errata_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'tempdir' => '/tmp/errata_parser_cache'
}.freeze

def fatal(message, code=42, show_help=false)
def fatal(message, code=42, show_help: false)
warn message
warn @opts if show_help
exit code
Expand Down Expand Up @@ -103,8 +103,8 @@ def write_errata_file(filename, errata, name: '', verbose: false, remove_empty_p
write_json_file(
filename,
data,
name: name,
verbose: verbose
name:,
verbose:
)
end

Expand Down Expand Up @@ -138,7 +138,7 @@ def load_config(filename)
## Sanity checks
fatal('No Errata-type specified!', 2, true) unless options.key?(:ubuntu) || options.key?(:ubuntu_esm) || options.key?(:debian)

parser = DebianErrataParser.new(options[:verbose])
parser = DebianErrataParser.new(verbose: options[:verbose])
extend Downloader

if options.key? :debian
Expand Down Expand Up @@ -201,8 +201,8 @@ def load_config(filename)
mutex.synchronize do
# save Meta-data
metadata[:releases][deb_rel.release_name] = {
'architectures': deb_rel.architectures,
'components': deb_rel.components
architectures: deb_rel.architectures,
components: deb_rel.components
}
metadata[:releases][deb_rel.release_name][:aliases] = cfg['aliases']['releases'][deb_rel.release_name] if
cfg.key?('aliases') && cfg['aliases'].key?('releases') && cfg['aliases']['releases'].key?(deb_rel.release_name)
Expand Down Expand Up @@ -286,30 +286,28 @@ def load_config(filename)

repository['releases'].each do |s|
threads << Thread.new do
begin
Thread.current[:repo_url] = repository['repo_url']
if repository.key?('credentials')
url = URI.parse(Thread.current[:repo_url])
url.user = repository['credentials']['user']
url.password = repository['credentials']['pass']
Thread.current[:repo_url] = url.to_s
end
warn "START Download #{s.inspect} from #{Thread.current[:repo_url].sub(/:[^:@]+@/, ':*****@')}" if options[:verbose]
deb_rel = DebRelease.new(Thread.current[:repo_url], s)
deb_rel.release_name = fix_release(deb_rel.release_name, cfg['aliases']) if deb_rel.release_name.include? '-'
deb_rel.whitelist_comp = get_whitelist(cfg, 'components')
deb_rel.whitelist_arch = whitelist_arch
pkgs = deb_rel.all_packages

# merge package-list
mutex.synchronize do
DebRelease.assemble_ubuntu_packages(packages, pkgs)
end
warn "FINISH Download #{s.inspect} from #{Thread.current[:repo_url].sub(/:[^:@]+@/, ':*****@')}" if options[:verbose]
rescue Net::HTTPServerException => e
warn "FAILED Download #{s.inspect} from #{Thread.current[:repo_url].sub(/:[^:@]+@/, ':*****@')}: #{e}" if options[:verbose]
raise e
Thread.current[:repo_url] = repository['repo_url']
if repository.key?('credentials')
url = URI.parse(Thread.current[:repo_url])
url.user = repository['credentials']['user']
url.password = repository['credentials']['pass']
Thread.current[:repo_url] = url.to_s
end
warn "START Download #{s.inspect} from #{Thread.current[:repo_url].sub(/:[^:@]+@/, ':*****@')}" if options[:verbose]
deb_rel = DebRelease.new(Thread.current[:repo_url], s)
deb_rel.release_name = fix_release(deb_rel.release_name, cfg['aliases']) if deb_rel.release_name.include? '-'
deb_rel.whitelist_comp = get_whitelist(cfg, 'components')
deb_rel.whitelist_arch = whitelist_arch
pkgs = deb_rel.all_packages

# merge package-list
mutex.synchronize do
DebRelease.assemble_ubuntu_packages(packages, pkgs)
end
warn "FINISH Download #{s.inspect} from #{Thread.current[:repo_url].sub(/:[^:@]+@/, ':*****@')}" if options[:verbose]
rescue Net::HTTPClientException => e
warn "FAILED Download #{s.inspect} from #{Thread.current[:repo_url].sub(/:[^:@]+@/, ':*****@')}: #{e}" if options[:verbose]
raise e
end
end

Expand Down Expand Up @@ -379,31 +377,29 @@ def load_config(filename)

repository['releases'].each do |s|
threads << Thread.new do
begin
Thread.current[:repo_url] = repository['repo_url']
if repository.key?('credentials')
url = URI.parse(Thread.current[:repo_url])
url.user = repository['credentials']['user']
url.password = repository['credentials']['pass']
Thread.current[:repo_url] = url.to_s
end
warn "START Download #{s.inspect} from #{Thread.current[:repo_url].sub(/:[^:@]+@/, ':*****@')}" if options[:verbose]
deb_rel = DebRelease.new(Thread.current[:repo_url], s)
deb_rel.release_name = fix_release(deb_rel.release_name, cfg['aliases']) if deb_rel.release_name.include? '-'
deb_rel.whitelist_comp = get_whitelist(cfg, 'components')
deb_rel.whitelist_arch = whitelist_arch
pkgs = deb_rel.all_packages

# merge package-list
mutex.synchronize do
# ESM-Errata need debian style package-struct
DebRelease.assemble_debian_packages(packages_by_name, pkgs)
end
warn "FINISH Download #{s.inspect} from #{Thread.current[:repo_url].sub(/:[^:@]+@/, ':*****@')}" if options[:verbose]
rescue Net::HTTPServerException => e
warn "FAILED Download #{s.inspect} from #{Thread.current[:repo_url].sub(/:[^:@]+@/, ':*****@')}: #{e}" if options[:verbose]
raise e
Thread.current[:repo_url] = repository['repo_url']
if repository.key?('credentials')
url = URI.parse(Thread.current[:repo_url])
url.user = repository['credentials']['user']
url.password = repository['credentials']['pass']
Thread.current[:repo_url] = url.to_s
end
warn "START Download #{s.inspect} from #{Thread.current[:repo_url].sub(/:[^:@]+@/, ':*****@')}" if options[:verbose]
deb_rel = DebRelease.new(Thread.current[:repo_url], s)
deb_rel.release_name = fix_release(deb_rel.release_name, cfg['aliases']) if deb_rel.release_name.include? '-'
deb_rel.whitelist_comp = get_whitelist(cfg, 'components')
deb_rel.whitelist_arch = whitelist_arch
pkgs = deb_rel.all_packages

# merge package-list
mutex.synchronize do
# ESM-Errata need debian style package-struct
DebRelease.assemble_debian_packages(packages_by_name, pkgs)
end
warn "FINISH Download #{s.inspect} from #{Thread.current[:repo_url].sub(/:[^:@]+@/, ':*****@')}" if options[:verbose]
rescue Net::HTTPClientException => e
warn "FAILED Download #{s.inspect} from #{Thread.current[:repo_url].sub(/:[^:@]+@/, ':*****@')}: #{e}" if options[:verbose]
raise e
end
end

Expand Down
Loading

0 comments on commit ccb700a

Please sign in to comment.