def run(self, args, offer_save_opts=True, work_args=None): """ Parses the command line or the args passed in and figures out whether the user wishes to use a config file or command line switches. """ try: # Do we need to have a clean directory to work in? if self.needs_empty_dir: work_dir = os.path.abspath(args.path) for elem in os.listdir(work_dir): if elem.startswith("zato") and elem.endswith("config"): # This is a zato.{}.config file. The had been written there # before we got to this point and it's OK to skip it. continue else: msg = ( "Directory {} is not empty, please re-run the command " + "in an empty directory" # noqa ).format( work_dir ) # noqa self.logger.info(msg) sys.exit(self.SYS_ERROR.DIR_NOT_EMPTY) # noqa # Do we need the directory to contain any specific files? if self.file_needed: full_path = os.path.join(args.path, self.file_needed) if not os.path.exists(full_path): msg = "Could not find file {}".format(full_path) self.logger.info(msg) sys.exit(self.SYS_ERROR.FILE_MISSING) # noqa check_password = [] for opt_dict in self.opts: name = opt_dict["name"] if "password" in name or "secret" in name: # Don't required password on SQLite if "odb" in name and args.odb_type == "sqlite": continue check_password.append((name, opt_dict["help"])) self.before_execute(args) if check_password and self.is_password_required(): args = self._check_passwords(args, check_password) # GH #328 - zato create web_admin treats boolean admin_created as an exit code # https://github.com/zatosource/zato/issues/328 return_code = self.execute(args) if isinstance(return_code, (int, long)): sys.exit(return_code) else: sys.exit(0) except Exception: self.reset_logger(self.args) self.logger.error(get_full_stack()) sys.exit(self.SYS_ERROR.EXCEPTION_CAUGHT)
def run(self, args, offer_save_opts=True, work_args=None): """ Parses the command line or the args passed in and figures out whether the user wishes to use a config file or command line switches. """ try: # Do we need to have a clean directory to work in? if self.needs_empty_dir: work_dir = os.path.abspath(args.path) for elem in os.listdir(work_dir): if elem.startswith('zato') and elem.endswith('config'): # This is a zato.{}.config file. The had been written there # before we got to this point and it's OK to skip it. continue else: msg = ( 'Directory {} is not empty, please re-run the command ' + # noqa 'in an empty directory').format(work_dir) # noqa self.logger.info(msg) sys.exit(self.SYS_ERROR.DIR_NOT_EMPTY) # noqa # Do we need the directory to contain any specific files? if self.file_needed: full_path = os.path.join(args.path, self.file_needed) if not os.path.exists(full_path): msg = 'Could not find file {}'.format(full_path) self.logger.info(msg) sys.exit(self.SYS_ERROR.FILE_MISSING) # noqa check_password = [] for opt_dict in self.opts: name = opt_dict['name'] if 'password' in name or 'secret' in name: # Don't required password on SQLite if 'odb' in name and args.odb_type == 'sqlite': continue check_password.append((name, opt_dict['help'])) self.before_execute(args) if check_password and self.is_password_required(): args = self._check_passwords(args, check_password) # GH #328 - zato create web_admin treats boolean admin_created as an exit code # https://github.com/zatosource/zato/issues/328 return_code = self.execute(args) if isinstance(return_code, (int, long)): sys.exit(return_code) else: sys.exit(0) except Exception: self.reset_logger(self.args) self.logger.error(get_full_stack()) sys.exit(self.SYS_ERROR.EXCEPTION_CAUGHT)