]> TLD Linux GIT Repositories - tld-builder.git/blobdiff - TLD_Builder/request.py
- merged PLD changes, now it works with python 3.x
[tld-builder.git] / TLD_Builder / request.py
index 27bc426364538a683cf287a487d8e84dcd4bffc8..039cf76627cc7821edac766ec19a419a4d8e937a 100644 (file)
@@ -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)
@@ -103,17 +116,34 @@ class Group:
             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(
             "<div id=\"%(no)d\" class=\"request %(flags)s\">\n"
             "<a href=\"#%(no)d\">%(no)d</a>. "
-            "<time class=\"timeago\" datetime=\"%(datetime)s\">%(time)s</time> "
+            "<time class=\"timeago\" title=\"%(datetime)s\" datetime=\"%(datetime)s\">%(time)s</time> "
             "from <b class=requester>%(requester)s</b> "
             "<small>%(id)s, prio=%(priority)d, jobs=%(max_jobs)d, %(flags)s</small>\n"
         % {
             'no': self.no,
             'id': '<a href="srpms/%(id)s">%(id)s</a>' % {'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,
@@ -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 = []
@@ -259,23 +299,49 @@ class Batch:
     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("<li>\n")
         if self.is_command():
             desc = "SH: <pre>%s</pre> 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 (<a href=\"%(package_url)s\">%(spec)s -r %(branch)s</a>%(rpmopts)s)" % {
                 'src_rpm': self.src_rpm,
                 'spec': self.spec,
@@ -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
@@ -387,7 +442,12 @@ class Batch:
 
         # add php version based ignores
         if self.defines.has_key('php_suffix'):
-            ignores.extend(self.php_ignores())
+            # 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:
            <spec>%s</spec>
            <branch>%s</branch>
            <info>%s</info>\n""" % (self.b_id,
-                 string.join(map(lambda (b): b.b_id, self.depends_on)),
+                 string.join(list(map(lambda (b): b.b_id, self.depends_on))),
                  escape(self.src_rpm),
                  escape(' '.join(self.command_flags)), escape(self.command),
                  escape(self.spec), escape(self.branch), escape(self.info)))
@@ -505,6 +565,15 @@ 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":