Skip to content

Commit e488a9d

Browse files
committed
Revert "Merge branch 'master' into 1.1.0-dev"
This reverts commit 0272410, reversing changes made to 204d09e.
1 parent 14c49b2 commit e488a9d

16 files changed

+368
-62
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------
2-
# Copyright (c) 2020, PTC Inc. and/or all its affiliates. All rights reserved.
2+
# Copyright (c) PTC Inc. and/or all its affiliates. All rights reserved.
33
# See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
@@ -13,6 +13,7 @@ _notes
1313
_new*
1414
_test*
1515
_build*
16+
_dev*
1617
/docs
1718
mkdocs.yml
1819

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ SDK allows for *GET*, *ADD*, *DELETE*, and *MODIFY* functions for the following
2020
| **Connectivity** <br /> *(Channel, Devices, Tags, Tag Groups)* | Y | Y |
2121
| **IoT Gateway** <br /> *(Agents, IoT Items)* | Y | Y |
2222
| **Datalogger** <br /> *(Log Groups, Items, Mapping, Triggers, Reset Mapping Service)* | Y | Y |
23-
| **Administration** <br /> *(User Groups, Users, UA Endpoints)* | Y* | Y |
23+
| **Administration** <br /> *(User Groups, Users, UA Endpoints, Local License Server)* | Y* | Y |
2424

25-
Note (*) - UA Endpoints supported for Kepware Edge only
25+
Note (*) - UA Endpoints and Local License Server supported for Kepware Edge only
2626

2727
Driver specific features:
2828

kepconfig/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------
2-
# Copyright (c) 2020, PTC Inc. and/or all its affiliates. All rights reserved.
2+
# Copyright (c) PTC Inc. and/or all its affiliates. All rights reserved.
33
# See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------

kepconfig/admin/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# -------------------------------------------------------------------------
2-
# Copyright (c) 2020, PTC Inc. and/or all its affiliates. All rights reserved.
2+
# Copyright (c) PTC Inc. and/or all its affiliates. All rights reserved.
33
# See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
66

77
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
8-
from . import users, user_groups,ua_server
8+
from . import users, user_groups,ua_server, lls

kepconfig/admin/lls.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c), PTC Inc. and/or all its affiliates. All rights reserved.
3+
# See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
7+
r"""`lls` exposes an API to allow modifications to Local License Server parameters in
8+
the Kepware Administration through the Kepware Configuration API
9+
"""
10+
from typing import Union
11+
from ..error import KepHTTPError, KepError
12+
13+
14+
LLS_ROOT = '/admin'
15+
LICENSING_SERVER_PORT = "libadminsettings.LICENSING_SERVER_PORT"
16+
LICENSING_SERVER_NAME = "libadminsettings.LICENSING_SERVER_NAME"
17+
LICENSING_SERVER_ENABLE = "libadminsettings.LICENSING_SERVER_ENABLE"
18+
LICENSING_CHECK_PERIOD_MINS = "libadminsettings.LICENSING_CHECK_PERIOD_MINS"
19+
LICENSING_SERVER_SSL_PORT = "libadminsettings.LICENSING_SERVER_SSL_PORT"
20+
LICENSING_SERVER_ALLOW_INSECURE_COMMS = "libadminsettings.LICENSING_SERVER_ALLOW_INSECURE_COMMS"
21+
LICENSING_SERVER_ALLOW_SELF_SIGNED_CERTS = "libadminsettings.LICENSING_SERVER_ALLOW_SELF_SIGNED_CERTS"
22+
LICENSING_CLIENT_ALIAS = "libadminsettings.LICENSING_CLIENT_ALIAS"
23+
24+
class lls_config:
25+
'''A class to represent a admin properties for the Local License Server connection from an instance of Kepware.
26+
This object is used to easily manage the LLS parameters for a Kepware instance.
27+
28+
Properties:
29+
30+
"server_name" - Host name or IP address of the LLS server
31+
"server_port" - HTTP/non-SSL port to target for the LLS server
32+
"check_period" - Period that Kepware checks licensing status
33+
"server_port_SSL" - HTTPS/SSL port to target for the LLS server
34+
"allow_insecure_comms" - When True, use HTTP/non-SSL connection to LLS
35+
"allow_self_signed_certs" - Allow for self signed certificates to be used during HTTPS/SSL connections to the LLS
36+
"instance_alias_name" - Alias name for LLS to use as reference to this Kepware instance
37+
'''
38+
39+
def __init__(self, config = {}):
40+
self.server_name = config[LICENSING_SERVER_NAME] if LICENSING_SERVER_NAME in config else ''
41+
self.server_port = config[LICENSING_SERVER_PORT] if LICENSING_SERVER_PORT in config else 7070
42+
self.check_period = config[LICENSING_CHECK_PERIOD_MINS] if LICENSING_CHECK_PERIOD_MINS in config else 5
43+
self.server_port_SSL = config[LICENSING_SERVER_SSL_PORT] if LICENSING_SERVER_SSL_PORT in config else 1883
44+
self.allow_insecure_comms = config[LICENSING_SERVER_ALLOW_INSECURE_COMMS] if LICENSING_SERVER_ALLOW_INSECURE_COMMS in config else False
45+
self.allow_self_signed_certs = config[LICENSING_SERVER_ALLOW_SELF_SIGNED_CERTS] if LICENSING_SERVER_ALLOW_SELF_SIGNED_CERTS in config else False
46+
self.instance_alias_name = config[LICENSING_CLIENT_ALIAS] if LICENSING_CLIENT_ALIAS in config else ''
47+
48+
def _get_dict(self):
49+
return {
50+
LICENSING_SERVER_PORT: self.server_port,
51+
LICENSING_SERVER_NAME: self.server_name,
52+
LICENSING_CHECK_PERIOD_MINS: self.check_period,
53+
LICENSING_SERVER_SSL_PORT: self.server_port_SSL,
54+
LICENSING_SERVER_ALLOW_INSECURE_COMMS: self.allow_insecure_comms,
55+
LICENSING_SERVER_ALLOW_SELF_SIGNED_CERTS: self.allow_self_signed_certs,
56+
LICENSING_CLIENT_ALIAS: self.instance_alias_name
57+
}
58+
59+
def __str__(self) -> str:
60+
return "{}".format(self._get_dict())
61+
62+
def get_lls_config(server) -> lls_config:
63+
'''Returns the properties of the Local License server properties. Returned object is lls_config class object.
64+
65+
INPUTS:
66+
"server" - instance of the "server" class
67+
68+
RETURNS:
69+
lls_config - class object with lls configuration
70+
71+
EXCEPTIONS:
72+
KepHTTPError - If urllib provides an HTTPError
73+
KepURLError - If urllib provides an URLError
74+
'''
75+
76+
r = server._config_get(server.url + LLS_ROOT)
77+
return lls_config(r.payload)
78+
79+
def update_lls_config(server, config: lls_config) -> bool:
80+
'''Updates the Local License Server admin properties for Kepware.
81+
82+
INPUTS:
83+
"server" - instance of the "server" class
84+
"config" - lls_config class object
85+
86+
RETURNS:
87+
True - If a "HTTP 200 - OK" is received from Kepware
88+
89+
EXCEPTIONS:
90+
KepHTTPError - If urllib provides an HTTPError
91+
KepURLError - If urllib provides an URLError
92+
'''
93+
94+
DATA = config._get_dict()
95+
r = server._config_update(server.url + LLS_ROOT, DATA)
96+
if r.code == 200: return True
97+
else: raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
98+
99+
def enable_lls(server) -> bool:
100+
'''Enables the Local License Server connection for Kepware.
101+
102+
INPUTS:
103+
"server" - instance of the "server" class
104+
105+
RETURNS:
106+
True - If a "HTTP 200 - OK" is received from Kepware
107+
108+
EXCEPTIONS:
109+
KepHTTPError - If urllib provides an HTTPError
110+
KepURLError - If urllib provides an URLError
111+
'''
112+
113+
r = server._config_update(server.url + LLS_ROOT, {LICENSING_SERVER_ENABLE: True})
114+
if r.code == 200: return True
115+
else: raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
116+
117+
def disable_lls(server) -> bool:
118+
'''Disables the Local License Server connection for Kepware.
119+
120+
INPUTS:
121+
"server" - instance of the "server" class
122+
123+
RETURNS:
124+
True - If a "HTTP 200 - OK" is received from Kepware
125+
126+
EXCEPTIONS:
127+
KepHTTPError - If urllib provides an HTTPError
128+
KepURLError - If urllib provides an URLError
129+
'''
130+
131+
r = server._config_update(server.url + LLS_ROOT, {LICENSING_SERVER_ENABLE: False})
132+
if r.code == 200: return True
133+
else: raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)

kepconfig/connection.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ def __init__(self, code = '', message = '', href = ''):
3737
def __str__(self):
3838
return '{"code": %s, "message": %s, "href": %s}' % (self.code, self.message, self.href)
3939

40+
class KepServiceStatus:
41+
'''A class to represent a status object when checking on a "service" API job state in Kepware. This is
42+
used to return the status of a "service" job
43+
44+
Properties:
45+
46+
"complete" - Boolean of service job completion status
47+
"status" - Status code of job
48+
"message" - Error message if service job fails
49+
50+
'''
51+
def __init__(self, complete = '', status = '', message = ''):
52+
self.status = status
53+
self.message = message
54+
self.complete = complete
55+
56+
def __str__(self):
57+
return '{"complete": %s, "status": %s, "message": %s}' % (self.complete, self.status, self.message)
58+
4059
class _HttpDataAbstract:
4160
def __init__(self):
4261
self.payload = ''
@@ -62,9 +81,12 @@ class server:
6281
6382
Methods:
6483
65-
"reinitialize()" - Reinitialize the Kepware server
84+
"reinitialize()" - reinitialize the Kepware server
6685
"get_trans_log()" - retrieve the Configuration API transaction logs
6786
"get_event_log()" - retrieve the Kepware Event Log
87+
"get_project_properties()" - retrieve the Kepware Project Properties
88+
"modify_project_properties()" - modify the Kepware Project Properties
89+
"service_status()" - retrive service job status
6890
'''
6991
__root_url = '/config'
7092
__version_url = '/v1'
@@ -213,6 +235,30 @@ def modify_project_properties(self, DATA, force = False) -> bool:
213235
r = self._config_update(self.url + '/project', prop_data)
214236
if r.code == 200: return True
215237
else: raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
238+
239+
def service_status(self, resp: KepServiceResponse):
240+
'''Returns the status of a service job. Used to verify if a service call
241+
has completed or not.
242+
243+
INPUT:
244+
"resp" - KepServiceResponse instance with job information
245+
246+
RETURNS:
247+
KepServiceStatus instance with job status
248+
249+
EXCEPTIONS:
250+
251+
KepHTTPError - If urllib provides an HTTPError
252+
KepURLError - If urllib provides an URLError
253+
'''
254+
# need to remove part of job href
255+
loc = resp.href.find(self.__root_url + self.__version_url)
256+
job_url = resp.href[loc + len(self.__root_url + self.__version_url):]
257+
258+
r = self._config_get(self.url + job_url)
259+
job = KepServiceStatus(r.payload['servermain.JOB_COMPLETE'],r.payload['servermain.JOB_STATUS'], r.payload['servermain.JOB_STATUS_MSG'])
260+
return job
261+
216262

217263
#Function used to Add an object to Kepware (HTTP POST)
218264
def _config_add(self, url, DATA):
@@ -279,7 +325,7 @@ def _force_update_check(self, force, DATA):
279325
pass
280326
return DATA
281327
# General service call handler
282-
def _kep_service_execute(self, url, TTL):
328+
def _kep_service_execute(self, url, TTL = None):
283329
try:
284330
if TTL != None:
285331
TTL = {"servermain.JOB_TIME_TO_LIVE_SECONDS": TTL}

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools", "wheel"]
3+
build-backend = "setuptools.build_meta"

release.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33

44
file_location = "kepconfig/__init__.py"
5-
version_re_string = "([0-9]+)\.([0-9]+)\.([0-9]+$|[0-9]+[ab][0-9]+)"
5+
version_re_string = "([0-9]+)\.([0-9]+)\.([0-9]+(?:[ab][0-9])?)"
66
version_search = re.compile(r'__version__ = "'+ version_re_string + '"')
77
version_check = re.compile(version_re_string)
88

@@ -12,7 +12,7 @@ def bump_version():
1212
m = version_search.search(s)
1313
v1, v2, v3 = m.groups()
1414
oldv = "{0}.{1}.{2}".format(v1, v2, v3)
15-
ans = input("Current version of kepconfig is: {0} \nUpdate new version to? (ctrl-c to exit): ".format(oldv))
15+
ans = input("Current version of kepconfig is: {} \nUpdate new version to? (ctrl-c to exit): ".format(oldv))
1616
if ans:
1717
m = version_check.search(ans)
1818
if (m==None):
@@ -22,7 +22,7 @@ def bump_version():
2222
else:
2323
print("Please enter updated version number. Exiting...")
2424
exit()
25-
print("\n"+ "Updating " + file_location + " version to {0}.".format(newv))
25+
print("\n"+ "Updating " + file_location + " version to {}.".format(newv))
2626
s = s.replace(oldv, newv)
2727
with open(file_location, "w") as f:
2828
f.write(s)
@@ -36,22 +36,24 @@ def release():
3636
os.system("git add " + file_location)
3737
os.system('git commit -m \"{} Release\"'.format(v))
3838
os.system("git tag {0}".format(v))
39-
ans = input("Change committed, push to server? (y/n)")
39+
ans = input("Change committed, push to server? (Y/n)")
4040
if ans.lower() in ("y", "yes"):
4141
# os.system("git push")
4242
# os.system("git push --tags")
4343
os.system("git push --follow-tags")
44-
ans = input("upload to pip?(Y/n)")
45-
if ans.lower() in ("y", "yes"):
46-
# os.system("rm -rf dist/*") #Linux
47-
os.system("RMDIR /S /Q dist") #Windows
48-
os.system("python setup.py sdist bdist_wheel")
44+
ans = input("Build dist packages?(Y/n)")
45+
if ans.lower() in ("y", "yes"):
46+
# os.system("rm -rf dist/*") #Linux
47+
os.system("RMDIR /S /Q dist") #Windows
48+
os.system("python -m build")
49+
ans = input("upload to pip?(Y/n)")
50+
if ans.lower() in ("y", "yes"):
4951

50-
# Test PyPi Server
51-
os.system("twine upload --repository testpypi dist/*")
52+
# Test PyPi Server
53+
os.system("twine upload --repository testpypi dist/*")
5254

53-
#Production PyPi Server
54-
# os.system("twine upload dist/*")
55+
#Production PyPi Server
56+
# os.system("twine upload dist/*")
5557

5658

5759
if __name__ == "__main__":

0 commit comments

Comments
 (0)