Skip to content

Commit e70a2e1

Browse files
committed
Add ruff auto format and fixes
1 parent 86e54c0 commit e70a2e1

File tree

15 files changed

+2780
-1630
lines changed

15 files changed

+2780
-1630
lines changed

channelfinder/CFDataTypes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
@author: shroffk
1010
"""
1111

12-
1312
from ._conf import PYTHON3
1413

1514
if PYTHON3:

channelfinder/ChannelFinderClient.py

Lines changed: 360 additions & 255 deletions
Large diffs are not rendered by default.

channelfinder/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from .CFDataTypes import *
2-
from .ChannelFinderClient import *
2+
from .ChannelFinderClient import *

channelfinder/_conf.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
password=MyPassword
1313
"""
1414

15-
1615
import sys
1716
import os.path
1817

@@ -26,15 +25,19 @@
2625
# Python 3 code in this block
2726
from configparser import ConfigParser
2827

28+
2929
def __loadConfig():
30-
dflt={'BaseURL':'http://localhost:8080/ChannelFinder'
31-
}
32-
cf=ConfigParser(defaults=dflt)
33-
# print os.path.normpath(os.path.expanduser('~/channelfinderapi.conf'))
34-
cf.read([
35-
'/etc/channelfinderapi.conf',
36-
os.path.expanduser('~/.channelfinderapi.conf'),
37-
'channelfinderapi.conf'
38-
])
30+
dflt = {"BaseURL": "http://localhost:8080/ChannelFinder"}
31+
cf = ConfigParser(defaults=dflt)
32+
# print os.path.normpath(os.path.expanduser('~/channelfinderapi.conf'))
33+
cf.read(
34+
[
35+
"/etc/channelfinderapi.conf",
36+
os.path.expanduser("~/.channelfinderapi.conf"),
37+
"channelfinderapi.conf",
38+
]
39+
)
3940
return cf
40-
basecfg=__loadConfig()
41+
42+
43+
basecfg = __loadConfig()

channelfinder/cfMonitorTest.py

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/python
2-
'''
2+
"""
33
Created on Mar 19, 2012
44
55
A python script to ensure that the cf-update-ioc is working correctly.
@@ -17,7 +17,8 @@
1717
python cf-monitor-test /complete/path/to/daemon/dir -i initialFile -f finalFile
1818
1919
@author: shroffk
20-
'''
20+
"""
21+
2122
import sys
2223
import os
2324
import re
@@ -26,51 +27,59 @@
2627

2728
from channelfinder import ChannelFinderClient
2829

29-
SEVR = {0:'OK ',
30-
1:'Minor ',
31-
2:'Major '}
30+
SEVR = {0: "OK ", 1: "Minor ", 2: "Major "}
3231

3332

3433
def main():
35-
requiredOpts = ['initial-file', 'final-file']
34+
requiredOpts = ["initial-file", "final-file"]
3635
usage = "usage: %prog -i initial-file -f final-file directory "
3736
parser = OptionParser(usage=usage)
38-
parser.add_option('-i', '--initial-file', \
39-
action='store', type='string', dest='initialFile', \
40-
help='the initial-file')
41-
parser.add_option('-f', '--final-file', \
42-
action='store', type='string', dest='finalFile', \
43-
help='the --final-file')
37+
parser.add_option(
38+
"-i",
39+
"--initial-file",
40+
action="store",
41+
type="string",
42+
dest="initialFile",
43+
help="the initial-file",
44+
)
45+
parser.add_option(
46+
"-f",
47+
"--final-file",
48+
action="store",
49+
type="string",
50+
dest="finalFile",
51+
help="the --final-file",
52+
)
4453
opts, args = parser.parse_args()
45-
if args == None or len(args) == 0 :
46-
parser.error('Please specify a directory')
54+
if args == None or len(args) == 0:
55+
parser.error("Please specify a directory")
4756
if not opts.initialFile:
48-
parser.error('Please specify a initial test files')
57+
parser.error("Please specify a initial test files")
4958
if not opts.finalFile:
50-
parser.error('Please specify a final test files')
59+
parser.error("Please specify a final test files")
5160
mainRun(opts, args)
5261

5362

5463
def mainRun(opts, args):
5564
for directory in args:
56-
initialFile = os.path.normpath(directory + '/' + opts.initialFile)
65+
initialFile = os.path.normpath(directory + "/" + opts.initialFile)
5766
iHostName, iIocName = getArgsFromFilename(initialFile)
58-
finalFile = os.path.normpath(directory + '/' + opts.finalFile)
67+
finalFile = os.path.normpath(directory + "/" + opts.finalFile)
5968
fHostName, fIocName = getArgsFromFilename(finalFile)
6069
if getPVNames(initialFile) != getPVNames(finalFile):
6170
sys.exit(1)
6271
pvNames = getPVNames(initialFile)
6372
if len(pvNames) == 0:
6473
sys.exit(1)
65-
'''
74+
"""
6675
Touch the initial file and check channelfinder
67-
'''
76+
"""
6877
touch(initialFile)
6978
sleep(2)
7079
check(pvNames, iHostName, iIocName)
71-
'''
80+
"""
7281
Touch the final file and check channelfinder
73-
'''
82+
"""
7483
touch(finalFile)
7584
sleep(2)
7685
check(pvNames, fHostName, fIocName)
@@ -81,8 +90,8 @@ def check(pvNames, hostName, iocName):
8190
try:
8291
client = ChannelFinderClient()
8392
except:
84-
raise RuntimeError('Unable to create a valid webResourceClient')
85-
channels = client.find(property=[('hostName', hostName), ('iocName', iocName)])
93+
raise RuntimeError("Unable to create a valid webResourceClient")
94+
channels = client.find(property=[("hostName", hostName), ("iocName", iocName)])
8695
if channels and len(pvNames) == len(channels):
8796
for channel in channels:
8897
if channel.Name not in pvNames:
@@ -92,40 +101,46 @@ def check(pvNames, hostName, iocName):
92101

93102

94103
def touch(fname, times=None):
95-
with open(fname, 'a'):
104+
with open(fname, "a"):
96105
os.utime(fname, times)
97106

98107

99108
def getArgsFromFilename(completeFilePath):
100109
fileName = os.path.split(os.path.normpath(completeFilePath))[1]
101-
pattern4Hostname = '(\S+?)\.\S+'
110+
pattern4Hostname = "(\S+?)\.\S+"
102111
match = re.search(pattern4Hostname, fileName)
103112
if match:
104113
hostName = match.group(1)
105114
else:
106115
hostName = None
107-
pattern4Iocname = '\S+?\.(\S+?)\.\S+'
116+
pattern4Iocname = "\S+?\.(\S+?)\.\S+"
108117
match = re.search(pattern4Iocname, fileName)
109118
if match:
110119
iocName = match.group(1)
111120
else:
112121
iocName = None
113122
return hostName, iocName
114123

124+
115125
def getPVNames(completeFilePath, pattern=None):
116126
try:
117127
f = open(completeFilePath)
118128
pvNames = f.read().splitlines()
119129
pvNames = map(lambda x: x.strip(), pvNames)
120130
pvNames = filter(lambda x: len(x) > 0, pvNames)
121131
if pattern:
122-
pvNames = [ re.match(pattern, pvName).group() for pvName in pvNames if re.match(pattern, pvName) ]
132+
pvNames = [
133+
re.match(pattern, pvName).group()
134+
for pvName in pvNames
135+
if re.match(pattern, pvName)
136+
]
123137
return pvNames
124138
except IOError:
125139
return None
126140
finally:
127141
f.close()
128142

129-
if __name__ == '__main__':
143+
144+
if __name__ == "__main__":
130145
main()
131146
pass

0 commit comments

Comments
 (0)