Skip to content

Commit 5fb33d7

Browse files
committed
added import and export methods
1 parent 5096a29 commit 5fb33d7

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

kepconfig/connection.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,50 @@ def modify_project_properties(self, DATA: dict, force: bool = False) -> bool:
218218
if r.code == 200: return True
219219
else: raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
220220

221+
def import_empty_project(self) -> KepServiceResponse:
222+
'''Executes JsonProjectLoad Service call to the Kepware instance with an empty project. This service
223+
imports an empty project configuration, acts like a FILE->NEW action and
224+
stop communications while the new project replaces the current project in the Kepware runtime.
225+
226+
:return: `KepServiceResponse` instance with job information
227+
228+
:raises KepHTTPError: If urllib provides an HTTPError (If not HTTP code 202 [Accepted] or 429 [Too Busy] returned)
229+
:raises KepURLError: If urllib provides an URLError
230+
'''
231+
return self.import_project_configuration({"project":{}})
232+
233+
234+
def import_project_configuration(self, DATA: dict) -> KepServiceResponse:
235+
'''Executes JsonProjectLoad Service call to the Kepware instance. This service imports project configuration
236+
data, expecting a complete project file in JSON/dict format. This service acts like a FILE->OPEN action and
237+
stop communications while the new project replaces the current project in the Kepware runtime.
238+
239+
:param DATA: Complete project configuration data in JSON/dict format.
240+
241+
:return: `KepServiceResponse` instance with job information
242+
243+
:raises KepHTTPError: If urllib provides an HTTPError (If not HTTP code 202 [Accepted] or 429 [Too Busy] returned)
244+
:raises KepURLError: If urllib provides an URLError
245+
'''
246+
url = self.url + self.__project_services_url + '/JsonProjectLoad'
247+
try:
248+
job = self._kep_service_execute(url, DATA)
249+
return job
250+
except Exception as err:
251+
raise err
252+
253+
def export_project_configuration(self) -> dict:
254+
'''Get a complete copy of the project configuration in JSON format. This will include the same
255+
configuration that is stored when you save the project file manually.
256+
257+
:return: Dict of the complete project configuration
258+
259+
:raises KepHTTPError: If urllib provides an HTTPError
260+
:raises KepURLError: If urllib provides an URLError
261+
'''
262+
r = self._config_get(self.url + '/project', params= {"content": "serialize"})
263+
return r.payload
264+
221265
def save_project(self, filename: str, password: str = None, job_ttl: int = None) -> KepServiceResponse:
222266
'''Executes a ProjectSave Service call to the Kepware instance. This saves
223267
a copy of the current project file to disk. The filename

0 commit comments

Comments
 (0)