Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions .project
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>python.channelfinder.api</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>python.channelfinder.api</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PROJECT_NAME = "Python ChannelFinder Client Library"
# This could be handy for archiving the generated documentation or
# if some version control system is used.

PROJECT_NUMBER = "1.1.0"
PROJECT_NUMBER = "3.0.0"

# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put.
Expand Down
371 changes: 191 additions & 180 deletions channelfinder/ChannelFinderClient.py

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions channelfinder/cfPropertyManager/CFPropertyManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
SEE cf-property-manager.cfg for example configuration file
'''
from channelfinder import ChannelFinderClient
from channelfinder.util import ChannelUtil
from optparse import OptionParser
from getpass import getpass
import re
import time
import sys
from channelfinder._conf import _conf

global username, client, exclusion_expression, password, SERVICE_URL, quiet, verbose

Expand Down Expand Up @@ -104,7 +102,7 @@ def applyExpression():
if value != "":
prop_list.append({u'name' : expression[1], u'owner' : username, u'value' : value})
else:
if(verbose): print "MISSING IN " + line
if(verbose): print "MISSING " + expression[1] + "IN " + channel_name
if verbose: print "UPDATE "+channel_name
try:
client.update(channel = {u'name' : channel_name, u'owner':username,u'properties':prop_list })
Expand Down
1 change: 1 addition & 0 deletions channelfinder/cfPropertyManager/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from CFPropertyManager import *
128 changes: 65 additions & 63 deletions channelfinder/cfUpdate/CFUpdateIOC.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ def getPVNames(completeFilePath, pattern=None):
try:
f = open(completeFilePath)
pvNames = f.read().splitlines()
pvNames=map(lambda x: x.strip(), pvNames)
pvNames=filter(lambda x: len(x)>0, pvNames)
pvNames = map(lambda x: x.strip(), pvNames)
pvNames = filter(lambda x: len(x)>0, pvNames)
if pattern:
pvNames=[ re.match(pattern,pvName).group() for pvName in pvNames if re.match(pattern, pvName) ]
pvNames = [re.match(pattern, pvName).group() for pvName in pvNames if re.match(pattern, pvName)]
return pvNames
except IOError:
return None
finally:
if f:
f.close()

def updateChannelFinder(pvNames, hostName, iocName, time, owner, \
def updateChannelFinder(pvNames, hostName, iocName, time, owner,
service=None, username=None, password=None):
'''
pvNames = list of pvNames
Expand All @@ -75,52 +75,54 @@ def updateChannelFinder(pvNames, hostName, iocName, time, owner, \
previousChannelsList = client.findByArgs([(u'hostName', hostName), (u'iocName', iocName)])
if previousChannelsList != None:
for ch in previousChannelsList:
if pvNames != None and ch.Name in pvNames:
if pvNames != None and ch['name'] in pvNames:
''''''
channels.append(updateChannel(ch,\
owner=owner, \
hostName=hostName, \
iocName=iocName, \
pvStatus=u'Active', \
channels.append(updateChannel(ch,
owner=owner,
hostName=hostName,
iocName=iocName,
pvStatus=u'Active',
time=time))
pvNames.remove(ch.Name)
elif pvNames == None or ch.Name not in pvNames:
pvNames.remove(ch['name'])
elif pvNames == None or ch['name'] not in pvNames:
'''Orphan the channel : mark as inactive, keep the old hostName and iocName'''
channels.append(updateChannel(ch, \
owner=owner, \
hostName=ch.getProperties()[u'hostName'], \
iocName=ch.getProperties()[u'iocName'], \
pvStatus=u'InActive', \
time=ch.getProperties()[u'time']))
oldHostName = [ prop[u'value'] for prop in ch[u'properties'] if prop[u'name'] == u'hostName'][0]
oldIocName = [ prop[u'value'] for prop in ch[u'properties'] if prop[u'name'] == u'iocName'][0]
channels.append(updateChannel(ch,
owner=owner,
hostName=oldHostName,
iocName=oldIocName,
pvStatus=u'Inactive',
time=time))
# now pvNames contains a list of pv's new on this host/ioc
for pv in pvNames:
ch = client.findByArgs([('~name',pv)])
if ch == None:
if not ch:
'''New channel'''
channels.append(createChannel(pv, \
chOwner=owner, \
hostName=hostName, \
iocName=iocName, \
pvStatus=u'Active', \
channels.append(createChannel(pv,
chOwner=owner,
hostName=hostName,
iocName=iocName,
pvStatus=u'Active',
time=time))
elif ch[0] != None:
'''update existing channel: exists but with a different hostName and/or iocName'''
channels.append(updateChannel(ch[0], \
owner=owner, \
hostName=hostName, \
iocName=iocName, \
pvStatus=u'Active', \
channels.append(updateChannel(ch[0],
owner=owner,
hostName=hostName,
iocName=iocName,
pvStatus=u'Active',
time=time))
client.set(channels=channels)

def updateChannel(channel, owner, hostName=None, iocName=None, pvStatus='InActive', time=None):
def updateChannel(channel, owner, hostName=None, iocName=None, pvStatus='Inactive', time=None):
'''
Helper to update a channel object so as to not affect the existing properties
'''

# properties list devoid of hostName and iocName properties
if channel[u'properties']:
properties = [property for property in channel[u'properties'] \
properties = [property for property in channel[u'properties']
if property[u'name'] != u'hostName' and property[u'name'] != u'iocName' and property[u'name'] != u'pvStatus']
else:
properties = []
Expand All @@ -135,7 +137,7 @@ def updateChannel(channel, owner, hostName=None, iocName=None, pvStatus='InActiv
channel[u'properties'] = properties
return channel

def createChannel(chName, chOwner, hostName=None, iocName=None, pvStatus=u'InActive', time=None):
def createChannel(chName, chOwner, hostName=None, iocName=None, pvStatus=u'Inactive', time=None):
'''
Helper to create a channel object with the required properties
'''
Expand Down Expand Up @@ -184,26 +186,26 @@ def mainRun(opts, args):
fHostName, fIocName = getArgsFromFilename(completeFilePath)
ftime = os.path.getctime(completeFilePath)
pattern = __getDefaultConfig('pattern', opts.pattern)
updateChannelFinder(getPVNames(completeFilePath, pattern=pattern), \
ifNoneReturnDefault(opts.hostName, fHostName), \
ifNoneReturnDefault(opts.iocName, fIocName), \
ifNoneReturnDefault(opts.time, ftime), \
ifNoneReturnDefault(opts.owner,__getDefaultConfig('username', opts.username)), \
service=__getDefaultConfig('BaseURL',opts.serviceURL), \
username=__getDefaultConfig('username',opts.username), \
updateChannelFinder(getPVNames(completeFilePath, pattern=pattern),
ifNoneReturnDefault(opts.hostName, fHostName),
ifNoneReturnDefault(opts.iocName, fIocName),
ifNoneReturnDefault(opts.time, ftime),
ifNoneReturnDefault(opts.owner,__getDefaultConfig('username', opts.username)),
service=__getDefaultConfig('BaseURL',opts.serviceURL),
username=__getDefaultConfig('username',opts.username),
password=__getDefaultConfig('password',opts.password))
else:
completeFilePath = os.path.abspath(filename)
fHostName, fIocName = getArgsFromFilename(completeFilePath)
ftime = os.path.getctime(completeFilePath)
pattern = __getDefaultConfig('pattern', opts.pattern)
updateChannelFinder(getPVNames(completeFilePath, pattern=pattern), \
ifNoneReturnDefault(opts.hostName, fHostName), \
ifNoneReturnDefault(opts.iocName, fIocName), \
ifNoneReturnDefault(opts.time, ftime), \
ifNoneReturnDefault(opts.owner,__getDefaultConfig('username', opts.username)), \
service=__getDefaultConfig('BaseURL',opts.serviceURL), \
username=__getDefaultConfig('username',opts.username), \
updateChannelFinder(getPVNames(completeFilePath, pattern=pattern),
ifNoneReturnDefault(opts.hostName, fHostName),
ifNoneReturnDefault(opts.iocName, fIocName),
ifNoneReturnDefault(opts.time, ftime),
ifNoneReturnDefault(opts.owner,__getDefaultConfig('username', opts.username)),
service=__getDefaultConfig('BaseURL',opts.serviceURL),
username=__getDefaultConfig('username',opts.username),
password=__getDefaultConfig('password',opts.password))

def __getDefaultConfig(arg, value):
Expand All @@ -218,30 +220,30 @@ def __getDefaultConfig(arg, value):
def main():
usage = "usage: %prog [options] filename"
parser = OptionParser(usage=usage)
parser.add_option('-H', '--hostname', \
action='store', type='string', dest='hostName', \
parser.add_option('-H', '--hostname',
action='store', type='string', dest='hostName',
help='the hostname')
parser.add_option('-i', '--iocname', \
action='store', type='string', dest='iocName', \
parser.add_option('-i', '--iocname',
action='store', type='string', dest='iocName',
help='the iocname')
parser.add_option('-s', '--service', \
action='store', type='string', dest='serviceURL', \
parser.add_option('-s', '--service',
action='store', type='string', dest='serviceURL',
help='the service URL')
parser.add_option('-o', '--owner', \
action='store', type='string', dest='owner', \
parser.add_option('-o', '--owner',
action='store', type='string', dest='owner',
help='owner if not specified username will default as owner')
parser.add_option('-r', '--pattern', \
action='store', type='string', dest='pattern', \
parser.add_option('-r', '--pattern',
action='store', type='string', dest='pattern',
help='pattern to match valid channel names')
parser.add_option('-u', '--username', \
action='store', type='string', dest='username', \
parser.add_option('-u', '--username',
action='store', type='string', dest='username',
help='username')
parser.add_option('-t', '--time', \
action='store', type='string', dest='time', \
parser.add_option('-t', '--time',
action='store', type='string', dest='time',
help='time')
parser.add_option('-p', '--password', \
action='callback', callback=getPassword, \
dest='password', \
parser.add_option('-p', '--password',
action='callback', callback=getPassword,
dest='password',
help='prompt user for password')
opts, args = parser.parse_args()
if len(args) == 0 or args == None:
Expand Down
Loading