X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FBootStates.py;h=d58bb93f3e53c5e509b6312c4552bbb1ffbbbf37;hb=1d3540bd2ece27d91a2ec5843628c5fa38a25024;hp=6757ca149f24c6a9ecfb9768cae3563b38195537;hpb=5dc283f954f5a2b82429aa0c5d5d8c5fc64eefac;p=plcapi.git diff --git a/PLC/BootStates.py b/PLC/BootStates.py index 6757ca1..d58bb93 100644 --- a/PLC/BootStates.py +++ b/PLC/BootStates.py @@ -4,8 +4,6 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id: BootStates.py,v 1.4 2006/10/10 21:54:20 mlhuang Exp $ -# from PLC.Faults import * from PLC.Parameter import Parameter @@ -25,34 +23,29 @@ class BootState(Row): } def validate_boot_state(self, name): - # Remove leading and trailing spaces - name = name.strip() - - # Make sure name is not blank after we removed the spaces - if not name: - raise PLCInvalidArgument, "Boot state must be specified" - - # Make sure boot state does not alredy exist - conflicts = BootStates(self.api, [name]) + # Make sure name is not blank + if not len(name): + raise PLCInvalidArgument("Boot state must be specified") + + # Make sure boot state does not already exist + conflicts = BootStates(self.api, [name]) if conflicts: - raise PLCInvalidArgument, "Boot state name already in use" + raise PLCInvalidArgument("Boot state name already in use") - return name + return name class BootStates(Table): """ Representation of the boot_states table in the database. """ - def __init__(self, api, names = None): + def __init__(self, api, boot_states = None): + Table.__init__(self, api, BootState) + sql = "SELECT %s FROM boot_states" % \ ", ".join(BootState.fields) - - if names: - # Separate the list into integers and strings - sql += " WHERE boot_state IN (%s)" % ", ".join(api.db.quote(names)) - rows = api.db.selectall(sql) + if boot_states: + sql += " WHERE boot_state IN (%s)" % ", ".join( [ api.db.quote (s) for s in boot_states ] ) - for row in rows: - self[row['boot_state']] = BootState(api, row) + self.selectall(sql)