from config import config, init_conf
import mailer
import path
-import wrap
import log
+import loop
import status
+import lock
retries_times = [5 * 60, 15 * 60, 60 * 60, 2 * 60 * 60, 5 * 60 * 60]
problem = ""
def main():
+ if lock.lock("sending-files", non_block = 1) == None:
+ return
init_conf("")
maybe_flush_queue(path.buildlogs_queue_dir)
maybe_flush_queue(path.ftp_queue_dir)
if __name__ == '__main__':
- wrap.wrap(main)
+ loop.run_loop(main)
import StringIO
import util
+import pipeutil
def verify_sig(buf):
"""Check signature.
object.
"""
(gpg_out, gpg_in, gpg_err) = popen2.popen3("gpg --decrypt")
- util.sendfile(buf, gpg_in)
- gpg_in.close()
- body = StringIO.StringIO()
- for l in gpg_out.xreadlines():
- body.write(l)
+ body = pipeutil.rw_pipe(buf, gpg_in, gpg_out)
rx = re.compile("^gpg: Good signature from .*<([^>]+)>")
emails = []
for l in gpg_err.xreadlines():
m = rx.match(l)
if m:
emails.append(m.group(1))
- body.seek(0)
- gpg_out.close()
gpg_err.close()
return (emails, body)
def sign(buf):
(gpg_out, gpg_in, gpg_err) = popen2.popen3("gpg --clearsign")
- util.sendfile(buf, gpg_in)
- gpg_in.close()
- body = StringIO.StringIO()
- for l in gpg_out.xreadlines():
- body.write(l)
- body.seek(0)
- gpg_out.close()
+ body = pipeutil.rw_pipe(buf, gpg_in, gpg_out)
gpg_err.close()
return body
import log
import status
import lock
-import wrap
+import loop
import rpm_builder
pass
if __name__ == '__main__':
- wrap.wrap(main)
+ loop.run_loop(main)
--- /dev/null
+import os
+import sys
+import time
+
+import wrap
+
+def run_loop(fnc, secs = 5, max = 60):
+ def run():
+ pid = os.fork()
+ if pid == 0:
+ wrap.wrap(fnc)
+ sys.exit(0)
+ else:
+ pid, s = os.waitpid(pid, 0)
+ if os.WIFEXITED(s):
+ s = os.WEXITSTATUS(s)
+ if s != 0:
+ sys.exit(s)
+ else:
+ sys.exit(10)
+
+ start = time.time()
+ while time.time() - start < max:
+ last = time.time()
+ run()
+ took = time.time() - last
+ if took < secs:
+ time.sleep(secs - took)
+
--- /dev/null
+import select
+import os
+import StringIO
+
+def rw_pipe(buf_, infd, outfd):
+ buf = StringIO.StringIO()
+ buf.write(buf_.read())
+ ret = StringIO.StringIO()
+ pos = 0
+ rd_fin = 0
+ wr_fin = 0
+ buf.seek(pos)
+ while not (rd_fin and wr_fin):
+ if wr_fin: o = []
+ else: o = [infd]
+ if rd_fin: i = []
+ else: i = [outfd]
+ i, o, e = select.select(i, o, [])
+ if i != []:
+ s = os.read(outfd.fileno(), 1000)
+ if s == "": rd_fin = 1
+ ret.write(s)
+ if o != []:
+ buf.seek(pos)
+ s = buf.read(1000)
+ if s == "":
+ infd.close()
+ wr_fin = 1
+ else:
+ cnt = os.write(infd.fileno(), s)
+ pos += cnt
+ outfd.close()
+ ret.seek(0)
+ return ret
except:
if default != None:
return default
- # get the same exception
- return e.attributes[a].value
+ raise
def escape(s):
return xml.sax.saxutils.escape(s)
import util
import gpg
import request
-import wrap
+import loop
from acl import acl
from bqueue import B_Queue
from config import config, init_conf
q.unlock()
def main():
- lock.lock("request_fetcher")
+ lck = lock.lock("request_fetcher")
init_conf("")
status.push("fetching requests")
f.write("%d\n" % max_no)
f.close()
status.pop()
+ lck.close()
if __name__ == '__main__':
- wrap.wrap(main)
+ # http connection is established (and few bytes transferred through it)
+ # each $secs seconds.
+ loop.run_loop(main, secs = 10)
from acl import acl
import lock
import util
-import wrap
+import loop
import path
import status
import log
notify.send()
def check_load():
+ do_exit = 0
try:
f = open("/proc/loadavg")
if float(string.split(f.readline())[2]) > config.max_load:
- sys.exit(0)
+ do_exit = 1
except:
pass
+ if do_exit:
+ sys.exit(0)
def main_for(builder):
init_conf(builder)
return main_for(sys.argv[1])
if __name__ == '__main__':
- wrap.wrap(main)
+ loop.run_loop(main)
import log
import path
import util
-import wrap
+import loop
import chroot
import buildlogs
import ftp
status.pop()
if __name__ == '__main__':
- wrap.wrap(main)
+ loop.run_loop(main)
import traceback
import StringIO
import os
+import time
# this module, as it deals with internal error handling shouldn't
# import anything beside status