def get_property(self,*args): """ get_property(property) or get_property(device_regexp,property) """ property = args[-1] devs = self.get_all_devices() if len(args)==2: devs = [d for d in devs if fun.matchCl(args[0],d)] r = dict((d,list(fun.toList(self.db.get_device_property(d,[property])[property]))) for d in devs) return r # if len(r)>1 else r.values()[0]
def get_property(self, *args): """ get_property(property) or get_property(device_regexp,property) """ property = args[-1] devs = self.get_all_devices() if len(args) == 2: devs = [d for d in devs if fun.matchCl(args[0], d)] r = dict( (d, list( fun.toList( self.db.get_device_property(d, [property])[property]))) for d in devs) return r # if len(r)>1 else r.values()[0]
under = lambda s: '<u>\n'+str(s)+'\n</u>' camel = lambda s: ''.join(r[0].upper()+(r[1:] or '').lower() for r in s.split()) color = lambda s,color: '<font color="%s">%s</font>'%(camel(color),s) colors = "black white yellow blue green red gray fuchsia lime maroon aqua navy olive purple silver teal".split() size = lambda s,size: '<font size="%s">%s</font>'%(size,s) link = lambda s,url: '<a href="%s">%s</a>' % (url,s) iname = lambda s: s.replace(' ','').lower() iurl = lambda url: '#'+iname(url) ilink = lambda s,url: '<a name="%s">%s</a>' % (iname(s),s) title = lambda s,n=1: '<a name="%s"><h%d>%s</h%d></a>' % (iname(s),n,s,n) #<a> allows to make titles linkable title1 = lambda s: '<h1>%s</h1>'%s row,cell = (lambda s: '<tr>%s</tr>'%s) , (lambda s: '<td>%s</td>'%s) table = lambda s: '<table border=1>\n'+'\n'.join([row(''.join([ (cell('%s'%c) if (len(s)==1 or j or (len(toList(r))<3 and i)) else cell(bold('%s'%c))) for j,c in enumerate(toList(r))])) for i,r in enumerate(s)] )+'\n</table>' def list_to_ulist(l): return ulist('\n'.join(item(str(s)) for s in l)) def dicts2table(dcts,keys=None,formatter=None): """ :param dcts: a list of dictionaries :param keys: an alternative list of keys """ if not keys: keys = sorted(set(k for dct in dcts for k in dct.keys())) if not formatter: formatter = lambda s:s lines = [keys,]
under = lambda s: '<u>\n'+str(s)+'\n</u>' camel = lambda s: ''.join(r[0].upper()+(r[1:] or '').lower() for r in s.split()) color = lambda s,color: '<font color="%s">%s</font>'%(camel(color),s) colors = "black white yellow blue green red gray fuchsia lime maroon aqua navy olive purple silver teal".split() size = lambda s,size: '<font size="%s">%s</font>'%(size,s) link = lambda s,url: '<a href="%s">%s</a>' % (url,s) iname = lambda s: s.replace(' ','').lower() iurl = lambda url: '#'+iname(url) ilink = lambda s,url: '<a name="%s">%s</a>' % (iname(s),s) title = lambda s,n=1: '<a name="%s"><h%d>%s</h%d></a>' % (iname(s),n,s,n) #<a> allows to make titles linkable title1 = lambda s: '<h1>%s</h1>'%s row,cell = (lambda s: '<tr>%s</tr>'%s) , (lambda s: '<td>%s</td>'%s) table = lambda s: '<table border=1>\n'+'\n'.join([row(''.join([ (cell('%s'%c) if (len(s)==1 or j or (len(toList(r))<3 and i)) else cell(bold('%s'%c))) for j,c in enumerate(toList(r))])) for i,r in enumerate(s)] )+'\n</table>' def list_to_ulist(l): return ulist('\n'.join(item(str(s)) for s in l)) def dicts2table(dcts,keys=None,formatter=None): """ :param dcts: a list of dictionaries :param keys: an alternative list of keys """ if not keys: keys = sorted(set(k for k in dct.keys() for dct in dcts)) if not formatter: formatter = lambda s:s lines = [keys,]