Example #1
0
def restore_pvs(filepath, debug=False):
    """ 
    Restore pvs from a save file via Channel Access 
    
    debug - Set to True if you want a line printed for each value set

    Returns True if all pvs were restored successfully.
    """
    success = True
    fout = open(filepath, 'r')
    lines = fout.readlines()
    fout.close()
    for line in lines:
        if line.startswith('<END'):
            break
        if line.startswith('#'):
            continue
        pvname, value = [w.strip() for w in line[:-1].split(' ', 1)]            
        if value.startswith('<JSON>:'):  # for older version, could be deprecated
            value = value.replace('<JSON>:', '@array@')
        if value.startswith('@array@'):
            value = value.replace('@array@', '').strip()
            if value.startswith('{') and value.endswith('}'):
                value = value[1:-1]
            value = json.loads(value)            
        if debug:
            print( "Setting %s to %s..." % (pvname, value))
        try:
            thispv = PV(pvname)
            pvconnectedstatus=thispv.wait_for_connection()
            if not pvconnectedstatus:
                print("Cannot connect to %s" % (pvname))
                success = False
            elif not thispv.write_access:
                print("No write access to %s" % (pvname))
                success = False
            else:
                thispv.put(value, wait=False)

        except:
            exctype, excvalue, exctrace = sys.exc_info()
            print("Error restoring %s to %s : %s" % (pvname, value,
                                                     exctype, excvalue))
            success = False
    return success
Example #2
0
def restore_pvs(filepath, debug=False):
    """ 
    Restore pvs from a save file via Channel Access 
    
    debug - Set to True if you want a line printed for each value set

    Returns True if all pvs were restored successfully.
    """
    success = True
    fout = open(filepath, 'r')
    lines = fout.readlines()
    fout.close()
    for line in lines:
        if line.startswith('<END'):
            break
        if line.startswith('#'):
            continue
        pvname, value = [w.strip() for w in line[:-1].split(' ', 1)]
        if value.startswith(
                '<JSON>:'):  # for older version, could be deprecated
            value = value.replace('<JSON>:', '@array@')
        if value.startswith('@array@'):
            value = value.replace('@array@', '').strip()
            if value.startswith('{') and value.endswith('}'):
                value = value[1:-1]
            value = json.loads(value)
        if debug:
            print("Setting %s to %s..." % (pvname, value))
        try:
            thispv = PV(pvname)
            thispv.connect()
            if not thispv.connected:
                print("Cannot connect to %s" % (pvname))
            elif not thispv.write_access:
                print("No write access to %s" % (pvname))
            else:
                thispv.put(value, wait=False)

        except:
            exctype, excvalue, exctrace = sys.exc_info()
            print("Error restoring %s to %s : %s" %
                  (pvname, value, exctype, excvalue))
            success = False
    return success
Example #3
0
def restore_pvs(filepath, debug=False):
    """ 
    Restore pvs from a save file via Channel Access 
    
    debug - Set to True if you want a line printed for each value set

    Returns True if all pvs were restored successfully.

    """
    success = True
    values = [x for x in sav_file.parseFile(filepath).asList() if len(x) > 0]
    print("Restoring %d values..." % (len(values)))
    for v in values:
        if debug:
            print("Setting %s to %s..." % (v[0], v[1]))
        try:
            pv = PV(v[0])
            pv.put(v[1])  # hopefully this is good enough as conversions go
        except Exception(e):
            print("Error restoring %s to %s : %s" % (v[0], v[1], e))
            success = False
    return success
Example #4
0
def restore_pvs(filepath, debug=False):
    """ 
    Restore pvs from a save file via Channel Access 
    
    debug - Set to True if you want a line printed for each value set

    Returns True if all pvs were restored successfully.

    """
    success = True
    values = [ x for x in sav_file.parseFile(filepath).asList() if len(x) > 0 ]
    print( "Restoring %d values..." % ( len(values) ))
    for v in values:
        if debug:
            print( "Setting %s to %s..." % (v[0], v[1]))
        try:
            pv = PV(v[0])
            pv.put(v[1]) # hopefully this is good enough as conversions go           
        except Exception(e):
            print( "Error restoring %s to %s : %s" % (v[0], v[1], e))
            success = False
    return success