def main(): import sys times = [] def p(msg=''): """Print progress messages while echomesh loads.""" print(msg, end='\n' if msg else '') global COUNT dot = str(COUNT % 10) if USE_DIGITS_FOR_PROGRESS_BAR else '.' print(dot, end='') COUNT += 1 sys.stdout.flush() import time times.append(time.time()) p('Loading echomesh ') from echomesh.base import Path p() Path.fix_sys_path() p() from echomesh.base import Args p() Args.set_arguments(sys.argv) p() from echomesh.base import Config p() Config.recalculate() p() if Config.get('autostart') and not Config.get('permission', 'autostart'): print() from echomesh.util import Log Log.logger(__name__).info("Not autostarting because autostart=False") exit(0) p() from echomesh import Instance print() if Config.get('diagnostics', 'startup_times'): print() for i in range(len(times) - 1): print(i, ':', int(1000 * (times[i + 1] - times[i]))) print() Instance.main() if Config.get('diagnostics', 'unused_configs'): import yaml print(yaml.safe_dump(Config.get_unvisited()))
def _args_to_settings(self, args, error): args = ' '.join(args) settings = {} base_settings = self.file_settings[0][1][0] assert isinstance(base_settings, dict) try: split_args = Args.split(args) except Exception as e: e.arg = '%s %s' % (error, args) raise for addr, value in split_args: try: GetPrefix.set_assignment( addr, value, base_settings, settings, unmapped_keys=Merge.SETTINGS_EXCEPTIONS) except GetPrefix.PrefixException: raise Exception('Can\'t understand settings address "%s"' % addr) except Exception: raise Exception( 'Can\'t understand settings value "%s" in %s=%s' % (value, addr, value)) return settings
def _assignment_to_config(self, args, error): args = ' '.join(args) config = {} base_config = self.file_configs[0][1][0] assert isinstance(base_config, dict) try: split_args = Args.split(args) except Exception as e: e.arg = '%s %s' % (error, args) raise for addr, value in split_args: try: GetPrefix.set_assignment(addr, value, base_config, config, unmapped_names=Merge.CONFIG_EXCEPTIONS) except GetPrefix.PrefixException: raise Exception('Can\'t understand configuration address "%s"' % addr) except Exception: raise Exception('Can\'t understand configuration value "%s" in %s=%s' % (value, addr, value)) return config
def assertTest(self, args, expected): try: result = Args.split(args) except Exception as e: result = 'ERROR: %s' % str(e) self.assertEqual(result, expected)
def assign(*values): assignments = Args.split_args(values) merged = MergeConfig.merge_assignments(CONFIG, assignments) if merged: update_clients() return merged