Ejemplo n.º 1
0
def parse_operation_argument(operation_arg_dir: Directory):
    # assuming none var type has size 3 (int 16, float 32, bool 1, char 8, string 2)
    is_link_val = operation_arg_dir.is_var_linked()

    if is_link_val:  # is link
        import function_utils
        invoked_function: Function = function_utils.get_currently_invoked_function(
        )
        arg_val = invoked_function.get_var(
            value_parsing.parse_link(operation_arg_dir)).value

    elif operation_arg_dir.dirlen(
    ) != 3:  # not link and not operation -> simple type
        _type = value_parsing.len_types[operation_arg_dir.dirlen()]
        arg_val = value_parsing.parse_generic_value(
            operation_arg_dir, _type, value_parsing.types_len[_type])

    else:  # arg is operation
        arg_val = operation_parsing(operation_arg_dir)

    return arg_val
Ejemplo n.º 2
0
def _while(directory):
    if directory.dirlen() != 2:  # logical condition, list of commands
        error_factory.ErrorFactory.invalid_command_dir_number(
            [2], directory.path, directory.dirlen(), "WHILE")

    condition_dir = directory.navigate_to_nth_child(0)
    counter = 1
    while parse_value(condition_dir, Types.boolean, 1):
        logger.debug(_while.__name__ + f" executing {counter} times")
        root = Directory(directory.navigate_to_nth_child(1).path)
        execute_all_loop_commands(root)
        counter += 1
Ejemplo n.º 3
0
def parse_link(self):
    if self.dirlen() == 1:
        logger.debug(parse_link.__name__ + " LINK")
        return (os.readlink(self.navigate_to_nth_child(0).path),
                os.readlink(
                    self.navigate_to_nth_child(0).path)[:-1])[os.readlink(
                        self.navigate_to_nth_child(0).path).endswith('/')]
    elif self.dirlen() == 3:
        logger.debug(parse_link.__name__ + " NAME")
        str_dirs = list(
            filter(lambda it_dir: not os.path.islink(it_dir.path),
                   self.get_directory_children()))
        return parse_string_value([Directory(children=str_dirs)])
    else:
        error_factory.ErrorFactory.command_not_found(self.path, self.dirlen())
Ejemplo n.º 4
0
class Function:
    function_stack = []
    variable_returning = 0

    # 1 folder - list of commands, 2 folder - args no (if empty 0 arg fun),
    # 3 folder return value name (if empty void func)
    def __init__(self, pointer, name, args_no, return_val_id):
        self.variable_stack = VariableStack()
        self.root = Directory(pointer)
        self.name = name
        self.args_no = args_no
        self.return_val_id = return_val_id

    def perform_function_code(self):
        logger.info(Function.perform_function_code.__name__ +
                    " PERFORMING FUNCTION: " + self.name)
        for directory in self.root.get_directory_children():
            logger.debug(Function.perform_function_code.__name__ +
                         " FUN COMMAND AT " + self.name + directory.path)
            commands.expression(directory)
        if self.return_val_id is not None:
            return self.find_var_by_name(self.return_val_id).value

    def find_var_by_name(self, var_name):
        return self.variable_stack.get_var_by_name(var_name)

    def find_var_by_path(self, var_pointer):
        return self.variable_stack.get_var_by_path(var_pointer)

    def clear_var_stack(self):
        self.variable_stack.clear()

    def get_var(self, param):
        if param.startswith('/'):
            return self.find_var_by_path(param)
        else:
            return self.find_var_by_name(param)

    def get_arguments_len(self):
        return len(self.args_no)

    def __str__(self):
        return ",".join(
            [str(s) for s in [self.root.path, self.name, self.return_val_id]])

    def __eq__(self, other):
        isinstance(other, Function.__class__) and self.root == other.root
Ejemplo n.º 5
0
def _if(directory):
    if not 3 >= directory.dirlen() >= 2:
        error_factory.ErrorFactory.invalid_command_dir_number(
            [2, 3], directory.path, directory.dirlen(), "IF")
    if parse_value(directory.navigate_to_nth_child(0), Types.boolean, 1):
        logger.debug(_if.__name__ + ": true execution")
        root = Directory(directory.navigate_to_nth_child(1).path)
        for directory in root.get_directory_children():
            logger.debug(_if.__name__ + ": COMPLEX TRUE " + directory.path)
            commands.expression(directory)

    elif directory.dirlen() == 3:
        logger.debug(_if.__name__ + ": false execution")
        root = Directory(directory.navigate_to_nth_child(2).path)
        for directory in root.get_directory_children():
            logger.debug(_if.__name__ + ": COMPLEX FALSE " + directory.path)
            commands.expression(directory)
Ejemplo n.º 6
0
def wait_for_input(input_dir, link_path):
    while (len(os.listdir(input_dir)) == 0):
        time.sleep(0.2)
    declare(Directory(input_dir).navigate_to_nth_child(0), link=link_path)
    shutil.rmtree(input_dir)
Ejemplo n.º 7
0
 def __init__(self, pointer, name, args_no, return_val_id):
     self.variable_stack = VariableStack()
     self.root = Directory(pointer)
     self.name = name
     self.args_no = args_no
     self.return_val_id = return_val_id