diff options
Diffstat (limited to 'MgaRepo/log.py')
-rw-r--r-- | MgaRepo/log.py | 134 |
1 files changed, 36 insertions, 98 deletions
diff --git a/MgaRepo/log.py b/MgaRepo/log.py index 8e062ad..fab7d6e 100644 --- a/MgaRepo/log.py +++ b/MgaRepo/log.py @@ -1,3 +1,4 @@ +#!/usr/bin/python3 from MgaRepo import Error, config, layout from MgaRepo.svn import SVN from MgaRepo.util import execcmd @@ -7,7 +8,6 @@ from io import StringIO import sys import os -import os.path import re import time import locale @@ -27,6 +27,7 @@ def getrelease(pkgdirurl, rev=None, macros=[], exported=None, create=False): Is here where things should be changed if "automatic release increasing" will be used. """ + from MgaRepo.rpmutil import rpm_macros_defs svn = SVN() pkgcurrenturl = os.path.join(pkgdirurl, "current") specurl = os.path.join(pkgcurrenturl, "SPECS") @@ -42,11 +43,17 @@ def getrelease(pkgdirurl, rev=None, macros=[], exported=None, create=False): if not found: raise Error("no .spec file found inside %s" % specurl) specpath = found[0] - options = [("--define", expr) for expr in macros] - command = ["rpm", "-q", "--qf", "%{EPOCH}:%{VERSION}-%{RELEASE}\n", - "--specfile", specpath] - command.extend(options) - status, output = execcmd(*command) + options = rpm_macros_defs(macros) + command = (("rpm -q --qf '%%{EPOCH}:%%{VERSION}-%%{RELEASE}\n' " + "--specfile %s %s") % + (specpath, options)) + pipe = subprocess.Popen(command, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, shell=True) + pipe.wait() + output = pipe.stdout.read().decode('utf8') + error = pipe.stderr.read().decode('utf8') + if pipe.returncode != 0: + raise Error("Error in command %s: %s" % (command, error)) releases = output.split() try: epoch, vr = releases[0].split(":", 1) @@ -74,11 +81,17 @@ def getrelease(pkgdirurl, rev=None, macros=[], exported=None, create=False): if not found: raise Error("no .src.rpm file found inside %s" % srpmurl) srpmpath = found[0] - options = [("--define", expr) for expr in macros] - command = ["rpm", "-q", "--qf", "%{EPOCH}:%{VERSION}-%{RELEASE}\n", - "--specfile", specpath] - command.extend(options) - status, output = execcmd(*command) + options = rpm_macros_defs(macros) + command = (("rpm -qp --qf '%%{EPOCH}:%%{VERSION}-%%{RELEASE}\n' " + " %s %s") % + (srpmpath, options)) + pipe = subprocess.Popen(command, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, shell=True) + pipe.wait() + output = pipe.stdout.read().decode('utf8') + error = pipe.stderr.read().decode('utf8') + if pipe.returncode != 0: + raise Error("Error in command %s: %s" % (command, error)) releases = output.split() try: epoch, vr = releases[0].split(":", 1) @@ -244,12 +257,11 @@ def group_revisions_by_author(currentlog): emailpat = re.compile("(?P<name>.*?)\s*<(?P<email>.*?)>") -usermap = {} + def get_author_name(author): found = emailpat.match(config.get("users", author, author)) - gold = emailpat.match(usermap.get(author,"")) - name = ((found and found.group("name")) or (gold and gold.group("name")) or author) - email = ((found and found.group("email")) or (gold and gold.group("email")) or author+"@mageia.org") + name = ((found and found.group("name")) or author) + email = ((found and found.group("email")) or author) return name, email def parse_raw_date(rawdate): @@ -342,18 +354,15 @@ def dump_file(releases, currentlog=None, template=None): first = False else: draft = draft + spaces + line + "\n" - if rel is not releases_author[-1]: - draft += "\n" + draft += '\n' else: # default template if not releases_author[-1].visible: releases_author = releases_author[:-1] for rel in releases_author: if not rel.released: - unreleased = " (not released yet)\n" - else: - unreleased = "" - draft = draft + "* {0} {1} <{2}> {3}-{4}\n{5}+ Revision: {6}\n".format(rel.date, rel.author_name, rel.author_email, rel.version, rel.release, unreleased, rel.revision) + draft = " (not released yet)\n" + draft = draft + "* {0} {1} <{2}> {3}-{4}\n+ Revision: {5}\n".format(rel.date, rel.author_name, rel.author_email, rel.version, rel.release, rel.revision) if not rel.visible: draft = draft + "+ rebuild (emptylog)\n" for rev in rel.release_revisions: @@ -366,8 +375,7 @@ def dump_file(releases, currentlog=None, template=None): for rev in author.revisions: for line in rev.lines: draft = draft + line + "\n" - if rel is not releases_author[-1]: - draft += "\n" + draft += "\n" return draft class InvalidEntryError(Exception): @@ -570,14 +578,14 @@ def get_old_log(pkgdirurl): chlog = StringIO() oldurl = config.get("log", "oldurl") if oldurl: - svn = SVN(url=oldurl) + svn = SVN() tmpdir = tempfile.mktemp() try: if oldurl == '.' or oldurl.startswith('./'): pkgoldurl = os.path.join(pkgdirurl, oldurl) else: pkgname = layout.package_name(pkgdirurl) - pkgoldurl = os.path.join(svn.url, pkgname) + pkgoldurl = os.path.join(oldurl, pkgname) try: # we're using HEAD here because fixes in misc/ (oldurl) may # be newer than packages' last changed revision. @@ -598,74 +606,9 @@ def get_old_log(pkgdirurl): chlog.seek(0) return chlog -from html.parser import HTMLParser -from urllib.request import urlopen -class UserTagParser(HTMLParser): - li = False - ahref = False - userpage = None - namepat = re.compile("(?P<name>.*?)\s*\((?P<user>.*?)\)") - usermap = {} - usermapfile = None - - def __init__(self, url=None, defaultmail=None, *cmd, **kwargs): - HTMLParser.__init__(self, *cmd, **kwargs) - self.url = url or "http://people.mageia.org/u/" - self.defaultmail = defaultmail or "mageia.org" - - def handle_starttag(self, tag, attrs): - if tag == "li": - self.li = True - if self.li and tag == "a": - for att in attrs: - if att[0] == "href": - self.ahref = True - self.userpage = att[1] - - def handle_endtag(self, tag): - if self.li and tag == "a": - self.ahref = False - self.userpage = None - if tag == "li": - self.li = False - - def handle_data(self, data): - if self.li and self.ahref: - found = self.namepat.match(data) - if found: - user = found.group("user") - name = found.group("name") - if user and name and user+".html" == self.userpage: - self.usermap[user] = "%s <%s@%s>" % (name, user, self.defaultmail) - - def get_user_map(self): - f = urlopen(self.url) - userhtml = f.read().decode("UTF-8") - f.close() - self.feed(userhtml) - return self.usermap - - def get_user_map_file(self): - if not self.usermap: - self.get_user_map() - self.usermapfile = tempfile.mkstemp(suffix=".txt", prefix="usermap") - f = open(self.usermapfile[0], "w", encoding="UTF-8") - f.writelines("%s = %s\n" % user for user in sorted(self.usermap.items())) - f.close() - return self.usermapfile[1] - - def cleanup(self): - if os.path.exists(self.usermapfile[1]): - os.unlink(self.usermapfile[1]) - -def _map_user_names(): - if not usermap: - parser = UserTagParser() - usermap.update(parser.get_user_map()) - def get_changelog(pkgdirurl, another=None, svn=True, rev=None, size=None, submit=False, sort=False, template=None, macros=[], exported=None, - oldlog=False, create=False, fullnames=False): + oldlog=False, create=False): """Generates the changelog for a given package URL @another: a stream with the contents of a changelog to be merged with @@ -691,9 +634,6 @@ def get_changelog(pkgdirurl, another=None, svn=True, rev=None, size=None, """ newlog = StringIO() if svn: - if fullnames: - if not usermap: - _map_user_names() rawsvnlog = svn2rpm(pkgdirurl, rev=rev, size=size, submit=submit, template=template, macros=macros, exported=exported, create=create) newlog.write(rawsvnlog) @@ -708,21 +648,19 @@ def get_changelog(pkgdirurl, another=None, svn=True, rev=None, size=None, return newlog def specfile_svn2rpm(pkgdirurl, specfile, rev=None, size=None, - submit=False, sort=False, template=None, macros=[], exported=None, create=False, fullnames=False): + submit=False, sort=False, template=None, macros=[], exported=None, create=False): with open(specfile, encoding = 'utf-8') as fi: spec, oldchlog = split_spec_changelog(fi) another = None if config.getbool("log", "merge-spec", False): another = oldchlog sort = sort or config.getbool("log", "sort", False) - if fullnames: - _map_user_names() chlog = get_changelog(pkgdirurl, another=another, rev=rev, size=size, submit=submit, sort=sort, template=template, macros=macros, exported=exported, oldlog=True, create=create) with open(specfile, "w", encoding='utf-8') as fo: fo.writelines(spec) - fo.write("\n%changelog\n") + fo.write("\n\n%changelog\n") fo.writelines(chlog) if __name__ == "__main__": |