Exemple #1
0
    def savePvGroups(self):        
        for k,v in sorted(pvgroups.items()):
            __file = "/".join((self.__filepath, v[0]))
            if os.path.exists(__file): 
                if os.path.isfile(__file):
#                    pvlist = None
                    try:
                        # remove all empty lines
                        with open(__file) as f_in:
                            lines = filter(None, (line.strip() for line in f_in))
#                        f = open(__file, 'r')
#                        pvlist = f.read()
#                        pvlist = pvlist.split('\n')
#                        if len(pvlist[len(pvlist)-1]) == 0:
#                            pvlist = pvlist[:-1]
                        if len(lines) > 0:
                            savePvGroup(self.conn, k, func=v[1])
                            saveGroupPvs(self.conn, k, lines)
                    finally:
                        if f_in:
                            f_in.close()
                    print ('Finished saving pvs in {0}'.format(v[0]))
                else:
                    raise Exception ("""PV list ({0}) is not a file.""".format(v[0]))
            else:
                raise Exception ("""Can not find pv list file ({0})""".format(v[0]))
Exemple #2
0
def initPvGroups():        
    for k,v in sorted(pvgroups.items()):
        __file = '/'.join((os.path.abspath(os.path.dirname(__file__)), 'pvs', v[0]))
        if os.path.exists(__file): 
            if os.path.isfile(__file):
                pvlist = None
                try:
                    f = open(__file, 'r')
                    pvlist = f.read()
                    pvlist = pvlist.split('\n')
                    if len(pvlist[len(pvlist)-1]) == 0:
                        pvlist = pvlist[:-1]
                    savePvGroup(conn, k, func=v[1])
                    saveGroupPvs(conn, k, pvlist)
#                    results = retrieveGroupPvs(conn, pvgroup_id[0])
                finally:
                    if f:
                        f.close()
                print ('finished saving {0}'.format(v[0]))
            else:
                print ("""pv list file ({0}) is not a file.""".format(v[0]))
        else:
            print ("""pv list file ({0}) does not exist.""".format(v[0]))