# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
import sys
-if sys.version_info[0] == 2:
- import ConfigParser
-else:
- import configparser as ConfigParser
+import configparser as ConfigParser
import string
import fnmatch
import os
import gzip
import time
import sys
-if sys.version_info[0] == 2:
- import StringIO
-else:
- from io import StringIO
+from io import StringIO
import os
import fcntl
import string
import tempfile
+import shutil
# TLD_Builder:
import gpg
sio = StringIO()
self._write_to(sio)
sio.seek(0)
- sio.write(gpg.sign(sio.read()))
+ sio.write(util.to_str(gpg.sign(sio.read())))
sio.seek(0)
(fdno, tmpname) = tempfile.mkstemp(dir=os.path.dirname(name))
f = os.fdopen(fdno, "w")
- if re.search(r"\.gz$", name):
- fgz = gzip.GzipFile(filename=name, mode="w", compresslevel=6, fileobj=f)
- util.sendfile(sio, fgz)
- fgz.close()
- else:
- util.sendfile(sio, f)
+ util.sendfile(sio, f)
f.flush()
os.fsync(f.fileno())
f.close()
- os.chmod(tmpname, 0o0644)
- os.rename(tmpname, name)
+ if re.search(r"\.gz$", name):
+ f_in = open(tmpname, 'rb')
+ f_out = gzip.open(name, 'wb')
+ shutil.copyfileobj(f_in, f_out)
+ f_in.close();
+ f_out.flush();
+ os.fsync(f_out.fileno())
+ f_out.close();
+ os.remove(tmpname)
+ else:
+ os.rename(tmpname, name)
+ os.chmod(name, 0o0644)
def add(self, req):
self.requests.append(req)
import os
import re
import random
+import util
try:
from hashlib import md5 as md5
def cp(file, outfile, user="builder", rm=False):
m = md5()
- m.update(str(random.sample(range(100000), 500)).encode('utf-8'))
+ m.update(util.to_bytes(str(random.sample(range(100000), 500))))
digest = m.hexdigest()
marker_start = "--- FILE BEGIN DIGEST %s ---" % digest
me = l.find(marker_end)
if me != -1:
l = l[:me]
- f.write(l)
+ f.write(util.to_bytes(l))
marker = False
break
if marker:
- f.write(l)
+ f.write(util.to_bytes(l))
rp = p.close()
rf = f.close()
if rp == None:
# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
import sys
-if sys.version_info[0] == 2:
- import ConfigParser
-else:
- import configparser as ConfigParser
+import configparser as ConfigParser
import string
import os
import syslog
import subprocess
import re
import sys
-if sys.version_info[0] == 2:
- import StringIO
-else:
- from io import StringIO
-
+from io import StringIO
import util
import os
import pipeutil
cmd = ['/usr/bin/gpg', '--batch', '--no-tty', '--decrypt']
gpg_run = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
try:
- d_stdout, d_stderr = gpg_run.communicate(buf.decode().encode('utf-8'))
+ d_stdout, d_stderr = gpg_run.communicate(util.to_bytes(buf))
except OSError as e:
log.error("gnupg run, does gpg binary exist? : %s" % e)
raise
rx = re.compile("^gpg:.*using\s[DR]SA\skey\s(?:ID\s)?(\w+)")
keys = []
- for l in d_stderr.decode().split('\n'):
+ for l in util.to_str(d_stderr).split('\n'):
m = rx.match(l)
if m:
keys.append(m.group(1))
cmd = ['/usr/bin/gpg', '--batch', '--no-tty', '--decrypt']
gpg_run = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
try:
- d_stdout, d_stderr = gpg_run.communicate(buf.decode().encode('utf-8'))
+ d_stdout, d_stderr = gpg_run.communicate(util.to_bytes(buf))
except OSError as e:
log.error("gnupg run failed, does gpg binary exist? : %s" % e)
raise
rx = re.compile("^gpg: (Good signature from| aka) .*<([^>]+)>")
emails = []
- for l in d_stderr.decode().split('\n'):
+ for l in util.to_str(d_stderr).split('\n'):
m = rx.match(l)
if m:
emails.append(m.group(2))
# TODO: check for gpg return code!
gpg_run = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
try:
- d_stdout, d_stderr = gpg_run.communicate(buf.decode().encode('utf-8'))
+ d_stdout, d_stderr = gpg_run.communicate(util.to_bytes(buf))
except OSError as e:
log.error("gnupg signing failed, does gpg binary exist? : %s" % e)
raise
if len(d_stderr):
- log.error("gpg: %s" % d_stderr.decode())
+ log.error("gpg: %s" % util.to_str(d_stderr))
return d_stdout
import re, os
import string
import sys
-if sys.version_info[0] == 2:
- import StringIO
-else:
- from io import StringIO
-
+from io import StringIO
import chroot
import util
import log
import time
import os
import sys
-if sys.version_info[0] == 2:
- import StringIO
-else:
- from io import StringIO
-
+from io import StringIO
from config import config
import util
import log
# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
import sys
-if sys.version_info[0] == 2:
- import StringIO
-else:
- from io import StringIO
-
+from io import StringIO
import mailer
import gpg
import util
sio = StringIO()
self.xml.write("</notification>\n")
self.xml.seek(0)
- sio.write(gpg.sign(self.xml.read()))
+ sio.write(util.to_str(gpg.sign(self.xml.read())))
self.xml = None
sio.seek(0)
notifyq.init(r)
import select
import os
import sys
-if sys.version_info[0] == 2:
- import StringIO
-else:
- from io import StringIO
+from io import StringIO
def rw_pipe(buf_, infd, outfd):
buf = StringIO()
import fnmatch
import os
import urllib
-import cgi
+import html
import pytz
import tempfile
import subprocess
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,
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))
+ % (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):
'color' : c,
'builder' : b,
'status' : s,
- 'tooltip' : cgi.escape(tooltip, True),
+ 'tooltip' : html.escape(tooltip, True),
}
+ link_post)
f.write("%s]</small></li>\n" % ' '.join(builders))
import urllib
import urllib2
import sys
-if sys.version_info[0] == 2:
- import StringIO
-else:
- from io import StringIO
+from io import StringIO
import gzip
-
import path
import log
import status
import time
import os
import sys
-if sys.version_info[0] == 2:
- import StringIO
-else:
- from io import StringIO
import fnmatch
-
import gpg
import request
import log
return False
def fetch_src(r, b):
- src_url = config.control_url + "/srpms/" + r.id + "/" + urllib.quote(b.src_rpm)
+ src_url = config.control_url + "/srpms/" + r.id + "/" + urllib.parse.quote(b.src_rpm)
b.log_line("fetching %s" % src_url)
start = time.time()
good = False
print("error.reason exception %s" % e)
raise
- o = chroot.popen("cat > %s" % b.src_rpm, mode = "w")
+ o = chroot.popen("cat > %s" % b.src_rpm, mode = "wb")
try:
bytes = util.sendfile(f, o)
import time
import os
import sys
-if sys.version_info[0] == 2:
- import StringIO
-else:
- from io import StringIO
import re
import shutil
import atexit
import os
import log
import string
+import codecs
def uuid_python():
return str(uuid_random())
def __ne__(self, other):
return mycmp(self.obj, other.obj) != 0
return K
+
+def to_bytes(s):
+ if type(s) is bytes:
+ return s
+ elif type(s) is str or (sys.version_info[0] < 3 and type(s) is unicode):
+ return codecs.encode(s, 'utf-8')
+ else:
+ raise TypeError("Expected bytes or string, but got %s." % type(s))
+
+def to_str(s):
+ if type(s) is bytes:
+ return codecs.decode(s, 'utf-8')
+ elif type(s) is str or (sys.version_info[0] < 3 and type(s) is unicode):
+ return s
+ else:
+ raise TypeError("Expected bytes or string, but got %s." % type(s))
import log
import traceback
import sys
-if sys.version_info[0] == 2:
- import StringIO
-else:
- from io import StringIO
+from io import StringIO
import os
import time