Beispiel #1
0
def loadFromDir(section, command, commandsDir):
    result = {}
    if section:
        section = utils.lcfirst(section)
    if command:
        command = utils.lcfirst(command)
    for f in os.listdir(commandsDir):
        if f[0] == '_' or f.split('.')[-1:][0] != 'py':
            continue
        f = f.split('.')[:1][0]
        if f == 'Help':
            continue
        tmp = utils.caseSplit(f, firstOnly=True)
        _section = tmp[0]
        _command = tmp[1]
        if section and section != _section:
            continue
        if command and command != _command:
            continue
        if not result.has_key(_section):
            result[_section] = {}
        result[_section][_command] = utils.newObject(pkgName=f,
                                                     className='Command%s' % f,
                                                     path=commandsDir + '/' +
                                                     f + '.py')
    return result
Beispiel #2
0
def loadFromDir(section, command, commandsDir):
    result = {}
    if section:
        section = utils.lcfirst(section)
    if command:
        command = utils.lcfirst(command)
    for f in os.listdir(commandsDir):
        if f[0] == '_' or f.split('.')[-1:][0] != 'py':
            continue
        f = f.split('.')[:1][0]
        if f == 'Help':
            continue
        tmp = utils.caseSplit(f, firstOnly=True)
        _section = tmp[0]
        _command = tmp[1]
        if section and section != _section:
            continue
        if command and command != _command:
            continue
        if not result.has_key(_section):
            result[_section] = {}
        result[_section][_command] = utils.newObject(
            pkgName = f,
            className = 'Command%s' % f,
            path = commandsDir + '/' + f + '.py'
        )
    return result
Beispiel #3
0
    def runAction(self, action, args):

        if action == 'sendRaw':
            return self.sercmd(args[0])
        if action == 'describe':
            return self.action_describe()

        access  = action[:3]                   # "get" or "set"
        element = utils.lcfirst(action[3:])    # f.ex. power, inputSelect, etc
        spec    = self.getSpecElement(element) # config from self.spec for element
        if access not in ['get', 'set'] or not spec:
            raise Exception('No such action: %s' % action)
        if access == 'get':
            arg = 'ff'
        else:
            arg = args[0]

        #log.info('Action: action=%s access=%s element=%s arg=%s spec=%s' % (action, access, element, arg, spec))

        params = [access]
        for v in spec:
            params.append(v)
        params.append(arg)

        result = self._onCommand(*params)

        if access == 'set':
            self.sendEvent(element, {'value': arg})

        return result
Beispiel #4
0
    def runAction(self, action, args):

        if action == 'sendRaw':
            return self.sercmd(args[0])
        if action == 'describe':
            return self.action_describe()

        access = action[:3]  # "get" or "set"
        element = utils.lcfirst(action[3:])  # f.ex. power, inputSelect, etc
        spec = self.getSpecElement(
            element)  # config from self.spec for element
        if access not in ['get', 'set'] or not spec:
            raise Exception('No such action: %s' % action)
        if access == 'get':
            arg = 'ff'
        else:
            arg = args[0]

        #log.info('Action: action=%s access=%s element=%s arg=%s spec=%s' % (action, access, element, arg, spec))

        params = [access]
        for v in spec:
            params.append(v)
        params.append(arg)

        result = self._onCommand(*params)

        if access == 'set':
            self.sendEvent(element, {'value': arg})

        return result