[Demi-commits] r75 - bin lib
John Morrissey
jwm-guest at costa.debian.org
Wed Feb 8 01:32:20 UTC 2006
Author: jwm-guest
Date: 2006-02-08 01:32:18 +0000 (Wed, 08 Feb 2006)
New Revision: 75
Modified:
bin/add-demi-machine
lib/machine.py
Log:
move from getopt to optparse
Submitted by: Jason Harrison <jharrison at linuxbs.org>
also, have machine.add() return the machine; chances are, we're going to
want to manipulate the machine after we add it
Modified: bin/add-demi-machine
===================================================================
--- bin/add-demi-machine 2006-02-01 21:18:52 UTC (rev 74)
+++ bin/add-demi-machine 2006-02-08 01:32:18 UTC (rev 75)
@@ -18,37 +18,20 @@
#
# $Id$
-import sys
-from getopt import getopt
+from optparse import OptionParser
from os.path import basename
+import sys
-import demi
-from demi.machine import Machine
+from demi import machine
-def usage():
- print """\
-Usage: %s HOSTNAME [HOSTNAME]...
-Add a machine to Demi.
+parser = OptionParser(
+ usage = "%prog HOSTNAME [HOSTNAME]...\nAdd a machine to Demi.")
+(options, args) = parser.parse_args()
- -h, --help display this help and exit""" % (basename(sys.argv[0]))
+if not args:
+ parser.print_help()
+ exit
-# FIXME: this trap doesn't work right
-try:
- [opts, args] = getopt(sys.argv[1:], "h", ["help"])
-except getopt.GetoptError:
- usage()
-
-if len(opts) == 0 and len(args) == 0:
- usage()
-
-for option in opts:
- if option[0] == "--help" or option[0] == "-h":
- usage()
- else:
- print basename(sys.argv[0]) + ": invalid option -- " + option[0]
- usage()
-
for hostname in args:
- demi.machine.add(hostname)
- newMachine = Machine(hostname)
+ newMachine = machine.add(hostname)
newMachine.update()
Modified: lib/machine.py
===================================================================
--- lib/machine.py 2006-02-01 21:18:52 UTC (rev 74)
+++ lib/machine.py 2006-02-08 01:32:18 UTC (rev 75)
@@ -56,6 +56,8 @@
c.execute(query, args)
_allMachines = []
+ return Machine(hostname)
+
class UnknownMachine(Exception):
"""Raised when the requested machine hostname/ID cannot be found.
More information about the Demi-commits
mailing list