def test_with_npc_dir(self, campaign): campaign.populate_from_fixture_dir('util', 'campaign_root', 'initialized') assert util.find_campaign_root() == campaign.basedir
def test_no_npc_dir(self, campaign): campaign.populate_from_fixture_dir('util', 'campaign_root', 'empty') assert util.find_campaign_root() == campaign.basedir
def start(argv=None): """ Run the command-line interface Args: argv (list): Arguments from the command invocation. When running from code, this should just include the arguments you want to use, not the name of the script itself. When left blank, sys.argv will be used instead after chopping off the first argument. Returns: Integer code of zero for success or non-zero for failure. """ # create parser and parse args parser = _make_parser() if not argv: argv = sys.argv[1:] args = parser.parse_args(argv) # change to the proper campaign directory if needed base = args.campaign if base == 'auto': base = util.find_campaign_root() try: chdir(base) except OSError as err: util.print_err("{}: '{}'".format(err.strerror, base)) return 4 # load settings data try: prefs = settings.Settings(args.debug) except OSError as err: util.print_err(err.strerror) return 4 setting_errors = settings.lint_settings(prefs) if setting_errors: print("Error in settings") print("\n".join(setting_errors)) return 5 # show help when no input was given if not hasattr(args, 'func'): parser.print_help() return 0 # get args as a dict full_args = vars(args) full_args['prefs'] = prefs # load default character path if search field is at its default if full_args.get('search') is None: full_args['search'] = [prefs.get('paths.required.characters')] # run the command try: result = args.func(full_args) except AttributeError as err: if args.debug: raise util.print_err(err) return 6 # handle errors if not result.success: util.print_err(result) return result.errcode if not args.batch: # print any messages that were returned if result.printables: print("\n".join(result.printables)) # open the resulting files, if allowed if result.openable: util.open_files(*result.openable, prefs=prefs) return 0