Ejemplo n.º 1
0
 def set_scope(self, value):
     """ narrows the scopes the commands """
     set_scope(value)
     if self.default_command:
         self.default_command += ' ' + value
     else:
         self.default_command += value
     return value
Ejemplo n.º 2
0
 def set_scope(self, value):
     """ narrows the scopes the commands """
     set_scope(value)
     if self.default_command:
         self.default_command += ' ' + value
     else:
         self.default_command += value
     return value
Ejemplo n.º 3
0
    def handle_scoping_input(self, continue_flag, cmd, text):
        default_split = text.partition(SELECT_SYMBOL['scope'])[2].split()
        cmd = cmd.replace(SELECT_SYMBOL['scope'], '')

        if text and SELECT_SYMBOL['scope'] == text[0:2]:
            continue_flag = True

            if not default_split:
                self.default_command = ""
                set_scope("", add=False)
                print('unscoping all')

                return continue_flag, cmd

            while default_split:
                if not text:
                    value = ''
                else:
                    value = default_split[0]

                if self.default_command:
                    tree_val = self.default_command + " " + value
                else:
                    tree_val = value

                if in_tree(self.completer.command_tree, tree_val.strip()):
                    self.set_scope(value)
                    print("defaulting: " + value)
                    cmd = cmd.replace(SELECT_SYMBOL['scope'], '')
                    telemetry.track_ssg('scope command', value)

                elif SELECT_SYMBOL['unscope'] == default_split[0] and \
                        len(self.default_command.split()) > 0:

                    value = self.default_command.split()[-1]
                    self.default_command = ' ' + ' '.join(
                        self.default_command.split()[:-1])

                    if not self.default_command.strip():
                        self.default_command = self.default_command.strip()
                    set_scope(self.default_command, add=False)
                    print('unscoping: ' + value)

                elif SELECT_SYMBOL['unscope'] not in text:
                    print("Scope must be a valid command")

                default_split = default_split[1:]
        else:
            return continue_flag, cmd
        return continue_flag, cmd
Ejemplo n.º 4
0
    def handle_scoping_input(self, continue_flag, cmd, text):
        """ handles what to do with a scoping gesture """
        default_split = text.partition(SELECT_SYMBOL['scope'])[2].split()
        cmd = cmd.replace(SELECT_SYMBOL['scope'], '')

        continue_flag = True

        if not default_split:
            self.default_command = ""
            set_scope("", add=False)
            print('unscoping all', file=self.output)

            return continue_flag, cmd

        while default_split:
            if not text:
                value = ''
            else:
                value = default_split[0]

            if self.default_command:
                tree_val = self.default_command + " " + value
            else:
                tree_val = value

            if in_tree(self.completer.command_tree, tree_val.strip()):
                self.set_scope(value)
                print("defaulting: " + value, file=self.output)
                cmd = cmd.replace(SELECT_SYMBOL['scope'], '')
                telemetry.track_ssg('scope command', value)

            elif SELECT_SYMBOL['unscope'] == default_split[0] and \
                    len(self.default_command.split()) > 0:

                value = self.default_command.split()[-1]
                self.default_command = ' ' + ' '.join(self.default_command.split()[:-1])

                if not self.default_command.strip():
                    self.default_command = self.default_command.strip()
                set_scope(self.default_command, add=False)
                print('unscoping: ' + value, file=self.output)

            elif SELECT_SYMBOL['unscope'] not in text:
                print("Scope must be a valid command", file=self.output)

            default_split = default_split[1:]
        return continue_flag, cmd