#
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")
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"
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:
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: ")
print "Unknown subcommand %s" % mod_op
sys.exit(1)
update_rsyncd_secrets()
- update_hosts_list()
elif op == "add":
hostname = raw_input("Machine hostname: ")
try:
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: