def call(args=None,locals_=None):
    """
    Calls a method from local scope parsing a pipe-like argument list
    """
    if args is None:
        import sys
        args = sys.argv[1:]
    f,args = args[0],args[1:]
    
    print(f,args)
    
    if not isCallable(f):
        locals_ = locals_ or globals()
        if f=='help':
            if args and args[0] in locals_:
                n,o = args[0],locals_[args[0]]
                if hasattr(o,'func_code'):
                    n = n+str(o.func_code.co_varnames)
                return '%s:\n%s' % (n,o.__doc__)
            else:
                m = [k for k,v in locals_.items() if isCallable(v)]
                return ('\n'.join(sorted(m,key=str.lower)))
        f = locals_.get(f,None) 
    if all(isString(a) for a in args):
        args = map(str2type,args)
    return f(*args)    
Example #2
0
    def trigger_callbacks(self, regs=None):
        """
        regs = list of addresses that changed
        """
        if not self.callbacks:
            return
        for key, cb in self.callbacks.items():
            try:
                rs, push, org = regs, False, cb
                if fn.isSequence(cb):
                    rs = regs and [r for r in regs if r in cb]
                    if not regs or rs or (len(cb) == 1
                                          and fn.isCallable(cb[0])):
                        cb = cb[-1]
                    else:
                        continue
                msg = ('%s: %s.trigger_callbacks(%s,%s): %s:%s' %
                       (fn.time2str(), self.name, fn.shortstr(
                           regs, 40), rs, key, org))
                if self.plc_obj is not None:
                    self.plc_obj.debug(msg)
                else:
                    print(msg)
                if fn.isCallable(cb):
                    cb(key)  #,push=push)
                else:
                    cb = getattr(cb, 'push_event',
                                 getattr(cb, 'event_received', None))
                    cb and cb(key)

                fn.wait(1.e-4)

            except Exception as e:
                print(fn.except2str())
                print('%s.callback(%s,%s): %s' % (self, key, cb, e))
def call(args=None, locals_=None):
    """
    Calls a method from local scope parsing a pipe-like argument list
    """
    if args is None:
        import sys
        args = sys.argv[1:]
    f, args = args[0], args[1:]

    print(f, args)

    if not isCallable(f):
        locals_ = locals_ or globals()
        if f == 'help':
            if args and args[0] in locals_:
                n, o = args[0], locals_[args[0]]
                if hasattr(o, 'func_code'):
                    n = n + str(o.func_code.co_varnames)
                return '%s:\n%s' % (n, o.__doc__)
            else:
                m = [k for k, v in locals_.items() if isCallable(v)]
                return ('\n'.join(sorted(m, key=str.lower)))
        f = locals_.get(f, None)
    if all(isString(a) for a in args):
        args = map(str2type, args)
    return f(*args)
Example #4
0
    def wrapper(instance,f,*args,**kwargs):
        try:
            from taurus.qt.qtgui.plot import TaurusPlot
            obj = ArchivedTrendLogger(trend=instance)
            menu = f(instance)
            before = MenuActionAppender.before \
                or instance._usePollingBufferAction
            menu.insertSeparator(before)

            for t in MenuActionAppender.ACTIONS:
                if len(t)==4:
                    actname,label,method,args = t
                else:
                    actname,label,method = t
                    args = (instance,)
                action = getattr(instance,actname,None)
                if not action: 
                    setattr(instance,actname,Qt.QAction(label, None))
                    action = getattr(instance,actname)
                    instance.connect(action,Qt.SIGNAL("triggered()"),
                        (lambda o=instance,m=method,a=args,l=obj:
                            (l.warning(','.join(map(str,(o,m,a)))),
                            (m(o) if fn.isCallable(m) 
                                else getattr(o,m,
                                    getattr(l,m,None)))(*a)))
                        )

                menu.insertAction(before,action)
            menu.insertSeparator(before)
            return menu
        
        except:
            traceback.print_exc()
    def wrapper(instance, f, *args, **kwargs):
        try:
            from taurus.qt.qtgui.plot import TaurusPlot
            obj = ArchivedTrendLogger(trend=instance)
            menu = f(instance)
            before = MenuActionAppender.before \
                or instance._usePollingBufferAction
            menu.insertSeparator(before)

            for t in MenuActionAppender.ACTIONS:
                if len(t) == 4:
                    actname, label, method, args = t
                else:
                    actname, label, method = t
                    args = (instance, )
                action = getattr(instance, actname, None)
                if not action:
                    setattr(instance, actname, Qt.QAction(label, None))
                    action = getattr(instance, actname)
                    instance.connect(
                        action, Qt.SIGNAL("triggered()"),
                        (lambda o=instance, m=method, a=args, l=obj:
                         (l.warning(','.join(map(str, (o, m, a)))),
                          (m(o) if fn.isCallable(m) else getattr(
                              o, m, getattr(l, m, None)))(*a))))

                menu.insertAction(before, action)
            menu.insertSeparator(before)
            return menu

        except:
            traceback.print_exc()
Example #6
0
 def is_local(obj, module):
     if not fn.isCallable(obj): return False
     m = getattr(obj, '__module__', None)
     if m is not None:
         if not m or m == module:
             return True
         else:
             return False
     #class R():pass
     #classobj = type(R)
     #if isinstance(obj,R): return True
     return True
Example #7
0
 def is_local(obj,module):
   if not fn.isCallable(obj): return False
   m = getattr(obj,'__module__',None)
   if m is not None:
     if not m or m == module:
       return True
     else:
       return False
   #class R():pass
   #classobj = type(R)
   #if isinstance(obj,R): return True
   return True
 def get_alarm_as_text(self,alarm=None,cols=None,
         formatters=None,lengths=[],sep=' - '):
     alarm = self.get_alarm(alarm)
     cols = cols or VIEW_FIELDS
     formatters = formatters or FORMATTERS
     s = '  '
     try:
         for i,r in enumerate(cols):
             if s.strip(): s+=sep
             v = getattr(alarm,r)
             args = [v() if fd.isCallable(v) else v]
             if lengths: args.append(lengths[i])
             s += formatters[r](*args)
         return s
     except:
         print traceback.format_exc()
         return s
Example #9
0
VERBOSE = '-v' in sys.argv

@fandango.CatchedArgs(verbose=VERBOSE)
def test_parse_property(
    kwargs = {'name':'',
        'value':'tango://alba03.cells.es:10000/building/ct/alarms-scw/state'
            ';strategy=ALWAYS;ttl=0'},
    result = {'name': 
            'tango://alba03.cells.es:10000/building/ct/alarms-scw/state',
                'strategy': 'ALWAYS',
                'ttl': '0'} ):
        
    return ptau.parse_property(**kwargs) == result

#test_parse_property = fandango.Catched(test_parse_property, verbose=False)

if __name__ == '__main__':
    
    print('\nTesting PyTangoArchiving.utils\n')
    r = True
    for f,ff in locals().items():
        if fandango.isCallable(ff):
            v = ff()
            print('\t%s:\t%s' % (f,v))
            r = r and v
    print('\n')
    sys.exit(int(not r))