def impl(self): if self.get_options().start: GlobalVariables.get_instance().set(Time.GLOBAL_VAR_NAME, time.time(), level='_internal') return 0 if self.get_options().stop: delta = time.time() - GlobalVariables.get_instance().get(Time.GLOBAL_VAR_NAME, level='_internal') disp('Elapsed time: {0:.3f} secs ='.format(delta)) return 0 disp(datetime.now().strftime('%A %Y-%m-%d %H:%M:%S.%f %Z')) return 0
def impl(self): if self.get_options().start: GlobalVariables.get_instance().set(Time.GLOBAL_VAR_NAME, time.time(), level='_internal') return 0 if self.get_options().stop: delta = time.time() - GlobalVariables.get_instance().get( Time.GLOBAL_VAR_NAME, level='_internal') disp('Elapsed time: {0:.3f} secs ='.format(delta)) return 0 disp(datetime.now().strftime('%A %Y-%m-%d %H:%M:%S.%f %Z')) return 0
def read(): """Read all the history and return it in a list.""" with open(GlobalVariables.get_instance().get('history_filename'), 'rb') as fin: lines = [] for line in fin.readlines(): lines.append(line.replace('\n', '').strip()) fin.close() return lines
def wrapped_f(*args): if GlobalVariables.get_instance().get('timeit_commands') != 'True': return f(*args) ts = time.time() r = f(*args) te = time.time() disp('\n= Executed in {0:.3f} secs ='.format(te - ts), color='yellow') return r
def __init__(self): super(AliasLoader, self).__init__(GlobalVariables.get_instance().get('aliases_filename')) command_resolver = CommandResolver.get_instance() for key, value in self.load(): for cmd_name, options in CommandParser.parse(value): cmd_class, cmd_opts = command_resolver.get_class(cmd_name) if cmd_class is None: raise PyCoLoaderException('Invalid alias: "{0} = {1}" (unknown "{2}")'.format(key, value, cmd_name)) command_resolver.add(key, cmd_class, cmd_opts + options)
def __init__(self): super(AliasLoader, self).__init__( GlobalVariables.get_instance().get('aliases_filename')) command_resolver = CommandResolver.get_instance() for key, value in self.load(): for cmd_name, options in CommandParser.parse(value): cmd_class, cmd_opts = command_resolver.get_class(cmd_name) if cmd_class is None: raise PyCoLoaderException( 'Invalid alias: "{0} = {1}" (unknown "{2}")'.format( key, value, cmd_name)) command_resolver.add(key, cmd_class, cmd_opts + options)
def impl(self): if self.get_options().list: name, value = GlobalVariables.get_instance().get_all() spacing = len(max(name, key=len)) disp('{0: <{1}} {2}'.format('Name:', spacing, 'Value:')) for n, v in sorted(zip(name, value)): disp('{0: <{1}} = {2}'.format(n, spacing, v)) return 0 if self.get_options().echo is not None: disp(GlobalVariables.get_instance().get(self.get_options().echo)) return 0 if self.get_options().unset is not None: GlobalVariables.get_instance().unset(self.get_options().unset) return 0 else: GlobalVariables.get_instance().set(self.get_options().name, ' '.join(self.get_options().value)) # disp('{0} = {1}'.format(self.get_options().name, GlobalVariables.get_instance().get(self.get_options().name))) # noqa return 0
def impl(self): if self.get_options().list: name, value = GlobalVariables.get_instance().get_all() spacing = len(max(name, key=len)) disp('{0: <{1}} {2}'.format('Name:', spacing, 'Value:')) for n, v in sorted(zip(name, value)): disp('{0: <{1}} = {2}'.format(n, spacing, v)) return 0 if self.get_options().echo is not None: disp(GlobalVariables.get_instance().get(self.get_options().echo)) return 0 if self.get_options().unset is not None: GlobalVariables.get_instance().unset(self.get_options().unset) return 0 else: GlobalVariables.get_instance().set( self.get_options().name, ' '.join(self.get_options().value)) # disp('{0} = {1}'.format(self.get_options().name, GlobalVariables.get_instance().get(self.get_options().name))) # noqa return 0
def __init__(self, config_file_path): super(ConfigLoader, self).__init__(config_file_path) for key, value in self.load(): disp('{0} = {1}'.format(key, value)) GlobalVariables.get_instance().set(key, value)
author = 'Pierluigi' date = '2016-05-12' """ from pyco.core.buffer import PycoStringBuffer from pyco.core.loaders import AliasLoader from pyco.core.loaders import ConfigLoader from pyco.core.exceptions import PyCoQuitException from pyco.core.global_variables import GlobalVariables from pyco.core.history import History from pyco.core.prompt import Prompt from pyco.core.resolver import CommandResolver from pyco.utils import disp from pyco.initialize import get_input _GV_ = GlobalVariables.get_instance() def main(): command_resolver = CommandResolver.get_instance() history = History.get_instance() disp('Loading config...') try: ConfigLoader('.config') except Exception as e: disp('ConfigLoader: {0}'.format(e), color='red') disp('Loading aliases...') try:
def __init__(self): GlobalVariables.get_instance().set(PycoStringBuffer.BUFFER_NAME, '', level='_internal')
def delete(): os.remove(GlobalVariables.get_instance().get('history_filename'))
def write(self, txt): buf = GlobalVariables.get_instance().get(PycoStringBuffer.BUFFER_NAME, level='_internal') GlobalVariables.get_instance().set(PycoStringBuffer.BUFFER_NAME, buf + txt, level='_internal')
def get(): return GlobalVariables.get_instance().get(PycoStringBuffer.BUFFER_NAME, level='_internal')
def append(command): """Append the command to the history.""" with open(GlobalVariables.get_instance().get('history_filename'), 'ab') as fin: fin.write('{0}\n'.format(command)) fin.close()
def _get_pyco_debug_status(): """Return the curret status for the PyCo debug.""" debug = GlobalVariables.get_instance().get('debug') if debug is None: return False return True if debug.strip().lower() == 'true' else False