def save(self): saved_files = [] for f, settings in self.file_settings: if len(settings) > 2 and settings[2]: saved_files.append(f) settings[1] = Merge.merge(*settings[1:]) while len(settings) > 2: settings.pop() if os.path.exists(f): with open(f, 'r') as fo: data = fo.read().split(Yaml.SEPARATOR)[0] else: data = '' parent = os.path.dirname(f) if not os.path.exists(parent): from echomesh.util import Log Log.logger(__name__).info('Creating directory %s.', parent) os.makedirs(parent) with open(f, 'wb') as fw: if data: fw.write(data) fw.write(Yaml.SEPARATOR) fw.write(Yaml.encode_one(settings[1])) self.arg_settings = Merge.difference_strict( self.arg_settings, self.changed) self.recalculate() return saved_files
def save(self): saved_files = [] for f, settings in self.file_settings: if len(settings) > 2 and settings[2]: saved_files.append(f) settings[1] = Merge.merge(*settings[1:]) while len(settings) > 2: settings.pop() if os.path.exists(f): with open(f, 'r') as fo: data = fo.read().split(Yaml.SEPARATOR)[0] else: data = '' parent = os.path.dirname(f) if not os.path.exists(parent): from echomesh.util import Log Log.logger(__name__).info('Creating directory %s.', parent) os.makedirs(parent) with open(f, 'wb') as fw: if data: fw.write(data) fw.write(Yaml.SEPARATOR) fw.write(Yaml.encode_one(settings[1])) self.arg_settings = Merge.difference_strict(self.arg_settings, self.changed) self.recalculate() return saved_files
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 _load_library(name): """Try to load a shared library, report an error on failure.""" try: import ctypes return ctypes.CDLL('lib%s.so' % name) except: from echomesh.util import Log Log.logger(__name__).error("Couldn't load library %s" % name)
# pylint: disable=W0611 from echomesh.command import ElementCommands, GetSettings from echomesh.command import RemoteCommands, SetSettings from echomesh.command import Show # Must be the last one to load. from echomesh.command import Help # pylint: enable=W0611 # TODO: use the late loading from echomesh.element from echomesh.util import Log from echomesh.util.string import FindComment from echomesh.util.string import Split LOGGER = Log.logger(__name__) COMMENT_HELP = """ Comment lines start with a # - everything after that is ignored. """ Registry.registry().register(lambda e: None, '#', COMMENT_HELP) Registry.registry().register(None, 'sample', 'This is a sample with just help') def _fix_exception_message(m, name): loc = m.find(')') if loc >= 0: m = m[loc + 1:] m = (m.replace('1', '0').replace('2', '1').replace('3', '2').replace( '4', '3').replace('1 arguments', '1 argument'))
from __future__ import absolute_import, division, print_function, unicode_literals from echomesh.command import Registry from echomesh.command import Show from echomesh.util import Log LOGGER = Log.logger(__name__) HELP = """ echomesh has the following help topics: %s Type "help TOPIC" for more information - for example, "help quit" or "help run". """ def _help(_, *parts): if not parts: LOGGER.info(HELP, Registry.registry().join_keys(command_only=False)) else: cmd, parts = parts[0], parts[1:] if not parts: help_text = Registry.registry().get_help(cmd) LOGGER.info(help_text or ('No help text available for "%s"' % cmd)) elif cmd == 'show': sub = parts[0] help_text = Show.SHOW_REGISTRY.get_help(sub) LOGGER.info('\nshow %s:', sub) LOGGER.info(help_text or ('No help text available for "show %s"' % sub))
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 Version if Version.TOO_NEW: print(Version.ERROR) from echomesh.base import Path if not Path.project_path(): return p() Path.fix_home_directory_environment_variable() p() Path.fix_sys_path() p() from echomesh.base import Settings p() Settings.read_settings(sys.argv[1:]) p() if Settings.get('execution', 'autostart') and not Settings.get( 'permission', 'autostart'): print() from echomesh.util import Log Log.logger(__name__).info('No permission to autostart') return p() from echomesh.base import Quit p() Quit.register_atexit(Settings.save) p() from echomesh.Instance import Instance p() instance = Instance() print() p() if Settings.get('diagnostics', 'startup_times'): print() for i in range(len(times) - 1): print(i, ':', int(1000 * (times[i + 1] - times[i]))) print() instance.main()