X-Git-Url: http://git.samba.org/?a=blobdiff_plain;f=admin.py;h=b78fb32822121f2a7f1ece486ba966009554db23;hb=b60f215d1fa2f04bee4c650efbba629a215fda6f;hp=890917630fb47c0e5c2563fd3bd23d6ce13503ca;hpb=53f8095d8c116c7c6810e4e96523ddf9b627900f;p=build-farm.git diff --git a/admin.py b/admin.py index 89091763..b78fb328 100755 --- a/admin.py +++ b/admin.py @@ -18,19 +18,17 @@ # from buildfarm import ( + BuildFarm, hostdb, ) -from buildfarm.sqldb import StormCachingBuildFarm import commands import os import smtplib import sys import time from email.MIMEText import MIMEText -from storm.tracer import debug -debug(True, sys.stdout) -buildfarm = StormCachingBuildFarm() +buildfarm = BuildFarm() def update_rsyncd_secrets(): temp_rsyncd_secrets = os.path.join(os.path.dirname(__file__), "../rsyncd.secrets.new") @@ -40,22 +38,16 @@ def update_rsyncd_secrets(): os.rename(temp_rsyncd_secrets, "../rsyncd.secrets") -def update_hosts_list(): - temp_hosts_list_file = os.path.join(os.path.dirname(__file__), "web", "hosts.list.new") - f = open(temp_hosts_list_file, "w") - f.writelines(buildfarm.hostdb.create_hosts_list()) - f.close() - - os.rename(temp_hosts_list_file, os.path.join(os.path.dirname(__file__), "web/hosts.list")) - dry_run = False print "Samba Build farm management tool" print "================================" -if len(sys.argv) > 1: - op = sys.argv[1] -else: +args = sys.argv[1:] + +try: + op = args.pop(0) +except IndexError: print "Initialize the buildfarm: init" print "Add Machine to build farm: add" print "Remove Machine from build farm: remove" @@ -71,16 +63,17 @@ else: if op == "init": buildfarm.commit() elif op == "remove": - hostname = raw_input("Please enter hostname to delete: ") - try: - buildfarm.hostdb.deletehost(hostname) - except hostdb.NoSuchHost, e: - print "No such host '%s'" % e.name - sys.exit(1) - else: - buildfarm.hostdb.commit() - update_rsyncd_secrets() - update_hosts_list() + if not args: + args = [raw_input("Please enter hostname to delete: ")] + for hostname in args: + try: + buildfarm.hostdb.deletehost(hostname) + except hostdb.NoSuchHost, e: + print "No such host '%s'" % e.name + sys.exit(1) + else: + buildfarm.hostdb.commit() + update_rsyncd_secrets() elif op == "modify": hostname = raw_input("Please enter hostname to modify: ") try: @@ -96,7 +89,7 @@ elif op == "modify": mod_op = "platform" if mod_op == "platform": platform = raw_input("Enter new platform: ") - host.update_platform(platform) + host.update_platform(platform.decode('utf-8')) buildfarm.commit() elif mod_op == "owner": owner = raw_input("Enter new owner's name: ") @@ -107,7 +100,6 @@ elif op == "modify": print "Unknown subcommand %s" % mod_op sys.exit(1) update_rsyncd_secrets() - update_hosts_list() elif op == "add": hostname = raw_input("Machine hostname: ") try: @@ -191,24 +183,22 @@ Thanks, your friendly Samba build farm administrator """ % owne s.sendmail(msg["From"], recipients, msg.as_string()) s.quit() update_rsyncd_secrets() - update_hosts_list() elif op == "info": - q = """ - SELECT host.fqdn, host.id, host.join_time, host.last_dead_mail, host.name, host.owner_email, host.owner, host.password, host.permission, host.platform, host.ssh_access FROM host WHERE host.name = 'fjall'""" - import pdb; pdb.set_trace() - hostname = raw_input("Hostname: ") - try: - host = buildfarm.hostdb[hostname] - except hostdb.NoSuchHost, e: - print "No such host '%s'" % e.name - sys.exit(1) - if host.fqdn: - opt_fqdn = " (%s)" % host.fqdn - else: - opt_fqdn = "" - print "Host: %s%s" % (host.name, opt_fqdn) - print "Platform: %s" % host.platform - print "Owner: %s <%s>" % host.owner + if not args: + args = [raw_input("Hostname: ")] + for hostname in args: + try: + host = buildfarm.hostdb[hostname] + except hostdb.NoSuchHost, e: + print "No such host '%s'" % e.name + sys.exit(1) + if host.fqdn: + opt_fqdn = " (%s)" % host.fqdn + else: + opt_fqdn = "" + print "Host: %s%s" % (host.name, opt_fqdn) + print "Platform: %s" % host.platform + print "Owner: %s <%s>" % host.owner elif op == "list": for host in buildfarm.hostdb.host_ages(): if host.last_update: