enhancerepo 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +27 -0
  3. data/bin/enhancerepo +2 -3
  4. data/lib/enhance_repo.rb +8 -13
  5. data/lib/enhance_repo/array_arg.rb +85 -0
  6. data/lib/enhance_repo/cli.rb +23 -78
  7. data/lib/enhance_repo/config_opts.rb +207 -13
  8. data/lib/enhance_repo/logger.rb +14 -10
  9. data/lib/enhance_repo/other.rb +11 -12
  10. data/lib/enhance_repo/package_id.rb +21 -12
  11. data/lib/enhance_repo/pattern.rb +50 -0
  12. data/lib/enhance_repo/product_id.rb +3 -1
  13. data/lib/enhance_repo/rpm_md.rb +3 -1
  14. data/lib/enhance_repo/rpm_md/data.rb +6 -7
  15. data/lib/enhance_repo/rpm_md/delta_info.rb +58 -67
  16. data/lib/enhance_repo/rpm_md/extra_primary_data.rb +4 -4
  17. data/lib/enhance_repo/rpm_md/file_lists.rb +12 -13
  18. data/lib/enhance_repo/rpm_md/index.rb +32 -27
  19. data/lib/enhance_repo/rpm_md/other.rb +7 -8
  20. data/lib/enhance_repo/rpm_md/pattern_writer.rb +131 -0
  21. data/lib/enhance_repo/rpm_md/patterns.rb +158 -0
  22. data/lib/enhance_repo/rpm_md/primary.rb +32 -33
  23. data/lib/enhance_repo/rpm_md/products.rb +19 -24
  24. data/lib/enhance_repo/rpm_md/repo.rb +33 -36
  25. data/lib/enhance_repo/rpm_md/resource.rb +6 -6
  26. data/lib/enhance_repo/rpm_md/suse_data.rb +41 -50
  27. data/lib/enhance_repo/rpm_md/suse_info.rb +12 -15
  28. data/lib/enhance_repo/rpm_md/update.rb +65 -36
  29. data/lib/enhance_repo/rpm_md/update_info.rb +38 -42
  30. data/lib/enhance_repo/rpm_md/update_smart_fields.rb +24 -24
  31. data/lib/enhance_repo/susetags/pattern_reader.rb +142 -0
  32. data/lib/enhance_repo/version.rb +5 -0
  33. data/lib/enhance_repo/xml_comparer.rb +28 -24
  34. metadata +190 -221
  35. data/CHANGELOG.rdoc +0 -18
  36. data/Manifest.txt +0 -85
  37. data/README +0 -10
  38. data/README.rdoc +0 -15
  39. data/Rakefile +0 -48
  40. data/TODO.rdoc +0 -4
  41. data/lib/tempdir.rb +0 -62
  42. data/lib/tempdir/tempfile.rb +0 -21
  43. data/test/all_tests.rb +0 -27
  44. data/test/data/packages/a-1.0.spec +0 -19
  45. data/test/data/packages/a-2.0.spec +0 -24
  46. data/test/data/repodata/update-test-11.1/filelists.xml.gz +0 -0
  47. data/test/data/repodata/update-test-11.1/other.xml.gz +0 -0
  48. data/test/data/repodata/update-test-11.1/primary.xml.gz +0 -0
  49. data/test/data/repodata/update-test-11.1/repomd.xml +0 -21
  50. data/test/data/repomd.xml +0 -21
  51. data/test/data/rpms/repo-1/a-1.0-0.x86_64.rpm +0 -0
  52. data/test/data/rpms/repo-1/a-1.0_2.0-0_0.x86_64.delta.rpm +0 -0
  53. data/test/data/rpms/repo-1/a-2.0-0.x86_64.rpm +0 -0
  54. data/test/data/rpms/repo-1/repodata/deltainfo.xml.gz +0 -0
  55. data/test/data/rpms/repo-1/repodata/deltainfo.xml.gz.gz +0 -0
  56. data/test/data/rpms/repo-1/repodata/filelists.xml.gz +0 -0
  57. data/test/data/rpms/repo-1/repodata/other.xml.gz +0 -0
  58. data/test/data/rpms/repo-1/repodata/primary.xml.gz +0 -0
  59. data/test/data/rpms/repo-1/repodata/repomd.xml +0 -45
  60. data/test/data/rpms/repo-1/repodata/susedata.xml.gz +0 -0
  61. data/test/data/rpms/repo-1/repodata/updateinfo.xml.gz +0 -0
  62. data/test/data/rpms/repo-1/repoparts/update-a-1.xml +0 -22
  63. data/test/data/rpms/repo-with-product/a-1.0-0.x86_64.rpm +0 -0
  64. data/test/data/rpms/repo-with-product/openSUSE-release-11.2-1.6.i586.rpm +0 -0
  65. data/test/data/rpms/repo-with-product/openSUSE-release-dvd-11.2-1.6.i586.rpm +0 -0
  66. data/test/data/rpms/repo-with-product/repodata/filelists.xml.gz +0 -0
  67. data/test/data/rpms/repo-with-product/repodata/other.xml.gz +0 -0
  68. data/test/data/rpms/repo-with-product/repodata/primary.xml.gz +0 -0
  69. data/test/data/rpms/repo-with-product/repodata/products.xml.gz +0 -0
  70. data/test/data/rpms/repo-with-product/repodata/repomd.xml +0 -27
  71. data/test/data/rpms/update-test-11.1/update-test-affects-package-manager.rpm +0 -0
  72. data/test/data/rpms/update-test-11.1/update-test-interactive.rpm +0 -0
  73. data/test/data/rpms/update-test-11.1/update-test-optional.rpm +0 -0
  74. data/test/data/rpms/update-test-11.1/update-test-reboot-needed.rpm +0 -0
  75. data/test/data/rpms/update-test-11.1/update-test-security.rpm +0 -0
  76. data/test/data/rpms/update-test-11.1/update-test-trival.rpm +0 -0
  77. data/test/data/rpms/update-test-factory/update-test-affects-package-manager-0-9999.1.2.noarch.rpm +0 -0
  78. data/test/data/rpms/update-test-factory/update-test-interactive-0-9999.1.2.noarch.rpm +0 -0
  79. data/test/data/rpms/update-test-factory/update-test-optional-0-9999.1.2.noarch.rpm +0 -0
  80. data/test/data/rpms/update-test-factory/update-test-reboot-needed-0-9999.1.2.noarch.rpm +0 -0
  81. data/test/data/rpms/update-test-factory/update-test-relogin-suggested-0-9999.1.2.noarch.rpm +0 -0
  82. data/test/data/rpms/update-test-factory/update-test-security-0-9999.1.2.noarch.rpm +0 -0
  83. data/test/deltainfo_test.rb +0 -50
  84. data/test/extensions_test.rb +0 -31
  85. data/test/index_test.rb +0 -51
  86. data/test/primary_test.rb +0 -51
  87. data/test/products_test.rb +0 -51
  88. data/test/repo_test.rb +0 -72
  89. data/test/repomdindex_test.rb +0 -58
  90. data/test/rpmmd_test.rb +0 -60
  91. data/test/susedata_test.rb +0 -53
  92. data/test/tempdir_test.rb +0 -62
  93. data/test/test_helper.rb +0 -53
  94. data/test/update_test.rb +0 -80
  95. data/test/updateinfo_test.rb +0 -59
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: '0286c73b863193259c5ff0c0bd832637144d4e11'
4
+ data.tar.gz: 00b9f1514ec31b3cf26b6b7d78bbe86e195c6008
5
+ SHA512:
6
+ metadata.gz: 5a804dab6d6265dff84730925a4e89e6958bf1a5e8766c9a4bcfe4471c866e462f252e117913a76b329f219a12b1aa409177c5428630435e6639428617ce39d3
7
+ data.tar.gz: a98bbf20cddc4426a94c6d7fcca65b1cd8c00e8b5d41bcdc4a9af99f438c45e4dc8b6e4e524e48edcaa861ee7eedeb4b64bb7080c3ba31759cb030f541c02ba9
@@ -0,0 +1,27 @@
1
+
2
+ # enhancerepo
3
+
4
+ ![reviving](https://img.shields.io/badge/stability-reviving-yellow.svg)
5
+ ![maintained](https://img.shields.io/maintenance/yes/2014.svg)
6
+ [![Build Status](https://travis-ci.org/openSUSE/enhancerepo.svg?branch=master)](https://travis-ci.org/openSUSE/enhancerepo)
7
+
8
+ * http://en.opensuse.org/Enhancerepo
9
+
10
+ ## Introduction
11
+
12
+ Reference implementation for future rpmmd extensions.
13
+
14
+ requires ruby-rpm.
15
+
16
+ ## TODO
17
+
18
+ - [ ] give some love to rpm-ffi to supress warnings
19
+ - [ ] cleanup rubocop issues (see .rubocop_todo.yml)
20
+ - [ ] re-do rpm package
21
+ - [ ] get rid of ActiveSupport
22
+ - [ ] refactor CLI (may be subcommands)
23
+
24
+ ## Authors
25
+
26
+ * Duncan Mac-Vicar P. <dmacvicar@suse.de>
27
+
@@ -1,4 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- $: << '../lib'
3
- $: << 'lib'
4
- require 'enhance_repo/cli.rb'
2
+ $LOAD_PATH.push(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'enhance_repo/cli'
@@ -1,5 +1,7 @@
1
+ # Encoding: utf-8
2
+
1
3
  #--
2
- #
4
+ #
3
5
  # enhancerepo is a rpm-md repository metadata tool.
4
6
  # Copyright (C) 2008, 2009 Novell Inc.
5
7
  # Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
@@ -22,15 +24,8 @@
22
24
  #
23
25
  #++
24
26
  #
25
- module EnhanceRepo
26
- VERSION = "0.4.1"
27
- end
28
-
29
- lib = File.dirname(__FILE__)
30
-
31
- require File.join(lib, 'enhance_repo', 'logger.rb')
32
- require File.join(lib, 'enhance_repo', 'config_opts.rb')
33
- require File.join(lib, 'enhance_repo', 'rpm_md.rb')
34
-
35
-
36
-
27
+ require 'enhance_repo/version'
28
+ require 'enhance_repo/logger'
29
+ require 'enhance_repo/config_opts'
30
+ require 'enhance_repo/rpm_md'
31
+ require 'enhance_repo/array_arg'
@@ -0,0 +1,85 @@
1
+ # Encoding: utf-8
2
+
3
+ #--
4
+ #
5
+ # enhancerepo is a rpm-md repository metadata tool.
6
+ # Copyright (C) 2008, 2009 Novell Inc.
7
+ # Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
8
+ #
9
+ # This program is free software; you can redistribute it and/or modify
10
+ # it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation; either version 2 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # This program is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License
20
+ # along with this program; if not, write to the Free Software
21
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22
+ # MA 02110-1301, USA. A copy of the GNU General Public License is
23
+ # also available at http://www.gnu.org/copyleft/gpl.html.
24
+ #
25
+ #++
26
+ #
27
+ module EnhanceRepo
28
+ # Helper class to turn an array like:
29
+ # ['a', 'b', '/foo/file.txt', 'd'] into an
30
+ # array containing the content of file.txt
31
+ # (each line) merged into the place of the
32
+ # file name
33
+ #
34
+ class ArrayArg
35
+ include Enumerable
36
+
37
+ # initialize the wrapper with an array
38
+ def initialize(array)
39
+ @array = array
40
+ @array ||= []
41
+ @expanded_cache = nil
42
+ end
43
+
44
+ # yields one element per line in
45
+ # the file
46
+ def expand_file(file)
47
+ ret = []
48
+ File.open(file) do |f|
49
+ f.each_line do |line|
50
+ stripped_line = line.strip
51
+ ret << stripped_line unless stripped_line.empty?
52
+ end
53
+ end
54
+ ret
55
+ end
56
+
57
+ # expand the wrapped array with fles
58
+ def expanded
59
+ return @expanded_cache if @expanded_cache
60
+ ret = []
61
+ @array.each do |element|
62
+ if File.exist?(element) && !File.directory?(element)
63
+ EnhanceRepo.logger.info "Expanding the content of file '#{element}'..."
64
+ ret += expand_file(element)
65
+ else
66
+ ret << element
67
+ end
68
+ end
69
+ @expanded_cache = ret
70
+ ret
71
+ end
72
+
73
+ # delegate other methods to the expanded array
74
+ def method_missing(method, *args)
75
+ each.to_a.send(method, *args)
76
+ end
77
+
78
+ # see Enumerable
79
+ def each
80
+ return enum_for(:each) unless block_given?
81
+ expanded.each { |x| yield x }
82
+ self
83
+ end
84
+ end
85
+ end
@@ -1,5 +1,7 @@
1
+ # Encoding: utf-8
2
+
1
3
  #--
2
- #
4
+ #
3
5
  # enhancerepo is a rpm-md repository metadata tool.
4
6
  # Copyright (C) 2008, 2009 Novell Inc.
5
7
  # Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
@@ -22,76 +24,14 @@
22
24
  #
23
25
  #++
24
26
  #
25
- require 'rubygems'
26
- require 'trollop'
27
- require 'enhance_repo'
28
27
  require 'pathname'
29
28
  require 'benchmark'
30
29
  require 'fileutils'
30
+ require 'enhance_repo'
31
31
 
32
- EnhanceRepo::enable_logger
33
-
34
- opts = Trollop::options do
35
- version "enhancerepo #{EnhanceRepo::VERSION}"
36
- banner <<-EOS
37
- enhancerepo is a rpm-md metadata tool
38
-
39
- Usage:
40
- enhancerepo [options] DIR
41
-
42
- DIR: The repo base directory ( where repodata/ directory is located )
43
- EOS
44
- opt :help, 'Show help'
45
- opt :outputdir, 'Generate metadata to a different directory', :short => :o
46
- opt :index, "Reindex the metadata and regenerates repomd.xml, even if nothing was changed using enhancerepo. Use this if you did manual changes to the metadata", :short => :x
47
- opt :benchmark, 'Show benchmark statistics at the end'
48
-
49
- opt :primary, 'Add data from rpm files and generate primary.xml (EXPERIMENTAL)', :short => :p
50
- opt :sign, 'Generates signature for the repository using key keyid', :short => :s, :type => :string
51
- opt :updates, 'Add updates from *.updates files and generate updateinfo.xml', :short => :u
52
- opt :generate_update, 'Generates an update from the given package list comparing package\'s last version changes', :type => :strings
53
- opt :updates_base_dir, 'Looks for package also in <dir> Useful if you keep old packages in a different repos and updates in this one.', :type => :string
54
- opt :split_updates, 'Splits current updateinfo.xml into update parts files in repoparts/'
55
- opt :indent, 'Generate indented xml. Default: no', :short => :i
56
-
57
- opt :expire, 'Set repository expiration hint (Can be used to detect dead mirrors)', :type => :date, :short => :e
58
- opt :repo_product, 'Adds product compatibility information', :type => :strings
59
- opt :repo_keyword, 'Tags repository with keyword', :type => :strings
60
-
61
- # === SUSE specific package data (susedata.xml)
62
-
63
- opt :eulas, 'Reads packagename.eula files and add the information to susedata.xml', :short => :l
64
- opt :keywords, 'Reads packagename.keywords files and add keyword metadata to susedata.xml', :short => :k
65
- opt :disk_usage, 'Reads rpm packages, generates disk usage information on susedata.xml', :short => :d
66
-
67
- # Note: your .eula or .keywords file will be added to
68
- # a package if it matches its name. If you want to add
69
- # the attributes to a specific package, name the file
70
- # name-version, name-version-release or
71
- # name-version-release.arch
72
-
73
- # === Package deltas support
74
- opt :'create-deltas',
75
- 'Create [num] deltas for different versions of a package. If there is foo-1.rpm, foo-2.rpm, foo-3.rpm, foo-4.rpm num=1 will create a delta to go from version 3 to 4, while num=2 will create one from 2 to 4 too. This does not index the deltas. Use --deltas for that.', :default => 1
76
- opt :deltas, 'Reads all *.delta.rpm files and add the information to deltainfo.xml. This indexes existing deltas, but won\'t create them. See --create-deltas for deltas creation.'
77
-
78
- # === Product information support
79
-
80
- opt :products, 'Reads release packages and generating product information in products.xml based on the information contained in the .prod files included in the packages.'
81
-
82
- # other
83
- opt :debug, 'Show debug information'
84
- end
32
+ EnhanceRepo.enable_logger
85
33
 
86
- config = EnhanceRepo::ConfigOpts.new(opts)
87
- dir = ARGV.shift
88
- config.dir = Pathname.new(dir) if not dir.nil?
89
-
90
- # Check if dir is given
91
- if config.dir.nil?
92
- EnhanceRepo.logger.fatal "Missing dir argument (try --help)"
93
- exit 0
94
- end
34
+ config = EnhanceRepo::ConfigOpts.instance.parse_args!
95
35
 
96
36
  repomd = EnhanceRepo::RpmMd::Repo.new(config)
97
37
 
@@ -109,42 +49,47 @@ time = Benchmark.measure do
109
49
  repomd.suseinfo.products.merge(config.repoproducts)
110
50
  repomd.suseinfo.keywords.merge(config.repokeywords)
111
51
 
112
- repomd.susedata.add_eulas if config.eulas
52
+ repomd.susedata.add_eulas if config.eulas
113
53
  repomd.susedata.add_keywords if config.keywords
114
54
  repomd.susedata.add_disk_usage if config.diskusage
115
55
 
116
- if not config.generate_update.nil?
117
- repomd.updateinfo.generate_update(config.generate_update, File.join(config.outputdir, 'repoparts') )
56
+ unless config.generate_update.nil?
57
+ repomd.updateinfo.generate_update(config.generate_update, File.join(config.outputdir, 'repoparts'))
118
58
  end
119
59
 
120
- repomd.updateinfo.read_repoparts if config.updates
121
- repomd.updateinfo.split_updates(File.join(config.outputdir, 'repoparts')) if config.split_updates
60
+ repomd.updateinfo.read_repoparts if config.updates
61
+ repomd.updateinfo.split_updates(File.join(config.outputdir, 'repoparts')) if config.split_updates
62
+
63
+ repomd.patterns.split_patterns(File.join(config.outputdir, 'repoparts')) if config.split_patterns
64
+ unless config.generate_patterns.nil?
65
+ repomd.patterns.generate_patterns(config.generate_patterns, File.join(config.outputdir, 'repoparts'))
66
+ end
67
+ repomd.patterns.read_repoparts if config.patterns || !config.generate_patterns.nil?
122
68
 
123
- repomd.deltainfo.create_deltas(:outputdir => config.outputdir, :n => config.create_deltas) if config.create_deltas
69
+ repomd.deltainfo.create_deltas(outputdir: config.outputdir, n: config.create_deltas) if config.create_deltas
124
70
  repomd.deltainfo.add_deltas if config.deltas
125
71
 
126
72
  repomd.products.read_packages if config.products
127
73
 
128
74
  # add expiration date
129
- repomd.suseinfo.expire = config.expire if not config.expire.nil?
75
+ repomd.suseinfo.expire = config.expire unless config.expire.nil?
130
76
 
131
77
  # index if requested
132
78
  repomd.index if config.index
133
-
79
+
134
80
  # write the repository out
135
81
  repomd.write
136
82
 
137
83
  # perform signature of the repository
138
- repomd.sign(config.signkey) if not config.signkey.nil?
84
+ repomd.sign(config.signkey) unless config.signkey.nil?
139
85
  rescue Exception => excp
140
86
  EnhanceRepo.logger.fatal excp.message
141
- if EnhanceRepo::enable_debug
87
+ if EnhanceRepo.enable_debug
142
88
  EnhanceRepo.logger.fatal excp.class
143
89
  EnhanceRepo.logger.fatal(excp.backtrace.join("\n"))
144
90
  else
145
- EnhanceRepo.logger.info "Pass --debug for more information..."
91
+ EnhanceRepo.logger.info 'Pass --debug for more information...'
146
92
  end
147
93
  end
148
-
149
94
  end
150
95
  EnhanceRepo.logger.info(time) if config.benchmark
@@ -1,5 +1,7 @@
1
+ # Encoding: utf-8
2
+
1
3
  #--
2
- #
4
+ #
3
5
  # enhancerepo is a rpm-md repository metadata tool.
4
6
  # Copyright (C) 2008, 2009 Novell Inc.
5
7
  # Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
@@ -22,16 +24,130 @@
22
24
  #
23
25
  #++
24
26
  #
27
+ require 'digest'
25
28
  require 'set'
29
+ require 'trollop'
30
+ require 'enhance_repo/array_arg'
31
+ require 'singleton'
26
32
 
27
33
  module EnhanceRepo
28
-
29
34
  # Configuration class to hold the options
30
35
  # passed from the command line to the
31
36
  # components doing the work
32
37
  #
33
38
 
34
39
  class ConfigOpts
40
+ include Singleton
41
+ include Logger
42
+
43
+ def read_command_line
44
+ opts = Trollop.options do
45
+ version "enhancerepo #{EnhanceRepo::VERSION}"
46
+ banner <<-EOS
47
+ enhancerepo is a rpm-md metadata tool
48
+
49
+ Usage:
50
+ enhancerepo [options] DIR
51
+
52
+ DIR: The repo base directory ( where repodata/ directory is located )
53
+
54
+ EOS
55
+ opt :help, 'Show help'
56
+ opt :outputdir, 'Generate metadata to a different directory',
57
+ short: :o, type: :string
58
+ opt :index, "Reindex the metadata and regenerates repomd.xml, '\
59
+ 'even if nothing was changed using enhancerepo.'\
60
+ ' Use this if you did manual changes to the metadata",
61
+ short: :x
62
+ opt :benchmark, 'Show benchmark statistics at the end'
63
+
64
+ opt :primary, 'Add data from rpm files and generate primary.xml (EXPERIMENTAL)',
65
+ short: :p
66
+ opt :sign, 'Generates signature for the repository using key keyid',
67
+ short: :s, type: :string
68
+ opt :updates, 'Add updates from *.updates files and generate updateinfo.xml',
69
+ short: :u
70
+ opt :generate_update, 'Generates an update from the given package list'\
71
+ ' comparing package\'s last version changes',
72
+ type: :strings
73
+ opt :updates_base_dir, 'Looks for package also in <dir> Useful if you'\
74
+ ' keep old packages in a different repos and updates in this one.',
75
+ type: :string
76
+ opt :split_updates, 'Splits current updateinfo.xml into update parts'\
77
+ ' files in repoparts/'
78
+ opt :indent, 'Generate indented xml. Default: no',
79
+ short: :i
80
+
81
+ opt :expire, 'Set repository expiration hint (Can be used to detect dead mirrors)',
82
+ type: :date, short: :e
83
+ opt :repo_product, 'Adds product compatibility information',
84
+ type: :strings
85
+ opt :repo_keyword, 'Tags repository with keyword',
86
+ type: :strings
87
+
88
+ opt :digest_type, 'Algorithm used to compute the digests. Default SHA1',
89
+ type: :string
90
+
91
+ # === SUSE specific package data (susedata.xml)
92
+
93
+ opt :eulas,
94
+ 'Reads packagename.eula files and add the information to susedata.xml',
95
+ short: :l
96
+ opt :keywords,
97
+ 'Reads packagename.keywords files and add keyword metadata to susedata.xml',
98
+ short: :k
99
+ opt :disk_usage,
100
+ 'Reads rpm packages, generates disk usage information on susedata.xml',
101
+ short: :d
102
+
103
+ # Note: your .eula or .keywords file will be added to
104
+ # a package if it matches its name. If you want to add
105
+ # the attributes to a specific package, name the file
106
+ # name-version, name-version-release or
107
+ # name-version-release.arch
108
+
109
+ # === Package deltas support
110
+ opt :'create-deltas',
111
+ 'Create [num] deltas for different versions of a package.'\
112
+ ' If there is foo-1.rpm, foo-2.rpm, foo-3.rpm, '\
113
+ 'foo-4.rpm num=1 will create a delta to go from'\
114
+ ' version 3 to 4, while num=2 will create one from'\
115
+ ' 2 to 4 too. This does not index the deltas.'\
116
+ ' Use --deltas for that.',
117
+ default: 1
118
+ opt :deltas,
119
+ 'Reads all *.delta.rpm files and add the information'\
120
+ ' to deltainfo.xml. This indexes existing deltas, but'\
121
+ ' won\'t create them. See --create-deltas for deltas'\
122
+ 'creation.'
123
+
124
+ # === Product information support
125
+
126
+ opt :products,
127
+ 'Reads release packages and generating product'\
128
+ ' information in products.xml based on the information'\
129
+ ' contained in the .prod files included in the packages.'
130
+
131
+ # === Pattern information support
132
+
133
+ opt :patterns,
134
+ 'Add patterns from pattern-*.xml files and generate'\
135
+ ' patterns.xml',
136
+ short: :P
137
+ opt :generate_patterns,
138
+ 'Generate patterns.xml from the old style'\
139
+ ' pattern given as parameter to this option',
140
+ type: :strings
141
+ opt :split_patterns,
142
+ 'Splits current patterns.xml into pattern'\
143
+ ' parts files in repoparts/'
144
+
145
+ # other
146
+ opt :debug, 'Show debug information'
147
+ end
148
+ opts
149
+ end
150
+
35
151
  attr_accessor :index
36
152
  attr_accessor :indent
37
153
  attr_accessor :repoproducts
@@ -59,40 +175,118 @@ module EnhanceRepo
59
175
  attr_accessor :products
60
176
 
61
177
  attr_accessor :benchmark
62
-
178
+
179
+ attr_accessor :patterns
180
+ attr_accessor :generate_patterns
181
+ attr_accessor :split_patterns
182
+ attr_accessor :digest_name, :digest_class
183
+
63
184
  def outputdir
64
185
  return @dir if @outputdir.nil?
65
- return @outputdir
186
+ @outputdir
187
+ end
66
188
 
189
+ def initialize
190
+ @digest_name, @digest_class = allocate_digest(nil)
67
191
  end
68
-
69
- def initialize(opts)
192
+
193
+ def parse_args!
70
194
  @repoproducts = Set.new
71
195
  @repokeywords = Set.new
196
+ opts = read_command_line
72
197
  read_opts(opts)
198
+
199
+ unless @dir
200
+ @dir = ARGV.shift
201
+ Trollop.die 'Need to specify target directory.' unless @dir
202
+ end
203
+
204
+ if !File.exist?(@dir) || !File.directory?(@dir)
205
+ Trollop.die "'#{@dir}' is not a valid directory."
206
+ end
207
+ if !File.directory?(File.join(@dir, 'repodata')) && !(opts[:primary] || opts[:help])
208
+ Trollop.die "'#{@dir}' is not a valid repository directory"
209
+ end
210
+ # dump
211
+ self
73
212
  end
74
-
213
+
75
214
  def read_opts(opts)
76
215
  @index = opts[:index]
77
216
  @expire = opts[:expire]
78
217
  @primary = opts[:primary]
79
- @repoproducts = @repoproducts.merge([*opts[:repo_products]])
80
- @repokeywords = @repokeywords.merge([*opts[:repo_keywords]])
218
+ @repoproducts = @repoproducts.merge([*ArrayArg.new(opts[:repo_products])]) if opts[:repo_products]
219
+ @repokeywords = @repokeywords.merge([*ArrayArg.new(opts[:repo_keywords])]) if opts[:repo_keywords]
81
220
  @signkey = opts[:sign]
82
221
  @updates = opts[:updates]
83
222
  @split_updates = opts[:split_updates]
84
- @generate_update = opts[:generate_update]
223
+ @generate_update = ArrayArg.new(opts[:generate_update]) if opts[:generate_update]
85
224
  @eulas = opts[:eulas]
86
225
  @keywords = opts[:keywords]
87
226
  @diskusage = opts[:disk_usage]
88
227
  @deltas = opts[:deltas]
89
228
  @create_deltas = opts[:create_deltas]
90
229
  @products = opts[:products]
91
- @benchmark = opts[:benchmark]
230
+ @benchmark = opts[:benchmark]
231
+ @patterns = opts[:patterns]
232
+ @split_patterns = opts[:split_patterns]
233
+ @generate_patterns = Array.new(opts[:generate_patterns]) if opts[:generate_patterns]
92
234
  @updatesbasedir = Pathname.new(opts[:updates_base_dir]) if opts[:updates_base_dir]
93
235
  @outputdir = Pathname.new(opts[:outputdir]) if opts[:outputdir]
94
- @dir = Pathname.new(opts[:dir]) if opts[:dir]
236
+ @digest_name, @digest_class = allocate_digest(opts[:digest_type])
237
+ end
238
+
239
+ def dump
240
+ logger = EnhanceRepo.logger
241
+
242
+ logger.info "index #{@index}"
243
+ logger.info "expire #{@expire}"
244
+ logger.info "primary #{@primary}"
245
+ logger.info "repoproducts #{@repoproducts}"
246
+ logger.info "repokeywords #{@repokeywords}"
247
+ logger.info "signkey #{@signkey}"
248
+ logger.info "updates #{@updates}"
249
+ logger.info "split_updates #{@split_updates}"
250
+ logger.info "generate_update #{@generate_update}"
251
+ logger.info "eulas #{@eulas}"
252
+ logger.info "keywords #{@keywords}"
253
+ logger.info "diskusage #{@diskusage}"
254
+ logger.info "deltas #{@deltas}"
255
+ logger.info "create_deltas #{@create_deltas}"
256
+ logger.info "products #{@products}"
257
+ logger.info "benchmark #{@benchmark}"
258
+ logger.info "patterns #{@patterns}"
259
+ logger.info "split_patterns #{@split_patterns}"
260
+ unless @generate_patterns.nil?
261
+ @generate_patterns.each do |p|
262
+ logger.info "generate_patterns #{p}"
263
+ end
264
+ end
265
+ logger.info "updatesbasedir #{@updatesbasedir}"
266
+ logger.info "outputdir #{@outputdir}"
267
+ logger.info "dir #{@dir}"
268
+ end
269
+
270
+ private
271
+
272
+ def allocate_digest(digest_name)
273
+ return ['sha', Digest::SHA1] unless digest_name
274
+
275
+ valid_names = %w[sha sha1 sha2 sha256 md5]
276
+ unless valid_names.include?(digest_name.downcase)
277
+ warn "Invalid digest type #{digest_name}"
278
+ warn "Accepted types: #{valid_names.join(', ')}"
279
+ exit 1
280
+ end
281
+
282
+ case digest_name.downcase
283
+ when /^(sha2|sha256)$/
284
+ ['sha256', Digest::SHA2]
285
+ when /^(sha|sha1)$/
286
+ ['sha', Digest::SHA1]
287
+ when 'md5'
288
+ ['md5', Digest::MD5]
289
+ end
95
290
  end
96
-
97
291
  end
98
292
  end