1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-02-26 04:02:11 +01:00

- updatepacmetafromspec: also update the Url in the metadata (patch by Lenz Grimmer <lenz@grimmer.com>) (applied slightly modified version)

- read_meta_from_spec(): use the re module to find tags and sections to avoid problems with lowercase/uppercase letters (e.g. "Url" vs. "URL")
This commit is contained in:
Marcus Hüwe 2008-08-03 19:36:07 +00:00
parent 3c5847e054
commit 707b057891

View File

@ -1031,8 +1031,9 @@ rev: %s
'with --specfile' 'with --specfile'
sys.exit(1) sys.exit(1)
data = read_meta_from_spec(specfile, 'Summary:', '%description') data = read_meta_from_spec(specfile, 'Summary', 'Url', '%description')
self.summary = data['Summary:'] self.summary = data['Summary']
self.url = data['Url']
self.descr = data['%description'] self.descr = data['%description']
@ -1053,6 +1054,10 @@ rev: %s
tree = ET.parse(filename) tree = ET.parse(filename)
tree.find('title').text = self.summary tree.find('title').text = self.summary
tree.find('description').text = ''.join(self.descr) tree.find('description').text = ''.join(self.descr)
url = tree.find('url')
if not url:
url = ET.SubElement(tree.getroot(), 'url')
url.text = self.url
tree.write(filename) tree.write(filename)
print '*' * 36, 'old', '*' * 36 print '*' * 36, 'old', '*' * 36
@ -1780,10 +1785,10 @@ def show_upstream_rev(apiurl, prj, pac):
def read_meta_from_spec(specfile, *args): def read_meta_from_spec(specfile, *args):
import codecs, locale import codecs, locale, re
""" """
Read tags and sections from spec file. To read out Read tags and sections from spec file. To read out
a tag the passed argument must end with a colon. To a tag the passed argument mustn't end with a colon. To
read out a section the passed argument must start with read out a section the passed argument must start with
a '%'. a '%'.
This method returns a dictionary which contains the This method returns a dictionary which contains the
@ -1804,27 +1809,26 @@ def read_meta_from_spec(specfile, *args):
spec_data = {} spec_data = {}
for itm in args: for itm in args:
if itm.endswith(':'): if itm.startswith('%'):
tags.append(itm)
elif itm.startswith('%'):
sections.append(itm) sections.append(itm)
else: else:
print >>sys.stderr, 'error - \'%s\' is not a tag nor a section' % itm tags.append(itm)
sys.exit(1)
tag_pat = '(?P<tag>^%s)\s*:\s*(?P<val>.*)'
for tag in tags: for tag in tags:
for line in lines: m = re.compile(tag_pat % tag, re.I | re.M).search(''.join(lines))
if line.startswith(tag): if m and m.group('val'):
spec_data[tag] = line.split(':')[1].strip() spec_data[tag] = m.group('val').strip()
break else:
if not spec_data.has_key(tag):
print >>sys.stderr, 'error - tag \'%s\' does not exist' % tag print >>sys.stderr, 'error - tag \'%s\' does not exist' % tag
sys.exit(1) sys.exit(1)
section_pat = '^%s\s*'
for section in sections: for section in sections:
try: m = re.compile(section_pat % section, re.I | re.M).search(''.join(lines))
start = lines.index(section + '\n') + 1 if m:
except ValueError: start = lines.index(m.group()) + 1
else:
print >>sys.stderr, 'error - section \'%s\' does not exist' % section print >>sys.stderr, 'error - section \'%s\' does not exist' % section
sys.exit(1) sys.exit(1)
data = [] data = []