@@ -157,6 +157,10 @@ def SSL_trust_all_certs(self, val):
157157 def reinitialize (self , job_ttl = None ) -> KepServiceResponse :
158158 '''Executes a Reinitialize call to the Kepware instance.
159159
160+ INPUTS:
161+
162+ "job_ttl" (optional) - Determines the number of seconds a job instance will exist following completion.
163+
160164 RETURNS:
161165 KepServiceResponse instance with job information
162166
@@ -167,7 +171,7 @@ def reinitialize(self, job_ttl = None) -> KepServiceResponse:
167171 '''
168172 url = self .url + self .__project_services_url + '/ReinitializeRuntime'
169173 try :
170- job = self ._kep_service_execute (url ,job_ttl )
174+ job = self ._kep_service_execute (url , None , job_ttl )
171175 return job
172176 except Exception as err :
173177 raise err
@@ -236,6 +240,74 @@ def modify_project_properties(self, DATA, force = False) -> bool:
236240 if r .code == 200 : return True
237241 else : raise KepHTTPError (r .url , r .code , r .msg , r .hdrs , r .payload )
238242
243+ def save_project (self , filename : str , password : str = None , job_ttl : int = None ) -> KepServiceResponse :
244+ '''Executes a ProjectSave Service call to the Kepware instance. This saves
245+ a copy of the current project file to disk. The filename
246+
247+ INPUTS:
248+
249+ "filename" - Fully qualified relative file path and name of project file including the file extension.
250+ location of project file save defaults:
251+ TKS or KEP (Windows): C:\\ PROGRAMDATA\\ PTC\\ Thingworx Kepware Server\\ V6 or
252+ C:\\ PROGRAMDATA\\ Kepware\\ KEPServerEX\\ V6
253+ TKE (Linux): /opt/tkedge/v1/user_data
254+
255+
256+ "password" (optional) - Specify a password with which to load or save an encrypted project file.
257+ This password will be required to load this project file.
258+
259+ "job_ttl" (optional) - Determines the number of seconds a job instance will exist following completion.
260+
261+ RETURNS:
262+ KepServiceResponse instance with job information
263+
264+ EXCEPTIONS (If not HTTP 200 or 429 returned):
265+
266+ KepHTTPError - If urllib provides an HTTPError
267+ KepURLError - If urllib provides an URLError
268+ '''
269+ url = self .url + self .__project_services_url + '/ProjectSave'
270+ prop_data = {'servermain.PROJECT_FILENAME' : filename }
271+ if password != None : prop_data ['servermain.PROJECT_PASSWORD' ] = password
272+ try :
273+ job = self ._kep_service_execute (url , prop_data , job_ttl )
274+ return job
275+ except Exception as err :
276+ raise err
277+
278+ def load_project (self , filename : str , password : str = None , job_ttl : int = None ) -> KepServiceResponse :
279+ '''Executes a ProjectLoad Service call to the Kepware instance. This loads
280+ a project file to disk.
281+
282+ INPUTS:
283+
284+ "filename" - Fully qualified path and name of project file including the file extension. Absolute
285+ paths required for TKS and KEP while file path is relative for TKE
286+ ex: Windows - filename = C:\\ filepath\\ test.opf
287+ Linux - filename = filepath/test.lpf - Location is /opt/tkedge/v1/user_data/filepath/test.lpf
288+
289+ "password" (optional) - Specify a password with which to load or save an encrypted project file.
290+
291+ "job_ttl" (optional) - Determines the number of seconds a job instance will exist following completion.
292+
293+ RETURNS:
294+ KepServiceResponse instance with job information
295+
296+ EXCEPTIONS (If not HTTP 200 or 429 returned):
297+
298+ KepHTTPError - If urllib provides an HTTPError
299+ KepURLError - If urllib provides an URLError
300+ '''
301+ url = self .url + self .__project_services_url + '/ProjectLoad'
302+ prop_data = {'servermain.PROJECT_FILENAME' : filename }
303+ if password != None : prop_data ['servermain.PROJECT_PASSWORD' ] = password
304+ try :
305+ job = self ._kep_service_execute (url , prop_data , job_ttl )
306+ return job
307+ except Exception as err :
308+ raise err
309+
310+
239311 def service_status (self , resp : KepServiceResponse ):
240312 '''Returns the status of a service job. Used to verify if a service call
241313 has completed or not.
@@ -325,11 +397,12 @@ def _force_update_check(self, force, DATA):
325397 pass
326398 return DATA
327399 # General service call handler
328- def _kep_service_execute (self , url , TTL = None ):
400+ def _kep_service_execute (self , url , DATA = None , TTL = None ):
329401 try :
330402 if TTL != None :
331- TTL = {"servermain.JOB_TIME_TO_LIVE_SECONDS" : TTL }
332- r = self ._config_update (url , TTL )
403+ if DATA == None : DATA = {}
404+ DATA ["servermain.JOB_TIME_TO_LIVE_SECONDS" ]= TTL
405+ r = self ._config_update (url , DATA )
333406 job = KepServiceResponse (r .payload ['code' ],r .payload ['message' ], r .payload ['href' ])
334407 return job
335408 except KepHTTPError as err :
0 commit comments