X-Git-Url: https://git.tld-linux.org/?p=tld-builder.git;a=blobdiff_plain;f=TLD_Builder%2Frequest.py;h=efedbb96fb23fc59f3c3f8b55a5b6aaa9f77b512;hp=27bc426364538a683cf287a487d8e84dcd4bffc8;hb=b7bf1e2b6deab33a0a91bbeb14f3dddf701707ba;hpb=b999f53d4bf5d44586ecf028876e8bc20b5fd2ce diff --git a/TLD_Builder/request.py b/TLD_Builder/request.py index 27bc426..efedbb9 100644 --- a/TLD_Builder/request.py +++ b/TLD_Builder/request.py @@ -16,7 +16,6 @@ import util import log from acl import acl from config import config -from subprocess import call __all__ = ['parse_request', 'parse_requests'] @@ -39,6 +38,20 @@ def attr(e, a, default = None): def escape(s): return xml.sax.saxutils.escape(s) +# return timestamp with timezone information +# so we could parse it in javascript +def tzdate(t): + # as strftime %z is unofficial, and does not work, need to make it numeric ourselves + date = time.strftime("%a %b %d %Y %H:%M:%S", time.localtime(t)) + # NOTE: the altzone is showing CURRENT timezone, not what the "t" reflects + # NOTE: when DST is off timezone gets it right, altzone not + if time.daylight: + tzoffset = time.altzone + else: + tzoffset = time.timezone + tz = '%+05d' % (-tzoffset / 3600 * 100) + return date + ' ' + tz + # return date in iso8601 format def iso8601(ts, timezone='UTC'): tz = pytz.timezone(timezone) @@ -46,7 +59,7 @@ def iso8601(ts, timezone='UTC'): return dt.isoformat() def is_blank(e): - return e.nodeType == Element.TEXT_NODE and string.strip(e.nodeValue) == "" + return e.nodeType == Element.TEXT_NODE and e.nodeValue.strip() == "" class Group: def __init__(self, e): @@ -59,7 +72,7 @@ class Group: self.requester = "" self.max_jobs = 0 self.requester_email = "" - self.flags = string.split(attr(e, "flags", "")) + self.flags = attr(e, "flags", "").split() for c in e.childNodes: if is_blank(c): continue @@ -84,7 +97,7 @@ class Group: deps = [] m[b.b_id] = b for dep in b.depends_on: - if m.has_key(dep): + if dep in m: # avoid self-deps if id(m[dep]) != id(b): deps.append(m[dep]) @@ -97,28 +110,45 @@ class Group: def dump(self, f): f.write("group: %d (id=%s pri=%d)\n" % (self.no, self.id, self.priority)) f.write(" from: %s\n" % self.requester) - f.write(" flags: %s\n" % string.join(self.flags)) + f.write(" flags: %s\n" % self.flags.join()) f.write(" time: %s\n" % time.asctime(time.localtime(self.time))) for b in self.batches: b.dump(f) f.write("\n") + # return structure usable for json encoding + def dump_json(self): + batches = [] + for b in self.batches: + batches.append(b.dump_json()) + + return dict( + no=self.no, + id=self.id, + time=self.time, + requester=self.requester, + priority=self.priority, + max_jobs=self.max_jobs, + flags=self.flags, + batches=batches, + ) + def dump_html(self, f): f.write( "
\n" "%(no)d. " - " " + " " "from %(requester)s " "%(id)s, prio=%(priority)d, jobs=%(max_jobs)d, %(flags)s\n" % { 'no': self.no, 'id': '%(id)s' % {'id': self.id}, - 'time': escape(time.strftime("%a %b %d %Y %H:%M:%S %z", time.localtime(self.time))), + 'time': escape(tzdate(self.time)), 'datetime': escape(iso8601(self.time)), 'requester': escape(self.requester), 'priority': self.priority, 'max_jobs': self.max_jobs, - 'flags': string.join(self.flags) + 'flags': self.flags.join() }) f.write("
    \n") for b in self.batches: @@ -132,7 +162,7 @@ class Group: %s %d - %d\n""" % (self.id, self.no, string.join(self.flags), + %d\n""" % (self.id, self.no, self.flags.join(), escape(self.requester_email), escape(self.requester), self.time, self.priority, self.max_jobs)) for b in self.batches: @@ -146,7 +176,17 @@ class Group: ok = 0 return ok +# transform php package name (52) to version (5.2) +def php_name_to_ver(v): + return '.'.join(list(v)) + +# transform php version (5.2) to package name (52) +def php_ver_to_name(v): + return v.replace('.', '') + class Batch: + DEFAULT_PHP = '5.3' + def __init__(self, e): self.bconds_with = [] self.bconds_without = [] @@ -166,7 +206,7 @@ class Batch: self.skip = [] self.gb_id = "" self.b_id = attr(e, "id") - self.depends_on = string.split(attr(e, "depends-on")) + self.depends_on = attr(e, "depends-on").split() self.upgraded = True self.parse_xml(e) @@ -193,7 +233,7 @@ class Batch: elif c.nodeName == "command": self.spec = "COMMAND" self.command = text(c).strip() - self.command_flags = string.split(attr(c, "flags", "")) + self.command_flags = attr(c, "flags", "").split() elif c.nodeName == "info": self.info = text(c) elif c.nodeName == "kernel": @@ -254,28 +294,54 @@ class Batch: builders = [] for b in self.builders: builders.append("%s:%s" % (b, self.builders_status[b])) - f.write(" builders: %s\n" % string.join(builders)) + f.write(" builders: %s\n" % builders.join()) def is_command(self): return self.command != "" + # return structure usable for json encoding + def dump_json(self): + return dict( + command=self.command, + command_flags=self.command_flags, + + spec=self.spec, + branch=self.branch, + package=self.spec[:-5], + src_rpm=self.src_rpm, + + bconds_with=self.bconds_with, + bconds_without=self.bconds_without, + + kernel=self.kernel, + target=self.target, + defines=self.defines, + + builders=self.builders, + builders_status=self.builders_status, + builders_status_time=self.builders_status_time, + builders_status_buildtime=self.builders_status_buildtime, + ) + def dump_html(self, f, rid): f.write("
  1. \n") if self.is_command(): desc = "SH:
    %s
    flags: [%s]" % (self.command, ' '.join(self.command_flags)) else: - cmd = "/usr/bin/git ls-remote --heads git://git.tld-linux.org/packages/%s 1>/dev/null 2>&1" % (self.spec[:-5]) - r = call(cmd, shell=True) - if r == 0: - dist = "tld" - else: - dist = "pld" - package_url = "http://git.%(dist)s-linux.org/?p=packages/%(package)s.git;a=blob;f=%(spec)s;hb=%(branch)s" % { - 'dist': dist, - 'spec': urllib.quote(self.spec), - 'branch': urllib.quote(self.branch), - 'package': urllib.quote(self.spec[:-5]), - } + cmd = "/usr/bin/git ls-remote --heads git://git.tld-linux.org/packages/%s 1>/dev/null 2>&1" % (self.spec[:-5]) + r = call(cmd, shell=True) + if r == 0: + package_url = "http://git.tld-linux.org/?p=packages/%(package)s.git;a=blob;f=%(spec)s;hb=%(branch)s" % { + 'spec': urllib.quote(self.spec), + 'branch': urllib.quote(self.branch), + 'package': urllib.quote(self.spec[:-5]), + } + else: + package_url = "http://git.pld-linux.org/gitweb.cgi?p=packages/%(package)s.git;f=%(spec)s;h=%(branch)s;a=shortlog" % { + 'spec': urllib.quote(self.spec), + 'branch': urllib.quote(self.branch), + 'package': urllib.quote(self.spec[:-5]), + } desc = "%(src_rpm)s (%(spec)s -r %(branch)s%(rpmopts)s)" % { 'src_rpm': self.src_rpm, 'spec': self.spec, @@ -312,8 +378,8 @@ class Batch: bld = lin_ar.split('-') tree_name = '-'.join(bld[:-1]) tree_arch = '-'.join(bld[-1:]) - link_pre = "" \ - % (urllib.quote(tree_name), urllib.quote(tree_arch), urllib.quote(bl_name), urllib.quote(rid)) + link_pre = "" \ + % (urllib.quote(tree_name), urllib.quote(tree_arch), urllib.quote(bl_name), urllib.quote(rid)) link_post = "" def ftime(s): @@ -335,7 +401,7 @@ class Batch: 'tooltip' : cgi.escape(tooltip, True), } + link_post) - f.write("%s]
  2. \n" % string.join(builders)) + f.write("%s]\n" % builders.join()) def rpmbuild_opts(self): """ @@ -350,20 +416,9 @@ class Batch: "--define '_builddir %{_topdir}/BUILD' " return rpmdefs + rpmopts - def php_ignores(self): - # transform php package name (52) to version (5.2) - def php_name_to_ver(v): - return '.'.join(list(v)) - - # transform php version (5.2) to package name (52) - def php_ver_to_name(v): - return v.replace('.', '') - + def php_ignores(self, php_version): # available php versions in distro - php_versions = ['4', '5.2', '5.3', '5.4', '5.5', '5.6', '7.0'] - - # current version if -D php_suffix is present - php_version = php_name_to_ver(self.defines['php_suffix']) + php_versions = ['7.2', '7.3', '7.4', '8.0'] # remove current php version try: @@ -375,7 +430,7 @@ class Batch: # map them to poldek ignores # always ignore hhvm res = ['hhvm-*'] - for v in map(php_ver_to_name, php_versions): + for v in list(map(php_ver_to_name, php_versions)): res.append("php%s-*" % v) return res @@ -386,8 +441,13 @@ class Batch: ignores = [] # add php version based ignores - if self.defines.has_key('php_suffix'): - ignores.extend(self.php_ignores()) + if 'php_suffix' in self.defines: + # current version if -D php_suffix is present + php_version = php_name_to_ver(self.defines['php_suffix']) + else: + php_version = self.DEFAULT_PHP + + ignores.extend(self.php_ignores(php_version)) # return empty string if the list is empty if len(ignores) == 0: @@ -396,7 +456,7 @@ class Batch: def add_ignore(s): return "--ignore=%s" % s - return " ".join(map(add_ignore, ignores)) + return " ".join(list(map(add_ignore, ignores))) def kernel_string(self): r = "" @@ -441,7 +501,7 @@ class Batch: %s %s %s\n""" % (self.b_id, - string.join(map(lambda (b): b.b_id, self.depends_on)), + list(map(lambda b: b.b_id, self.depends_on)).join(), escape(self.src_rpm), escape(' '.join(self.command_flags)), escape(self.command), escape(self.spec), escape(self.branch), escape(self.info))) @@ -456,7 +516,7 @@ class Batch: if self.defines: f.write(" %s\n" % self.defines_xml()) for b in self.builders: - if self.builders_status_buildtime.has_key(b): + if b in self.builders_status_buildtime: t = self.builders_status_buildtime[b] else: t = "0" @@ -505,11 +565,20 @@ class Notification: else: log.panic("xml: evil notification child (%s)" % c.nodeName) + # return structure usable for json encoding + def dump_json(self): + return dict( + id=self.group_id, + builder=self.builder, + batches=self.batches, + batches_buildtime=self.batches_buildtime, + ) + def apply_to(self, q): for r in q.requests: if r.kind == "group": for b in r.batches: - if self.batches.has_key(b.b_id): + if b.b_id in self.batches: b.builders_status[self.builder] = self.batches[b.b_id] b.builders_status_time[self.builder] = time.time() b.builders_status_buildtime[self.builder] = "0" #self.batches_buildtime[b.b_id]