summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlav Vitters <ovitters@mageia.org>2012-02-14 10:38:56 +0000
committerOlav Vitters <ovitters@mageia.org>2012-02-14 10:38:56 +0000
commit2bc96a516bbb42b401b711787de7625f0a2558bd (patch)
tree263a497eb061c99c9e0d4aa695c4f84048b62549
parent2f5a66b157683ccbba55922f835f246aea3a5044 (diff)
downloadmgagnome-2bc96a516bbb42b401b711787de7625f0a2558bd.tar
mgagnome-2bc96a516bbb42b401b711787de7625f0a2558bd.tar.gz
mgagnome-2bc96a516bbb42b401b711787de7625f0a2558bd.tar.bz2
mgagnome-2bc96a516bbb42b401b711787de7625f0a2558bd.tar.xz
mgagnome-2bc96a516bbb42b401b711787de7625f0a2558bd.zip
add option to add dep3 headers to existing patch
-rwxr-xr-xmgagnome92
1 files changed, 85 insertions, 7 deletions
diff --git a/mgagnome b/mgagnome
index 5849a37..50c1e0e 100755
--- a/mgagnome
+++ b/mgagnome
@@ -9,6 +9,8 @@ import urllib2
import urlparse
import argparse
import errno
+import tempfile
+import shutil
from sgmllib import SGMLParser
MEDIA="Core Release Source"
@@ -47,7 +49,40 @@ class Patch(object):
return self.path if self.show_path else os.path.basename(self.path)
def add_dep3(self):
- pass
+ if self.dep3['valid']:
+ return False
+
+ new_headers = (
+ ('Author', self.svn_author),
+ ('Subject', ''),
+ ('Applied-Upstream', ''),
+ ('Forwarded', ''),
+ ('Bug', ''),
+ )
+
+ with tempfile.NamedTemporaryFile(dir=os.path.dirname(self.path), delete=False) as fdst:
+ with open(self.path, "r") as fsrc:
+ # Start with any existing DEP3 headers
+ for i in range(self.dep3['last_nr']):
+ fdst.write(fsrc.read())
+
+ # After that add the DEP3 headers
+ add_line = False
+ for header, data in new_headers:
+ if header in self.dep3['headers']:
+ continue
+
+ # XXX - wrap this at 80 chars
+ add_line = True
+ print >>fdst, "%s: %s" % (header, data)
+
+ if add_line: print >>fdst, ""
+ # Now copy any other data and the patch
+ shutil.copyfileobj(fsrc, fdst)
+
+ fdst.flush()
+ os.rename(fdst.name, self.path)
+
#Author: fwang
#Subject: Build fix: Fix glib header inclusion
#Applied-Upstream: commit:30602
@@ -57,32 +92,48 @@ class Patch(object):
def _read_dep3(self):
"""This will also parse git headers"""
dep3 = {}
+ headers = {}
last_header = None
+ last_nr = 0
+ nr = 0
try:
with open(self.path, "r") as f:
for line in line_input(f):
- # Check for start of real patch
+ nr += 1
+ # stop trying to parse when real patch begins
if line == '---':
break
r = self.re_dep3.match(line)
if r:
info = r.groupdict()
- dep3[info['header']] = info['data']
+ headers[info['header']] = info['data']
last_header = info['header']
+ last_nr = nr
continue
r = self.re_dep3_cont.match(line)
if r:
info = r.groupdict()
if last_header:
- dep3[last_header] = " ".join((dep3[last_header], info['data']))
+ headers[last_header] = " ".join((headers[last_header], info['data']))
+ last_nr = nr
continue
last_header = None
except IOError:
pass
+
+ dep3['valid'] = \
+ (('Description' in headers and headers['Description'].strip() != '')
+ or ('Subject' in headers and headers['Subject'].strip() != '')) \
+ and (('Origin' in headers and headers['Origin'].strip() != '') \
+ or ('Author' in headers and headers['Author'].strip() != '') \
+ or ('From' in headers and headers['From'].strip() != ''))
+ dep3['last_nr'] = last_nr
+ dep3['headers'] = headers
+
self._dep3 = dep3
@property
@@ -92,6 +143,22 @@ class Patch(object):
return self._dep3
+ @property
+ def svn_author(self):
+ if not hasattr(self, '_svn_author'):
+ p = subprocess.Popen(['svn', 'log', '-q', "--", self.path], stdout=subprocess.PIPE, close_fds=True)
+ contents = p.stdout.read().strip("\n").splitlines()
+ ecode = p.wait()
+ if ecode == 0:
+ for line in contents:
+ if ' | ' not in line:
+ continue
+
+ fields = line.split(' | ')
+ if len(fields) >= 3:
+ self._svn_author = fields[1]
+
+ return self._svn_author
def get_upstream_names():
urlopen = urllib2.build_opener()
@@ -180,8 +247,14 @@ def cmd_patches(options, parser):
if '.patch' in filename or '.diff' in filename:
p = Patch(os.path.join(path, srpm, "SOURCES", filename), show_path=options.path)
print "\t".join((module, srpm, str(p)))
- if p.dep3:
- pprint.pprint(p.dep3)
+ if p.dep3['headers']:
+ pprint.pprint(p.dep3['headers'])
+ if p.dep3['valid']:
+ print "VALID"
+
+def cmd_dep3(options, parser):
+ p = Patch(options.patch)
+ p.add_dep3()
def main():
description = """Mageia GNOME commands."""
@@ -203,11 +276,16 @@ def main():
subparser = subparsers.add_parser('patches', help='list all GNOME patches')
subparser.add_argument("-p", "--path", action="store_true", dest="path",
- help="Full path to patch")
+ help="Show full path to patch")
subparser.set_defaults(
func=cmd_patches, path=False
)
+ subparser = subparsers.add_parser('dep3', help='Add dep3 headers')
+ subparser.add_argument("patch", help="Patch")
+ subparser.set_defaults(
+ func=cmd_dep3, path=False
+ )
if len(sys.argv) == 1:
parser.print_help()