33
44@author: kjnether
55'''
6- import logging
7- import FMEUtil .PyFMEServerV2
6+ import copy
87import datetime
9- import os .path
108import json
11- import deepdiff
12- import copy
9+ import logging
10+ import os . path
1311import pprint
1412
13+ import FMEUtil .PyFMEServerV2
14+ import deepdiff
15+
16+
1517class Schedules (object ):
1618
1719 '''
@@ -37,7 +39,8 @@ class Schedules(object):
3739 :type flds2Ignore: list
3840 '''
3941
40- def __init__ (self , fmeServUrl , fmeServToken , cacheLabel , cacheDir , refreshCache = False , ignorePP = False ):
42+ def __init__ (self , fmeServUrl , fmeServToken , cacheLabel , cacheDir ,
43+ refreshCache = False , ignorePP = False ):
4144 '''
4245 :param fmeServUrl: url to fme server, don't include paths
4346 :param fmeServToken: token to fme server
@@ -68,7 +71,7 @@ def __init__(self, fmeServUrl, fmeServToken, cacheLabel, cacheDir, refreshCache=
6871 # when doing comparisons between the two structures
6972 self .flds2Ignore = ['begin' , 'enabled' ]
7073 # this switch can be set using the method setIgnoredFields()
71- # when set to true published parameters are not considered in the
74+ # when set to true published parameters are not considered in the
7275 # comparison of the schedules.
7376 self .ignorePP = ignorePP
7477 # this data struct will get populated with everything in self.schedStruct
@@ -90,6 +93,13 @@ def getPyFME(self):
9093 '''
9194 return self .fme
9295
96+ def getScheduleData (self ):
97+ '''
98+ :return: the data structure that describes the schedules in this
99+ object.
100+ '''
101+ return self .schedStruct
102+
93103 def setIgnoredFields (self , flds , ignorePublishedParameters = True ):
94104 '''
95105 When doing a comparison between schedule objects you can set a
@@ -102,7 +112,7 @@ def setIgnoredFields(self, flds, ignorePublishedParameters=True):
102112 self .ignorePP = ignorePublishedParameters
103113 self .flds2Ignore = flds
104114 schedStructCleaned = []
105- #schedIterator = self.schedStruct[0:]
115+ # schedIterator = self.schedStruct[0:]
106116 schedIterator = copy .deepcopy (self .schedStruct )
107117 for schedRef in schedIterator :
108118 sched = schedRef .copy ()
@@ -112,12 +122,16 @@ def setIgnoredFields(self, flds, ignorePublishedParameters=True):
112122 del sched [fld2Del ]
113123 if self .ignorePP :
114124 # getting rid of published parameters too!
115- #self.pp.pprint(sched)
125+ # self.pp.pprint(sched)
116126 del sched ['request' ]['publishedParameters' ]
117127 schedStructCleaned .append (sched )
118128 self .schedStructComparison = schedStructCleaned
119129
120130 def isEnabled (self , scheduleName ):
131+ '''
132+ :return: indicates if the schedule is enabled or not
133+ :rtype: boolean
134+ '''
121135 schedStruct = self .getScheduleByName (scheduleName )
122136 return schedStruct ['enabled' ]
123137
@@ -140,6 +154,7 @@ def getSchedules(self):
140154 self .logger .info ("retrieving the schedules from fme server, this" + \
141155 "may take a while" )
142156 schedStruct = self .scheds .getSchedules ()
157+ self .logger .debug ("schedStruct: {0}" .format (schedStruct ))
143158 with open (self .cacheFile , 'w' ) as outfile :
144159 msg = "dumping the schedules to the cache file {0}"
145160 self .logger .info (msg .format (cacheFile ))
@@ -164,7 +179,7 @@ def getScheduleByName(self, scheduleName):
164179 break
165180 return retVal
166181
167- def __contains__ (self , sched ):
182+ def __contains__ (self , sched ): # pylint: disable=invalid-name
168183 '''
169184 :param sched: returns true or false based on whether the sched
170185 object exists in this collection of schedules
@@ -177,7 +192,7 @@ def __contains__(self, sched):
177192 for fld in sched .keys ():
178193 if fld not in self .flds2Ignore :
179194 schedCleaned [fld ] = copy .deepcopy (sched [fld ])
180- # if the ignore published parameters flag is set then
195+ # if the ignore published parameters flag is set then
181196 # don't look at them if they are defined.
182197 if self .ignorePP :
183198 if 'request' in schedCleaned :
@@ -190,10 +205,10 @@ def __contains__(self, sched):
190205 for curSched in self .schedStructComparison :
191206 if curSched ['name' ] == schedCleaned ['name' ]:
192207 diffs = deepdiff .DeepDiff (schedCleaned , curSched )
193- self .logger .info ("differences for {1}: {0}" .format (diffs , curSched ['name' ]))
208+ self .logger .info ("differences for {1}: {0}" .format (diffs , curSched ['name' ]))
194209 return retVal
195210
196- def __sub__ (self , schedules ):
211+ def __sub__ (self , schedules ): # pylint: disable=invalid-name
197212 '''
198213 identifies schedules that are in self, but not in supplied
199214 schedules
@@ -223,6 +238,11 @@ def __init__(self, schedule, scheduleName):
223238 self .scheduleStruct = self .schedule .getScheduleByName (scheduleName )
224239
225240 def getPublishedParameters (self ):
241+ '''
242+ :return: the published parameters associated with the specified schedule.
243+ These are retrieved not from the schedule but from the FMW that the
244+ schedule calls.
245+ '''
226246 workspcName = self .scheduleStruct ['workspace' ]
227247 repoName = self .scheduleStruct ['repository' ]
228248
@@ -232,10 +252,10 @@ def getPublishedParameters(self):
232252 pubParams = wrkspcs .getPublishedParams4Schedule (workspcName )
233253 return pubParams
234254
235- def fixSchedulePublishedParameters (self , setEnabled = True ):
255+ def fixSchedulePublishedParameters (self ):
236256 '''
237- Returns a schedule json struct that can be sent to FME Server to define
238- a new schedule.
257+ :return: a schedule json struct that can be sent to FME Server to define
258+ a new schedule.
239259 '''
240260 # published parameters retrieved from the workspace on fme server
241261 pubParams = self .getPublishedParameters ()
@@ -246,7 +266,7 @@ def fixSchedulePublishedParameters(self, setEnabled=True):
246266 pp .pprint (self .scheduleStruct )
247267 schedulePubParams = self .scheduleStruct ['request' ]['publishedParameters' ]
248268
249- fixedSchedule = self .scheduleStruct ['request' ]['publishedParameters' ][0 :]
269+ # fixedSchedule = self.scheduleStruct['request']['publishedParameters'][0:]
250270
251271 # Iterating through the published parameters associated with the
252272 # workspace and overriding values with values that were retrieved
@@ -270,22 +290,3 @@ def fixSchedulePublishedParameters(self, setEnabled=True):
270290 # raise
271291 self .scheduleStruct ['request' ]['publishedParameters' ] = params4Schedule
272292 return self .scheduleStruct
273-
274- def setDisabled (self , schedule ):
275- '''
276- :param schedule: the schedule json object
277- :return: the same schedule as was recieved but with the enabled
278- parameter set to false.
279- '''
280-
281- pass
282-
283- def setDestDbEnvKey (self , schedule , key ):
284- '''
285- searches the schedule for the DEST_DB_ENV_KEY if one is found
286- then the parameter is set to the value defined in 'key'
287-
288- :param key: the value to assign to DEST_DB_ENV_KEY if it exists.
289- '''
290- pass
291-
0 commit comments