def test_get_config_dne(self, patch_import): # test if config does not exist patch_import.side_effect = ImportError with self.assertRaises(SystemExit): get_config() patch_import.assert_called_once_with('config')
def cmd_extract_x4(args): setup_logging(args.verbosity) config = get_config() if args.file: out_path = '{}/custom'.format(config.PWD) else: out_path = config.SRC parser = CatParser( out_path=out_path, scripts_only=args.scripts, signatures=args.signatures, ) if args.file: parser.extract(cat_filename=args.file) else: method = parser.list if args.list else parser.extract cats = sorted(glob.iglob(f'{config.X4}/*.cat')) for cat in cats: method(cat_filename=cat)
for filename in sorted(glob.glob(self.mod_path+'/*.csv')): self.read_csv(filename, self.csv_data) def __init__(self, mod_name, config): self.mod_name = mod_name self.mod_macros = [] self.mod_components = [] self.mod_ts = {} self.mod_wares = [] self.csv_data = None if config: self.mod_path = config.MODS + '/' + self.mod_name self.src_path = config.SRC self.src_macros = self.get_macros(src_path=config.SRC) self.src_components = self.get_components(src_path=config.SRC) self.src_wares = self.get_wares(src_path=config.SRC) self.old_wares = self.get_wares(src_path=self.mod_path, allow_fail=True) self.read_mod_csv_data() if __name__ == '__main__': logger.addHandler(logging.StreamHandler()) logger.setLevel(logging.INFO) args = sys.argv[1:] if len(args) < 1: logger.info("%s <mod_name>", sys.argv[0]) else: compiler = X4ModCompiler(name=args[0], config=get_config()) compiler.compile()
macro=component_ref, license=license, factions=factions, ) def index_all(self): self.index_ts() self.index_wares() def search(search_str, fields=None, limit=3): hits = models.Ware.objects.search(search_str, fields=fields, limit=limit) for hit in hits: h = hit.highlights('all', top=10) logger.info(f'{h}\n' f'{dict(hit)}\n') if __name__ == '__main__': logging.getLogger().addHandler(logging.StreamHandler()) logging.getLogger().setLevel(logging.INFO) args = sys.argv[1:] if len(args) < 1: logger.info("%s -i to index dbs", sys.argv[0]) logger.info("%s <search text>", sys.argv[0]) elif args[0] == '-i': indexer = Indexer(config=get_config()) indexer.index_all() else: search_str = ' '.join(args) search(search_str)
def test_get_config(self, patch_import): self.assertEqual(get_config(), patch_import.return_value) patch_import.assert_called_once_with('config')
#!/usr/bin/env python3 """ Pack mods/{mod name}/* mod files into {game dir}/extensions/{mod name}/* (cat+dat) Use: python3 pack_mod.py {mod name} """ import sys import logging from lib.x4lib import get_config, require_python_version from pack_x4 import pack_path require_python_version(3, 5) logger = logging.getLogger('x4.' + __name__) def pack_mod(mod_name, config): pack_path(src='{}/{}/'.format(config.MODS, mod_name), dst='{}/extensions/{}/'.format(config.X4, mod_name)) if __name__ == '__main__': logger.addHandler(logging.StreamHandler()) logger.setLevel(logging.INFO) args = sys.argv[1:] if len(args) < 1: logger.info("%s <mod_name>", sys.argv[0]) else: pack_mod(mod_name=args[0], config=get_config())
def cmd_pack_mod(args): setup_logging(args.verbosity) pack_mod(mod_name=args.mod_name, config=get_config())
def cmd_compile_mod(args): setup_logging(args.verbosity) compiler = X4ModCompiler(mod_name=args.mod_name, config=get_config()) compiler.compile()
parser = CatParser( out_path=config.SRC, scripts_only=scripts_only, signatures=signatures, ) method = parser.extract if extract else parser.list for f in cats: method(cat_filename='{}/{}'.format(config.X4, f)) if __name__ == '__main__': logger.addHandler(logging.StreamHandler()) logger.setLevel(logging.INFO) args = set(sys.argv[1:]) if not args: logger.info("%s <--extract | --list> <--all>", sys.argv[0]) exit(0) if args & {'--extract', '--list'}: extract_x4(extract='--extract' in args, scripts_only='--all' not in args, config=get_config()) else: config = get_config() CatParser( out_path='{}/custom'.format(config.PWD), scripts_only=False, ).extract(cat_filename=sys.argv[1])