def connect(ip="0.0.0.0", port=2222): key = input("[ergo: remote]: Please enter a key: ") Env = Environment() Env.prompt = "({}).: ".format(ip) while True: stdin = str(prompt(Env, {})) for line in file_lines(stdin): print(sendmsg(ip, port, key + line))
class Pipeline(object): """Defines a pipeline object for redirecting the output of some functions to others.""" # tokenized functions to be piped to operations = [] args = [] env = Environment() namespace = {} def __init__(self, env, namespace): """Initialize a Pipeline object.""" self.env = env self.namespace = namespace def append_operation(self, operation): """Add an Operation type to the end of the Pipeline.""" self.operations.append(operation) def stdout(self): """Evaluate the entire pipeline, giving the final output.""" cur = [] for operation in self.operations: if not callable(operation.function): # then call as shell command os.system("%s %s" % (operation.function, " ".join(operation.arguments))) else: # for some reason pylint thinks _operation and argv are undefined and/or unused _operation = operation argv = [str(x) for x in _operation.arguments] # pylint: disable=unused-variable try: # it's pretty much impossible to shorten this # pylint: disable=line-too-long, undefined-variable current_op = lambda x, _operation=_operation, argv=argv: _operation.function(ArgumentsContainer(self.env, self.namespace, x, get_typed_args(_operation.function.__doc__, argv))) except DocoptException as error: return "[ergo: ArgumentError]: %s." % str(error) if cur == []: cur = current_op(None) else: cur = current_op(cur) if cur is None: cur = [] else: cur = list(cur) self.operations = [] self.args = [] return cur
from ergonomica import ErgonomicaError from ergonomica.lib.lang.tokenizer import tokenize from ergonomica.lib.lang.docopt import docopt, DocoptException # # ergonomica library imports # from ergonomica.lib.lib import ns from ergonomica.lib.lang.environment import Environment from ergonomica.lib.lang.arguments import ArgumentsContainer from ergonomica.lib.lang.builtins import Namespace, namespace from ergonomica.lib.lang.parser import Symbol, parse, file_lines # initialize environment variables ENV = Environment() PROFILE_PATH = os.path.join(os.path.expanduser("~"), ".ergo", ".ergo_profile") # Override printing. This is done because # the output of shell commands is printed procedurally, # and you don't want the same output printed twice. PRINT_OVERRIDE = False class function(object): def __init__(self, args, body, ns): self.args = args self.body = body self.ns = ns def __call__(self, *args):
from ergonomica.lib.lang.bash import run_bash from ergonomica.lib.lang.ergo2bash import ergo2bash from ergonomica.lib.load.load_commands import verbs from ergonomica.lib.misc.arguments import print_arguments from ergonomica.lib.misc.arguments import process_arguments from ergonomica.lib.interface.completer import ErgonomicaCompleter from ergonomica.lib.interface.key_bindings_manager import manager_for_environment from prompt_toolkit import prompt from prompt_toolkit.history import FileHistory # set terminal title sys.stdout.write("\x1b]2;ergonomica\x07") # initialize environment ENV = Environment() ENV.verbs = verbs # read history try: history = FileHistory( os.path.join(os.path.expanduser("~"), ".ergo", ".ergo_history")) except IOError as error: print( "[ergo: ConfigError]: No such file ~/.ergo_history. Please run ergo_setup. " + str(error), file=sys.stderr) # load .ergo_profile verbs["load_config"](ENV, [], [])
from docopt import docopt # # ergonomica library imports # from ergonomica.lib.interface.prompt import prompt from ergonomica.lib.lib import ns from ergonomica.lib.lang.environment import Environment from ergonomica.lib.lang.pipe import Pipeline, Operation from ergonomica.lib.lang.tokenizer import tokenize from ergonomica.lib.lang.parser_types import Function # , Command # initialize environment variable ENV = Environment() PROFILE_PATH = os.path.join(os.path.expanduser("~"), ".ergo", ".ergo_profile") def true(argc): """t: Return true. Usage: t """ return [True] def false(argc): """f: Return false.