[SCM] ci-tooling packaging branch, master, updated. a4c428e2f4b0527e13faa11d33225a0fa0d347b4
Harald Sitter
apachelogger-guest at moszumanska.debian.org
Thu Apr 9 08:30:50 UTC 2015
Gitweb-URL: http://git.debian.org/?p=pkg-kde/ci-tooling.git;a=commitdiff;h=a0ae292
The following commit has been merged in the master branch:
commit a0ae292f7c21a71c2a4a41ba3fb412fbf6bf75c0
Author: Harald Sitter <sitter at kde.org>
Date: Thu Apr 9 10:29:53 2015 +0200
fix control style to make rubocop happier (still some warnings left)
---
lib/debian/control.rb | 349 +++++++++++++++++++++++++-------------------------
1 file changed, 177 insertions(+), 172 deletions(-)
diff --git a/lib/debian/control.rb b/lib/debian/control.rb
index bbbc9f9..35e8b73 100644
--- a/lib/debian/control.rb
+++ b/lib/debian/control.rb
@@ -1,194 +1,199 @@
+# Helper class that ignores the case on its key.
class CaseHash < Hash
- def [](key)
- key.respond_to?(:downcase) ? super(key.downcase) : super(key)
- end
+ def [](key)
+ key.respond_to?(:downcase) ? super(key.downcase) : super(key)
+ end
- def []=(key, value)
- key.respond_to?(:downcase) ? super(key.downcase, value) : super(key, value)
- end
+ def []=(key, value)
+ key.respond_to?(:downcase) ? super(key.downcase, value) : super(key, value)
+ end
- def key?(key)
- key.respond_to?(:downcase) ? super(key.downcase) : super(key)
- end
+ def key?(key)
+ key.respond_to?(:downcase) ? super(key.downcase) : super(key)
+ end
- def fetch(key, default)
- key.respond_to?(:downcase) ? super(key.downcase, default) : super(key, default)
- end
+ def fetch(key, default)
+ key.respond_to?(:downcase) ? super(key.downcase, default) : super(key, default)
+ end
end
+# A package relationship.
class Relationship
- attr_reader :name
- attr_reader :operator
- attr_reader :version
-
- def initialize(string)
- @name = nil
- @operator = nil
- @version = nil
-
- string.strip!
- return if string.empty?
-
- # Fancy plain text description:
- # - Start of line
- # - any word character, at least once
- # - 0-n space characters
- # - at the most once:
- # - (
- # - any of the version operators, but only once
- # - anything before closing ')'
- # - )
- # Random note: all matches are stripped, so we don't need to
- # handle whitespaces being in the matches.
- match = string.match(/^(\S+)\s*(\((<|<<|<=|=|>=|>>|>){1}(.*)\))?/)
- # 0 full match
- # 1 name
- # 2 version definition (or nil)
- # 3 operator
- # 4 version
- @name = match[1] ? match[1].strip : nil
- @operator = match[3] ? match[3].strip : nil
- @version = match[4] ? match[4].strip : nil
- end
+ attr_reader :name
+ attr_reader :operator
+ attr_reader :version
+
+ def initialize(string)
+ @name = nil
+ @operator = nil
+ @version = nil
+
+ string.strip!
+ return if string.empty?
+
+ # Fancy plain text description:
+ # - Start of line
+ # - any word character, at least once
+ # - 0-n space characters
+ # - at the most once:
+ # - (
+ # - any of the version operators, but only once
+ # - anything before closing ')'
+ # - )
+ # Random note: all matches are stripped, so we don't need to
+ # handle whitespaces being in the matches.
+ match = string.match(/^(\S+)\s*(\((<|<<|<=|=|>=|>>|>){1}(.*)\))?/)
+ # 0 full match
+ # 1 name
+ # 2 version definition (or nil)
+ # 3 operator
+ # 4 version
+ @name = match[1] ? match[1].strip : nil
+ @operator = match[3] ? match[3].strip : nil
+ @version = match[4] ? match[4].strip : nil
+ end
end
+# debian/control parser
class DebianControl
- attr_reader :source
- attr_reader :binaries
-
- def initialize
- @source = nil
- @binaries = nil
+ attr_reader :source
+ attr_reader :binaries
+
+ def initialize
+ @source = nil
+ @binaries = nil
+ end
+
+ def parse_relationships(line)
+ ret = []
+ line.split(',').each do |string|
+ r = Relationship.new(string)
+ next unless r.name # Invalid name, ignore this bugger.
+ ret << r
end
-
- def parse_relationships(line)
- ret = []
- line.split(',').each do | string |
- r = Relationship.new(string)
- next unless r.name # Invalid name, ignore this bugger.
- ret << r
+ ret
+ end
+
+ def parse_paragraph(lines, fields = {})
+ mandatory_fields = fields[:mandatory] || []
+ multiline_fields = fields[:multiline] || []
+ foldable_fields = fields[:foldable] || []
+ relationship_fields = fields[:relationship] || []
+
+ current_header = nil
+ data = CaseHash.new
+
+ while (line = lines.shift) && line && !line.strip.empty?
+ next if line.start_with?('#') # Comment
+
+ header_match = line.match(/^(\S+):(.*)/)
+ unless header_match.nil?
+ # 0 = full match
+ # 1 = key match
+ # 2 = value match
+ key = header_match[1].lstrip
+ value = header_match[2].lstrip
+ current_header = key
+ if relationship_fields.include?(key.downcase)
+ value = parse_relationships(value)
+ elsif foldable_fields.include?(key.downcase)
+ value = [value.chomp(',').strip]
end
- return ret
- end
+ data[key] = value
+ next
+ end
- def parse_paragraph(lines, fields = {})
- mandatory_fields = fields[:mandatory] || []
- multiline_fields = fields[:multiline] || []
- foldable_fields = fields[:foldable] || []
- relationship_fields = fields[:relationship] || []
-
- current_header = nil
- data = CaseHash.new
-
- while (line = lines.shift) and line and !line.strip.empty?
- next if line.start_with?("#") # Comment
-
- header_match = line.match(/^(\S+):(.*)/)
- unless header_match.nil?
- # 0 = full match
- # 1 = key match
- # 2 = value match
- key = header_match[1].lstrip
- value = header_match[2].lstrip
- current_header = key
- if relationship_fields.include?(key.downcase)
- value = parse_relationships(value)
- elsif foldable_fields.include?(key.downcase)
- value = [value.chomp(',').strip]
- end
- data[key] = value
- next
- end
-
- fold_match = line.match(/^\s+(.+)/)
- unless fold_match.nil?
- # Folding value encountered -> append to header.
- # 0 full match
- # 1 value match
- value = fold_match[1].lstrip
-
- # Fold matches can either be proper RFC 5322 folds or
- # multiline continuations, latter wants to preserve
- # newlines and so forth.
- # The type is entirely dependent on what the header field is.
- if foldable_fields.include?(current_header.downcase)
- # We do not care about whitespaces for folds, so strip everything.
- if relationship_fields.include?(current_header.downcase)
- value = parse_relationships(value)
- else
- value = [value.strip]
- end
- data[current_header] += value
- elsif multiline_fields.include?(current_header.downcase)
- # For multiline we want to preserve right hand side whitespaces.
- data[current_header] << value
- else
- raise "A field is folding that is not allowed to #{current_header}"
- end
-
- next
- end
-
- # TODO: user defined fields
-
- raise "Paragraph parsing ran into an unknown line: '#{line}'"
+ fold_match = line.match(/^\s+(.+)/)
+ unless fold_match.nil?
+ # Folding value encountered -> append to header.
+ # 0 full match
+ # 1 value match
+ value = fold_match[1].lstrip
+
+ # Fold matches can either be proper RFC 5322 folds or
+ # multiline continuations, latter wants to preserve
+ # newlines and so forth.
+ # The type is entirely dependent on what the header field is.
+ if foldable_fields.include?(current_header.downcase)
+ # We do not care about whitespaces for folds, so strip everything.
+ if relationship_fields.include?(current_header.downcase)
+ value = parse_relationships(value)
+ else
+ value = [value.strip]
+ end
+ data[current_header] += value
+ elsif multiline_fields.include?(current_header.downcase)
+ # For multiline we want to preserve right hand side whitespaces.
+ data[current_header] << value
+ else
+ fail "A field is folding that is not allowed to #{current_header}"
end
- # If the entire stanza was commented out we can end up with no data, it is very sad.
- return nil if data.empty?
+ next
+ end
- mandatory_fields.each do |field|
- # TODO: this should really make a list and complain all at once or something.
- raise "Missing mandatory field #{field}" unless data.include?(field)
- end
+ # TODO: user defined fields
- return data
+ fail "Paragraph parsing ran into an unknown line: '#{line}'"
end
- def parse!
- lines = File.new('debian/control').readlines
-
- # Source Paragraph
- fields = {}
- fields[:mandatory] = [
- 'source',
- 'maintainer'
- ]
- fields[:relationship] = [
- 'build-depends',
- 'build-depends-indep',
- 'build-conflicts',
- 'build-conflicts-indep'
- ]
- fields[:foldable] = ['uploaders'] + fields[:relationship]
- @source = parse_paragraph(lines, fields)
-
- # Binary Paragraphs
- fields = {}
- fields[:mandatory] = [
- 'package',
- 'architecture',
- 'description'
- ]
- fields[:multiline] = ['description']
- fields[:relationship] = [
- 'depends',
- 'recommends',
- 'suggests',
- 'enhances',
- 'pre-depends',
- 'breaks',
- 'replaces',
- 'conflicts',
- 'provides'
- ]
- fields[:foldable] = fields[:relationship]
- @binaries = []
- while not lines.empty?
- data = parse_paragraph(lines, fields)
- @binaries << data if data
- end
+ # If the entire stanza was commented out we can end up with no data, it
+ # is very sad.
+ return nil if data.empty?
- # TODO: Strip custom fields and add a Control::flags_for(entry) method.
+ mandatory_fields.each do |field|
+ # TODO: this should really make a list and complain all at once or
+ # something.
+ fail "Missing mandatory field #{field}" unless data.include?(field)
end
+
+ data
+ end
+
+ def parse!
+ lines = File.new('debian/control').readlines
+
+ # Source Paragraph
+ fields = {}
+ fields[:mandatory] = %w(
+ source
+ maintainer
+ )
+ fields[:relationship] = %w(
+ build-depends
+ build-depends-indep
+ build-conflicts
+ build-conflicts-indep
+ )
+ fields[:foldable] = ['uploaders'] + fields[:relationship]
+ @source = parse_paragraph(lines, fields)
+
+ # Binary Paragraphs
+ fields = {}
+ fields[:mandatory] = %w(
+ package
+ architecture
+ description
+ )
+ fields[:multiline] = ['description']
+ fields[:relationship] = %w(
+ depends
+ recommends
+ suggests
+ enhances
+ pre-depends
+ breaks
+ replaces
+ conflicts
+ provides
+ )
+ fields[:foldable] = fields[:relationship]
+ @binaries = []
+ until lines.empty?
+ data = parse_paragraph(lines, fields)
+ @binaries << data if data
+ end
+
+ # TODO: Strip custom fields and add a Control::flags_for(entry) method.
+ end
end
--
ci-tooling packaging
More information about the pkg-kde-commits
mailing list