Example #1
0
 def main(self, result):
     ret = ''
     if result['info']:
         ret += 'Info:'
         ret += '\n  %s\n' % result['info']
     if result['actions']:
         ret += 'Actions:'
         ret += '\n'
         for item in result['actions']:
             info = item['info']
             if not info:
                 info = ucfirst(item['name'])
             ret += '\n  # %s' % info
             astr = ''
             for a in item['args']:
                 if astr != '':
                     astr += ', '
                 if a['type']:
                     astr += '(%s) ' % a['type']
                 #if a['required']:
                 #    astr += '*'
                 astr += a['key']
                 if a['default']:
                     astr += '=%s' % a['default']
             ret += '\n  %s(%s)' % (item['name'], astr)
             ret += '\n'
     if result['events']:
         ret += '\nEvents:'
         for ev in result['event']:
             ret += '\n  %s' % ev
     return ret
Example #2
0
 def main(self, result):
     ret = ''
     if result['info']:
         ret += 'Info:'
         ret += '\n  %s\n' % result['info']
     if result['actions']:
         ret += 'Actions:'
         ret += '\n'
         for item in result['actions']:
             info = item['info']
             if not info:
                 info = ucfirst(item['name'])
             ret += '\n  # %s' % info
             astr = ''
             for a in item['args']:
                 if astr != '':
                     astr += ', '
                 if a['type']:
                     astr += '(%s) ' % a['type']
                 #if a['required']:
                 #    astr += '*'
                 astr += a['key']
                 if a['default']:
                     astr += '=%s' % a['default']
             ret += '\n  %s(%s)' % (item['name'], astr)
             ret += '\n'
     if result['events']:
         ret += '\nEvents:'
         for ev in result['event']:
             ret += '\n  %s' % ev
     return ret
Example #3
0
def load(formatterName):
    formatterName = utils.ucfirst(formatterName)
    for dir in getFormatterDirs():
        path = '%s/%s.py' % (dir, formatterName)
        if os.path.exists(path):
            try:
                return utils.newObject(
                    pkgName   = formatterName, #'chains.commandline.formatter.%s' % formatterName, 
                    className = 'Formatter%s' % formatterName,
                    path = '%s/%s.py' % (dir, formatterName)
                )
            except ImportError:
                pass
    raise Exception('Formatter not found: %s' % formatterName)
Example #4
0
    def onDescribe(self):
        data = {
            'info': 'LG TV - works with LG 42LH4000 (and probably all others with a RS232 port?)',
            'actions': [],
            'events': []
        }
        for cfg in self.spec:
            cmd = cfg[0]
            args = cfg[3]
            values = None

            getCommand = {
                'info': 'Get %s' % cmd,
                'name': 'get%s' % utils.ucfirst(cmd),
                'args': []
            }

            setCommand = {
                'info': 'Set %s' % cmd,
                'name': 'set%s' % utils.ucfirst(cmd),
                'args': []
            }

            if type(args) == type({}):
                setCommand['args'].append({
                    'info':     'Value',
                    'default':  None,
                    'required': True,
                    'valid':    args.keys(),
                    'type':     'string'
                })
            elif args.__class__ == LgRange:
                setCommand['args'].append({
                    'info':     'Value (%s-%s)' % (LgRange.min,LgRange.max),
                    'default':  None,
                    'required': True,
                    'valid':    None,
                    'type':     'int'
                })
            elif args.__class__ == LgBool:
                setCommand['args'].append({
                    'info':     'Value',
                    'default':  None,
                    'required': True,
                    'valid':    None,
                    'type':     'boolean'
                })
            else:
                setCommand['args'].append({
                    'info':     'Value',
                    'default':  None,
                    'required': True,
                    'valid':    None,
                    'type':     'string'
                })

            #if cmd not in ['power']:
            #    data['actions'].append(cg)
            #data['actions'].append(cs)

            data['actions'].append(getCommand)
            data['actions'].append(setCommand)

        return data
Example #5
0
    def onDescribe(self):
        data = {
            'info':
            'LG TV - works with LG 42LH4000 (and probably all others with a RS232 port?)',
            'actions': [],
            'events': []
        }
        for cfg in self.spec:
            cmd = cfg[0]
            args = cfg[3]
            values = None

            getCommand = {
                'info': 'Get %s' % cmd,
                'name': 'get%s' % utils.ucfirst(cmd),
                'args': []
            }

            setCommand = {
                'info': 'Set %s' % cmd,
                'name': 'set%s' % utils.ucfirst(cmd),
                'args': []
            }

            if type(args) == type({}):
                setCommand['args'].append({
                    'info': 'Value',
                    'default': None,
                    'required': True,
                    'valid': args.keys(),
                    'type': 'string'
                })
            elif args.__class__ == LgRange:
                setCommand['args'].append({
                    'info':
                    'Value (%s-%s)' % (LgRange.min, LgRange.max),
                    'default':
                    None,
                    'required':
                    True,
                    'valid':
                    None,
                    'type':
                    'int'
                })
            elif args.__class__ == LgBool:
                setCommand['args'].append({
                    'info': 'Value',
                    'default': None,
                    'required': True,
                    'valid': None,
                    'type': 'boolean'
                })
            else:
                setCommand['args'].append({
                    'info': 'Value',
                    'default': None,
                    'required': True,
                    'valid': None,
                    'type': 'string'
                })

            #if cmd not in ['power']:
            #    data['actions'].append(cg)
            #data['actions'].append(cs)

            data['actions'].append(getCommand)
            data['actions'].append(setCommand)

        return data