X-Git-Url: http://git.samba.org/?a=blobdiff_plain;f=admin.py;h=60679f815da553e827d91e90fb38a621544a46d1;hb=3af7f627f3b9bfc1940d5273f181180791e41f9b;hp=909d3034c0446bf799cf17f6b1240fdfa1ce499f;hpb=ecd61407c8e7c6e59a18c810a3038493f54e37e9;p=build-farm.git diff --git a/admin.py b/admin.py index 909d3034..60679f81 100755 --- a/admin.py +++ b/admin.py @@ -18,8 +18,8 @@ # from buildfarm import ( - hostdb, BuildFarm, + hostdb, ) import commands import os @@ -30,16 +30,25 @@ from email.MIMEText import MIMEText buildfarm = BuildFarm() -db = buildfarm.hostdb +def update_rsyncd_secrets(): + temp_rsyncd_secrets = os.path.join(os.path.dirname(__file__), "../rsyncd.secrets.new") + f = open(temp_rsyncd_secrets, "w") + f.writelines(buildfarm.hostdb.create_rsync_secrets()) + f.close() + + os.rename(temp_rsyncd_secrets, "../rsyncd.secrets") 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" print "Modify build farm account: modify" @@ -51,16 +60,27 @@ else: if op == "": op = "add" -if op == "remove": - hostname = raw_input("Please enter hostname to delete: ") +if op == "init": + buildfarm.commit() +elif op == "remove": + 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: - db.deletehost(hostname) + host = buildfarm.hostdb[hostname] except hostdb.NoSuchHost, e: print "No such host '%s'" % e.name sys.exit(1) -elif op == "modify": - hostname = raw_input("Please enter hostname to modify: ") - host = db.host(hostname) print "Owner: %s <%s>" % host.owner print "Platform: %s" % host.platform print "" @@ -69,24 +89,26 @@ elif op == "modify": mod_op = "platform" if mod_op == "platform": platform = raw_input("Enter new platform: ") - try: - db.update_platform(hostname, platform) - except hostdb.NoSuchHost, e: - print "No such host: %s" % e.name - sys.exit(1) + host.update_platform(platform) + buildfarm.commit() elif mod_op == "owner": owner = raw_input("Enter new owner's name: ") owner_email = raw_input("Enter new owner's e-mail address: ") - try: - db.update_owner(hostname, owner, owner_email) - except hostdb.NoSuchHost, e: - print "No such host: %s" % e.name - sys.exit(1) + host.update_owner(owner, owner_email.decode("utf-8")) + buildfarm.commit() else: print "Unknown subcommand %s" % mod_op sys.exit(1) + update_rsyncd_secrets() elif op == "add": hostname = raw_input("Machine hostname: ") + try: + buildfarm.hostdb[hostname] + except hostdb.NoSuchHost, e: + pass + else: + print "A host with the name %s already exists." % e.name + sys.exit(1) platform = raw_input("Machine platform (eg Fedora 9 x86_64): ") owner = raw_input("Machine Owner Name: ") owner_email = raw_input("Machine Owner E-mail: ") @@ -102,10 +124,15 @@ elif op == "add": line = raw_input("") try: - db.createhost(hostname, platform, owner, owner_email, password, "".join(permission)) + buildfarm.hostdb.createhost(hostname, platform.decode("utf-8"), + owner.decode("utf-8"), owner_email.decode("utf-8"), + password.decode("utf-8"), + "".join(permission).decode("utf-8", "replace")) except hostdb.HostAlreadyExists, e: print "A host with the name %s already exists." % e.name sys.exit(1) + else: + buildfarm.commit() body = """ Welcome to the Samba.org build farm. @@ -155,22 +182,25 @@ Thanks, your friendly Samba build farm administrator """ % owne recipients.append(msg["Bcc"]) s.sendmail(msg["From"], recipients, msg.as_string()) s.quit() - + update_rsyncd_secrets() elif op == "info": - hostname = raw_input("Hostname: ") - host = db.host(hostname) - 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 - - # Don't run the update of the text files - sys.exit(0) + 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 db.host_ages(): + for host in buildfarm.hostdb.host_ages(): if host.last_update: age = time.time() - host.last_update else: @@ -179,17 +209,3 @@ elif op == "list": else: print "Unknown command %s" % op sys.exit(1) - -temp_rsyncd_secrets = os.path.join(os.path.dirname(__file__), "../rsyncd.secrets.new") -f = open(temp_rsyncd_secrets, "w") -f.writelines(db.create_rsync_secrets()) -f.close() - -os.rename(temp_rsyncd_secrets, "../rsyncd.secrets") - -temp_hosts_list_file = os.path.join(os.path.dirname(__file__), "web", "hosts.list.new") -f = open(temp_hosts_list_file, "w") -f.writelines(db.create_hosts_list()) -f.close() - -os.rename(temp_hosts_list_file, os.path.join(os.path.dirname(__file__), "web/hosts.list"))