Example #1
0
 def append_log(self, log):
     s = os.stat(log)
     if s.st_size > 50000:
         # just head and tail
         f = open(log)
         line_cnt = 0
         for l in f.xreadlines():
             line_cnt += 1
         f.seek(0)
         line = 0
         for l in f.xreadlines():
             if line < 100 or line > line_cnt - 100:
                 self.body.write(recode(l))
             if line == line_cnt - 100:
                 self.body.write("\n\n[...]\n\n")
             line += 1
     else:
         util.sendfile(open(log), self.body)
Example #2
0
 def write_signed(self, name):
     sio = StringIO.StringIO()
     self._write_to(sio)
     sio.seek(0)
     sio.write(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)
     f.flush()
     os.fsync(f.fileno())
     f.close()
     os.chmod(tmpname, 0644)
     os.rename(tmpname, name)
Example #3
0
 def write_signed(self, name):
     sio = StringIO.StringIO()
     self._write_to(sio)
     sio.seek(0)
     sio.write(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)
     f.flush()
     os.fsync(f.fileno())
     f.close()
     os.chmod(tmpname, 0644)
     os.rename(tmpname, name)
Example #4
0
                errno = error.errno
            except AttributeError:
                # python 2.4
                errno = error.reason[0]

            if errno in [-3, 60, 61, 110, 111]:
                b.log_line("unable to connect to %s... trying again" %
                           (src_url))
                continue
            else:
                raise

    o = chroot.popen("cat > %s" % b.src_rpm, mode="w")

    try:
        bytes = util.sendfile(f, o)
    except IOError, e:
        b.log_line("error: unable to write to `%s': %s" % (b.src_rpm, e))
        raise

    f.close()
    o.close()
    t = time.time() - start
    if t == 0:
        b.log_line("fetched %d bytes" % bytes)
    else:
        b.log_line("fetched %d bytes, %.1f K/s" % (bytes, bytes / 1024.0 / t))


def prepare_env(logfile=None):
    chroot.run("""
def fetch_queue(control_url):
    signal.signal(signal.SIGALRM, alarmalarm)
    socket.setdefaulttimeout(240)
    signal.alarm(300)
    try:
        headers = { 'Cache-Control': 'no-cache', 'Pragma': 'no-cache' }
        req = urllib2.Request(url=control_url + "/queue.gz", headers=headers)
        f = urllib2.urlopen(req)
        signal.alarm(0)
    except Exception, e:
        signal.alarm(0)
        log.error("can't fetch %s: %s" % (control_url + "/queue.gz", e))
        sys.exit(1)
    sio = StringIO.StringIO()
    util.sendfile(f, sio)
    f.close()
    sio.seek(0)
    f = gzip.GzipFile(fileobj = sio)
    (signers, body) = gpg.verify_sig(f.read())
    u = acl.user_by_email(signers)
    if u == None:
        log.alert("queue.gz not signed with signature of valid user: %s" % signers)
        sys.exit(1)
    if not u.can_do("sign_queue", "all"):
        log.alert("user %s is not allowed to sign my queue" % u.login)
        sys.exit(1)
    return request.parse_requests(body)

def handle_reqs(builder, reqs):
    qpath = path.queue_file + "-" + builder
def fetch_queue(control_url):
    signal.signal(signal.SIGALRM, alarmalarm)
    socket.setdefaulttimeout(240)
    signal.alarm(300)
    try:
        headers = {'Cache-Control': 'no-cache', 'Pragma': 'no-cache'}
        req = urllib2.Request(url=control_url + "/queue.gz", headers=headers)
        f = urllib2.urlopen(req)
        signal.alarm(0)
    except Exception, e:
        signal.alarm(0)
        log.error("can't fetch %s: %s" % (control_url + "/queue.gz", e))
        sys.exit(1)
    sio = StringIO.StringIO()
    util.sendfile(f, sio)
    f.close()
    sio.seek(0)
    f = gzip.GzipFile(fileobj=sio)
    (signers, body) = gpg.verify_sig(f.read())
    u = acl.user_by_email(signers)
    if u == None:
        log.alert("queue.gz not signed with signature of valid user: %s" %
                  signers)
        sys.exit(1)
    if not u.can_do("sign_queue", "all"):
        log.alert("user %s is not allowed to sign my queue" % u.login)
        sys.exit(1)
    return request.parse_requests(body)

Example #7
0
            try:
                errno = error.errno
            except AttributeError:
                # python 2.4
                errno = error.reason[0]

            if errno in [-3, 60, 61, 110, 111]:
                b.log_line("unable to connect to %s... trying again" % (src_url))
                continue
            else:
                raise

    o = chroot.popen("cat > %s" % b.src_rpm, mode = "w")

    try:
        bytes = util.sendfile(f, o)
    except IOError, e:
        b.log_line("error: unable to write to `%s': %s" % (b.src_rpm, e))
        raise

    f.close()
    o.close()
    t = time.time() - start
    if t == 0:
        b.log_line("fetched %d bytes" % bytes)
    else:
        b.log_line("fetched %d bytes, %.1f K/s" % (bytes, bytes / 1024.0 / t))

def prepare_env(logfile = None):
    chroot.run("""
        test ! -f /proc/uptime && mount /proc 2>/dev/null
Example #8
0
 def write_to(self, f):
     for k, v in self.headers.items():
         f.write("%s: %s\n" % (k, v))
     f.write("\n")
     self.body.seek(0)
     util.sendfile(self.body, f)