]> TLD Linux GIT Repositories - tld-builder.git/blobdiff - TLD_Builder/request.py
- fix urllib imports
[tld-builder.git] / TLD_Builder / request.py
index 039cf76627cc7821edac766ec19a419a4d8e937a..1d72f2e70f52032e1a103853fe57550473a3e470 100644 (file)
@@ -7,10 +7,11 @@ import time
 import xml.sax.saxutils
 import fnmatch
 import os
-import urllib
-import cgi
+import urllib.parse
+import html
 import pytz
 import tempfile
+import subprocess
 
 import util
 import log
@@ -59,7 +60,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):
@@ -72,7 +73,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
 
@@ -97,7 +98,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])
@@ -110,7 +111,7 @@ 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" % ' '.join(self.flags))
         f.write("  time: %s\n" % time.asctime(time.localtime(self.time)))
         for b in self.batches:
             b.dump(f)
@@ -148,7 +149,7 @@ class Group:
             'requester': escape(self.requester),
             'priority': self.priority,
             'max_jobs': self.max_jobs,
-            'flags': string.join(self.flags)
+            'flags': ' '.join(self.flags)
         })
         f.write("<ol>\n")
         for b in self.batches:
@@ -162,7 +163,7 @@ class Group:
          <requester email='%s'>%s</requester>
          <time>%d</time>
          <priority>%d</priority>
-         <maxjobs>%d</maxjobs>\n""" % (self.id, self.no, string.join(self.flags),
+         <maxjobs>%d</maxjobs>\n""" % (self.id, self.no, ' '.join(self.flags),
                     escape(self.requester_email), escape(self.requester),
                     self.time, self.priority, self.max_jobs))
         for b in self.batches:
@@ -206,7 +207,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)
@@ -233,7 +234,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":
@@ -294,7 +295,7 @@ 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" % ' '.join(builders))
 
     def is_command(self):
         return self.command != ""
@@ -329,18 +330,18 @@ class Batch:
             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)
+            r = subprocess.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]),
+                    'spec': urllib.parse.quote(self.spec),
+                    'branch': urllib.parse.quote(self.branch),
+                    'package': urllib.parse.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]),
+                    'spec': urllib.parse.quote(self.spec),
+                    'branch': urllib.parse.quote(self.branch),
+                    'package': urllib.parse.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,
@@ -378,8 +379,8 @@ class Batch:
                 bld = lin_ar.split('-')
                 tree_name = '-'.join(bld[:-1])
                 tree_arch = '-'.join(bld[-1:])
-               link_pre = "<a href=\"http://buildlogs.tld-linux.org/index.php?dist=%s&arch=%s&name=%s&id=%s&action=download\">" \
-                       % (urllib.quote(tree_name), urllib.quote(tree_arch), urllib.quote(bl_name), urllib.quote(rid))
+                link_pre = "<a href=\"http://buildlogs.tld-linux.org/index.php?dist=%s&arch=%s&name=%s&id=%s&action=download\">" \
+                    % (urllib.parse.quote(tree_name), urllib.parse.quote(tree_arch), urllib.parse.quote(bl_name), urllib.parse.quote(rid))
                 link_post = "</a>"
 
             def ftime(s):
@@ -398,10 +399,10 @@ class Batch:
                     'color' : c,
                     'builder' : b,
                     'status' : s,
-                    'tooltip' : cgi.escape(tooltip, True),
+                    'tooltip' : html.escape(tooltip, True),
             }
             + link_post)
-        f.write("%s]</small></li>\n" % string.join(builders))
+        f.write("%s]</small></li>\n" % ' '.join(builders))
 
     def rpmbuild_opts(self):
         """
@@ -441,7 +442,7 @@ class Batch:
         ignores = []
 
         # add php version based ignores
-        if self.defines.has_key('php_suffix'):
+        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:
@@ -501,7 +502,7 @@ class Batch:
            <spec>%s</spec>
            <branch>%s</branch>
            <info>%s</info>\n""" % (self.b_id,
-                 string.join(list(map(lambda (b): b.b_id, self.depends_on))),
+                 ' '.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)))
@@ -516,7 +517,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"
@@ -578,7 +579,7 @@ class Notification:
         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]