Class: EnhanceRepo::ConfigOpts

Inherits:
Object
  • Object
show all
Includes:
Logger, Singleton
Defined in:
lib/enhance_repo/config_opts.rb

Overview

Configuration class to hold the options passed from the command line to the components doing the work

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#log

Constructor Details

#initializeConfigOpts

Returns a new instance of ConfigOpts.



189
190
191
# File 'lib/enhance_repo/config_opts.rb', line 189

def initialize
  @digest_name, @digest_class = allocate_digest(nil)
end

Instance Attribute Details

#benchmarkObject

Returns the value of attribute benchmark.



177
178
179
# File 'lib/enhance_repo/config_opts.rb', line 177

def benchmark
  @benchmark
end

#create_deltasObject

wether to create delta rpm files and how many



171
172
173
# File 'lib/enhance_repo/config_opts.rb', line 171

def create_deltas
  @create_deltas
end

#deltasObject

whether to index delta rpms



173
174
175
# File 'lib/enhance_repo/config_opts.rb', line 173

def deltas
  @deltas
end

#digest_classObject

Returns the value of attribute digest_class.



182
183
184
# File 'lib/enhance_repo/config_opts.rb', line 182

def digest_class
  @digest_class
end

#digest_nameObject

Returns the value of attribute digest_name.



182
183
184
# File 'lib/enhance_repo/config_opts.rb', line 182

def digest_name
  @digest_name
end

#dirObject

Returns the value of attribute dir.



155
156
157
# File 'lib/enhance_repo/config_opts.rb', line 155

def dir
  @dir
end

#diskusageObject

Returns the value of attribute diskusage.



168
169
170
# File 'lib/enhance_repo/config_opts.rb', line 168

def diskusage
  @diskusage
end

#eulasObject

Returns the value of attribute eulas.



166
167
168
# File 'lib/enhance_repo/config_opts.rb', line 166

def eulas
  @eulas
end

#expireObject

Returns the value of attribute expire.



160
161
162
# File 'lib/enhance_repo/config_opts.rb', line 160

def expire
  @expire
end

#generate_patternsObject

Returns the value of attribute generate_patterns.



180
181
182
# File 'lib/enhance_repo/config_opts.rb', line 180

def generate_patterns
  @generate_patterns
end

#generate_updateObject

Returns the value of attribute generate_update.



163
164
165
# File 'lib/enhance_repo/config_opts.rb', line 163

def generate_update
  @generate_update
end

#indentObject

Returns the value of attribute indent.



152
153
154
# File 'lib/enhance_repo/config_opts.rb', line 152

def indent
  @indent
end

#indexObject

Returns the value of attribute index.



151
152
153
# File 'lib/enhance_repo/config_opts.rb', line 151

def index
  @index
end

#keywordsObject

Returns the value of attribute keywords.



167
168
169
# File 'lib/enhance_repo/config_opts.rb', line 167

def keywords
  @keywords
end

#outputdirObject



184
185
186
187
# File 'lib/enhance_repo/config_opts.rb', line 184

def outputdir
  return @dir if @outputdir.nil?
  @outputdir
end

#patternsObject

Returns the value of attribute patterns.



179
180
181
# File 'lib/enhance_repo/config_opts.rb', line 179

def patterns
  @patterns
end

#primaryObject

Returns the value of attribute primary.



161
162
163
# File 'lib/enhance_repo/config_opts.rb', line 161

def primary
  @primary
end

#productsObject

Returns the value of attribute products.



175
176
177
# File 'lib/enhance_repo/config_opts.rb', line 175

def products
  @products
end

#repokeywordsObject

Returns the value of attribute repokeywords.



154
155
156
# File 'lib/enhance_repo/config_opts.rb', line 154

def repokeywords
  @repokeywords
end

#repoproductsObject

Returns the value of attribute repoproducts.



153
154
155
# File 'lib/enhance_repo/config_opts.rb', line 153

def repoproducts
  @repoproducts
end

#signkeyObject

Returns the value of attribute signkey.



159
160
161
# File 'lib/enhance_repo/config_opts.rb', line 159

def signkey
  @signkey
end

#split_patternsObject

Returns the value of attribute split_patterns.



181
182
183
# File 'lib/enhance_repo/config_opts.rb', line 181

def split_patterns
  @split_patterns
end

#split_updatesObject

Returns the value of attribute split_updates.



164
165
166
# File 'lib/enhance_repo/config_opts.rb', line 164

def split_updates
  @split_updates
end

#updatesObject

Returns the value of attribute updates.



162
163
164
# File 'lib/enhance_repo/config_opts.rb', line 162

def updates
  @updates
end

#updatesbasedirObject

Returns the value of attribute updatesbasedir.



165
166
167
# File 'lib/enhance_repo/config_opts.rb', line 165

def updatesbasedir
  @updatesbasedir
end

Instance Method Details

#dumpObject



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/enhance_repo/config_opts.rb', line 239

def dump
  logger = EnhanceRepo.logger

  logger.info "index #{@index}"
  logger.info "expire #{@expire}"
  logger.info "primary #{@primary}"
  logger.info "repoproducts #{@repoproducts}"
  logger.info "repokeywords #{@repokeywords}"
  logger.info "signkey #{@signkey}"
  logger.info "updates #{@updates}"
  logger.info "split_updates #{@split_updates}"
  logger.info "generate_update #{@generate_update}"
  logger.info "eulas #{@eulas}"
  logger.info "keywords #{@keywords}"
  logger.info "diskusage #{@diskusage}"
  logger.info "deltas #{@deltas}"
  logger.info "create_deltas #{@create_deltas}"
  logger.info "products #{@products}"
  logger.info "benchmark #{@benchmark}"
  logger.info "patterns #{@patterns}"
  logger.info "split_patterns #{@split_patterns}"
  unless @generate_patterns.nil?
    @generate_patterns.each do |p|
      logger.info "generate_patterns #{p}"
    end
  end
  logger.info "updatesbasedir #{@updatesbasedir}"
  logger.info "outputdir #{@outputdir}"
  logger.info "dir #{@dir}"
end

#parse_args!Object



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/enhance_repo/config_opts.rb', line 193

def parse_args!
  @repoproducts = Set.new
  @repokeywords = Set.new
  opts = read_command_line
  read_opts(opts)

  unless @dir
    @dir = ARGV.shift
    Trollop.die 'Need to specify target directory.' unless @dir
  end

  if !File.exist?(@dir) || !File.directory?(@dir)
    Trollop.die "'#{@dir}' is not a valid directory."
  end
  if !File.directory?(File.join(@dir, 'repodata')) && !(opts[:primary] || opts[:help])
    Trollop.die "'#{@dir}' is not a valid repository directory"
  end
  # dump
  self
end

#read_command_lineObject



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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/enhance_repo/config_opts.rb', line 43

def read_command_line
  opts = Trollop.options do
    version "enhancerepo #{EnhanceRepo::VERSION}"
    banner <<-EOS
enhancerepo is a rpm-md metadata tool

Usage:
    enhancerepo [options] DIR

    DIR: The repo base directory ( where repodata/ directory is located )

EOS
    opt :help, 'Show help'
    opt :outputdir, 'Generate metadata to a different directory',
        short: :o, type: :string
    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
    opt :benchmark, 'Show benchmark statistics at the end'

    opt :primary, 'Add data from rpm files and generate primary.xml (EXPERIMENTAL)',
        short: :p
    opt :sign, 'Generates signature for the repository using key keyid',
        short: :s, type: :string
    opt :updates, 'Add updates from *.updates files and generate updateinfo.xml',
        short: :u
    opt :generate_update, 'Generates an update from the given package list'\
        ' comparing package\'s last version changes',
        type: :strings
    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
    opt :split_updates, 'Splits current updateinfo.xml into update parts'\
        ' files in repoparts/'
    opt :indent, 'Generate indented xml. Default: no',
        short: :i

    opt :expire, 'Set repository expiration hint (Can be used to detect dead mirrors)',
        type: :date, short: :e
    opt :repo_product, 'Adds product compatibility information',
        type: :strings
    opt :repo_keyword, 'Tags repository with keyword',
        type: :strings

    opt :digest_type, 'Algorithm used to compute the digests. Default SHA1',
        type: :string

    # === SUSE specific package data (susedata.xml)

    opt :eulas,
        'Reads packagename.eula files and add the information to susedata.xml',
        short: :l
    opt :keywords,
        'Reads packagename.keywords files and add keyword metadata to susedata.xml',
        short: :k
    opt :disk_usage,
        'Reads rpm packages, generates disk usage information on susedata.xml',
        short: :d

    # Note: your .eula or .keywords file will be added to
    # a package if it matches its name. If you want to add
    # the attributes to a specific package, name the file
    # name-version, name-version-release or
    # name-version-release.arch

    # === Package deltas support
    opt :'create-deltas',
        '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
    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.'

    # === Product information support

    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.'

    # === Pattern information support

    opt :patterns,
        'Add patterns from pattern-*.xml files and generate'\
        ' patterns.xml',
        short: :P
    opt :generate_patterns,
        'Generate patterns.xml from the old style'\
        ' pattern given as parameter to this option',
        type: :strings
    opt :split_patterns,
        'Splits current patterns.xml into pattern'\
        ' parts files in repoparts/'

    # other
    opt :debug, 'Show debug information'
  end
  opts
end

#read_opts(opts) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/enhance_repo/config_opts.rb', line 214

def read_opts(opts)
  @index = opts[:index]
  @expire = opts[:expire]
  @primary = opts[:primary]
  @repoproducts = @repoproducts.merge([*ArrayArg.new(opts[:repo_products])]) if opts[:repo_products]
  @repokeywords = @repokeywords.merge([*ArrayArg.new(opts[:repo_keywords])]) if opts[:repo_keywords]
  @signkey = opts[:sign]
  @updates = opts[:updates]
  @split_updates = opts[:split_updates]
  @generate_update = ArrayArg.new(opts[:generate_update]) if opts[:generate_update]
  @eulas = opts[:eulas]
  @keywords = opts[:keywords]
  @diskusage = opts[:disk_usage]
  @deltas = opts[:deltas]
  @create_deltas = opts[:create_deltas]
  @products = opts[:products]
  @benchmark = opts[:benchmark]
  @patterns = opts[:patterns]
  @split_patterns = opts[:split_patterns]
  @generate_patterns = Array.new(opts[:generate_patterns]) if opts[:generate_patterns]
  @updatesbasedir = Pathname.new(opts[:updates_base_dir]) if opts[:updates_base_dir]
  @outputdir = Pathname.new(opts[:outputdir]) if opts[:outputdir]
  @digest_name, @digest_class = allocate_digest(opts[:digest_type])
end