#
from buildfarm import (
- hostdb,
BuildFarm,
+ hostdb,
)
import commands
import os
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(db.create_rsync_secrets())
+ f.writelines(buildfarm.hostdb.create_rsync_secrets())
f.close()
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(db.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"
print "Modify build farm account: modify"
if op == "":
op = "add"
-if op == "remove":
- hostname = raw_input("Please enter hostname to delete: ")
- try:
- db.deletehost(hostname.decode("utf-8"))
- except hostdb.NoSuchHost, e:
- print "No such host '%s'" % e.name
- sys.exit(1)
- else:
- update_rsyncd_secrets()
- update_hosts_list()
+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:
- host = db.host(hostname.decode("utf-8"))
+ host = buildfarm.hostdb[hostname]
except hostdb.NoSuchHost, e:
print "No such host '%s'" % e.name
sys.exit(1)
mod_op = "platform"
if mod_op == "platform":
platform = raw_input("Enter new platform: ")
- host.update_platform(platform.decode("utf-8"))
+ 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: ")
- host.update_owner(owner.decode("utf-8"), owner_email.decode("utf-8"))
+ host.update_owner(owner, owner_email.decode("utf-8"))
+ buildfarm.commit()
else:
print "Unknown subcommand %s" % mod_op
sys.exit(1)
update_rsyncd_secrets()
- update_hosts_list()
elif op == "add":
hostname = raw_input("Machine hostname: ")
try:
- db.host(hostname.decode("utf-8"))
+ buildfarm.hostdb[hostname]
except hostdb.NoSuchHost, e:
pass
else:
line = raw_input("")
try:
- db.createhost(hostname.decode("utf-8"), platform.decode("utf-8"),
+ 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.
s.sendmail(msg["From"], recipients, msg.as_string())
s.quit()
update_rsyncd_secrets()
- update_hosts_list()
elif op == "info":
- hostname = raw_input("Hostname: ")
- try:
- host = db.host(hostname.decode("utf-8"))
- 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
-
- # 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: