def _find_cmd(self, action, arguments=[], future_pkns=[], dry_run=False): ''' Perform the action on the system, importing modules from the package and running the appropriate method on the class within. action -- INSTALL, UNINSTALL, CONFIGURE, VERIFY future_pkns -- future package names. Some packages want to know about the packages that will come after them dry_run -- boolean flag to see if we're really going to do this ''' ret_val = None if type(action) == type(1): action = ACTION_REVERSE_LOOKUP[action] cwd = get_slash_cwd() obj, rand_string = self._get_object(future_pkns) try: if not hasattr(obj, action): msg = "Class %s does not have a %s method." raise BadPackage(self.name, msg % (self.class_name, action)) if not dry_run: if arguments: if ACTION_LOOKUP.get(action) == RESTORE: if len(arguments) != 1: Logger.error("Incorrect number of arguments passed to restore") return FAIL restore_path = make_path(get_spkg_path(), "archive", self.name, str(arguments[0])) if not os.path.isdir(restore_path): msg = "Cannot execute restore: archive data does not "\ "exist in %s" % (restore_path) Logger.error(msg) return FAIL self._prepare_restore(obj, restore_path) exec("ret_val = obj.%s('%s')" % (action, restore_path)) else: exec("ret_val = obj.%s()" % (action)) else: ret_val = OK self._cleanup(obj) del rand_string except SystemExit, err: if err.code: ret_val = err.code else: ret_val = OK del rand_string
def __init__(self, action_string, package_name, script_name, arguments): ''' action_string -- one of the following: uninstall, configure, install, verify, reconcile, check_status, execute, fix, purge, dry_run, or init package_name -- the name of a package to act upon script_name -- the name of a script to act upon arguments -- currently only used for restore ''' action_const = ACTION_LOOKUP.get(action_string.lower().strip()) if action_const == None: raise InvalidAction(package_name, action_string) name = "Bombardier-%s-%s" % (action_string, package_name) AbstractCommand.__init__(self, name) self.action = action_const self.package_name = package_name self.script_name = script_name if type(arguments) != type([]): msg = "Invalid arguments passed. Expected list, got: (%s)" % arguments raise InvalidBombardierCommand(msg) self.arguments = arguments self.debug = False
del rand_string except KeyboardInterrupt: Logger.error("Keyboard interrupt detected. Exiting...") ret_val = FAIL sys.exit(10) # FIXME: Literal except SyntaxError, err: self._dump_error(err, self.class_name) ret_val = FAIL del rand_string except StandardError, err: self._dump_error(err, self.class_name) ret_val = FAIL del rand_string os.chdir(cwd) if ACTION_LOOKUP.get(action) == BACKUP: if type(ret_val) != type({}): erstr = "%s: backup method did not return a "\ "properly formatted dictionary" % self.full_name Logger.error(erstr) return FAIL return self._backup(obj, ret_val, future_pkns, dry_run) if ret_val == None: ret_val = OK if ret_val == REBOOT: raise RebootRequiredException(self.name) if ret_val != OK: erstr = "%s: failed with status %s" % (self.full_name, ret_val) Logger.error(erstr) return FAIL return OK