示例#1
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
示例#2
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
示例#3
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
示例#4
0
 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
示例#5
0
 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)
示例#6
0
 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)
示例#7
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
示例#8
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
示例#9
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)
示例#10
0
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:
示例#11
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)
示例#12
0
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:
示例#13
0
 def __init__(self):
     GlobalVariables.get_instance().set(PycoStringBuffer.BUFFER_NAME,
                                        '',
                                        level='_internal')
示例#14
0
 def delete():
     os.remove(GlobalVariables.get_instance().get('history_filename'))
示例#15
0
 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')
示例#16
0
 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')
示例#17
0
 def get():
     return GlobalVariables.get_instance().get(PycoStringBuffer.BUFFER_NAME,
                                               level='_internal')
示例#18
0
 def __init__(self):
     GlobalVariables.get_instance().set(PycoStringBuffer.BUFFER_NAME, '', level='_internal')
示例#19
0
 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()
示例#20
0
 def get():
     return GlobalVariables.get_instance().get(PycoStringBuffer.BUFFER_NAME, level='_internal')
示例#21
0
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