[SCM] patch-parser packaging branch, master, updated. 43474b21f016a6c6ceaa1bd528e34a0ab6b65fbb
Harald Sitter
apachelogger-guest at moszumanska.debian.org
Tue Apr 14 07:55:59 UTC 2015
Gitweb-URL: http://git.debian.org/?p=pkg-kde/patch-parser.git;a=commitdiff;h=0320ed2
The following commit has been merged in the master branch:
commit 0320ed2c4912b14f22f46c46a468140262955323
Author: Harald Sitter <sitter at kde.org>
Date: Mon Apr 13 13:14:34 2015 +0200
isolate dep3 class into own file
---
lib/dep3.rb | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
patch-parser.rb | 140 +------------------------------------------------------
2 files changed, 143 insertions(+), 138 deletions(-)
diff --git a/lib/dep3.rb b/lib/dep3.rb
new file mode 100644
index 0000000..e6e5bdf
--- /dev/null
+++ b/lib/dep3.rb
@@ -0,0 +1,141 @@
+# Dep3 parser
+# use .parse! -> check .valid -> read with []
+#
+# Be very mindful of which functions from standard Hash are overriden here.
+# This class adds compatibility mapping on top of certain Hash functions, if
+# a function is not overriden it likely doesn't have the mapping so not all
+# possibly key values outlined in the spec will work.
+# Specifically this class always uses the first mentioned version of a field
+# name in the spec as the key value for internal storage. For example
+# Author > From.
+# So, while you can use d['From'] just fine, internally it is really d['Author']
+# that you get returned. Should you then try to use the From key on
+# non-overriden functions like delete you'll not have deleted the key because
+# it was called Author all along. To transparently map you can use
+# {get_alias} which will always give you the correct key name.
+class Dep3 < Hash
+ # nothing to see here
+ NONE_STATE = 0
+ # actively working on a header field, following fields may be folding
+ HEADER_STATE = 1
+ # processing freeform content
+ FREEFORM_STATE = 2
+
+ attr_reader :filepath
+ attr_accessor :valid
+
+ def initialize(filepath)
+ @filepath = filepath
+ @valid = false
+ @aliases = {
+ 'Description' => 'Subject',
+ 'Author' => 'From',
+ 'Reviewed-by' => 'Acked-by',
+ }
+ end
+
+ def get_alias(key)
+ @aliases.each do |alias_key, alias_value|
+ return alias_key if key == alias_value
+ end
+ return key
+ end
+
+ def [](key)
+ super(get_alias(key))
+ end
+
+ def []=(key,value)
+ super(get_alias(key), value)
+ end
+
+ def parse!()
+ state = NONE_STATE
+ current_header = nil
+
+ data = {}
+
+ File.readlines(@filepath).each do |line|
+ begin
+ break if line.strip == '---'
+ rescue
+ pp "This patch is weird"
+ next
+ end
+
+ header_match = line.match(/^(\S+):(.*)/)
+ if not header_match.nil?
+ # 0 = full match
+ # 1 = key match
+ # 2 = value match
+ key = header_match[1].lstrip
+ value = header_match[2].lstrip
+ if self[key].nil?
+ self[key] = value
+ else # append
+ self[key] << "
#{value}"
+ end
+ state = HEADER_STATE
+ current_header = key
+ next
+ end
+
+ fold_match = line.match(/^\s(.+)/)
+ if not fold_match.nil? and state == HEADER_STATE
+ # Folding value encountered -> append to header.
+ # 0 full match
+ # 1 value match
+ value = fold_match[1].lstrip
+ self[current_header] << "
#{value}"
+ next
+ end
+
+ if line == '
' and state == FREEFORM_STATE
+ state = NONE_STATE
+ next
+ end
+
+ # The line is not a header, nor is it an exepected folding value or
+ # ending freeform parsing.
+ # In all cases we are now entering a freeform state. The only
+ # way to leave free form is through
or parsing end.
+ # In freeform all lines are appended to __freeDescription verbatim.
+ # Later if an actual description field was found it will be
+ # appended to the Description field for outside consumption.
+ # The dep3 spec explicitly requires a Description or Subject
+ # field to be present, directly appending to the relevant field
+ # in the hash therefore would make checking this unnecessarily
+ # difficult.
+
+ # drop
to prevent newlines piling up, except when there is only
+ # a newline, we want to preserve those.
+ line.chomp! unless line.dup.chomp!.length == 0
+
+ if self['__freeDescription'].nil?
+ self['__freeDescription'] = line
+ else
+ self['__freeDescription'] << "
#{line}"
+ end
+
+ state = FREEFORM_STATE
+ current_header = nil
+ next
+ end
+
+ # Check for required headers.
+ return if self['Description'].nil?
+ return if self['Origin'].nil? and self['Author'].nil?
+
+ # Patch is legit dep3, append free form description lines to actual
+ # description.
+ self['Description'] << "
#{self['__freeDescription']}"
+ self.delete('__freeDescription')
+
+ # Bonus: strip useless characters from all values
+ self.each do |key, value|
+ self[key].strip!
+ end
+
+ @valid = true
+ end
+end
diff --git a/patch-parser.rb b/patch-parser.rb
index 192648a..7cbccd5 100644
--- a/patch-parser.rb
+++ b/patch-parser.rb
@@ -6,143 +6,7 @@ require 'mail'
require 'time'
require 'date'
-# Dep3 parser
-# use .parse! -> check .valid -> read with []
-#
-# Be very mindful of which functions from standard Hash are overriden here.
-# This class adds compatibility mapping on top of certain Hash functions, if
-# a function is not overriden it likely doesn't have the mapping so not all
-# possibly key values outlined in the spec will work.
-# Specifically this class always uses the first mentioned version of a field name
-# in the spec as the key value for internal storage. For example Author > From.
-# So, while you can use d['From'] just fine, internally it is really d['Author']
-# that you get returned. Should you then try to use the From key on non-overriden
-# functions like delete you'll not have deleted the key because it was called
-# Author all along. To transparently map you can use .get_alias(key) which will
-# always give you the correct key name.
-class Dep3 < Hash
- NONE_STATE = 0 # nothing to see here
- HEADER_STATE = 1 # actively working on a header field, following fields may be folding
- FREEFORM_STATE = 2 # processing freeform content
-
- attr_reader :filepath
- attr_accessor :valid
-
- def initialize(filepath)
- @filepath = filepath
- @valid = false
- @aliases = {
- 'Description' => 'Subject',
- 'Author' => 'From',
- 'Reviewed-by' => 'Acked-by',
- }
- end
-
- def get_alias(key)
- @aliases.each do |alias_key, alias_value|
- return alias_key if key == alias_value
- end
- return key
- end
-
- def [](key)
- super(get_alias(key))
- end
-
- def []=(key,value)
- super(get_alias(key), value)
- end
-
- def parse!()
- state = NONE_STATE
- current_header = nil
-
- data = {}
-
- File.readlines(@filepath).each do |line|
- begin
- break if line.strip == '---'
- rescue
- pp "This patch is weird"
- next
- end
-
- header_match = line.match(/^(\S+):(.*)/)
- if not header_match.nil?
- # 0 = full match
- # 1 = key match
- # 2 = value match
- key = header_match[1].lstrip
- value = header_match[2].lstrip
- if self[key].nil?
- self[key] = value
- else # append
- self[key] << "
#{value}"
- end
- state = HEADER_STATE
- current_header = key
- next
- end
-
- fold_match = line.match(/^\s(.+)/)
- if not fold_match.nil? and state == HEADER_STATE
- # Folding value encountered -> append to header.
- # 0 full match
- # 1 value match
- value = fold_match[1].lstrip
- self[current_header] << "
#{value}"
- next
- end
-
- if line == '
' and state == FREEFORM_STATE
- state = NONE_STATE
- next
- end
-
- # The line is not a header, nor is it an exepected folding value or
- # ending freeform parsing.
- # In all cases we are now entering a freeform state. The only
- # way to leave free form is through
or parsing end.
- # In freeform all lines are appended to __freeDescription verbatim.
- # Later if an actual description field was found it will be
- # appended to the Description field for outside consumption.
- # The dep3 spec explicitly requires a Description or Subject
- # field to be present, directly appending to the relevant field
- # in the hash therefore would make checking this unnecessarily
- # difficult.
-
- # drop
to prevent newlines piling up, except when there is only
- # a newline, we want to preserve those.
- line.chomp! unless line.dup.chomp!.length == 0
-
- if self['__freeDescription'].nil?
- self['__freeDescription'] = line
- else
- self['__freeDescription'] << "
#{line}"
- end
-
- state = FREEFORM_STATE
- current_header = nil
- next
- end
-
- # Check for required headers.
- return if self['Description'].nil?
- return if self['Origin'].nil? and self['Author'].nil?
-
- # Patch is legit dep3, append free form description lines to actual
- # description.
- self['Description'] << "
#{self['__freeDescription']}"
- self.delete('__freeDescription')
-
- # Bonus: strip useless characters from all values
- self.each do |key, value|
- self[key].strip!
- end
-
- @valid = true
- end
-end
+require_relative 'lib/dep3'
if ARGV.empty?
pp "Need atleast one argument"
@@ -249,6 +113,6 @@ File.open('patch.html', 'w'){ |f| f.write(@page.to_s) }
# subject 'Missing Dep 3 headers'
# body EMAIL_BODY + array.join('
')
# end
-#
+#
# mail.deliver!
# end
--
patch-parser packaging
More information about the pkg-kde-commits
mailing list