Ejemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser(description='Coolbee command line',
                                     prog="coolbee",
                                     usage="%(prog)s [command]\n",
                                     add_help=False)


    main = parser.add_argument_group("commands")

    for command in get_commands():
        # Exclude main
        if command != "main":
            link = path.join(COMMAND_DIR, command, "description")

            try:
                help = open(link).read()
            except:
                help = ""

            main.add_argument(command, help=help)

    if len(argv) == 1:
        parser.print_help()
    else:
        args = parser.parse_args(argv)
Ejemplo n.º 2
0
    def _cmdsFunctionFormat(self):
        '''set up maya.cmds functions'''
        # mayaBinDir = os.path.dirname(sys.executable)
        # cmdsList = os.path.join(mayaBinDir, 'commandList')

        functions = '\\b('
        # with open(cmdsList) as phile:
        #     for line in phile:
        #         functions += line.split(' ')[0] + '|'

        maya_ver=utils.get_maya_version()
        maya_commands = utils.get_commands(version=maya_ver)
        for c in maya_commands:
            functions += c + '|'




        # global MEL procedures
        try:
            melProcedures = cmds.melInfo()
            maxlen = 1400
            stop = len(melProcedures) / maxlen
            melProc = []
            melProc.append('\\b(' + '|'.join(melProcedures[:maxlen]) + ')\\b')
            for i in range(1, stop - 1):
                start = maxlen * i
                end = maxlen * (i + 1)
                melProc.append('\\b(' + '|'.join(melProcedures[start:end]) + ')\\b')
            melProc.append('\\b(' + '|'.join(melProcedures[maxlen*stop:]) + ')\\b')
        except:
            pass

        # TODO: should update it when a plug-in was load.
        try:
            # function from plug-ins
            plugins = cmds.pluginInfo(q=1, listPlugins=1)
            for plugin in plugins:
                funcFromPlugin = cmds.pluginInfo(plugin, q=1, command=1)
                if funcFromPlugin:
                    functions += '|'.join(funcFromPlugin)
        except:
            pass

        functions = functions[:-1] + ')\\b'

        # function format
        funcFormat = QtGui.QTextCharFormat()
        funcFormat.setForeground(self._keywordColor)
        self.__rules.append((re.compile(functions), funcFormat))
        try:
            for mp in melProc:
                self.__rules.append((re.compile(mp), funcFormat))
        except:
            pass
Ejemplo n.º 3
0
    def _cmdsFunctionFormat(self):
        '''set up maya.cmds functions'''
        # mayaBinDir = os.path.dirname(sys.executable)
        # cmdsList = os.path.join(mayaBinDir, 'commandList')

        functions = '\\b('
        # with open(cmdsList) as phile:
        #     for line in phile:
        #         functions += line.split(' ')[0] + '|'

        maya_ver = utils.get_maya_version()
        maya_commands = utils.get_commands(version=maya_ver)
        for c in maya_commands:
            functions += c + '|'

        # global MEL procedures
        try:
            melProcedures = cmds.melInfo()
            maxlen = 1400
            stop = len(melProcedures) / maxlen
            melProc = []
            melProc.append('\\b(' + '|'.join(melProcedures[:maxlen]) + ')\\b')
            for i in range(1, stop - 1):
                start = maxlen * i
                end = maxlen * (i + 1)
                melProc.append('\\b(' + '|'.join(melProcedures[start:end]) +
                               ')\\b')
            melProc.append('\\b(' + '|'.join(melProcedures[maxlen * stop:]) +
                           ')\\b')
        except:
            pass

        # TODO: should update it when a plug-in was load.
        try:
            # function from plug-ins
            plugins = cmds.pluginInfo(q=1, listPlugins=1)
            for plugin in plugins:
                funcFromPlugin = cmds.pluginInfo(plugin, q=1, command=1)
                if funcFromPlugin:
                    functions += '|'.join(funcFromPlugin)
        except:
            pass

        functions = functions[:-1] + ')\\b'

        # function format
        funcFormat = QtGui.QTextCharFormat()
        funcFormat.setForeground(self._keywordColor)
        self.__rules.append((re.compile(functions), funcFormat))
        try:
            for mp in melProc:
                self.__rules.append((re.compile(mp), funcFormat))
        except:
            pass
Ejemplo n.º 4
0
def get_message():
    # from_number = request.form['From']
    req_body = request.form['Body']
    print(req_body)
    # Check first word in body to see if it is custom command
    commands = get_commands(req_body)
    # If custom command, run function associated with it
    # If not custom command, run the body as normal os command
    #p = Process(target = execute_commands, args = (commands, request.form['Channel']))
    execute_commands(commands, request.form['Channel'])
    #p.start()
    #p.join()
    return 'ok'
Ejemplo n.º 5
0
args = parser.parse_args()


if (args.mode == 'self_driving'):
    print('Vehicle started in self driving mode.')

    # Load self-driving pre-train model
    model, graph = load_autopilot('autopilot.hdf5')

    print('Model loaded...')

    # Create Axionaut car with default settings
    axionaut = vehicles.Axionaut()

    # Configure PDW control commands as default
    axionaut.commands = get_commands(path=None, default=True)

    # Test camera position
    axionaut.camera_test()

    print('Hardware configured...')

    # Set Axionaut to auto pilot mode / Wrap driving model to vehicle
    axionaut.autopilot(model, graph)

    # Start Axtionaut :)
    raw_input('Self self_driving started. Pres any key to start driving. Press Crtl + C to exit.')
    
    axionaut.start()

elif(args.mode == 'training'):
Ejemplo n.º 6
0
from utils import get_commands, execute_commands

req_body = ''

while req_body != 'exit':
    req_body = input('Turtle Command$ ')

    # Check first word in body to see if it is custom command
    commands = get_commands(req_body)
    # If custom command, run function associated with it
    # If not custom command, run the body as normal os command
    output = execute_commands(commands)

    print(output)
Ejemplo n.º 7
0

def get_main_file(path):
    for filename in os.listdir(path):
        if filename.startswith(MAIN_FILE_NAME + "."):
            return filename
    return None


if __name__ == '__main__':

    # Pop file name
    argv.pop(0)

    # If no command specified, exec help for main
    if len(argv) == 0:
        Python().execute_command(args=argv, command="main")
        sys.exit(1)

    commands = get_commands()

    # Get the command
    command = argv[0]

    if command in commands:
        argv.pop(0)

        Python().execute_command(command=command)
    else:
        Python().execute_command(command="main")
        # print 'Unrecognized command.'
Ejemplo n.º 8
0
    assert is_git_clean(out.stdout)


@utils.timeout()
@pytest.mark.parametrize("host", utils.get_host())
def test_iio_info_device(host, target_info):
    assert target_info
    command = 'iio_info | grep iio:device'
    out = host.run(command)
    for target in target_info.get('iio_devices'):
        assert target in out.stdout


@utils.timeout()
@pytest.mark.parametrize("lib", utils.get_built_libs())
@pytest.mark.parametrize("host", utils.get_host())
def test_libs(host, lib):
    command = '/usr/sbin/ldconfig -v 2> /dev/null | grep {}'.format(lib)
    out = host.run(command)
    assert out.rc == 0
    assert out.stdout
    assert not out.stderr


@utils.timeout()
@pytest.mark.parametrize("command", utils.get_commands())
@pytest.mark.parametrize("host", utils.get_host())
def test_commands(host, command):
    out = host.exists(command)
    assert out
Ejemplo n.º 9
0
class MelHighlighter(QSyntaxHighlighter):
    """Syntax highlighter for the Python language.
    """
    # Python keywords from 2015
    keywords = [
        'false', 'exists', 'int', 'float', 'warning', 'in', 'yes', 'if',
        'matrix', 'for', 'switch', 'source', 'vector', 'proc', 'do', 'global',
        'return', 'string', 'trace', 'else', 'break', 'catch', 'true', 'case',
        'on', 'off', 'objExists', 'default', 'attributeExists', 'alias',
        'while', 'continue', 'error'
    ]

    # add maya commands as keywords
    maya_ver = utils.get_maya_version()
    maya_commands = utils.get_commands(version=maya_ver)

    pyKeywords = keyword.kwlist + ['False', 'True', 'None']
    # keywords+=maya_commands

    # Python operators
    operators = [
        '=',
        # Comparison
        '==',
        '!=',
        '<',
        '<=',
        '>',
        '>=',
        # Arithmetic
        '\+',
        '-',
        '\*',
        '/',
        '\%',  # '\*\*',
        # In-place
        '\+=',
        '-=',
        '\*=',
        '/=',
        '\%=',
        # Bitwise
        # '\^', '\|', '\&', '\~', '>>', '<<',
    ]

    # Python braces
    braces = [
        '\{',
        '\}',
        '\(',
        '\)',
        '\[',
        '\]',
    ]

    def __init__(self, document):
        QSyntaxHighlighter.__init__(self, document)

        # Multi-line strings (expression, flag, style)
        # FIXME: The triple-quotes in these two lines will mess up the
        # syntax highlighting from this point onward
        # self.tri_single = (QRegExp("'''"), 1, STYLES['string2'])
        # self.tri_double = (QRegExp('"""'), 2, STYLES['string2'])

        rules = []

        # Keyword, operator, and brace rules
        rules += [(r'\b%s\b' % w, 0, STYLES['keyword'])
                  for w in MelHighlighter.keywords]
        rules += [(r'%s' % o, 0, STYLES['operator'])
                  for o in MelHighlighter.operators]
        rules += [(r'%s' % b, 0, STYLES['brace'])
                  for b in MelHighlighter.braces]

        rules += [(r'%s' % b, 0, STYLES['keyword'])
                  for b in MelHighlighter.pyKeywords]

        rules += [(r'%s' % "|".join(MelHighlighter.pyKeywords), 0,
                   STYLES['keyword'])]

        # All other rules
        rules += [
            # 'self'
            # (r'\bself\b', 0, STYLES['self']),

            # Double-quoted string, possibly containing escape sequences
            (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']),

            # Single-quoted string, possibly containing escape sequences
            # (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']),

            # 'proc' followed by an identifier
            # (r'\bproc\b\s*(\w+)', 1, STYLES['defclass']),
            # 'global proc' followed by an identifier
            # (r'\bglobal proc\b\s*(\w+)', 1, STYLES['defclass']),

            # Numeric literals
            (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']),
            (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']),
            (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0,
             STYLES['numbers']),

            # From '//' until a newline
            (r'//[^\n]*', 0, STYLES['comment']),
        ]

        # Build a QRegExp for each pattern
        self.rules = [(QRegExp(pat), index, fmt)
                      for (pat, index, fmt) in rules]

        # Quotes
        self._singleQuotes = QtCore.QRegExp("'''")
        self._doubleQuotes = QtCore.QRegExp('"""')

        # mel multi-line comment: /*  */
        self._melMLComStart = re.compile('/\\*')
        self._melMLComEnd = re.compile('\\*/')

    def _melMLCommentFormat(self, text):
        '''set up mel multi-line comment: /*  */'''
        startIndex = 0
        commentLen = 0
        self.setCurrentBlockState(0)
        if self.previousBlockState() != 1:
            searchStart = self._melMLComStart.search(text)
            if searchStart:
                startIndex = searchStart.start()
                searchEnd = self._melMLComEnd.search(text)
                if searchEnd:
                    commentLen = searchEnd.end() - startIndex
                else:
                    self.setCurrentBlockState(1)
                    commentLen = len(text) - startIndex
        else:
            searchEnd = self._melMLComEnd.search(text)
            if searchEnd:
                commentLen = searchEnd.end()
            else:
                self.setCurrentBlockState(1)
                commentLen = len(text)
        if commentLen > 0:
            # self.setFormat(startIndex, commentLen, self._commentFormat)
            self.setFormat(startIndex, commentLen, STYLES['comment'])

    def quotesFormat(self, text, regExp, state):
        '''set up single or double quotes strings format'''
        if self.previousBlockState() == state:
            startIndex = 0
            add = 0
        else:
            startIndex = regExp.indexIn(text)
            add = regExp.matchedLength()

        while startIndex >= 0:
            end = regExp.indexIn(text, startIndex + add)
            if end >= add:
                quotesLen = end - startIndex + regExp.matchedLength()
                self.setCurrentBlockState(0)
            else:
                self.setCurrentBlockState(state)
                quotesLen = len(text) - startIndex + add
            # self.setFormat(startIndex, quotesLen, self._quotationFormat)
            self.setFormat(startIndex, quotesLen, STYLES['comment'])

            startIndex = regExp.indexIn(text, startIndex + quotesLen)

        if self.currentBlockState() == state:
            return True
        else:
            return False

    def highlightBlock(self, text):
        """Apply syntax highlighting to the given block of text.
        """
        # Do other syntax formatting
        for expression, nth, format in self.rules:
            index = expression.indexIn(text, 0)

            while index >= 0:
                # We actually want the index of the nth match
                index = expression.pos(nth)
                length = expression.cap(nth).length()
                self.setFormat(index, length, format)
                index = expression.indexIn(text, index + length)

        self.setCurrentBlockState(0)

        # # Do multi-line strings
        # in_multiline = self.match_multiline(text, *self.tri_single)
        # if not in_multiline:
        #     in_multiline = self.match_multiline(text, *self.tri_double)

        # blocks
        self._melMLCommentFormat(text)
        quotesState = self.quotesFormat(text, self._singleQuotes, 2)
        if not quotesState:
            self.quotesFormat(text, self._doubleQuotes, 3)