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
25 changes: 14 additions & 11 deletions cf-monitor-test
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ python cf-monitor-test /complete/path/to/daemon/dir -i initialFile -f finalFile

@author: shroffk
'''
from channelfinder import ChannelFinderClient, Channel, Property
from optparse import OptionParser
from time import sleep
import sys
import os
import re
from optparse import OptionParser
from time import sleep

from channelfinder import ChannelFinderClient

SEVR = {0:'OK ',
1:'Minor ',
2:'Major '}


def main():
requiredOpts = ['initial-file', 'final-file']
usage = "usage: %prog -i initial-file -f final-file directory "
Expand All @@ -46,19 +49,18 @@ def main():
if not opts.finalFile:
parser.error('Please specify a final test files')
mainRun(opts, args)



def mainRun(opts, args):
for directory in args:
initialFile = os.path.normpath(directory + '/' + opts.initialFile)
iHostName, iIocName = getArgsFromFilename(initialFile)
finalFile = os.path.normpath(directory + '/' + opts.finalFile)
fHostName, fIocName = getArgsFromFilename(finalFile)
if getPVNames(initialFile) != getPVNames(finalFile):
# raise Exception, 'initial and final file should have the same pvs'
sys.exit(1)
pvNames = getPVNames(initialFile)
if len(pvNames) == 0:
# raise Exception, 'no pv\'s specified in the test file'
sys.exit(1)
'''
Touch the initial file and check channelfinder
Expand All @@ -74,25 +76,26 @@ def mainRun(opts, args):
check(pvNames, fHostName, fIocName)
sys.exit


def check(pvNames, hostName, iocName):
try:
client = ChannelFinderClient()
except:
raise Exception, 'Unable to create a valid webResourceClient'
raise RuntimeError('Unable to create a valid webResourceClient')
channels = client.find(property=[('hostName', hostName), ('iocName', iocName)])
if channels and len(pvNames) == len(channels):
for channel in channels:
if channel.Name not in pvNames:
# raise Exception, 'Failed check for ' + channel.Name
sys.exit(2)
else:
# raise Exception, 'Failed check for ' + str(pvNames) + ' with: ' + hostName + ' & ' + iocName
sys.exit(2)


def touch(fname, times=None):
with file(fname, 'a'):
with open(fname, 'a'):
os.utime(fname, times)



def getArgsFromFilename(completeFilePath):
fileName = os.path.split(os.path.normpath(completeFilePath))[1]
pattern4Hostname = '(\S+?)\.\S+'
Expand Down
116 changes: 64 additions & 52 deletions channelfinder/CFDataTypes.py
Original file line number Diff line number Diff line change
@@ -1,94 +1,106 @@
'''
# -*- coding: utf-8 -*-

"""
Copyright (c) 2010 Brookhaven National Laboratory
All rights reserved. Use is subject to license terms and conditions.

Created on Feb 11, 2011

@author: shroffk
'''
"""


from ._conf import PYTHON3

if PYTHON3:
# cmp function is gone in Python 3.
# Define for backward compatibility
def cmp(a, b):
return (a > b) - (a < b)


class Channel(object):
'''
A Channel object consists of a unique name, an owner and an optional list
of Tags and Properties
'''
# TODO
# updated the properties datastructure by splitting it into 2 dict

# updated the properties data structure by splitting it into 2 dict

# All the attributes are private and read only in an attempt to make the channel object immutable
Name = property(lambda self: self.__Name)
Owner = property(lambda self: self.__Owner)

def __init__(self, name, owner, properties=None, tags=None):
'''
Constructor
name = channel name
owner = channel owner
properties = list of properties of type Property
tags = list of tags of type Tag
'''
self.__Name = str(name).strip();
self.__Owner = str(owner).strip();
"""
Channel object constructor.
A Channel object consists of a unique name, an owner and an optional list
of Tags and Properties

:param name: channel name
:param owner: channel owner
:param properties: list of properties of type Property
:param tags: list of tags of type Tag
"""
self.__Name = str(name).strip()
self.__Owner = str(owner).strip()
self.Properties = properties
self.Tags = tags

## All the attributes are private and read only in an attempt to make the channel object immutable
Name = property(lambda self:self.__Name)
Owner = property(lambda self:self.__Owner)
# Properties = property(lambda self:self.Properties)
# Tags = property(lambda self:self.Tags)

## TODO don't recreate the dictionary with every get,
## TODO don't recreate the dictionary with every get
def getProperties(self):
'''
getProperties returns a dictionary containing all properties associated with calling channel.
the key= propertyName and the value=propertyValue
'''
"""
Get all properties associated with calling channel.
It returns a dictionary with format:
{"property name": "property value",
...
}

:return: dictionary of properties, or None if property is empty
"""
propDictionary = {}
if self.Properties == None:
if self.Properties is None:
return None
for property in self.Properties:
propDictionary[property.Name] = property.Value
for prop in self.Properties:
propDictionary[prop.Name] = prop.Value
return propDictionary

# properties = property(getProperties)

## TODO don't recreate the list with each get call
def getTags(self):
'''
get tags returns a list of tagNames for the tags associated with this channel
'''
if self.Tags == None:
"""
Get all tags associated with calling channel.
All names in the results are unique, and duplicated name are removed.
It returns a list of tag names with format ['tag 1', 'tag 2', ...]

:return: list of tags, or None if tag is empty
"""
if self.Tags is None:
return None
else:
return set([ tag.Name for tag in self.Tags])

# tags = property(getTags)
return set([tag.Name for tag in self.Tags])


class Property(object):
'''
Property consists of a name, an owner and a value
'''

def __init__(self, name, owner, value=None):
"""
Property consists of a name, an owner and a value
"""
self.Name = str(name).strip()
self.Owner = str(owner).strip()
self.Value = value
if self.Value:
str(value).strip()

def __cmp__(self, *arg, **kwargs):
if arg[0] == None:
if arg[0] is None:
return 1
return cmp((self.Name, self.Value), (arg[0].Name, arg[0].Value))



class Tag(object):
'''
Tag object consists on a name and an owner
'''

def __init__(self, name, owner):
"""
Tag object consists on a name and an owner
"""
self.Name = str(name).strip()
self.Owner = str(owner).strip()

def __cmp__(self, *arg, **kwargs):
if arg[0] == None:
if arg[0] is None:
return 1
return cmp(self.Name, arg[0].Name)
Loading