def _listing_buildset(store, buildset_ident): # A specific buildset has been specified. List that. buildset = db.buildset.getByIdent(store, buildset_ident) if not buildset: dlog("Error: No such buildset " + buildset_ident) return False print "\nScripts executed in buildset '" + buildset.name + "':\n" db.buildset.dumpScriptNames(buildset, sys.stdout.write) print ""
def re(args): argc = len(args) store = db.initdb() bs = lookup_or_create_buildset_by_regex(args[1], store) # now create that build b = db.build.createFromBuildset(bs) if not utils.lockPid(OPTIONS.pid_file): dlog("Already building in this dir (Pidfile exists) -> aborting") return False building.run_build(b, store) # Clean up for next run os.remove(OPTIONS.pid_file)
def enqueue(args): argc = len(args) store = db.initdb() if argc < 2: dlog("Usage: %s enqueue <buildset name/idx>" % sys.argv[0]) dlog("\nAvailable buildsets:\n") db.buildset.dumpNames(store, sys.stdout.write) return False if not utils.lockPid(OPTIONS.pid_file): dlog("Pidfile already exists -> aborting") return False buildset = db.buildset.getByIdent(store, unicode(args[1])) if not buildset: print u"Error: No buildset called '%s'" % unicode(args[1]) # Clean up for next run os.remove(PID_FILE) return print u'Using buildset "%s"' % buildset.name build = db.build.createFromBuildset(buildset) building.run_build(build, store) # Clean up for next run os.remove(OPTIONS.pid_file)
def build(args): argc = len(args) store = db.initdb() if argc < 2: dlog("Usage: %s build <buildset name/idx>" % sys.argv[0]) dlog("\nAvailable buildsets:\n") db.buildset.dumpNames(store, sys.stdout.write) return False buildset = db.buildset.getByIdent(store, unicode(args[1])) if not buildset: print u"Error: No buildset called '%s'" % unicode(args[1]) # Clean up for next run return print u'Using buildset "%s"' % buildset.name build = db.build.createFromBuildset(buildset) if not utils.lockPid(OPTIONS.pid_file): dlog("Already building in this dir (Pidfile exists) -> aborting") return False building.run_build(build, store) # Clean up for next run os.remove(OPTIONS.pid_file)
def add(args): argc = len(args) # Add specified script to buildset # allow creating the database if this is a addscript store = db.initdb() command = args[0] if argc < 3: if command == "add": dlog("Usage: %s add <buildset name/idx> <script name/idx> [before name/idx]" % sys.argv[0]) dlog(" if before idx is not provided, the script will be") dlog(" inserted at end of buildset") else: dlog("Usage: %s rm <buildset name/idx> <script name/idx>" % sys.argv[0]) return False buildset_ident = unicode(args[1]) buildset = db.buildset.getByIdent(store, buildset_ident) idents = map(lambda a: a.strip(), unicode(args[2]).split(",")) for ident in idents: pack_ident = unicode(ident) pack = db.script.getByIdent(store, pack_ident) if buildset is None and command == "rm": dlog("Error: No such buildset " + buildset_ident) return False if pack is None: dlog("Error: No such script " + pack_ident) return False if buildset is None: dlog("No such buildset " + args[1] + " -> Adding") buildset = db.buildset() buildset.name = buildset_ident store.add(buildset) store.flush() if command == "add": pack_idx = sys.maxint if argc > 3: before_pack = db.script.getByName(store, unicode(args[3])) # before name if before_pack: pack_idx = buildset.getScriptIndex(before_pack) else: pack_idx = int(args[3]) scripts = pack.getLeafs() for i in scripts: dlog("Adding script %s to buildset %s" % (i.name, buildset.name)) buildset.addScript(i, pack_idx) else: try: idx = int(pack_ident) except: idx = pack buildset.removeScript(idx) store.commit() return True
def log(args): argc = len(args) pid = None try: pid = open(OPTIONS.pid_file, 'r').read() except: pass store = db.initdb(False) if not store: if pid: dlog("Error: database empty!") else: dlog("No build results available") return builds = store.find(db.build).order_by(Desc(db.build.id)) if not builds.count(): dlog("No builds available") for build in builds: dlog("Buildset '%s'" % build.buildset.name) indent = " " last_script = None bs = store.find( db.build_script_status, db.build_script_status.build_id == build.id, db.buildset_script.id == db.build_script_status.buildset_script_id).order_by(Asc(db.buildset_script.idx)) idx = 0 for status in bs: if idx < options.start_index and idx > options.stop_index: idx += 1 continue script = status.buildset_script.script dlog("-" * 70) dlog("Log for '%s'" % script.name) dlog(status.log) dlog("-" * 70) idx += 1 break
def status(args): argc = len(args) store = db.initdb() pid = None try: pid = open(OPTIONS.pid_file, 'r').read() except: pass show_count = 1 build_id = None if argc > 1: if args[1] == 'last': try: show_count = int(args[2]) except: pass else: try: build_id = int(args[1]) except: pass if build_id: builds = store.find(db.build, db.build.id == build_id).order_by( Desc(db.build.id)) else: builds = store.find(db.build).order_by(Desc(db.build.id)) if not builds.count(): dlog("No builds available") build_num = 1 for build in builds: dlog("Buildset '%s' (build %i)" % (build.buildset.name, build.id)) dlog("-" * 50) indent = " " last_script = None bs = store.find( db.build_script_status, db.build_script_status.build_id == build.id, db.buildset_script.id == db.build_script_status.buildset_script_id).order_by( Asc(db.buildset_script.idx)) for status in bs: fmt = "%-18s : %-9s (%s of %s)" script = status.buildset_script.script start_time = status.start_time end_time = status.end_time or datetime.utcnow() dur = (not start_time) and "--:--" or utils.sec2str( (end_time - start_time).seconds) eta_dur = status.buildset_script.last_duration eta_dur = eta_dur is not None and utils.sec2str(eta_dur) or "--:--" # print parent scripts that was not parent for the # last script lines, num = utils.render_tree_entry(script, last_script) last_script = script if status.end_time: status_str = (not status.exit_code and "Success" or "Failure") # ("exit(" + str(status.exit_code) + ")") ) else: status_str = status.start_time and "Running" or " -" while len(lines) != 1: dlog(lines.pop(0)) dlog(fmt % (lines[-1] + script.name, status_str, dur, eta_dur)) dur, eta_dur = build.getDurations() dlog("-" * 50) dlog("%-33s (%s of %s) " % ("Total duration", utils.sec2str( dur or 0), utils.sec2str(eta_dur or 0))) dlog("") if show_count == build_num: break build_num += 1 return f = open(os.path.expanduser(OPTIONS.work_dir) + "/" + pid, 'r') timings = pickle.load(f) buildset = buildsets.buildsets[timings[None][1]] now = datetime.utcnow() dur = now - timings[None][0] print "Buildset '" + buildset.name + "' progress " + str( dur).split('.')[0] + " of " + str( buildset.metadata.get('duration', 'n/a')).split('.')[0] del timings[None] keys = timings.keys() keys.sort() for pack in keys: symlink = os.readlink("buildsets/" + buildset.name + "/" + pack) script = buildsets.get_script_by_buildset_link(symlink) dur = script.metadata.get('duration', 'n/a') cur_dur = timings[pack] if type(cur_dur) is datetime: print " Script '" + script.name + "' " + str(now - cur_dur).split( '.')[0] + " of " + str(dur).split('.')[0] else: print " Script '" + script.name + "' " + str(cur_dur).split( '.')[0] + " done"
def status(args): argc = len(args) store = db.initdb() pid = None try: pid = open(OPTIONS.pid_file, "r").read() except: pass show_count = 1 build_id = None if argc > 1: if args[1] == "last": try: show_count = int(args[2]) except: pass else: try: build_id = int(args[1]) except: pass if build_id: builds = store.find(db.build, db.build.id == build_id).order_by(Desc(db.build.id)) else: builds = store.find(db.build).order_by(Desc(db.build.id)) if not builds.count(): dlog("No builds available") build_num = 1 for build in builds: dlog("Buildset '%s' (build %i)" % (build.buildset.name, build.id)) dlog("-" * 50) indent = " " last_script = None bs = store.find( db.build_script_status, db.build_script_status.build_id == build.id, db.buildset_script.id == db.build_script_status.buildset_script_id, ).order_by(Asc(db.buildset_script.idx)) for status in bs: fmt = "%-18s : %-9s (%s of %s)" script = status.buildset_script.script start_time = status.start_time end_time = status.end_time or datetime.utcnow() dur = (not start_time) and "--:--" or utils.sec2str((end_time - start_time).seconds) eta_dur = status.buildset_script.last_duration eta_dur = eta_dur is not None and utils.sec2str(eta_dur) or "--:--" # print parent scripts that was not parent for the # last script lines, num = utils.render_tree_entry(script, last_script) last_script = script if status.end_time: status_str = not status.exit_code and "Success" or "Failure" # ("exit(" + str(status.exit_code) + ")") ) else: status_str = status.start_time and "Running" or " -" while len(lines) != 1: dlog(lines.pop(0)) dlog(fmt % (lines[-1] + script.name, status_str, dur, eta_dur)) dur, eta_dur = build.getDurations() dlog("-" * 50) dlog("%-33s (%s of %s) " % ("Total duration", utils.sec2str(dur or 0), utils.sec2str(eta_dur or 0))) dlog("") if show_count == build_num: break build_num += 1 return f = open(os.path.expanduser(OPTIONS.work_dir) + "/" + pid, "r") timings = pickle.load(f) buildset = buildsets.buildsets[timings[None][1]] now = datetime.utcnow() dur = now - timings[None][0] print "Buildset '" + buildset.name + "' progress " + str(dur).split(".")[0] + " of " + str( buildset.metadata.get("duration", "n/a") ).split(".")[0] del timings[None] keys = timings.keys() keys.sort() for pack in keys: symlink = os.readlink("buildsets/" + buildset.name + "/" + pack) script = buildsets.get_script_by_buildset_link(symlink) dur = script.metadata.get("duration", "n/a") cur_dur = timings[pack] if type(cur_dur) is datetime: print " Script '" + script.name + "' " + str(now - cur_dur).split(".")[0] + " of " + str(dur).split(".")[0] else: print " Script '" + script.name + "' " + str(cur_dur).split(".")[0] + " done"
def add(args): argc = len(args) # Add specified script to buildset # allow creating the database if this is a addscript store = db.initdb() command = args[0] if argc < 3: if command == "add": dlog( "Usage: %s add <buildset name/idx> <script name/idx> [before name/idx]" % sys.argv[0]) dlog(" if before idx is not provided, the script will be") dlog(" inserted at end of buildset") else: dlog("Usage: %s rm <buildset name/idx> <script name/idx>" % sys.argv[0]) return False buildset_ident = unicode(args[1]) buildset = db.buildset.getByIdent(store, buildset_ident) idents = map(lambda a: a.strip(), unicode(args[2]).split(',')) for ident in idents: pack_ident = unicode(ident) pack = db.script.getByIdent(store, pack_ident) if buildset is None and command == 'rm': dlog("Error: No such buildset " + buildset_ident) return False if pack is None: dlog("Error: No such script " + pack_ident) return False if buildset is None: dlog("No such buildset " + args[1] + " -> Adding") buildset = db.buildset() buildset.name = buildset_ident store.add(buildset) store.flush() if command == "add": pack_idx = sys.maxint if argc > 3: before_pack = db.script.getByName(store, unicode( args[3])) # before name if before_pack: pack_idx = buildset.getScriptIndex(before_pack) else: pack_idx = int(args[3]) scripts = pack.getLeafs() for i in scripts: dlog("Adding script %s to buildset %s" % (i.name, buildset.name)) buildset.addScript(i, pack_idx) else: try: idx = int(pack_ident) except: idx = pack buildset.removeScript(idx) store.commit() return True
def init(args): argc = len(args) # If there is an argument present it is a repository to checkout # and cd into if argc > 1: repos = args[1] (status, output) = commands.getstatusoutput("git clone '%s' " % repos) if status: # Error checking out the repository print output print status return False # Now re-run the zbuild init command with any args repos_toks = repos.split('/') repos_name = repos_toks[-1] or repos_toks[-2] os.chdir(repos_name.endswith(".git") and repos_name[:-4] or repos_name) (status, output) = commands.getstatusoutput("%s/zbuild init" % OPTIONS.zbuild_install_dir) print output if status: # Error checking out the repository print status return False return True if not os.path.isdir(OPTIONS.work_dir): print "Creating zbuild working dir '%s'" % OPTIONS.work_dir mkdirp(OPTIONS.work_dir) if not os.path.isdir(OPTIONS.build_area): # print "Creating build dir '%s'" % OPTIONS.build_area mkdirp(OPTIONS.build_area) if not os.path.isdir(OPTIONS.released_debs_path): # print "Creating release dir '%s'" % OPTIONS.released_debs_path mkdirp(OPTIONS.released_debs_path) store = db.initdb(False) if store: dlog("This is already a zbuild dir") return store = db.initdb(True) script_dir = OPTIONS.work_dir + os.path.sep + "scripts" created_default_scripts = False if not os.path.isdir(OPTIONS.work_dir + os.path.sep + "scripts"): # Create a default scripts setup for this project to make it # easy to get started. shutil.copytree(OPTIONS.zbuild_install_dir + os.path.sep + "lib" + os.path.sep + "script_templates", script_dir) created_default_scripts = True print "Installed a script dir for your convenience in %s " % script_dir print "You may modify files in there to fit your needs or add new ones." # If we have a Rakefile in curdir we may have the posibility # to run rake tests. Offer to use rake tests in as default. # TODO... # Make all scripts visible by syncing com_sync.sync_scripts(script_dir, store) if created_default_scripts: # Create buildsets for builtin regex builds for builtin_re in ['unittest', 'functest', 'stage', 'release']: com_re.lookup_or_create_buildset_by_regex(builtin_re, store) print "Use 'zbuild list' for a listing of currently available buildsets"
def init(args): argc = len(args) # If there is an argument present it is a repository to checkout # and cd into if argc > 1: repos = args[1] (status, output) = commands.getstatusoutput("git clone '%s' " % repos) if status: # Error checking out the repository print output print status return False # Now re-run the zbuild init command with any args repos_toks = repos.split('/') repos_name = repos_toks[-1] or repos_toks[-2] os.chdir(repos_name.endswith(".git") and repos_name[:-4] or repos_name) (status, output) = commands.getstatusoutput("%s/zbuild init" % OPTIONS.zbuild_install_dir) print output if status: # Error checking out the repository print status return False return True if not os.path.isdir(OPTIONS.work_dir): print "Creating zbuild working dir '%s'" % OPTIONS.work_dir mkdirp(OPTIONS.work_dir) if not os.path.isdir(OPTIONS.build_area): # print "Creating build dir '%s'" % OPTIONS.build_area mkdirp(OPTIONS.build_area) if not os.path.isdir(OPTIONS.released_debs_path): # print "Creating release dir '%s'" % OPTIONS.released_debs_path mkdirp(OPTIONS.released_debs_path) store = db.initdb(False) if store: dlog("This is already a zbuild dir") return store = db.initdb(True) script_dir = OPTIONS.work_dir + os.path.sep + "scripts" created_default_scripts = False if not os.path.isdir(OPTIONS.work_dir + os.path.sep + "scripts"): # Create a default scripts setup for this project to make it # easy to get started. shutil.copytree( OPTIONS.zbuild_install_dir + os.path.sep + "lib" + os.path.sep + "script_templates", script_dir) created_default_scripts = True print "Installed a script dir for your convenience in %s " % script_dir print "You may modify files in there to fit your needs or add new ones." # If we have a Rakefile in curdir we may have the posibility # to run rake tests. Offer to use rake tests in as default. # TODO... # Make all scripts visible by syncing com_sync.sync_scripts(script_dir, store) if created_default_scripts: # Create buildsets for builtin regex builds for builtin_re in ['unittest', 'functest', 'stage', 'release']: com_re.lookup_or_create_buildset_by_regex(builtin_re, store) print "Use 'zbuild list' for a listing of currently available buildsets"