def main(): '''Command line tool for helping with administrative tasks around Kattis.''' the_bus = bus.Bus() core.TouchStructure() plugins = core.ListPlugins() def ConvertPlugins(plugin): if not isinstance(plugin, str): return plugin path = plugin type, value = core.ImportExternal(path) if type == 'success': return value plugins = map(ConvertPlugins, plugins) plugins = filter(lambda x: x is not None, plugins) plugins = list(plugins) for plugin in plugins: if hasattr(plugin, 'Init'): plugin.Init(the_bus) for plugin in plugins: if hasattr(plugin, 'CLI'): plugin.CLI(the_bus, cli_main) try: cli_main() except Exception as e: if hasattr(e, 'message'): print(e.message) else: print(e)
def DoTemplateTestWithType(topic, listen_topic, use_home=False, kwargs={}): assert core.TouchStructure() checker = CallChecker() bus = busmodule.Bus() init.Init(bus) template.Init(bus) bus.listen('kattcmd:init:directory-created', checker) home = os.environ['HOME'] bus.call('kattcmd:init', bus, folder=home) assert checker.yay checker = CallChecker() bus.listen(listen_topic, checker) if use_home: target = home else: target = os.path.join(home, 'kattis', 'hello') os.mkdir(target) bus.call(topic, bus, target, **kwargs) assert checker.yay assert os.listdir(target)
def test_CreatesKattcmdOptions(): assert core.TouchStructure() kattcmd_path = os.path.expanduser('~/.kattcmd') assert os.path.isfile(kattcmd_path) config = configparser.ConfigParser() config.read(kattcmd_path) assert 'options' in config assert 'kattisrc' in config['options'] assert 'plugins' in config['options']
def inner(*args, **kwargs): if not 'HOME' in os.environ or not os.environ['HOME'].startswith( '/tmp'): print(os.environ['HOME']) print('*' * 42) print( 'HOME NOT SET IN test.util.with_modules()! Make sure to put @with_modules innermost' ) print('*' * 42) if not core.TouchStructure(): raise AssertionError('Could not create home structure!') bus = busmodule.Bus() for module in modulelist: module.Init(bus) f(bus, *args, **kwargs)
def test_ListsPlugins(): assert core.TouchStructure() plugins = core.ListPlugins() assert isinstance(plugins, list)
def test_TouchTwice(): assert core.TouchStructure() assert not core.TouchStructure()