mirror of
https://github.com/OpenMTC/OpenMTC.git
synced 2025-05-02 08:42:50 +00:00
simple python2 -> python3 conversions
This commit is contained in:
parent
61b2dad009
commit
e23d6b7e9f
@ -30,21 +30,21 @@ parser.add_argument("--db-pw", help="InfluxDB User password")
|
|||||||
args, config = prepare_app(parser, __loader__, __name__, "config.json")
|
args, config = prepare_app(parser, __loader__, __name__, "config.json")
|
||||||
|
|
||||||
# variables
|
# variables
|
||||||
nm = get_value("name", (unicode, str), default_name, args, config)
|
nm = get_value("name", str, default_name, args, config)
|
||||||
cb = config.get("cse_base", "onem2m")
|
cb = config.get("cse_base", "onem2m")
|
||||||
ep = get_value("ep", (unicode, str), default_ep, args, config)
|
ep = get_value("ep", str, default_ep, args, config)
|
||||||
poas = config.get("poas", ["http://auto:23706"])
|
poas = config.get("poas", ["http://auto:23706"])
|
||||||
originator_pre = config.get("originator_pre", "//openmtc.org/mn-cse-1")
|
originator_pre = config.get("originator_pre", "//openmtc.org/mn-cse-1")
|
||||||
ssl_certs = config.get("ssl_certs", {})
|
ssl_certs = config.get("ssl_certs", {})
|
||||||
lbl = get_value("labels", list, default_labels, args, config)
|
lbl = get_value("labels", list, default_labels, args, config)
|
||||||
|
|
||||||
influx_host = get_value("influx_host", (unicode, str), "localhost", args, config)
|
influx_host = get_value("influx_host", str, "localhost", args, config)
|
||||||
influx_port = get_value("influx_port", (unicode, str), "8086", args, config)
|
influx_port = get_value("influx_port", str, "8086", args, config)
|
||||||
influx_user = get_value("influx_user", (unicode, str), "root", args, config)
|
influx_user = get_value("influx_user", str, "root", args, config)
|
||||||
influx_password = get_value("influx_password", (unicode, str), "root", args, config)
|
influx_password = get_value("influx_password", str, "root", args, config)
|
||||||
db_name = get_value("db_name", (unicode, str), "example", args, config)
|
db_name = get_value("db_name", str, "example", args, config)
|
||||||
db_user = get_value("db_user", (unicode, str), "test", args, config)
|
db_user = get_value("db_user", str, "test", args, config)
|
||||||
db_pw = get_value("db_pw", (unicode, str), "test", args, config)
|
db_pw = get_value("db_pw", str, "test", args, config)
|
||||||
|
|
||||||
# start
|
# start
|
||||||
app = InfluxdbApp(
|
app = InfluxdbApp(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from openmtc_app.onem2m import ResourceManagementXAE
|
from openmtc_app.onem2m import ResourceManagementXAE
|
||||||
from connector import InfluxDBConnector
|
from .connector import InfluxDBConnector
|
||||||
|
|
||||||
|
|
||||||
class InfluxdbApp(ResourceManagementXAE):
|
class InfluxdbApp(ResourceManagementXAE):
|
||||||
@ -18,7 +18,7 @@ class InfluxdbApp(ResourceManagementXAE):
|
|||||||
**kw
|
**kw
|
||||||
):
|
):
|
||||||
super(InfluxdbApp, self).__init__(*args, **kw)
|
super(InfluxdbApp, self).__init__(*args, **kw)
|
||||||
if isinstance(labels, basestring):
|
if isinstance(labels, str):
|
||||||
self.labels = {labels}
|
self.labels = {labels}
|
||||||
elif hasattr(labels, '__iter__') and len(labels):
|
elif hasattr(labels, '__iter__') and len(labels):
|
||||||
self.labels = set(labels)
|
self.labels = set(labels)
|
||||||
|
@ -35,8 +35,8 @@ def get_packages(package, package_dir, excluded_list=None, included_list=None):
|
|||||||
r_prefix = len(root) + 1
|
r_prefix = len(root) + 1
|
||||||
for path, dirs, files in os.walk(root, onerror=on_error):
|
for path, dirs, files in os.walk(root, onerror=on_error):
|
||||||
is_module = "__init__.py" in files and path != root
|
is_module = "__init__.py" in files and path != root
|
||||||
excluded = any(map(lambda x: x in path, excluded_list))
|
excluded = any([x in path for x in excluded_list])
|
||||||
included = any(map(lambda x: x in path, included_list))
|
included = any([x in path for x in included_list])
|
||||||
if is_module and (not excluded or included):
|
if is_module and (not excluded or included):
|
||||||
packages.append(package + "." + path[r_prefix:].replace("/", "."))
|
packages.append(package + "." + path[r_prefix:].replace("/", "."))
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ def get_pkg_files(base_dir, name):
|
|||||||
|
|
||||||
def enable_init_files(init_dir, init_dist_files):
|
def enable_init_files(init_dir, init_dist_files):
|
||||||
for f in init_dist_files:
|
for f in init_dist_files:
|
||||||
os.chmod(os.path.join(init_dir, os.path.basename(f)), 0755)
|
os.chmod(os.path.join(init_dir, os.path.basename(f)), 0o755)
|
||||||
|
|
||||||
|
|
||||||
def move_config_files(config_dir, config_files):
|
def move_config_files(config_dir, config_files):
|
||||||
@ -74,7 +74,7 @@ def create_openmtc_user(db_dir=None, log_dir=None):
|
|||||||
try:
|
try:
|
||||||
from pwd import getpwnam
|
from pwd import getpwnam
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print "Could not import the 'pwd' module. Skipping user management"
|
print("Could not import the 'pwd' module. Skipping user management")
|
||||||
else:
|
else:
|
||||||
# assuming DB_DIR was created by setup already
|
# assuming DB_DIR was created by setup already
|
||||||
try:
|
try:
|
||||||
|
@ -38,20 +38,17 @@ parser.add_argument(
|
|||||||
args, config = prepare_app(parser, __loader__, __name__, "config.json")
|
args, config = prepare_app(parser, __loader__, __name__, "config.json")
|
||||||
|
|
||||||
# variables
|
# variables
|
||||||
nm = get_value("name", (unicode, str), default_name, args, config)
|
nm = get_value("name", str, default_name, args, config)
|
||||||
cb = config.get("cse_base", "onem2m")
|
cb = config.get("cse_base", "onem2m")
|
||||||
ep = get_value("ep", (unicode, str), default_ep, args, config)
|
ep = get_value("ep", str, default_ep, args, config)
|
||||||
poas = config.get("poas", ["http://auto:25396"])
|
poas = config.get("poas", ["http://auto:25396"])
|
||||||
originator_pre = config.get("originator_pre", "//openmtc.org/mn-cse-1")
|
originator_pre = config.get("originator_pre", "//openmtc.org/mn-cse-1")
|
||||||
ssl_certs = config.get("ssl_certs", {})
|
ssl_certs = config.get("ssl_certs", {})
|
||||||
interval = get_value("interval", int, default_ep, args, config)
|
interval = get_value("interval", int, default_ep, args, config)
|
||||||
lbl = get_value("labels", list, default_labels, args, config)
|
lbl = get_value("labels", list, default_labels, args, config)
|
||||||
orion_host = get_value("orion_host", (unicode, str), default_orion_host, args,
|
orion_host = get_value("orion_host", str, default_orion_host, args, config)
|
||||||
config)
|
orion_api = get_value("orion_api", str, default_orion_api, args, config)
|
||||||
orion_api = get_value("orion_api", (unicode, str), default_orion_api, args,
|
accumulate_address = get_value("accumulate_address", str, default_accumulate_address, args, config)
|
||||||
config)
|
|
||||||
accumulate_address = get_value("accumulate_address", (unicode, str),
|
|
||||||
default_accumulate_address, args, config)
|
|
||||||
|
|
||||||
# start
|
# start
|
||||||
app = OrionContextBroker(
|
app = OrionContextBroker(
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
try:
|
from urllib.parse import urljoin
|
||||||
from urllib.parse import urljoin
|
|
||||||
except ImportError:
|
|
||||||
from urlparse import urljoin
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@ -32,16 +29,16 @@ class OrionAPI(LoggerMixin):
|
|||||||
|
|
||||||
def _get_type(self, element):
|
def _get_type(self, element):
|
||||||
if isinstance(element, int):
|
if isinstance(element, int):
|
||||||
return u"Int"
|
return "Int"
|
||||||
elif isinstance(element, float):
|
elif isinstance(element, float):
|
||||||
return u"Float"
|
return "Float"
|
||||||
elif isinstance(element, bool):
|
elif isinstance(element, bool):
|
||||||
return u"Boolean"
|
return "Boolean"
|
||||||
elif isinstance(element, (str, unicode)):
|
elif isinstance(element, str):
|
||||||
return u"String"
|
return "String"
|
||||||
else:
|
else:
|
||||||
self.logger.error('Type of "{}" unknown'.format(element))
|
self.logger.error('Type of "{}" unknown'.format(element))
|
||||||
return u"Unknown"
|
return "Unknown"
|
||||||
|
|
||||||
def is_host_alive(self):
|
def is_host_alive(self):
|
||||||
req = self._request(
|
req = self._request(
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
import re
|
import re
|
||||||
try:
|
from urllib.parse import urlparse
|
||||||
from urllib.parse import urlparse
|
|
||||||
except ImportError:
|
|
||||||
from urlparse import urlparse
|
|
||||||
|
|
||||||
from flask import Flask, Response, request
|
from flask import Flask, Response, request
|
||||||
from gevent.pywsgi import WSGIServer
|
from gevent.pywsgi import WSGIServer
|
||||||
|
|
||||||
from openmtc_app.onem2m import ResourceManagementXAE
|
from openmtc_app.onem2m import ResourceManagementXAE
|
||||||
from orion_api import OrionAPI
|
from .orion_api import OrionAPI
|
||||||
|
|
||||||
|
|
||||||
class OrionContextBroker(ResourceManagementXAE):
|
class OrionContextBroker(ResourceManagementXAE):
|
||||||
@ -20,7 +17,7 @@ class OrionContextBroker(ResourceManagementXAE):
|
|||||||
*args,
|
*args,
|
||||||
**kw):
|
**kw):
|
||||||
super(OrionContextBroker, self).__init__(*args, **kw)
|
super(OrionContextBroker, self).__init__(*args, **kw)
|
||||||
if isinstance(labels, basestring):
|
if isinstance(labels, str):
|
||||||
self.labels = {labels}
|
self.labels = {labels}
|
||||||
elif hasattr(labels, '__iter__'):
|
elif hasattr(labels, '__iter__'):
|
||||||
self.labels = set(labels)
|
self.labels = set(labels)
|
||||||
@ -103,9 +100,8 @@ class OrionContextBroker(ResourceManagementXAE):
|
|||||||
device_type = "sensor" if sensor_info.get("sensor_labels",
|
device_type = "sensor" if sensor_info.get("sensor_labels",
|
||||||
None) else "actuator"
|
None) else "actuator"
|
||||||
try:
|
try:
|
||||||
id_label = filter(
|
id_label = [x for x in sensor_info['{}_labels'.format(device_type)]
|
||||||
lambda x: (x.startswith('openmtc:id:')),
|
if x.startswith('openmtc:id:')].pop()
|
||||||
sensor_info['{}_labels'.format(device_type)]).pop()
|
|
||||||
cse_id, dev_id = re.sub('^openmtc:id:', '',
|
cse_id, dev_id = re.sub('^openmtc:id:', '',
|
||||||
id_label).split('/')[:2]
|
id_label).split('/')[:2]
|
||||||
except (IndexError, ValueError):
|
except (IndexError, ValueError):
|
||||||
|
@ -35,8 +35,8 @@ def get_packages(package, package_dir, excluded_list=None, included_list=None):
|
|||||||
r_prefix = len(root) + 1
|
r_prefix = len(root) + 1
|
||||||
for path, dirs, files in os.walk(root, onerror=on_error):
|
for path, dirs, files in os.walk(root, onerror=on_error):
|
||||||
is_module = "__init__.py" in files and path != root
|
is_module = "__init__.py" in files and path != root
|
||||||
excluded = any(map(lambda x: x in path, excluded_list))
|
excluded = any([x in path for x in excluded_list])
|
||||||
included = any(map(lambda x: x in path, included_list))
|
included = any([x in path for x in included_list])
|
||||||
if is_module and (not excluded or included):
|
if is_module and (not excluded or included):
|
||||||
packages.append(package + "." + path[r_prefix:].replace("/", "."))
|
packages.append(package + "." + path[r_prefix:].replace("/", "."))
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ def get_pkg_files(base_dir, name):
|
|||||||
|
|
||||||
def enable_init_files(init_dir, init_dist_files):
|
def enable_init_files(init_dir, init_dist_files):
|
||||||
for f in init_dist_files:
|
for f in init_dist_files:
|
||||||
os.chmod(os.path.join(init_dir, os.path.basename(f)), 0755)
|
os.chmod(os.path.join(init_dir, os.path.basename(f)), 0o755)
|
||||||
|
|
||||||
|
|
||||||
def move_config_files(config_dir, config_files):
|
def move_config_files(config_dir, config_files):
|
||||||
@ -74,7 +74,7 @@ def create_openmtc_user(db_dir=None, log_dir=None):
|
|||||||
try:
|
try:
|
||||||
from pwd import getpwnam
|
from pwd import getpwnam
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print "Could not import the 'pwd' module. Skipping user management"
|
print("Could not import the 'pwd' module. Skipping user management")
|
||||||
else:
|
else:
|
||||||
# assuming DB_DIR was created by setup already
|
# assuming DB_DIR was created by setup already
|
||||||
try:
|
try:
|
||||||
|
@ -42,28 +42,20 @@ parser.add_argument(
|
|||||||
args, config = prepare_app(parser, __loader__, __name__, "config.json")
|
args, config = prepare_app(parser, __loader__, __name__, "config.json")
|
||||||
|
|
||||||
# variables
|
# variables
|
||||||
nm = get_value("name", (unicode, str), default_name, args, config)
|
nm = get_value("name", str, default_name, args, config)
|
||||||
cb = config.get("cse_base", "onem2m")
|
cb = config.get("cse_base", "onem2m")
|
||||||
ep = get_value("ep", (unicode, str), default_ep, args, config)
|
ep = get_value("ep", str, default_ep, args, config)
|
||||||
poas = config.get("poas", ["http://auto:28300"])
|
poas = config.get("poas", ["http://auto:28300"])
|
||||||
originator_pre = config.get("originator_pre", "//openmtc.org/mn-cse-1")
|
originator_pre = config.get("originator_pre", "//openmtc.org/mn-cse-1")
|
||||||
ssl_certs = config.get("ssl_certs", {})
|
ssl_certs = config.get("ssl_certs", {})
|
||||||
csv_path = get_value("csv_path", (unicode, str), default_csv_path, args,
|
csv_path = get_value("csv_path", str, default_csv_path, args, config)
|
||||||
config)
|
csv_delim = get_value("csv_delim", str, default_csv_delim, args, config)
|
||||||
csv_delim = get_value("csv_delim", (unicode, str), default_csv_delim, args,
|
csv_quotechar = get_value("csv_quotechar", str, default_csv_quotechar, args, config)
|
||||||
config)
|
device_classifier = get_value("device_classifier", str, default_device_classifier, args, config)
|
||||||
csv_quotechar = get_value("csv_quotechar", (unicode, str),
|
date_classifier = get_value("date_classifier", (str, list), default_date_classifier, args, config)
|
||||||
default_csv_quotechar, args, config)
|
time_format = get_value("time_format", (str, list), default_time_format, args, config)
|
||||||
device_classifier = get_value("device_classifier", (unicode, str),
|
duration = get_value("duration", (int, float), default_duration, args, config)
|
||||||
default_device_classifier, args, config)
|
repeat = get_value("repeat", str, default_repeat, args, config)
|
||||||
date_classifier = get_value("date_classifier", (unicode, str, list),
|
|
||||||
default_date_classifier, args, config)
|
|
||||||
time_format = get_value("time_format", (unicode, str, list),
|
|
||||||
default_time_format, args, config)
|
|
||||||
duration = get_value("duration", (int, float),
|
|
||||||
default_duration, args, config)
|
|
||||||
repeat = get_value("repeat", (unicode, str),
|
|
||||||
default_repeat, args, config)
|
|
||||||
|
|
||||||
# start
|
# start
|
||||||
app = csvInjector(
|
app = csvInjector(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from openmtc_app.onem2m import XAE
|
from openmtc_app.onem2m import XAE
|
||||||
from openmtc_onem2m.model import Container
|
from openmtc_onem2m.model import Container
|
||||||
from csv_process import csvProcessor
|
from .csv_process import csvProcessor
|
||||||
import sched
|
import sched
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
@ -95,7 +95,7 @@ class csvInjector(XAE):
|
|||||||
if k == "Date" or k == self.device_classifier or event[k] in (
|
if k == "Date" or k == self.device_classifier or event[k] in (
|
||||||
"", None):
|
"", None):
|
||||||
continue
|
continue
|
||||||
if not k in self._recognized_measurement_containers[sensor].keys():
|
if k not in self._recognized_measurement_containers[sensor].keys():
|
||||||
self._create_measurement_container(sensor, k)
|
self._create_measurement_container(sensor, k)
|
||||||
timestamp = time.mktime(datetime.datetime.now().timetuple())
|
timestamp = time.mktime(datetime.datetime.now().timetuple())
|
||||||
senml = {
|
senml = {
|
||||||
|
@ -65,4 +65,4 @@ class csvProcessor(LoggerMixin):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
p = csvProcessor("example.csv", duration=300)
|
p = csvProcessor("example.csv", duration=300)
|
||||||
for e in p.csv_data:
|
for e in p.csv_data:
|
||||||
print e
|
print(e)
|
||||||
|
@ -35,8 +35,8 @@ def get_packages(package, package_dir, excluded_list=None, included_list=None):
|
|||||||
r_prefix = len(root) + 1
|
r_prefix = len(root) + 1
|
||||||
for path, dirs, files in os.walk(root, onerror=on_error):
|
for path, dirs, files in os.walk(root, onerror=on_error):
|
||||||
is_module = "__init__.py" in files and path != root
|
is_module = "__init__.py" in files and path != root
|
||||||
excluded = any(map(lambda x: x in path, excluded_list))
|
excluded = any([x in path for x in excluded_list])
|
||||||
included = any(map(lambda x: x in path, included_list))
|
included = any([x in path for x in included_list])
|
||||||
if is_module and (not excluded or included):
|
if is_module and (not excluded or included):
|
||||||
packages.append(package + "." + path[r_prefix:].replace("/", "."))
|
packages.append(package + "." + path[r_prefix:].replace("/", "."))
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ def get_pkg_files(base_dir, name):
|
|||||||
|
|
||||||
def enable_init_files(init_dir, init_dist_files):
|
def enable_init_files(init_dir, init_dist_files):
|
||||||
for f in init_dist_files:
|
for f in init_dist_files:
|
||||||
os.chmod(os.path.join(init_dir, os.path.basename(f)), 0755)
|
os.chmod(os.path.join(init_dir, os.path.basename(f)), 0o755)
|
||||||
|
|
||||||
|
|
||||||
def move_config_files(config_dir, config_files):
|
def move_config_files(config_dir, config_files):
|
||||||
@ -74,7 +74,7 @@ def create_openmtc_user(db_dir=None, log_dir=None):
|
|||||||
try:
|
try:
|
||||||
from pwd import getpwnam
|
from pwd import getpwnam
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print "Could not import the 'pwd' module. Skipping user management"
|
print("Could not import the 'pwd' module. Skipping user management")
|
||||||
else:
|
else:
|
||||||
# assuming DB_DIR was created by setup already
|
# assuming DB_DIR was created by setup already
|
||||||
try:
|
try:
|
||||||
|
@ -40,36 +40,27 @@ parser.add_argument("--mqtts-keyfile", help="Path to own mqtts key")
|
|||||||
args, config = prepare_app(parser, __loader__, __name__, "config.json")
|
args, config = prepare_app(parser, __loader__, __name__, "config.json")
|
||||||
|
|
||||||
# variables
|
# variables
|
||||||
nm = get_value("name", (unicode, str), default_name, args, config)
|
nm = get_value("name", str, default_name, args, config)
|
||||||
cb = config.get("cse_base", "onem2m")
|
cb = config.get("cse_base", "onem2m")
|
||||||
ep = get_value("ep", (unicode, str), default_ep, args, config)
|
ep = get_value("ep", str, default_ep, args, config)
|
||||||
poas = config.get("poas", ["http://auto:21753"])
|
poas = config.get("poas", ["http://auto:21753"])
|
||||||
originator_pre = config.get("originator_pre", "//openmtc.org/mn-cse-1")
|
originator_pre = config.get("originator_pre", "//openmtc.org/mn-cse-1")
|
||||||
ssl_certs = config.get("ssl_certs", {})
|
ssl_certs = config.get("ssl_certs", {})
|
||||||
|
|
||||||
broker_ep = config.get("broker_ep", "localhost:8883")
|
broker_ep = config.get("broker_ep", "localhost:8883")
|
||||||
|
topic_pre = get_value("topic_pre", str, default_topic_pre, args, config)
|
||||||
topic_pre = get_value("topic_pre", (unicode, str), default_topic_pre, args,
|
topic_index_location = get_value("topic_index_location", int,
|
||||||
config)
|
|
||||||
topic_index_location = get_value("topic_index_location", (int),
|
|
||||||
default_topic_index_location, args, config)
|
default_topic_index_location, args, config)
|
||||||
topic_index_device = get_value("topic_index_device", (int),
|
topic_index_device = get_value("topic_index_device", int,
|
||||||
default_topic_index_device, args, config)
|
default_topic_index_device, args, config)
|
||||||
fiware_service = get_value("fiware_service", (unicode, str),
|
fiware_service = get_value("fiware_service", str, default_fiware_service, args, config)
|
||||||
default_fiware_service, args, config)
|
broker_user = get_value("broker_user", str, default_broker_user, args, config)
|
||||||
broker_user = get_value("broker_user", (unicode, str), default_broker_user,
|
broker_user_pw = get_value("broker_user_pw", str, default_broker_user_pw, args, config)
|
||||||
args, config)
|
user_pw = get_value("broker_user_pw", str, default_broker_user_pw, args, config)
|
||||||
broker_user_pw = get_value("broker_user_pw", (unicode, str),
|
|
||||||
default_broker_user_pw, args, config)
|
|
||||||
user_pw = get_value("broker_user_pw", (unicode, str), default_broker_user_pw,
|
|
||||||
args, config)
|
|
||||||
mqtts_enabled = get_value("mqtts_enabled", (bool), False, args, config)
|
mqtts_enabled = get_value("mqtts_enabled", (bool), False, args, config)
|
||||||
mqtts_ca_certs = get_value("mqtts_ca_certs", (unicode, str),
|
mqtts_ca_certs = get_value("mqtts_ca_certs", str, default_mqtts_ca_certs, args, config)
|
||||||
default_mqtts_ca_certs, args, config)
|
mqtts_certfile = get_value("mqtts_certfile", str, default_mqtts_certfile, args, config)
|
||||||
mqtts_certfile = get_value("mqtts_certfile", (unicode, str),
|
mqtts_keyfile = get_value("mqtts_keyfile", str, default_mqtts_keyfile, args, config)
|
||||||
default_mqtts_certfile, args, config)
|
|
||||||
mqtts_keyfile = get_value("mqtts_keyfile", (unicode, str),
|
|
||||||
default_mqtts_keyfile, args, config)
|
|
||||||
# start
|
# start
|
||||||
app = mqttConnector(
|
app = mqttConnector(
|
||||||
broker_ep=broker_ep,
|
broker_ep=broker_ep,
|
||||||
|
@ -35,8 +35,8 @@ def get_packages(package, package_dir, excluded_list=None, included_list=None):
|
|||||||
r_prefix = len(root) + 1
|
r_prefix = len(root) + 1
|
||||||
for path, dirs, files in os.walk(root, onerror=on_error):
|
for path, dirs, files in os.walk(root, onerror=on_error):
|
||||||
is_module = "__init__.py" in files and path != root
|
is_module = "__init__.py" in files and path != root
|
||||||
excluded = any(map(lambda x: x in path, excluded_list))
|
excluded = any([x in path for x in excluded_list])
|
||||||
included = any(map(lambda x: x in path, included_list))
|
included = any([x in path for x in included_list])
|
||||||
if is_module and (not excluded or included):
|
if is_module and (not excluded or included):
|
||||||
packages.append(package + "." + path[r_prefix:].replace("/", "."))
|
packages.append(package + "." + path[r_prefix:].replace("/", "."))
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ def get_pkg_files(base_dir, name):
|
|||||||
|
|
||||||
def enable_init_files(init_dir, init_dist_files):
|
def enable_init_files(init_dir, init_dist_files):
|
||||||
for f in init_dist_files:
|
for f in init_dist_files:
|
||||||
os.chmod(os.path.join(init_dir, os.path.basename(f)), 0755)
|
os.chmod(os.path.join(init_dir, os.path.basename(f)), 0o755)
|
||||||
|
|
||||||
|
|
||||||
def move_config_files(config_dir, config_files):
|
def move_config_files(config_dir, config_files):
|
||||||
@ -74,7 +74,7 @@ def create_openmtc_user(db_dir=None, log_dir=None):
|
|||||||
try:
|
try:
|
||||||
from pwd import getpwnam
|
from pwd import getpwnam
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print "Could not import the 'pwd' module. Skipping user management"
|
print("Could not import the 'pwd' module. Skipping user management")
|
||||||
else:
|
else:
|
||||||
# assuming DB_DIR was created by setup already
|
# assuming DB_DIR was created by setup already
|
||||||
try:
|
try:
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import urllib
|
import urllib.request
|
||||||
|
import urllib.parse
|
||||||
|
import urllib.error
|
||||||
import ssl
|
import ssl
|
||||||
from socket import (
|
from socket import (
|
||||||
gaierror,
|
gaierror,
|
||||||
error as socket_error,
|
error as socket_error,
|
||||||
)
|
)
|
||||||
from time import time
|
from time import time
|
||||||
from urlparse import urlparse
|
from urllib.parse import urlparse
|
||||||
from aplus import Promise
|
from aplus import Promise
|
||||||
from futile.caching import LRUCache
|
from futile.caching import LRUCache
|
||||||
from geventhttpclient.client import HTTPClient
|
from geventhttpclient.client import HTTPClient
|
||||||
@ -145,7 +147,7 @@ class OneM2MHTTPClient(OneM2MClient):
|
|||||||
filter_criteria = onem2m_request.fc
|
filter_criteria = onem2m_request.fc
|
||||||
params.update({
|
params.update({
|
||||||
(get_short_attribute_name(name) or get_short_member_name(name)): val
|
(get_short_attribute_name(name) or get_short_member_name(name)): val
|
||||||
for name, val in filter_criteria.get_values(True).iteritems()
|
for name, val in filter_criteria.get_values(True).items()
|
||||||
})
|
})
|
||||||
|
|
||||||
if onem2m_request.ae_notifying:
|
if onem2m_request.ae_notifying:
|
||||||
@ -154,7 +156,7 @@ class OneM2MHTTPClient(OneM2MClient):
|
|||||||
path = normalize_path(onem2m_request.to)
|
path = normalize_path(onem2m_request.to)
|
||||||
|
|
||||||
if params:
|
if params:
|
||||||
path += '?' + urllib.urlencode(params, True)
|
path += '?' + urllib.parse.urlencode(params, True)
|
||||||
|
|
||||||
content_type, data = encode_onem2m_content(onem2m_request.content, self.content_type, path=path)
|
content_type, data = encode_onem2m_content(onem2m_request.content, self.content_type, path=path)
|
||||||
|
|
||||||
@ -165,7 +167,7 @@ class OneM2MHTTPClient(OneM2MClient):
|
|||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
header: getattr(onem2m_request, field)
|
header: getattr(onem2m_request, field)
|
||||||
for header, field in _header_to_field_map.iteritems()
|
for header, field in _header_to_field_map.items()
|
||||||
if getattr(onem2m_request, field) is not None
|
if getattr(onem2m_request, field) is not None
|
||||||
}
|
}
|
||||||
headers['content-type'] = content_type
|
headers['content-type'] = content_type
|
||||||
|
@ -32,7 +32,7 @@ from simplejson import (
|
|||||||
JSONDecodeError,
|
JSONDecodeError,
|
||||||
)
|
)
|
||||||
from socket import error as SocketError
|
from socket import error as SocketError
|
||||||
from urlparse import urlparse
|
from urllib.parse import urlparse
|
||||||
from openmtc_onem2m.util import split_onem2m_address
|
from openmtc_onem2m.util import split_onem2m_address
|
||||||
|
|
||||||
#: Dictionary mapping supported schemes to port numbers
|
#: Dictionary mapping supported schemes to port numbers
|
||||||
@ -353,7 +353,7 @@ class OneM2MMQTTClient(OneM2MClient):
|
|||||||
|
|
||||||
self.logger.debug('Decoded JSON request: %s' % (request, ))
|
self.logger.debug('Decoded JSON request: %s' % (request, ))
|
||||||
|
|
||||||
op = OneM2MOperation._member_map_.values()[request['op'] - 1]
|
op = list(OneM2MOperation._member_map_.values())[request['op'] - 1]
|
||||||
to = request['to']
|
to = request['to']
|
||||||
del request['op'], request['to']
|
del request['op'], request['to']
|
||||||
|
|
||||||
@ -485,7 +485,8 @@ class OneM2MMQTTClient(OneM2MClient):
|
|||||||
else:
|
else:
|
||||||
request.ty = None
|
request.ty = None
|
||||||
|
|
||||||
request.op = 1 + OneM2MOperation._member_map_.keys().index(OneM2MOperation[request.op].name)
|
request.op = 1 + list(OneM2MOperation._member_map_.keys()).index(
|
||||||
|
OneM2MOperation[request.op].name)
|
||||||
if request.pc:
|
if request.pc:
|
||||||
request.pc = self._decode(
|
request.pc = self._decode(
|
||||||
encode_onem2m_content(request.pc, 'application/json', path=request.to)[1]
|
encode_onem2m_content(request.pc, 'application/json', path=request.to)[1]
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
try:
|
from urllib.parse import urlparse
|
||||||
from urllib.parse import urlparse
|
|
||||||
except ImportError:
|
|
||||||
from urlparse import urlparse
|
|
||||||
|
|
||||||
from openmtc.mapper import BasicMapper, MapperError
|
from openmtc.mapper import BasicMapper, MapperError
|
||||||
from openmtc_onem2m import OneM2MRequest
|
from openmtc_onem2m import OneM2MRequest
|
||||||
|
@ -407,7 +407,7 @@ class FilterUsageE(OneM2MIntEnum):
|
|||||||
@unique
|
@unique
|
||||||
class CountryCodeE(OneM2MIntEnum):
|
class CountryCodeE(OneM2MIntEnum):
|
||||||
india = 91
|
india = 91
|
||||||
usa = 01
|
usa = 1
|
||||||
|
|
||||||
|
|
||||||
@unique
|
@unique
|
||||||
@ -1376,8 +1376,7 @@ long_to_short_attribute_mapping = {
|
|||||||
"relatedSemantics": "rels",
|
"relatedSemantics": "rels",
|
||||||
}
|
}
|
||||||
|
|
||||||
short_to_long_attribute_mapping = {v: k for k, v in
|
short_to_long_attribute_mapping = {v: k for k, v in long_to_short_attribute_mapping.items()}
|
||||||
long_to_short_attribute_mapping.items()}
|
|
||||||
|
|
||||||
|
|
||||||
def get_long_attribute_name(n):
|
def get_long_attribute_name(n):
|
||||||
@ -1459,8 +1458,7 @@ long_to_short_resource_mapping = {
|
|||||||
"dynamicAuthorizationConsultation": "dac"
|
"dynamicAuthorizationConsultation": "dac"
|
||||||
}
|
}
|
||||||
|
|
||||||
short_to_long_resource_mapping = {v: k for k, v in
|
short_to_long_resource_mapping = {v: k for k, v in long_to_short_resource_mapping.items()}
|
||||||
long_to_short_resource_mapping.items()}
|
|
||||||
|
|
||||||
|
|
||||||
def get_long_resource_name(n):
|
def get_long_resource_name(n):
|
||||||
@ -1584,8 +1582,7 @@ long_to_short_member_mapping = {
|
|||||||
"escertkeMessage": "eckm"
|
"escertkeMessage": "eckm"
|
||||||
}
|
}
|
||||||
|
|
||||||
short_to_long_member_mapping = {v: k for k, v in
|
short_to_long_member_mapping = {v: k for k, v in long_to_short_member_mapping.items()}
|
||||||
long_to_short_member_mapping.items()}
|
|
||||||
|
|
||||||
|
|
||||||
def get_long_member_name(n):
|
def get_long_member_name(n):
|
||||||
@ -1601,8 +1598,7 @@ long_to_short_root_mapping = {
|
|||||||
"responsePrimitive": "rsp"
|
"responsePrimitive": "rsp"
|
||||||
}
|
}
|
||||||
|
|
||||||
short_to_long_root_mapping = {v: k for k, v in
|
short_to_long_root_mapping = {v: k for k, v in long_to_short_root_mapping.items()}
|
||||||
long_to_short_root_mapping.items()}
|
|
||||||
|
|
||||||
|
|
||||||
def get_long_root_name(n):
|
def get_long_root_name(n):
|
||||||
@ -1636,8 +1632,7 @@ long_to_short_parameter_mapping = {
|
|||||||
"responseStatusCode": "rsc"
|
"responseStatusCode": "rsc"
|
||||||
}
|
}
|
||||||
|
|
||||||
short_to_long_parameter_mapping = {v: k for k, v in
|
short_to_long_parameter_mapping = {v: k for k, v in long_to_short_parameter_mapping.items()}
|
||||||
long_to_short_parameter_mapping.items()}
|
|
||||||
|
|
||||||
|
|
||||||
def get_long_parameter_name(n):
|
def get_long_parameter_name(n):
|
||||||
@ -1648,13 +1643,13 @@ def get_short_parameter_name(n):
|
|||||||
return long_to_short_parameter_mapping.get(n)
|
return long_to_short_parameter_mapping.get(n)
|
||||||
|
|
||||||
|
|
||||||
_all_types = {k: v for k, v in globals().iteritems()
|
_all_types = {k: v for k, v in globals().items()
|
||||||
if issubclass(v, OneM2MEntity) and not v.__subclasses__()}
|
if issubclass(v, OneM2MEntity) and not v.__subclasses__()}
|
||||||
|
|
||||||
_all_types_short = {}
|
_all_types_short = {}
|
||||||
_all_types_long = {}
|
_all_types_long = {}
|
||||||
|
|
||||||
for k, v in _all_types.iteritems():
|
for k, v in _all_types.items():
|
||||||
if get_short_resource_name(k):
|
if get_short_resource_name(k):
|
||||||
long_name = k
|
long_name = k
|
||||||
short_name = get_short_resource_name(k)
|
short_name = get_short_resource_name(k)
|
||||||
@ -1685,13 +1680,13 @@ for k, v in _all_types.iteritems():
|
|||||||
_all_types_long[long_name] = v
|
_all_types_long[long_name] = v
|
||||||
|
|
||||||
|
|
||||||
_resource_types = {k: v for k, v in _all_types.iteritems()
|
_resource_types = {k: v for k, v in _all_types.items()
|
||||||
if issubclass(v, ResourceC)}
|
if issubclass(v, ResourceC)}
|
||||||
|
|
||||||
_resource_types_short = {}
|
_resource_types_short = {}
|
||||||
_resource_types_long = {}
|
_resource_types_long = {}
|
||||||
|
|
||||||
for k, v in _resource_types.iteritems():
|
for k, v in _resource_types.items():
|
||||||
if get_short_resource_name(k):
|
if get_short_resource_name(k):
|
||||||
long_name = k
|
long_name = k
|
||||||
short_name = get_short_resource_name(k)
|
short_name = get_short_resource_name(k)
|
||||||
@ -1725,8 +1720,8 @@ def get_onem2m_resource_type(typename):
|
|||||||
|
|
||||||
|
|
||||||
def get_onem2m_types():
|
def get_onem2m_types():
|
||||||
return _all_types.values()
|
return list(_all_types.values())
|
||||||
|
|
||||||
|
|
||||||
def get_onem2m_resource_types():
|
def get_onem2m_resource_types():
|
||||||
return _resource_types.values()
|
return list(_resource_types.values())
|
||||||
|
@ -22,7 +22,7 @@ def create_onem2m_serializer(content_type):
|
|||||||
|
|
||||||
|
|
||||||
def get_onem2m_supported_content_types():
|
def get_onem2m_supported_content_types():
|
||||||
return _factories.keys()
|
return list(_factories.keys())
|
||||||
|
|
||||||
|
|
||||||
def get_onem2m_decoder(content_type):
|
def get_onem2m_decoder(content_type):
|
||||||
@ -37,6 +37,8 @@ def get_onem2m_decoder(content_type):
|
|||||||
serializer = create_onem2m_serializer(content_type)
|
serializer = create_onem2m_serializer(content_type)
|
||||||
_serializers[content_type] = serializer
|
_serializers[content_type] = serializer
|
||||||
return serializer
|
return serializer
|
||||||
|
|
||||||
|
|
||||||
get_serializer = get_onem2m_decoder
|
get_serializer = get_onem2m_decoder
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,9 +22,7 @@ def get_typename(tn):
|
|||||||
return _typename_matcher.findall(tn).pop()
|
return _typename_matcher.findall(tn).pop()
|
||||||
|
|
||||||
|
|
||||||
class OneM2MSerializer(LoggerMixin):
|
class OneM2MSerializer(LoggerMixin, metaclass=ABCMeta):
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def encode_resource(self, resource, response, pretty=False,
|
def encode_resource(self, resource, response, pretty=False,
|
||||||
encoding="utf-8", fields=None):
|
encoding="utf-8", fields=None):
|
||||||
@ -45,7 +43,7 @@ class OneM2MSerializer(LoggerMixin):
|
|||||||
res_type = ResourceTypeE(v["type"])
|
res_type = ResourceTypeE(v["type"])
|
||||||
res_cls = get_onem2m_resource_type(res_type.name)
|
res_cls = get_onem2m_resource_type(res_type.name)
|
||||||
return res_cls(v["name"], resourceID=v["value"], resourceType=res_type)
|
return res_cls(v["name"], resourceID=v["value"], resourceType=res_type)
|
||||||
child_resource = map(map_child_resource, child_resource)
|
child_resource = list(map(map_child_resource, child_resource))
|
||||||
except (TypeError, AttributeError, KeyError, ValueError):
|
except (TypeError, AttributeError, KeyError, ValueError):
|
||||||
raise CSEValueError("Invalid entry in child resources: %s",
|
raise CSEValueError("Invalid entry in child resources: %s",
|
||||||
child_resource)
|
child_resource)
|
||||||
@ -80,7 +78,7 @@ class OneM2MDictSerializer(OneM2MSerializer):
|
|||||||
)
|
)
|
||||||
representation["notificationEvent"] = {
|
representation["notificationEvent"] = {
|
||||||
get_short_attribute_name(k) or get_short_member_name(k): v
|
get_short_attribute_name(k) or get_short_member_name(k): v
|
||||||
for k, v in e.iteritems()
|
for k, v in e.items()
|
||||||
}
|
}
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
self.logger.exception("failed to encode notify")
|
self.logger.exception("failed to encode notify")
|
||||||
@ -104,7 +102,7 @@ class OneM2MDictSerializer(OneM2MSerializer):
|
|||||||
"nm": c.basename,
|
"nm": c.basename,
|
||||||
"typ": c.resourceType
|
"typ": c.resourceType
|
||||||
}
|
}
|
||||||
representation["childResource"] = map(get_child_rep, representation["childResource"])
|
representation["childResource"] = list(map(get_child_rep, representation["childResource"]))
|
||||||
|
|
||||||
if isinstance(resource, URIList):
|
if isinstance(resource, URIList):
|
||||||
representation = [make_val(path, x) for x in representation]
|
representation = [make_val(path, x) for x in representation]
|
||||||
@ -137,7 +135,7 @@ class OneM2MDictSerializer(OneM2MSerializer):
|
|||||||
return self.dumps({typename: representation})
|
return self.dumps({typename: representation})
|
||||||
|
|
||||||
def _handle_partial_addressing(self, resource, pretty):
|
def _handle_partial_addressing(self, resource, pretty):
|
||||||
for k, v in resource.iteritems():
|
for k, v in resource.items():
|
||||||
if k in ('latest', 'oldest') and isinstance(v, ContentInstance):
|
if k in ('latest', 'oldest') and isinstance(v, ContentInstance):
|
||||||
resource[k] = v.resourceID
|
resource[k] = v.resourceID
|
||||||
if pretty:
|
if pretty:
|
||||||
@ -148,7 +146,7 @@ class OneM2MDictSerializer(OneM2MSerializer):
|
|||||||
|
|
||||||
def convert_to_long_keys(d):
|
def convert_to_long_keys(d):
|
||||||
return {get_long_resource_name(k) or get_long_attribute_name(k) or
|
return {get_long_resource_name(k) or get_long_attribute_name(k) or
|
||||||
get_long_member_name(k) or k: v for k, v in d.iteritems()}
|
get_long_member_name(k) or k: v for k, v in d.items()}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if hasattr(s, "read"):
|
if hasattr(s, "read"):
|
||||||
@ -161,7 +159,7 @@ class OneM2MDictSerializer(OneM2MSerializer):
|
|||||||
self.logger.debug("Read data: %s", data)
|
self.logger.debug("Read data: %s", data)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
typename, data = data.items()[0]
|
typename, data = list(data.items())[0]
|
||||||
return get_onem2m_type(get_typename(typename)), data
|
return get_onem2m_type(get_typename(typename)), data
|
||||||
except (AttributeError, IndexError, TypeError):
|
except (AttributeError, IndexError, TypeError):
|
||||||
raise CSESyntaxError("Not a valid resource representation")
|
raise CSESyntaxError("Not a valid resource representation")
|
||||||
|
@ -212,7 +212,9 @@ class OneM2MRequest(object):
|
|||||||
self.to = to
|
self.to = to
|
||||||
# Originator ID
|
# Originator ID
|
||||||
self.originator = fr # original long name is from
|
self.originator = fr # original long name is from
|
||||||
self.request_identifier = rqi or ''.join(random.sample(string.letters + string.digits, 16))
|
self.request_identifier = rqi or ''.join(
|
||||||
|
random.sample(string.ascii_letters + string.digits, 16)
|
||||||
|
)
|
||||||
# Type of a created resource
|
# Type of a created resource
|
||||||
self.resource_type = ty
|
self.resource_type = ty
|
||||||
# Resource content to be transferred.
|
# Resource content to be transferred.
|
||||||
@ -423,7 +425,7 @@ class OneM2MRequest(object):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '%s: %s' % (self.__class__.__name__, ' | '.join([
|
return '%s: %s' % (self.__class__.__name__, ' | '.join([
|
||||||
'%s: %s' % (str(k), str(v)) for k, v in self.__dict__.iteritems()
|
'%s: %s' % (str(k), str(v)) for k, v in self.__dict__.items()
|
||||||
]))
|
]))
|
||||||
|
|
||||||
|
|
||||||
@ -556,7 +558,7 @@ class OneM2MResponse(object):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '%s: %s' % (self.__class__.__name__, ' | '.join([
|
return '%s: %s' % (self.__class__.__name__, ' | '.join([
|
||||||
'%s: %s' % (str(k), str(v)) for k, v in self.__dict__.iteritems()
|
'%s: %s' % (str(k), str(v)) for k, v in self.__dict__.items()
|
||||||
]))
|
]))
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import platform
|
||||||
import sys
|
import sys
|
||||||
from logging import DEBUG
|
from logging import DEBUG
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
@ -6,8 +7,8 @@ from traceback import print_stack
|
|||||||
from futile.logging import LoggerMixin
|
from futile.logging import LoggerMixin
|
||||||
from openmtc.exc import OpenMTCError
|
from openmtc.exc import OpenMTCError
|
||||||
|
|
||||||
if sys.subversion[0] != "CPython":
|
if platform.python_implementation != "CPython":
|
||||||
from inspect import ismethod, getargspec
|
from inspect import ismethod, getfullargspec
|
||||||
|
|
||||||
# TODO: kca: can't pass in values for then/error currently
|
# TODO: kca: can't pass in values for then/error currently
|
||||||
|
|
||||||
@ -160,11 +161,11 @@ class Promise(LoggerMixin):
|
|||||||
"""
|
"""
|
||||||
self._errbacks.append(f)
|
self._errbacks.append(f)
|
||||||
|
|
||||||
if sys.subversion[0] != "CPython":
|
if platform.python_implementation != "CPython":
|
||||||
def _invoke(self, func, value):
|
def _invoke(self, func, value):
|
||||||
try:
|
try:
|
||||||
if value is None:
|
if value is None:
|
||||||
args, _, _, _ = getargspec(func)
|
args = getfullargspec(func).args
|
||||||
arglen = len(args)
|
arglen = len(args)
|
||||||
if not arglen or (arglen == 1 and ismethod(func)):
|
if not arglen or (arglen == 1 and ismethod(func)):
|
||||||
return func()
|
return func()
|
||||||
@ -181,11 +182,11 @@ class Promise(LoggerMixin):
|
|||||||
try:
|
try:
|
||||||
if value is None:
|
if value is None:
|
||||||
try:
|
try:
|
||||||
target = func.im_func
|
target = func.__func__
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
argcount = func.func_code.co_argcount
|
argcount = func.__code__.co_argcount
|
||||||
else:
|
else:
|
||||||
argcount = target.func_code.co_argcount - 1
|
argcount = target.__code__.co_argcount - 1
|
||||||
|
|
||||||
if argcount == 0:
|
if argcount == 0:
|
||||||
return func()
|
return func()
|
||||||
@ -365,7 +366,7 @@ def listPromise(*args):
|
|||||||
if not arg.isFulfilled():
|
if not arg.isFulfilled():
|
||||||
return
|
return
|
||||||
|
|
||||||
value = map(lambda p: p.value, args)
|
value = [p.value for p in args]
|
||||||
ret._fulfill(value)
|
ret._fulfill(value)
|
||||||
|
|
||||||
for arg in args:
|
for arg in args:
|
||||||
|
@ -31,9 +31,7 @@ class ExtraOptionsStrategy(Enum):
|
|||||||
fatal = "fatal"
|
fatal = "fatal"
|
||||||
|
|
||||||
|
|
||||||
class ConfigurationOption(LoggerMixin):
|
class ConfigurationOption(LoggerMixin, metaclass=ABCMeta):
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
def __init__(self, type, default=NOT_SET, converter=identity,
|
def __init__(self, type, default=NOT_SET, converter=identity,
|
||||||
*args, **kw):
|
*args, **kw):
|
||||||
super(ConfigurationOption, self).__init__(*args, **kw)
|
super(ConfigurationOption, self).__init__(*args, **kw)
|
||||||
@ -76,7 +74,7 @@ class ListOption(SimpleOption):
|
|||||||
|
|
||||||
def _convert(self, v):
|
def _convert(self, v):
|
||||||
v = super(ListOption, self)._convert(v)
|
v = super(ListOption, self)._convert(v)
|
||||||
return map(self._convert_content, v)
|
return list(map(self._convert_content, v))
|
||||||
|
|
||||||
def _convert_content(self, v):
|
def _convert_content(self, v):
|
||||||
if not isinstance(v, self.content_type):
|
if not isinstance(v, self.content_type):
|
||||||
@ -92,7 +90,7 @@ class BooleanOption(ConfigurationOption):
|
|||||||
def _convert(self, v):
|
def _convert(self, v):
|
||||||
if isinstance(v, (bool, int)):
|
if isinstance(v, (bool, int)):
|
||||||
return bool(v)
|
return bool(v)
|
||||||
if isinstance(v, basestring):
|
if isinstance(v, str):
|
||||||
return v and v.lower() not in ("0", "no", "n", "f", "false")
|
return v and v.lower() not in ("0", "no", "n", "f", "false")
|
||||||
raise ConfigurationValueError("Illegal value for boolean: %s" % (v, ))
|
raise ConfigurationValueError("Illegal value for boolean: %s" % (v, ))
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class Collection(Sequence, Mapping):
|
|||||||
|
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
if isinstance(index, (int, slice)):
|
if isinstance(index, (int, slice)):
|
||||||
return self._map.values()[index]
|
return list(self._map.values())[index]
|
||||||
return self._map[index]
|
return self._map[index]
|
||||||
|
|
||||||
def __contains__(self, v):
|
def __contains__(self, v):
|
||||||
@ -47,7 +47,7 @@ class Collection(Sequence, Mapping):
|
|||||||
return self._map.get(k, default)
|
return self._map.get(k, default)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self._map.itervalues()
|
return iter(self._map.values())
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self._map)
|
return len(self._map)
|
||||||
@ -427,24 +427,22 @@ class ResourceType(ABCMeta):
|
|||||||
# TODO: caching
|
# TODO: caching
|
||||||
@property
|
@property
|
||||||
def attribute_names(self):
|
def attribute_names(self):
|
||||||
return map(attrgetter("name"), self.attributes)
|
return list(map(attrgetter("name"), self.attributes))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def collection_names(self):
|
def collection_names(self):
|
||||||
return map(attrgetter("name"), self.collections)
|
return list(map(attrgetter("name"), self.collections))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def subresource_names(self):
|
def subresource_names(self):
|
||||||
return map(attrgetter("name"), self.subresources)
|
return list(map(attrgetter("name"), self.subresources))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def member_names(self):
|
def member_names(self):
|
||||||
return map(attrgetter("name"), self.__members__)
|
return list(map(attrgetter("name"), self.__members__))
|
||||||
|
|
||||||
|
|
||||||
class Entity(LoggerMixin):
|
class Entity(LoggerMixin, metaclass=ResourceType):
|
||||||
__metaclass__ = ResourceType
|
|
||||||
|
|
||||||
def __init__(self, *args, **kw):
|
def __init__(self, *args, **kw):
|
||||||
self.set_values(kw)
|
self.set_values(kw)
|
||||||
|
|
||||||
@ -467,7 +465,7 @@ class Entity(LoggerMixin):
|
|||||||
# TODO: proper solution?
|
# TODO: proper solution?
|
||||||
if (v is not None and isinstance(member, ListAttribute) and
|
if (v is not None and isinstance(member, ListAttribute) and
|
||||||
not isinstance(v, (list, tuple, set))):
|
not isinstance(v, (list, tuple, set))):
|
||||||
v = v.values()[0]
|
v = list(v.values())[0]
|
||||||
setattr(self, member.name, v)
|
setattr(self, member.name, v)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
@ -487,7 +485,7 @@ class Entity(LoggerMixin):
|
|||||||
"""
|
"""
|
||||||
if values:
|
if values:
|
||||||
raise ModelTypeError("%s resource has no attribute %s" %
|
raise ModelTypeError("%s resource has no attribute %s" %
|
||||||
(self.typename, values.keys()[0]))
|
(self.typename, list(values.keys())[0]))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_typename(cls):
|
def get_typename(cls):
|
||||||
@ -569,7 +567,7 @@ class Resource(Entity):
|
|||||||
__model_version__ = None
|
__model_version__ = None
|
||||||
|
|
||||||
def __init__(self, path=None, parent=None, *args, **kw):
|
def __init__(self, path=None, parent=None, *args, **kw):
|
||||||
if path is not None and not isinstance(path, basestring):
|
if path is not None and not isinstance(path, str):
|
||||||
raise TypeError(path)
|
raise TypeError(path)
|
||||||
self.__path = path
|
self.__path = path
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
@ -629,7 +627,7 @@ class Resource(Entity):
|
|||||||
# FIXME: move into de-serializer and handle dicts
|
# FIXME: move into de-serializer and handle dicts
|
||||||
if (v is not None and isinstance(member, ListAttribute) and
|
if (v is not None and isinstance(member, ListAttribute) and
|
||||||
not isinstance(v, (list, tuple, set))):
|
not isinstance(v, (list, tuple, set))):
|
||||||
v = v.values()[0]
|
v = list(v.values())[0]
|
||||||
setattr(self, member.name, v)
|
setattr(self, member.name, v)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
try:
|
try:
|
||||||
@ -637,7 +635,7 @@ class Resource(Entity):
|
|||||||
# TODO: proper solution?
|
# TODO: proper solution?
|
||||||
if (v is not None and isinstance(member, ListAttribute) and
|
if (v is not None and isinstance(member, ListAttribute) and
|
||||||
not isinstance(v, (list, tuple, set))):
|
not isinstance(v, (list, tuple, set))):
|
||||||
v = v.values()[0]
|
v = list(v.values())[0]
|
||||||
setattr(self, member.name, v)
|
setattr(self, member.name, v)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
|
||||||
import urllib
|
import urllib.request
|
||||||
|
import urllib.parse
|
||||||
|
import urllib.error
|
||||||
from openmtc_app.onem2m import XAE
|
from openmtc_app.onem2m import XAE
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
@ -15,9 +17,9 @@ class DataVisualization(XAE):
|
|||||||
self.sensor_register = []
|
self.sensor_register = []
|
||||||
self.sensor_values = []
|
self.sensor_values = []
|
||||||
self.name = uuid.uuid1()
|
self.name = uuid.uuid1()
|
||||||
self.things_name = urllib.urlopen("https://dweet.io/follow/%s" % self.name)
|
self.things_name = urllib.request.urlopen("https://dweet.io/follow/%s" % self.name)
|
||||||
print "Thing name :", self.name
|
print("Thing name :", self.name)
|
||||||
print "link for the current data type and values :", self.things_name.geturl()
|
print("link for the current data type and values :", self.things_name.geturl())
|
||||||
# start endless loop
|
# start endless loop
|
||||||
self.periodic_discover(self.remote_cse,
|
self.periodic_discover(self.remote_cse,
|
||||||
{'labels': ["openmtc:sensor_data"]},
|
{'labels': ["openmtc:sensor_data"]},
|
||||||
@ -28,13 +30,13 @@ class DataVisualization(XAE):
|
|||||||
self.add_container_subscription(uri, self.handle_sensor_data)
|
self.add_container_subscription(uri, self.handle_sensor_data)
|
||||||
|
|
||||||
def handle_sensor_data(self, container, content):
|
def handle_sensor_data(self, container, content):
|
||||||
data ={}
|
data = {}
|
||||||
self.sensor_register.append(content[0]['n'])
|
self.sensor_register.append(content[0]['n'])
|
||||||
self.sensor_values.append(content[0]['v'])
|
self.sensor_values.append(content[0]['v'])
|
||||||
for i, k in zip(self.sensor_register , self.sensor_values):
|
for i, k in zip(self.sensor_register, self.sensor_values):
|
||||||
data.update({i: k})
|
data.update({i: k})
|
||||||
params = urllib.urlencode(data)
|
params = urllib.parse.urlencode(data)
|
||||||
urllib.urlopen("https://dweet.io/dweet/for/%s?%s" % (self.name, params))
|
urllib.request.urlopen("https://dweet.io/dweet/for/%s?%s" % (self.name, params))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -4,13 +4,13 @@ from openmtc_onem2m.model import AE
|
|||||||
|
|
||||||
my_app = AE()
|
my_app = AE()
|
||||||
|
|
||||||
print my_app.path
|
print(my_app.path)
|
||||||
#>>> None
|
#>>> None
|
||||||
print my_app.App_ID
|
print(my_app.App_ID)
|
||||||
#>>> None
|
#>>> None
|
||||||
print my_app.parent_path
|
print(my_app.parent_path)
|
||||||
#>>> None
|
#>>> None
|
||||||
print my_app.labels
|
print(my_app.labels)
|
||||||
#>>> None
|
#>>> None
|
||||||
print my_app.attributes
|
print(my_app.attributes)
|
||||||
#>>> [UnicodeAttribute(name="AE-ID", type=unicode), UnicodeAttribute(name="App-ID", type=unicode), ListAttribute(name="accessControlPolicyIDs", type=list), ListAttribute(name="announceTo", type=list), UnicodeAttribute(name="announcedAttribute", type=unicode), ListAttribute(name="childResources", type=list), DatetimeAttribute(name="creationTime", type=datetime), DatetimeAttribute(name="expirationTime", type=datetime), UnicodeAttribute(name="labels", type=unicode), DatetimeAttribute(name="lastModifiedTime", type=datetime), UnicodeAttribute(name="name", type=unicode), UnicodeAttribute(name="nodeLink", type=unicode), UnicodeAttribute(name="ontologyRef", type=unicode), ListAttribute(name="pointOfAccess", type=list)]
|
#>>> [UnicodeAttribute(name="AE-ID", type=unicode), UnicodeAttribute(name="App-ID", type=unicode), ListAttribute(name="accessControlPolicyIDs", type=list), ListAttribute(name="announceTo", type=list), UnicodeAttribute(name="announcedAttribute", type=unicode), ListAttribute(name="childResources", type=list), DatetimeAttribute(name="creationTime", type=datetime), DatetimeAttribute(name="expirationTime", type=datetime), UnicodeAttribute(name="labels", type=unicode), DatetimeAttribute(name="lastModifiedTime", type=datetime), UnicodeAttribute(name="name", type=unicode), UnicodeAttribute(name="nodeLink", type=unicode), UnicodeAttribute(name="ontologyRef", type=unicode), ListAttribute(name="pointOfAccess", type=list)]
|
||||||
|
@ -26,13 +26,13 @@ promise = client.send_onem2m_request(onem2m_request)
|
|||||||
# reteive the OneM2MResponse from the returned promise
|
# reteive the OneM2MResponse from the returned promise
|
||||||
onem2m_response = promise.get()
|
onem2m_response = promise.get()
|
||||||
|
|
||||||
print onem2m_response.to
|
print(onem2m_response.to)
|
||||||
#>>> onem2m
|
#>>> onem2m
|
||||||
print onem2m_response.response_status_code
|
print(onem2m_response.response_status_code)
|
||||||
#>>> STATUS(numeric_code=2001, description='CREATED', http_status_code=201)
|
#>>> STATUS(numeric_code=2001, description='CREATED', http_status_code=201)
|
||||||
print onem2m_response.content
|
print(onem2m_response.content)
|
||||||
#>>> AE(path='None', id='ae0')
|
#>>> AE(path='None', id='ae0')
|
||||||
print onem2m_response.content.App_ID
|
print(onem2m_response.content.App_ID)
|
||||||
#>>> myApp
|
#>>> myApp
|
||||||
print onem2m_response.content.labels
|
print(onem2m_response.content.labels)
|
||||||
#>>> [u'keyword1', u'keyword2']
|
#>>> [u'keyword1', u'keyword2']
|
||||||
|
@ -17,12 +17,12 @@ promise = client.send_onem2m_request(onem2m_request)
|
|||||||
|
|
||||||
onem2m_response = promise.get()
|
onem2m_response = promise.get()
|
||||||
|
|
||||||
print onem2m_response.response_status_code
|
print(onem2m_response.response_status_code)
|
||||||
#>>> STATUS(numeric_code=2001, description='CREATED', http_status_code=201)
|
#>>> STATUS(numeric_code=2001, description='CREATED', http_status_code=201)
|
||||||
|
|
||||||
# Build path to retieve from
|
# Build path to retieve from
|
||||||
path = "onem2m/" + onem2m_response.content.resourceName
|
path = "onem2m/" + onem2m_response.content.resourceName
|
||||||
print path
|
print(path)
|
||||||
#>>> onem2m/MYAPP
|
#>>> onem2m/MYAPP
|
||||||
|
|
||||||
# Retrieve the AE from the CSE
|
# Retrieve the AE from the CSE
|
||||||
@ -30,18 +30,18 @@ onem2m_request = OneM2MRequest("retrieve", to=path)
|
|||||||
promise = client.send_onem2m_request(onem2m_request)
|
promise = client.send_onem2m_request(onem2m_request)
|
||||||
onem2m_response = promise.get()
|
onem2m_response = promise.get()
|
||||||
|
|
||||||
print onem2m_response.response_status_code
|
print(onem2m_response.response_status_code)
|
||||||
#>>> STATUS(numeric_code=2000, description='OK', http_status_code=200)
|
#>>> STATUS(numeric_code=2000, description='OK', http_status_code=200)
|
||||||
print onem2m_response.content
|
print(onem2m_response.content)
|
||||||
#>>> AE(path='None', id='ae0')
|
#>>> AE(path='None', id='ae0')
|
||||||
|
|
||||||
# Set the local AE to the retrieved content
|
# Set the local AE to the retrieved content
|
||||||
my_app = None
|
my_app = None
|
||||||
my_app = onem2m_response.content
|
my_app = onem2m_response.content
|
||||||
|
|
||||||
print my_app.App_ID
|
print(my_app.App_ID)
|
||||||
#>>> myApp
|
#>>> myApp
|
||||||
print my_app.resourceName
|
print(my_app.resourceName)
|
||||||
#>>> MYAPP
|
#>>> MYAPP
|
||||||
print my_app.labels
|
print(my_app.labels)
|
||||||
#>>> [u'keyword1', u'keyword2']
|
#>>> [u'keyword1', u'keyword2']
|
||||||
|
@ -15,7 +15,7 @@ my_app = AE(App_ID="myApp",
|
|||||||
onem2m_request = OneM2MRequest("create", to="onem2m", ty=AE, pc=my_app)
|
onem2m_request = OneM2MRequest("create", to="onem2m", ty=AE, pc=my_app)
|
||||||
promise = client.send_onem2m_request(onem2m_request)
|
promise = client.send_onem2m_request(onem2m_request)
|
||||||
onem2m_response = promise.get()
|
onem2m_response = promise.get()
|
||||||
print onem2m_response.content.labels
|
print(onem2m_response.content.labels)
|
||||||
#>>> [u'keyword1', u'keyword2']
|
#>>> [u'keyword1', u'keyword2']
|
||||||
|
|
||||||
# Retrieve the AE from the CSE and check the labels
|
# Retrieve the AE from the CSE and check the labels
|
||||||
@ -23,7 +23,7 @@ path = "onem2m/" + onem2m_response.content.resourceName
|
|||||||
onem2m_request = OneM2MRequest("retrieve", to=path)
|
onem2m_request = OneM2MRequest("retrieve", to=path)
|
||||||
promise = client.send_onem2m_request(onem2m_request)
|
promise = client.send_onem2m_request(onem2m_request)
|
||||||
onem2m_response = promise.get()
|
onem2m_response = promise.get()
|
||||||
print onem2m_response.content.labels
|
print(onem2m_response.content.labels)
|
||||||
#>>> [u'keyword1', u'keyword2']
|
#>>> [u'keyword1', u'keyword2']
|
||||||
|
|
||||||
# Update the changes labels in the remote resource
|
# Update the changes labels in the remote resource
|
||||||
@ -33,11 +33,11 @@ tmp_app = AE(labels=["foo", "bar", "coffee"])
|
|||||||
onem2m_request = OneM2MRequest("update", to=path, pc=tmp_app)
|
onem2m_request = OneM2MRequest("update", to=path, pc=tmp_app)
|
||||||
promise = client.send_onem2m_request(onem2m_request)
|
promise = client.send_onem2m_request(onem2m_request)
|
||||||
onem2m_response = promise.get()
|
onem2m_response = promise.get()
|
||||||
print onem2m_response.content.labels
|
print(onem2m_response.content.labels)
|
||||||
#>>> [u'foo', u'bar', u'coffee']
|
#>>> [u'foo', u'bar', u'coffee']
|
||||||
|
|
||||||
# Set the local AE to the retrieved content
|
# Set the local AE to the retrieved content
|
||||||
my_app = None
|
my_app = None
|
||||||
my_app = onem2m_response.content
|
my_app = onem2m_response.content
|
||||||
print my_app.labels
|
print(my_app.labels)
|
||||||
#>>> [u'foo', u'bar', u'coffee']
|
#>>> [u'foo', u'bar', u'coffee']
|
||||||
|
@ -11,18 +11,18 @@ try:
|
|||||||
promise = client.send_onem2m_request(onem2m_request)
|
promise = client.send_onem2m_request(onem2m_request)
|
||||||
onem2m_response = promise.get()
|
onem2m_response = promise.get()
|
||||||
except OneM2MErrorResponse as e:
|
except OneM2MErrorResponse as e:
|
||||||
print "CSE reported an error:", e
|
print("CSE reported an error:", e)
|
||||||
raise
|
raise
|
||||||
except OpenMTCError as e:
|
except OpenMTCError as e:
|
||||||
print "Failed to reach the CSE:", e
|
print("Failed to reach the CSE:", e)
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# no exception was raised, the method returned normally.
|
# no exception was raised, the method returned normally.
|
||||||
print onem2m_response.to
|
print(onem2m_response.to)
|
||||||
#>>> onem2m
|
#>>> onem2m
|
||||||
print onem2m_response.response_status_code
|
print(onem2m_response.response_status_code)
|
||||||
#>>> STATUS(numeric_code=2000, description='OK', http_status_code=200)
|
#>>> STATUS(numeric_code=2000, description='OK', http_status_code=200)
|
||||||
print onem2m_response.content
|
print(onem2m_response.content)
|
||||||
#>>> CSEBase(path='None', id='cb0')
|
#>>> CSEBase(path='None', id='cb0')
|
||||||
|
@ -7,31 +7,31 @@ client = OneM2MHTTPClient("http://localhost:8000", False)
|
|||||||
|
|
||||||
onem2m_request = OneM2MRequest("retrieve", to="onem2m")
|
onem2m_request = OneM2MRequest("retrieve", to="onem2m")
|
||||||
onem2m_response = client.send_onem2m_request(onem2m_request).get()
|
onem2m_response = client.send_onem2m_request(onem2m_request).get()
|
||||||
print "---> Request to: http://localhost:8000" + "/" + onem2m_request.to
|
print("---> Request to: http://localhost:8000" + "/" + onem2m_request.to)
|
||||||
print onem2m_response.to
|
print(onem2m_response.to)
|
||||||
#>>> onem2m
|
#>>> onem2m
|
||||||
print onem2m_response.response_status_code
|
print(onem2m_response.response_status_code)
|
||||||
#>>> STATUS(numeric_code=2000, description='OK', http_status_code=200)
|
#>>> STATUS(numeric_code=2000, description='OK', http_status_code=200)
|
||||||
print onem2m_response.content
|
print(onem2m_response.content)
|
||||||
#>>> CSEBase(path='None', id='cb0')
|
#>>> CSEBase(path='None', id='cb0')
|
||||||
|
|
||||||
onem2m_request = OneM2MRequest("retrieve", to="~/mn-cse-1/onem2m")
|
onem2m_request = OneM2MRequest("retrieve", to="~/mn-cse-1/onem2m")
|
||||||
onem2m_response = client.send_onem2m_request(onem2m_request).get()
|
onem2m_response = client.send_onem2m_request(onem2m_request).get()
|
||||||
print "---> Request to: http://localhost:8000" + "/" + onem2m_request.to
|
print("---> Request to: http://localhost:8000" + "/" + onem2m_request.to)
|
||||||
print onem2m_response.to
|
print(onem2m_response.to)
|
||||||
#>>> ~/mn-cse-1/onem2m
|
#>>> ~/mn-cse-1/onem2m
|
||||||
print onem2m_response.response_status_code
|
print(onem2m_response.response_status_code)
|
||||||
#>>> STATUS(numeric_code=2000, description='OK', http_status_code=200)
|
#>>> STATUS(numeric_code=2000, description='OK', http_status_code=200)
|
||||||
print onem2m_response.content
|
print(onem2m_response.content)
|
||||||
#>>> CSEBase(path='None', id='cb0')
|
#>>> CSEBase(path='None', id='cb0')
|
||||||
|
|
||||||
client.port = 18000
|
client.port = 18000
|
||||||
onem2m_request = OneM2MRequest("retrieve", to="~/mn-cse-1/onem2m")
|
onem2m_request = OneM2MRequest("retrieve", to="~/mn-cse-1/onem2m")
|
||||||
onem2m_response = client.send_onem2m_request(onem2m_request).get()
|
onem2m_response = client.send_onem2m_request(onem2m_request).get()
|
||||||
print "---> Request to: http://localhost:18000" + "/" + onem2m_request.to
|
print("---> Request to: http://localhost:18000" + "/" + onem2m_request.to)
|
||||||
print onem2m_response.to
|
print(onem2m_response.to)
|
||||||
#>>> ~/mn-cse-1/onem2m
|
#>>> ~/mn-cse-1/onem2m
|
||||||
print onem2m_response.response_status_code
|
print(onem2m_response.response_status_code)
|
||||||
#>>> STATUS(numeric_code=2000, description='OK', http_status_code=200)
|
#>>> STATUS(numeric_code=2000, description='OK', http_status_code=200)
|
||||||
print onem2m_response.content
|
print(onem2m_response.content)
|
||||||
#>>> CSEBase(path='None', id='cb0')
|
#>>> CSEBase(path='None', id='cb0')
|
||||||
|
@ -4,13 +4,13 @@ from openmtc_onem2m.model import AE
|
|||||||
|
|
||||||
my_app = AE(App_ID="myApp", labels=["keyword1", "keyword2"])
|
my_app = AE(App_ID="myApp", labels=["keyword1", "keyword2"])
|
||||||
|
|
||||||
print my_app.path
|
print(my_app.path)
|
||||||
#>>> None
|
#>>> None
|
||||||
print my_app.App_ID
|
print(my_app.App_ID)
|
||||||
#>>> myApp
|
#>>> myApp
|
||||||
print my_app.parent_path
|
print(my_app.parent_path)
|
||||||
#>>> None
|
#>>> None
|
||||||
print my_app.labels
|
print(my_app.labels)
|
||||||
#>>> [u'keyword1', u'keyword2']
|
#>>> [u'keyword1', u'keyword2']
|
||||||
print my_app.attributes
|
print(my_app.attributes)
|
||||||
#>>> [UnicodeAttribute(name="AE-ID", type=unicode), UnicodeAttribute(name="App-ID", type=unicode), ListAttribute(name="accessControlPolicyIDs", type=list), ListAttribute(name="announceTo", type=list), UnicodeAttribute(name="announcedAttribute", type=unicode), ListAttribute(name="childResources", type=list), DatetimeAttribute(name="creationTime", type=datetime), DatetimeAttribute(name="expirationTime", type=datetime), UnicodeAttribute(name="labels", type=unicode), DatetimeAttribute(name="lastModifiedTime", type=datetime), UnicodeAttribute(name="name", type=unicode), UnicodeAttribute(name="nodeLink", type=unicode), UnicodeAttribute(name="ontologyRef", type=unicode), ListAttribute(name="pointOfAccess", type=list)]
|
#>>> [UnicodeAttribute(name="AE-ID", type=unicode), UnicodeAttribute(name="App-ID", type=unicode), ListAttribute(name="accessControlPolicyIDs", type=list), ListAttribute(name="announceTo", type=list), UnicodeAttribute(name="announcedAttribute", type=unicode), ListAttribute(name="childResources", type=list), DatetimeAttribute(name="creationTime", type=datetime), DatetimeAttribute(name="expirationTime", type=datetime), UnicodeAttribute(name="labels", type=unicode), DatetimeAttribute(name="lastModifiedTime", type=datetime), UnicodeAttribute(name="name", type=unicode), UnicodeAttribute(name="nodeLink", type=unicode), UnicodeAttribute(name="ontologyRef", type=unicode), ListAttribute(name="pointOfAccess", type=list)]
|
||||||
|
@ -4,5 +4,5 @@ from openmtc_onem2m.transport import OneM2MRequest
|
|||||||
|
|
||||||
request = OneM2MRequest("retrieve", to="onem2m")
|
request = OneM2MRequest("retrieve", to="onem2m")
|
||||||
|
|
||||||
print request.to
|
print(request.to)
|
||||||
#>>> onem2m
|
#>>> onem2m
|
||||||
|
@ -4,5 +4,5 @@ from openmtc_onem2m.transport import OneM2MRequest
|
|||||||
|
|
||||||
request = OneM2MRequest("delete", to="onem2m")
|
request = OneM2MRequest("delete", to="onem2m")
|
||||||
|
|
||||||
print request.to
|
print(request.to)
|
||||||
#>>> onem2m
|
#>>> onem2m
|
||||||
|
@ -7,7 +7,7 @@ my_app = AE(App_ID="myApp")
|
|||||||
|
|
||||||
request = OneM2MRequest("create", to="onem2m", pc="my_app")
|
request = OneM2MRequest("create", to="onem2m", pc="my_app")
|
||||||
|
|
||||||
print request.to
|
print(request.to)
|
||||||
#>>> onem2m
|
#>>> onem2m
|
||||||
print request.pc
|
print(request.pc)
|
||||||
#>>> myApp
|
#>>> myApp
|
||||||
|
@ -13,7 +13,7 @@ request = OneM2MRequest("create",
|
|||||||
pc=data_string,
|
pc=data_string,
|
||||||
ty="application/json")
|
ty="application/json")
|
||||||
|
|
||||||
print request.to
|
print(request.to)
|
||||||
#>>> onem2m
|
#>>> onem2m
|
||||||
print request.pc
|
print(request.pc)
|
||||||
#>>> {"type": "temperature", "value": 15}
|
#>>> {"type": "temperature", "value": 15}
|
||||||
|
@ -7,7 +7,7 @@ my_app = AE(App_ID="myApp")
|
|||||||
|
|
||||||
request = OneM2MRequest("notify", to="onem2m", pc=my_app)
|
request = OneM2MRequest("notify", to="onem2m", pc=my_app)
|
||||||
|
|
||||||
print request.to
|
print(request.to)
|
||||||
#>>> onem2m
|
#>>> onem2m
|
||||||
print request.pc.App_ID
|
print(request.pc.App_ID)
|
||||||
#>>> myApp
|
#>>> myApp
|
||||||
|
@ -13,7 +13,7 @@ request = OneM2MRequest("create",
|
|||||||
pc=data_string,
|
pc=data_string,
|
||||||
ty="application/json")
|
ty="application/json")
|
||||||
|
|
||||||
print request.to
|
print(request.to)
|
||||||
#>>> onem2m
|
#>>> onem2m
|
||||||
print request.pc
|
print(request.pc)
|
||||||
#>>> {"type": "temperature", "value": 15}
|
#>>> {"type": "temperature", "value": 15}
|
||||||
|
@ -7,7 +7,7 @@ my_app = AE(App_ID="myApp", labels=["keyword1", "keyword2"])
|
|||||||
|
|
||||||
request = OneM2MRequest("update", to="onem2m", pc=my_app.labels)
|
request = OneM2MRequest("update", to="onem2m", pc=my_app.labels)
|
||||||
|
|
||||||
print request.to
|
print(request.to)
|
||||||
#>>> onem2m
|
#>>> onem2m
|
||||||
print request.pc
|
print(request.pc)
|
||||||
#>>> [u'keyword1', u'keyword2']
|
#>>> [u'keyword1', u'keyword2']
|
||||||
|
@ -13,9 +13,9 @@ promise = client.send_onem2m_request(onem2m_request)
|
|||||||
# reteive the OneM2MResponse from the returned promise
|
# reteive the OneM2MResponse from the returned promise
|
||||||
onem2m_response = promise.get()
|
onem2m_response = promise.get()
|
||||||
|
|
||||||
print onem2m_response.to
|
print(onem2m_response.to)
|
||||||
#>>> onem2m
|
#>>> onem2m
|
||||||
print onem2m_response.response_status_code
|
print(onem2m_response.response_status_code)
|
||||||
#>>> STATUS(numeric_code=2000, description='OK', http_status_code=200)
|
#>>> STATUS(numeric_code=2000, description='OK', http_status_code=200)
|
||||||
print onem2m_response.content
|
print(onem2m_response.content)
|
||||||
#>>> CSEBase(path='None', id='cb0')
|
#>>> CSEBase(path='None', id='cb0')
|
||||||
|
@ -34,4 +34,4 @@ cd ${base_path}
|
|||||||
cd ..
|
cd ..
|
||||||
. ../common/prep-env.sh
|
. ../common/prep-env.sh
|
||||||
cd ${base_path}
|
cd ${base_path}
|
||||||
python ${app_file}
|
python3 ${app_file}
|
||||||
|
@ -31,16 +31,16 @@ parser.add_argument("devices", nargs="*")
|
|||||||
args, config = prepare_app(parser, __loader__, __name__, "config.json")
|
args, config = prepare_app(parser, __loader__, __name__, "config.json")
|
||||||
|
|
||||||
# variables
|
# variables
|
||||||
nm = get_value("name", (unicode, str), default_name, args, config)
|
nm = get_value("name", str, default_name, args, config)
|
||||||
cb = config.get("cse_base", "onem2m")
|
cb = config.get("cse_base", "onem2m")
|
||||||
ep = get_value("ep", (unicode, str), default_ep, args, config)
|
ep = get_value("ep", str, default_ep, args, config)
|
||||||
poas = config.get("poas", ["http://auto:28728"])
|
poas = config.get("poas", ["http://auto:28728"])
|
||||||
originator_pre = config.get("originator_pre", "//openmtc.org/mn-cse-1")
|
originator_pre = config.get("originator_pre", "//openmtc.org/mn-cse-1")
|
||||||
ssl_certs = config.get("ssl_certs", {})
|
ssl_certs = config.get("ssl_certs", {})
|
||||||
|
|
||||||
s = config.get("sim", False)
|
s = config.get("sim", False)
|
||||||
p = int(config.get("sim_period"))
|
p = int(config.get("sim_period"))
|
||||||
cul_device = get_value('cul_device', (unicode, str), default_device, args, config)
|
cul_device = get_value('cul_device', str, default_device, args, config)
|
||||||
device_mappings = get_value('device_mappings', dict, {}, args, config)
|
device_mappings = get_value('device_mappings', dict, {}, args, config)
|
||||||
devices = get_value('devices', list, [], args, config)
|
devices = get_value('devices', list, [], args, config)
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ class CUL868Coordinator(LoggerMixin):
|
|||||||
run_forever(period, self._generate_simulated_data)
|
run_forever(period, self._generate_simulated_data)
|
||||||
|
|
||||||
def _generate_simulated_data(self):
|
def _generate_simulated_data(self):
|
||||||
p = choice(self.sim_parsers.keys())
|
p = choice(list(self.sim_parsers.keys()))
|
||||||
fake_parser = self.sim_parsers[p]
|
fake_parser = self.sim_parsers[p]
|
||||||
dev_id, data = fake_parser(p)
|
dev_id, data = fake_parser(p)
|
||||||
handler = self.handlers[p]
|
handler = self.handlers[p]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
from cul_868_coordinator import CUL868Coordinator
|
from .cul_868_coordinator import CUL868Coordinator
|
||||||
from openmtc_app.onem2m import XAE
|
from openmtc_app.onem2m import XAE
|
||||||
from openmtc_onem2m.model import Container
|
from openmtc_onem2m.model import Container
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ class CUL868IPE(XAE):
|
|||||||
|
|
||||||
self.cul = CUL868Coordinator(device=device, sim=sim)
|
self.cul = CUL868Coordinator(device=device, sim=sim)
|
||||||
|
|
||||||
for d in map(lambda s: CULDevice(*s.split(":")[:2]), cul_devices):
|
for d in [CULDevice(*s.split(":")[:2]) for s in cul_devices]:
|
||||||
if d.type == "fs20":
|
if d.type == "fs20":
|
||||||
house_code, device_code = d.device_id.split("-")
|
house_code, device_code = d.device_id.split("-")
|
||||||
self.fs20.append((house_code, device_code))
|
self.fs20.append((house_code, device_code))
|
||||||
@ -85,11 +85,11 @@ class CUL868IPE(XAE):
|
|||||||
|
|
||||||
if func:
|
if func:
|
||||||
sub_labels.append('openmtc:actuator_data')
|
sub_labels.append('openmtc:actuator_data')
|
||||||
sub_labels += map(lambda x: "openmtc:actuator_data:%s" % x, l) if l else []
|
sub_labels += ["openmtc:actuator_data:%s" % x for x in l] if l else []
|
||||||
sub_cnt = Container(resourceName=c_id, maxNrOfInstances=0, labels=sub_labels)
|
sub_cnt = Container(resourceName=c_id, maxNrOfInstances=0, labels=sub_labels)
|
||||||
else:
|
else:
|
||||||
sub_labels.append('openmtc:sensor_data')
|
sub_labels.append('openmtc:sensor_data')
|
||||||
sub_labels += map(lambda x: "openmtc:sensor_data:%s" % x, l) if l else []
|
sub_labels += ["openmtc:sensor_data:%s" % x for x in l] if l else []
|
||||||
sub_cnt = Container(resourceName=c_id, labels=sub_labels)
|
sub_cnt = Container(resourceName=c_id, labels=sub_labels)
|
||||||
|
|
||||||
self.containers[s_id] = s_cnt = self.create_container(dev_cnt, sub_cnt)
|
self.containers[s_id] = s_cnt = self.create_container(dev_cnt, sub_cnt)
|
||||||
@ -123,7 +123,7 @@ class CUL868IPE(XAE):
|
|||||||
def _get_handle_switch(self, house_code, device_code):
|
def _get_handle_switch(self, house_code, device_code):
|
||||||
|
|
||||||
def handle_switch(container, content):
|
def handle_switch(container, content):
|
||||||
if isinstance(content, (str, unicode)): # fallback to old behavior
|
if isinstance(content, str): # fallback to old behavior
|
||||||
if content == 'TOGGLE':
|
if content == 'TOGGLE':
|
||||||
self.cul.toggle(house_code, device_code)
|
self.cul.toggle(house_code, device_code)
|
||||||
elif content == 'ON':
|
elif content == 'ON':
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from parsers import S300THParser, EM1000EMParser, FS20Parser
|
from .parsers import S300THParser, EM1000EMParser, FS20Parser
|
||||||
|
|
||||||
|
|
||||||
def test_parsers():
|
def test_parsers():
|
||||||
|
@ -35,8 +35,8 @@ def get_packages(package, package_dir, excluded_list=None, included_list=None):
|
|||||||
r_prefix = len(root) + 1
|
r_prefix = len(root) + 1
|
||||||
for path, dirs, files in os.walk(root, onerror=on_error):
|
for path, dirs, files in os.walk(root, onerror=on_error):
|
||||||
is_module = "__init__.py" in files and path != root
|
is_module = "__init__.py" in files and path != root
|
||||||
excluded = any(map(lambda x: x in path, excluded_list))
|
excluded = any([x in path for x in excluded_list])
|
||||||
included = any(map(lambda x: x in path, included_list))
|
included = any([x in path for x in included_list])
|
||||||
if is_module and (not excluded or included):
|
if is_module and (not excluded or included):
|
||||||
packages.append(package + "." + path[r_prefix:].replace("/", "."))
|
packages.append(package + "." + path[r_prefix:].replace("/", "."))
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ def get_pkg_files(base_dir, name):
|
|||||||
|
|
||||||
def enable_init_files(init_dir, init_dist_files):
|
def enable_init_files(init_dir, init_dist_files):
|
||||||
for f in init_dist_files:
|
for f in init_dist_files:
|
||||||
os.chmod(os.path.join(init_dir, os.path.basename(f)), 0755)
|
os.chmod(os.path.join(init_dir, os.path.basename(f)), 0o755)
|
||||||
|
|
||||||
|
|
||||||
def move_config_files(config_dir, config_files):
|
def move_config_files(config_dir, config_files):
|
||||||
@ -74,7 +74,7 @@ def create_openmtc_user(db_dir=None, log_dir=None):
|
|||||||
try:
|
try:
|
||||||
from pwd import getpwnam
|
from pwd import getpwnam
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print "Could not import the 'pwd' module. Skipping user management"
|
print("Could not import the 'pwd' module. Skipping user management")
|
||||||
else:
|
else:
|
||||||
# assuming DB_DIR was created by setup already
|
# assuming DB_DIR was created by setup already
|
||||||
try:
|
try:
|
||||||
|
@ -9,7 +9,7 @@ from openmtc_onem2m.model import (
|
|||||||
Subscription,
|
Subscription,
|
||||||
)
|
)
|
||||||
from openmtc_onem2m.serializer import get_onem2m_decoder
|
from openmtc_onem2m.serializer import get_onem2m_decoder
|
||||||
from urlparse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from openmtc_onem2m.util import split_onem2m_address
|
from openmtc_onem2m.util import split_onem2m_address
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ class NotificationManager(LoggerMixin):
|
|||||||
def _get_auto_host(ep):
|
def _get_auto_host(ep):
|
||||||
try:
|
try:
|
||||||
import socket
|
import socket
|
||||||
from urlparse import urlparse
|
from urllib.parse import urlparse
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
netloc = urlparse(ep).netloc.split(':')
|
netloc = urlparse(ep).netloc.split(':')
|
||||||
s.connect((netloc[0], int(netloc[1])))
|
s.connect((netloc[0], int(netloc[1])))
|
||||||
@ -156,7 +156,7 @@ class NotificationManager(LoggerMixin):
|
|||||||
del self.callbacks[sur]
|
del self.callbacks[sur]
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
for subscription in self.callbacks.keys():
|
for subscription in list(self.callbacks.keys()):
|
||||||
try:
|
try:
|
||||||
self.unsubscribe(subscription)
|
self.unsubscribe(subscription)
|
||||||
except OneM2MError:
|
except OneM2MError:
|
||||||
|
@ -94,7 +94,7 @@ class XAE(LoggerMixin):
|
|||||||
self.key_file = key_file
|
self.key_file = key_file
|
||||||
|
|
||||||
if expiration_time is not None:
|
if expiration_time is not None:
|
||||||
if isinstance(expiration_time, (str, unicode)):
|
if isinstance(expiration_time, str):
|
||||||
expiration_time = parse_date(expiration_time)
|
expiration_time = parse_date(expiration_time)
|
||||||
elif isinstance(expiration_time, (int, float)):
|
elif isinstance(expiration_time, (int, float)):
|
||||||
expiration_time = datetime.fromtimestamp(expiration_time, UTC)
|
expiration_time = datetime.fromtimestamp(expiration_time, UTC)
|
||||||
@ -483,7 +483,7 @@ class XAE(LoggerMixin):
|
|||||||
"""
|
"""
|
||||||
path = getattr(container, "path", container)
|
path = getattr(container, "path", container)
|
||||||
|
|
||||||
if isinstance(content, (str, unicode)):
|
if isinstance(content, str):
|
||||||
fmt = 'text/plain' if fmt is None else fmt
|
fmt = 'text/plain' if fmt is None else fmt
|
||||||
text = True if text is None else text
|
text = True if text is None else text
|
||||||
elif isinstance(content, (dict, list)):
|
elif isinstance(content, (dict, list)):
|
||||||
@ -529,7 +529,7 @@ class XAE(LoggerMixin):
|
|||||||
content = cin.content
|
content = cin.content
|
||||||
try:
|
try:
|
||||||
if int(encoding_type) == EncodingTypeE.base64String:
|
if int(encoding_type) == EncodingTypeE.base64String:
|
||||||
content = b64decode(content)
|
content = b64decode(content).decode('utf-8')
|
||||||
|
|
||||||
if media_type == 'application/json':
|
if media_type == 'application/json':
|
||||||
content = json_loads(content)
|
content = json_loads(content)
|
||||||
@ -567,10 +567,8 @@ class XAE(LoggerMixin):
|
|||||||
|
|
||||||
def _remove_route(self, route):
|
def _remove_route(self, route):
|
||||||
self.logger.debug("removing route: %s", route)
|
self.logger.debug("removing route: %s", route)
|
||||||
self.runner.flask_app.url_map._rules = filter(
|
self.runner.flask_app.url_map._rules = [x for x in self.runner.flask_app.url_map._rules
|
||||||
lambda x: x.rule != route,
|
if x.rule != route]
|
||||||
self.runner.flask_app.url_map._rules
|
|
||||||
)
|
|
||||||
|
|
||||||
def _add_subscription(self, path, _, handler, delete_handler, filter_criteria=None,
|
def _add_subscription(self, path, _, handler, delete_handler, filter_criteria=None,
|
||||||
expiration_time=None):
|
expiration_time=None):
|
||||||
@ -865,9 +863,9 @@ class ResourceManagementXAE(XAE):
|
|||||||
sub_ref = self._cse_id + '/' + sub_ref
|
sub_ref = self._cse_id + '/' + sub_ref
|
||||||
self._discovered_sensors = {k: v for k, v in self._discovered_sensors.items()
|
self._discovered_sensors = {k: v for k, v in self._discovered_sensors.items()
|
||||||
if v['sub_ref'] != sub_ref}
|
if v['sub_ref'] != sub_ref}
|
||||||
self._discovered_devices = {k: v for k, v in self._discovered_devices.items()
|
self._discovered_devices = {k: v for k, v in list(self._discovered_devices.items())
|
||||||
if any(filter(lambda x: x.startswith(k),
|
if any([x for x in list(self._discovered_sensors.keys())
|
||||||
self._discovered_sensors.keys()))
|
if x.startswith(k)])
|
||||||
or not sub_ref.startswith(k)}
|
or not sub_ref.startswith(k)}
|
||||||
|
|
||||||
def _handle_sensor_data(self, container, data):
|
def _handle_sensor_data(self, container, data):
|
||||||
|
@ -3,6 +3,7 @@ from json import load as json_load
|
|||||||
from operator import getitem
|
from operator import getitem
|
||||||
|
|
||||||
import futile
|
import futile
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
|
|
||||||
def prepare_app(parser, loader, name, default_config_file):
|
def prepare_app(parser, loader, name, default_config_file):
|
||||||
@ -11,7 +12,7 @@ def prepare_app(parser, loader, name, default_config_file):
|
|||||||
" specified multiple times.")
|
" specified multiple times.")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
module_ = loader.fullname.split("." + name).pop(0)
|
module_ = loader.name.split("." + name).pop(0)
|
||||||
|
|
||||||
futile.logging.set_default_level(futile.logging.DEBUG)
|
futile.logging.set_default_level(futile.logging.DEBUG)
|
||||||
logger = futile.logging.get_logger(name)
|
logger = futile.logging.get_logger(name)
|
||||||
|
@ -60,7 +60,7 @@ gevent.ssl.PROTOCOL_SSLv3 = gevent.ssl.PROTOCOL_TLSv1
|
|||||||
# gevent main
|
# gevent main
|
||||||
################################################################################
|
################################################################################
|
||||||
from openmtc.configuration import ConfigurationError
|
from openmtc.configuration import ConfigurationError
|
||||||
from openmtc_server.util.async import async_all
|
from openmtc_server.util.async_ import async_all
|
||||||
|
|
||||||
_components = []
|
_components = []
|
||||||
_plugins = []
|
_plugins = []
|
||||||
@ -168,7 +168,8 @@ def stop_component(component):
|
|||||||
|
|
||||||
|
|
||||||
def stop_components():
|
def stop_components():
|
||||||
map(stop_component, reversed(_components))
|
for c in reversed(_components):
|
||||||
|
stop_component(c)
|
||||||
logger.debug("Components stopped")
|
logger.debug("Components stopped")
|
||||||
|
|
||||||
|
|
||||||
@ -179,8 +180,10 @@ def stop_plugin(plugin):
|
|||||||
|
|
||||||
def stop_plugins():
|
def stop_plugins():
|
||||||
# stop transport plugins after the others
|
# stop transport plugins after the others
|
||||||
map(stop_plugin, filter(lambda p: not p.name.endswith('TransportPlugin'), _plugins))
|
for p in [p for p in _plugins if not p.name.endswith('TransportPlugin')]:
|
||||||
map(stop_plugin, filter(lambda p: p.name.endswith('TransportPlugin'), _plugins))
|
stop_plugin(p)
|
||||||
|
for p in [p for p in _plugins if p.name.endswith('TransportPlugin')]:
|
||||||
|
stop_plugin(p)
|
||||||
|
|
||||||
|
|
||||||
def init_component(component, api):
|
def init_component(component, api):
|
||||||
@ -278,7 +281,7 @@ def main(default_config_file, is_gateway):
|
|||||||
from openmtc_server.platform.default.Event import (ResourceFinishEvent,
|
from openmtc_server.platform.default.Event import (ResourceFinishEvent,
|
||||||
NetworkEvent)
|
NetworkEvent)
|
||||||
|
|
||||||
from GEventNetworkManager import GEventNetworkManager
|
from .GEventNetworkManager import GEventNetworkManager
|
||||||
|
|
||||||
from openmtc_server.util.db import load_db_module
|
from openmtc_server.util.db import load_db_module
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import controller
|
from . import controller
|
||||||
import openmtc_onem2m.model as model
|
import openmtc_onem2m.model as model
|
||||||
from aplus import Promise
|
from aplus import Promise
|
||||||
from openmtc.util import datetime_now
|
from openmtc.util import datetime_now
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
|
import base64
|
||||||
|
import binascii
|
||||||
import string
|
import string
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
from random import choice
|
from random import choice
|
||||||
from urlparse import urlparse
|
from urllib.parse import urlparse
|
||||||
import binascii
|
|
||||||
import base64
|
|
||||||
from xml.sax import SAXParseException
|
from xml.sax import SAXParseException
|
||||||
|
|
||||||
from iso8601.iso8601 import parse_date, ParseError
|
from iso8601.iso8601 import parse_date, ParseError
|
||||||
@ -40,14 +40,13 @@ from openmtc_server.db import DBError
|
|||||||
from openmtc_server.db.exc import DBNotFound
|
from openmtc_server.db.exc import DBNotFound
|
||||||
from openmtc_server.util import match_now_cron
|
from openmtc_server.util import match_now_cron
|
||||||
from openmtc_server.util import uri_safe
|
from openmtc_server.util import uri_safe
|
||||||
from openmtc_server.util.async import async_all
|
from openmtc_server.util.async_ import async_all
|
||||||
|
|
||||||
|
|
||||||
_resource_id_counter = {}
|
_resource_id_counter = {}
|
||||||
|
|
||||||
|
|
||||||
class OneM2MDefaultController(LoggerMixin):
|
class OneM2MDefaultController(LoggerMixin):
|
||||||
RANDOM_SOURCE = string.letters + string.digits
|
RANDOM_SOURCE = string.ascii_letters + string.digits
|
||||||
|
|
||||||
result_content_type = None
|
result_content_type = None
|
||||||
|
|
||||||
@ -99,8 +98,7 @@ class OneM2MDefaultController(LoggerMixin):
|
|||||||
self._abs_cse_id = self._sp_id + self._rel_cse_id # //openmtc.org/mn-cse-1
|
self._abs_cse_id = self._sp_id + self._rel_cse_id # //openmtc.org/mn-cse-1
|
||||||
|
|
||||||
# default policies
|
# default policies
|
||||||
self._default_privileges = map(lambda x: AccessControlRuleC(**x),
|
self._default_privileges = [AccessControlRuleC(**x) for x in self.onem2m_config.get("default_privileges", [])]
|
||||||
self.onem2m_config.get("default_privileges", []))
|
|
||||||
|
|
||||||
# dynamic authorization
|
# dynamic authorization
|
||||||
dynamic_authorization = self.onem2m_config.get("dynamic_authorization", {})
|
dynamic_authorization = self.onem2m_config.get("dynamic_authorization", {})
|
||||||
@ -269,7 +267,7 @@ class OneM2MDefaultController(LoggerMixin):
|
|||||||
self.logger.debug("Error getting policy: %s:", error)
|
self.logger.debug("Error getting policy: %s:", error)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return filter(None, map(get_policy, access_control_policy_ids))
|
return [_f for _f in map(get_policy, access_control_policy_ids) if _f]
|
||||||
|
|
||||||
# def _notify_das_server(self, notify_uri, payload):
|
# def _notify_das_server(self, notify_uri, payload):
|
||||||
def _notify_das_server(self, resource):
|
def _notify_das_server(self, resource):
|
||||||
@ -903,7 +901,7 @@ class OneM2MDefaultController(LoggerMixin):
|
|||||||
self._retrieve_children()
|
self._retrieve_children()
|
||||||
|
|
||||||
def _send_retrieve_response(self):
|
def _send_retrieve_response(self):
|
||||||
fields = self.resource.values.keys()
|
fields = list(self.resource.values.keys())
|
||||||
if self.request.rcn != ResultContentE.attributes_and_child_resource_references:
|
if self.request.rcn != ResultContentE.attributes_and_child_resource_references:
|
||||||
fields = [k for k in fields if k != 'childResource']
|
fields = [k for k in fields if k != 'childResource']
|
||||||
return OneM2MResponse(STATUS_OK, pc=self.result, request=self.request, fields=fields)
|
return OneM2MResponse(STATUS_OK, pc=self.result, request=self.request, fields=fields)
|
||||||
@ -1330,12 +1328,14 @@ class ContentInstanceController(OneM2MDefaultController):
|
|||||||
self.parent.oldest = None
|
self.parent.oldest = None
|
||||||
|
|
||||||
# handle_old_instances
|
# handle_old_instances
|
||||||
if 0 < self.parent.maxNrOfInstances <= self.parent.currentNrOfInstances:
|
if self.parent.maxNrOfInstances is not None:
|
||||||
remove_oldest_child()
|
if 0 < self.parent.maxNrOfInstances <= self.parent.currentNrOfInstances:
|
||||||
|
remove_oldest_child()
|
||||||
|
|
||||||
while (0 < self.parent.maxByteSize <
|
if self.parent.maxByteSize is not None:
|
||||||
self.parent.currentByteSize + self.resource.contentSize):
|
while (0 < self.parent.maxByteSize <
|
||||||
remove_oldest_child()
|
self.parent.currentByteSize + self.resource.contentSize):
|
||||||
|
remove_oldest_child()
|
||||||
|
|
||||||
# handle_new_instance
|
# handle_new_instance
|
||||||
self.parent.currentNrOfInstances += 1
|
self.parent.currentNrOfInstances += 1
|
||||||
|
@ -10,7 +10,7 @@ _logger = get_logger(__name__)
|
|||||||
def check_match(resource, filter_criteria):
|
def check_match(resource, filter_criteria):
|
||||||
_logger.debug("checking if filter criteria '%s' are matched by "
|
_logger.debug("checking if filter criteria '%s' are matched by "
|
||||||
"resource '%s'", filter_criteria, resource)
|
"resource '%s'", filter_criteria, resource)
|
||||||
for criteria, value in filter_criteria.get_values(True).iteritems():
|
for criteria, value in filter_criteria.get_values(True).items():
|
||||||
if not value:
|
if not value:
|
||||||
continue
|
continue
|
||||||
_logger.debug("checking if resource matches: %s=%s", criteria, value)
|
_logger.debug("checking if resource matches: %s=%s", criteria, value)
|
||||||
@ -37,10 +37,10 @@ def parse_filter_criteria(filter_criteria):
|
|||||||
int_criteria = ('stateTagSmaller', 'stateTagBigger', 'resourceType',
|
int_criteria = ('stateTagSmaller', 'stateTagBigger', 'resourceType',
|
||||||
'sizeAbove', 'sizeBelow', 'filterUsage', 'limit')
|
'sizeAbove', 'sizeBelow', 'filterUsage', 'limit')
|
||||||
parsed_criteria = {}
|
parsed_criteria = {}
|
||||||
for k, v in filter_criteria.iteritems():
|
for k, v in filter_criteria.items():
|
||||||
if k in int_criteria:
|
if k in int_criteria:
|
||||||
if isinstance(v, list):
|
if isinstance(v, list):
|
||||||
parsed_criteria[k] = map(int, v)
|
parsed_criteria[k] = list(map(int, v))
|
||||||
else:
|
else:
|
||||||
parsed_criteria[k] = int(v)
|
parsed_criteria[k] = int(v)
|
||||||
else:
|
else:
|
||||||
|
@ -8,11 +8,11 @@ from openmtc_onem2m.transport import OneM2MRequest, MetaInformation, \
|
|||||||
OneM2MOperation
|
OneM2MOperation
|
||||||
from openmtc_server.Plugin import Plugin
|
from openmtc_server.Plugin import Plugin
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from openmtc_server.util.async import async_all
|
from openmtc_server.util.async_ import async_all
|
||||||
from re import sub
|
from re import sub
|
||||||
from urlparse import urlparse
|
from urllib.parse import urlparse
|
||||||
# url join with coap compatibility
|
# url join with coap compatibility
|
||||||
from urlparse import urljoin, uses_relative, uses_netloc
|
from urllib.parse import urljoin, uses_relative, uses_netloc
|
||||||
|
|
||||||
uses_relative.append('coap')
|
uses_relative.append('coap')
|
||||||
uses_netloc.append('coap')
|
uses_netloc.append('coap')
|
||||||
@ -77,7 +77,7 @@ class AnnouncementHandler(Plugin):
|
|||||||
|
|
||||||
return retrieve_remote_cse_list() \
|
return retrieve_remote_cse_list() \
|
||||||
.then(
|
.then(
|
||||||
lambda remote_cse_list: async_all(map(get_cse, remote_cse_list))) \
|
lambda remote_cse_list: async_all(list(map(get_cse, remote_cse_list)))) \
|
||||||
.then(handle_remote_cse_list) \
|
.then(handle_remote_cse_list) \
|
||||||
.then(self._started)
|
.then(self._started)
|
||||||
# return self._started()
|
# return self._started()
|
||||||
@ -277,8 +277,8 @@ class AnnouncementHandler(Plugin):
|
|||||||
# from the cseList and no further actions for those CSEs are performed.
|
# from the cseList and no further actions for those CSEs are performed.
|
||||||
def check_cse_list():
|
def check_cse_list():
|
||||||
self.logger.debug("check_cse_list: %s vs %s" % (
|
self.logger.debug("check_cse_list: %s vs %s" % (
|
||||||
db_cse_list, self._cse_links.values()))
|
db_cse_list, list(self._cse_links.values())))
|
||||||
return filter(lambda x: x in db_cse_list, self._cse_links.values())
|
return [x for x in list(self._cse_links.values()) if x in db_cse_list]
|
||||||
|
|
||||||
# b) Send createXXXAnnouncementResourceRequestIndication (where XXX is
|
# b) Send createXXXAnnouncementResourceRequestIndication (where XXX is
|
||||||
# replaced by the type of the resource to be announced) for each CSE in
|
# replaced by the type of the resource to be announced) for each CSE in
|
||||||
@ -464,12 +464,12 @@ class AnnouncementHandler(Plugin):
|
|||||||
|
|
||||||
# filters out all False in the list
|
# filters out all False in the list
|
||||||
def filter_func(l):
|
def filter_func(l):
|
||||||
return filter(None, l)
|
return [_f for _f in l if _f]
|
||||||
|
|
||||||
return async_all([
|
return async_all([
|
||||||
(async_all(map(create_func, create_list)).then(filter_func)
|
(async_all(list(map(create_func, create_list))).then(filter_func)
|
||||||
.then(lambda l: l + filtered_cses)),
|
.then(lambda l: l + filtered_cses)),
|
||||||
async_all(map(delete_func, delete_list)).then(filter_func)
|
async_all(list(map(delete_func, delete_list))).then(filter_func)
|
||||||
])
|
])
|
||||||
|
|
||||||
return send_anncs(check_cse_list())
|
return send_anncs(check_cse_list())
|
||||||
@ -597,7 +597,7 @@ class AnnouncementHandler(Plugin):
|
|||||||
# TODO: conversion to set() is questionable
|
# TODO: conversion to set() is questionable
|
||||||
update_list = [x for x in cse_list if x not in set(add_list)]
|
update_list = [x for x in cse_list if x not in set(add_list)]
|
||||||
|
|
||||||
return async_all(map(send_update_annc_pre, update_list))
|
return async_all(list(map(send_update_annc_pre, update_list)))
|
||||||
|
|
||||||
self.logger.debug('No attributes changed, returning None')
|
self.logger.debug('No attributes changed, returning None')
|
||||||
return None
|
return None
|
||||||
|
@ -77,13 +77,13 @@ class NotificationHandler(Plugin):
|
|||||||
|
|
||||||
def _get_sub_list(self, pid, net):
|
def _get_sub_list(self, pid, net):
|
||||||
return [
|
return [
|
||||||
v['sub'] for v in self.subscriptions_info.itervalues()
|
v['sub'] for v in self.subscriptions_info.values()
|
||||||
if v['pid'] == pid and net in v['enc'].notificationEventType
|
if v['pid'] == pid and net in v['enc'].notificationEventType
|
||||||
]
|
]
|
||||||
|
|
||||||
def _delete_subs_from_parent(self, pid):
|
def _delete_subs_from_parent(self, pid):
|
||||||
self.subscriptions_info = {
|
self.subscriptions_info = {
|
||||||
k: v for k, v in self.subscriptions_info.iteritems() if v["pid"] != pid
|
k: v for k, v in self.subscriptions_info.items() if v["pid"] != pid
|
||||||
}
|
}
|
||||||
|
|
||||||
def _handle_subscription_created(self, subscription, _):
|
def _handle_subscription_created(self, subscription, _):
|
||||||
@ -143,24 +143,16 @@ class NotificationHandler(Plugin):
|
|||||||
def _handle_subscribable_resource_updated(self, resource, _):
|
def _handle_subscribable_resource_updated(self, resource, _):
|
||||||
self.logger.debug("_handle_subscribable_resource_updated for %s", resource)
|
self.logger.debug("_handle_subscribable_resource_updated for %s", resource)
|
||||||
|
|
||||||
map(
|
for sub in self._get_sub_list(
|
||||||
lambda sub: self._handle_subscription(resource, sub),
|
resource.resourceID, NotificationEventTypeE.updateOfResource,):
|
||||||
self._get_sub_list(
|
self._handle_subscription(resource, sub)
|
||||||
resource.resourceID,
|
|
||||||
NotificationEventTypeE.updateOfResource,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def _handle_subscribable_resource_created(self, resource, _):
|
def _handle_subscribable_resource_created(self, resource, _):
|
||||||
self.logger.debug("_handle_subscribable_resource_created for %s", resource)
|
self.logger.debug("_handle_subscribable_resource_created for %s", resource)
|
||||||
|
|
||||||
map(
|
for sub in self._get_sub_list(
|
||||||
lambda sub: self._handle_subscription(resource, sub),
|
resource.parentID, NotificationEventTypeE.createOfDirectChildResource,):
|
||||||
self._get_sub_list(
|
self._handle_subscription(resource, sub)
|
||||||
resource.parentID,
|
|
||||||
NotificationEventTypeE.createOfDirectChildResource,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def _handle_subscribable_resource_deleted(self, resource, _):
|
def _handle_subscribable_resource_deleted(self, resource, _):
|
||||||
self.logger.debug("_handle_subscribable_resource_deleted for %s", resource)
|
self.logger.debug("_handle_subscribable_resource_deleted for %s", resource)
|
||||||
|
@ -111,7 +111,7 @@ class RegistrationHandler(Plugin):
|
|||||||
remote_cse_poa = remote_cse.get("poa", [])
|
remote_cse_poa = remote_cse.get("poa", [])
|
||||||
self.api.add_poa_list(remote_cse_id, remote_cse_poa)
|
self.api.add_poa_list(remote_cse_id, remote_cse_poa)
|
||||||
|
|
||||||
return map(handle_remote_cse_method, remote_cses)
|
return list(map(handle_remote_cse_method, remote_cses))
|
||||||
|
|
||||||
def _handle_remote_cse_delete(self, remote_cse):
|
def _handle_remote_cse_delete(self, remote_cse):
|
||||||
""" Sends a delete request for the RemoteCSE resource.
|
""" Sends a delete request for the RemoteCSE resource.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import urlparse
|
import urllib.parse
|
||||||
import ssl
|
import ssl
|
||||||
from _socket import gaierror
|
from _socket import gaierror
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -104,8 +104,7 @@ class OpenMTCWSGIApplication(LoggerMixin):
|
|||||||
for interface in interfaces():
|
for interface in interfaces():
|
||||||
try:
|
try:
|
||||||
ifdata = ifaddresses(interface)[family]
|
ifdata = ifaddresses(interface)[family]
|
||||||
ifaddrs = map(lambda x: x.split("%")[0], pluck("addr",
|
ifaddrs = [x.split("%")[0] for x in pluck("addr", ifdata)]
|
||||||
ifdata))
|
|
||||||
addresses.update(ifaddrs)
|
addresses.update(ifaddrs)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
@ -268,7 +267,7 @@ class OpenMTCWSGIApplication(LoggerMixin):
|
|||||||
|
|
||||||
if http_request.query_string:
|
if http_request.query_string:
|
||||||
from openmtc_cse.methoddomain.filtercriteria import filters
|
from openmtc_cse.methoddomain.filtercriteria import filters
|
||||||
params = urlparse.parse_qs(http_request.query_string)
|
params = urllib.parse.parse_qs(http_request.query_string.decode("utf-8"))
|
||||||
get_param = params.get
|
get_param = params.get
|
||||||
f_c = {}
|
f_c = {}
|
||||||
|
|
||||||
@ -288,7 +287,7 @@ class OpenMTCWSGIApplication(LoggerMixin):
|
|||||||
setattr(onem2m_request, param, values[0])
|
setattr(onem2m_request, param, values[0])
|
||||||
elif param_long_name == 'attributeList':
|
elif param_long_name == 'attributeList':
|
||||||
onem2m_request.pc = AttributeList(
|
onem2m_request.pc = AttributeList(
|
||||||
map(get_long_attribute_name, values[0].split(' ')))
|
list(map(get_long_attribute_name, values[0].split(' '))))
|
||||||
elif param_long_name and hasattr(filters, param_long_name):
|
elif param_long_name and hasattr(filters, param_long_name):
|
||||||
self.logger.debug("got values for '%s' ('%s'): %s",
|
self.logger.debug("got values for '%s' ('%s'): %s",
|
||||||
param_long_name, param, values)
|
param_long_name, param, values)
|
||||||
@ -414,9 +413,7 @@ class OpenMTCWSGIApplication(LoggerMixin):
|
|||||||
setattr(onem2m_request, "_authenticated", False)
|
setattr(onem2m_request, "_authenticated", False)
|
||||||
if subject_alt_name is not None:
|
if subject_alt_name is not None:
|
||||||
setattr(onem2m_request, "_authenticated", True)
|
setattr(onem2m_request, "_authenticated", True)
|
||||||
impersonation_error = not bool(len(filter(
|
impersonation_error = not bool(len([x for x in subject_alt_name if x[0] == 'URI' and x[1] == onem2m_request.fr]))
|
||||||
lambda x: x[0] == 'URI' and x[1] == onem2m_request.fr,
|
|
||||||
subject_alt_name)))
|
|
||||||
if impersonation_error:
|
if impersonation_error:
|
||||||
onem2m_response = OneM2MResponse(STATUS_IMPERSONATION_ERROR,
|
onem2m_response = OneM2MResponse(STATUS_IMPERSONATION_ERROR,
|
||||||
request=onem2m_request)
|
request=onem2m_request)
|
||||||
|
@ -17,11 +17,11 @@ class MQTTTransportPlugin(Plugin):
|
|||||||
self._initialized()
|
self._initialized()
|
||||||
|
|
||||||
def _start(self):
|
def _start(self):
|
||||||
self.api.register_onem2m_client(portmap.keys(), get_client)
|
self.api.register_onem2m_client(list(portmap.keys()), get_client)
|
||||||
interface = self.config.get('interface', '127.0.0.1')
|
interface = self.config.get('interface', '127.0.0.1')
|
||||||
port = self.config.get('port', 1883)
|
port = self.config.get('port', 1883)
|
||||||
try:
|
try:
|
||||||
scheme = portmap.keys()[portmap.values().index(port)]
|
scheme = list(portmap.keys())[list(portmap.values()).index(port)]
|
||||||
except (KeyError, ValueError):
|
except (KeyError, ValueError):
|
||||||
scheme = 'mqtt'
|
scheme = 'mqtt'
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from urlparse import urlparse
|
from urllib.parse import urlparse
|
||||||
from netifaces import AF_INET, AF_INET6
|
from netifaces import AF_INET, AF_INET6
|
||||||
|
|
||||||
from aplus import Promise
|
from aplus import Promise
|
||||||
@ -64,7 +64,7 @@ class OneM2MTransportDomain(Component):
|
|||||||
self.events.resource_deleted.register_handler(self._handle_cse_deleted, RemoteCSE)
|
self.events.resource_deleted.register_handler(self._handle_cse_deleted, RemoteCSE)
|
||||||
|
|
||||||
interfaces = self._api.network_manager.get_interfaces().get()
|
interfaces = self._api.network_manager.get_interfaces().get()
|
||||||
self._addresses = {i.name: filter(self._filter_out_link_local, i.addresses)
|
self._addresses = {i.name: list(filter(self._filter_out_link_local, i.addresses))
|
||||||
for i in interfaces}
|
for i in interfaces}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -104,7 +104,7 @@ class OneM2MTransportDomain(Component):
|
|||||||
|
|
||||||
# interface handling
|
# interface handling
|
||||||
def _handle_interface_created(self, interface):
|
def _handle_interface_created(self, interface):
|
||||||
self._addresses[interface.name] = filter(self._filter_out_link_local, interface.addresses)
|
self._addresses[interface.name] = list(filter(self._filter_out_link_local, interface.addresses))
|
||||||
self._create_endpoints()
|
self._create_endpoints()
|
||||||
|
|
||||||
def _handle_interface_removed(self, interface):
|
def _handle_interface_removed(self, interface):
|
||||||
|
@ -5,9 +5,7 @@ from futile.logging import LoggerMixin
|
|||||||
from openmtc.model import Resource
|
from openmtc.model import Resource
|
||||||
|
|
||||||
|
|
||||||
class Event(LoggerMixin):
|
class Event(LoggerMixin, metaclass=ABCMeta):
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def fire(self, *event_data):
|
def fire(self, *event_data):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
@ -17,9 +15,7 @@ class Event(LoggerMixin):
|
|||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
class EventSpec(object):
|
class EventSpec(object, metaclass=ABCMeta):
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def matches(self, item):
|
def matches(self, item):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
@ -2,9 +2,7 @@ from abc import ABCMeta, abstractmethod
|
|||||||
from futile.logging import LoggerMixin
|
from futile.logging import LoggerMixin
|
||||||
|
|
||||||
|
|
||||||
class TaskRunner(LoggerMixin):
|
class TaskRunner(LoggerMixin, metaclass=ABCMeta):
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def run_task(self, task, *args, **kw):
|
def run_task(self, task, *args, **kw):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
@ -13,9 +13,7 @@ class Component(LoggerMixin):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Serializer(LoggerMixin):
|
class Serializer(LoggerMixin, metaclass=ABCMeta):
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def encode(self, resource):
|
def encode(self, resource):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
@ -5,9 +5,7 @@ from openmtc_server.db.exc import DBError
|
|||||||
from collections import MutableMapping
|
from collections import MutableMapping
|
||||||
|
|
||||||
|
|
||||||
class DBAdapter(LoggerMixin):
|
class DBAdapter(LoggerMixin, metaclass=ABCMeta):
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
def __init__(self, config, *args, **kw):
|
def __init__(self, config, *args, **kw):
|
||||||
super(DBAdapter, self).__init__(*args, **kw)
|
super(DBAdapter, self).__init__(*args, **kw)
|
||||||
|
|
||||||
@ -36,9 +34,7 @@ class DBAdapter(LoggerMixin):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Shelve(LoggerMixin, MutableMapping):
|
class Shelve(LoggerMixin, MutableMapping, metaclass=ABCMeta):
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def commit(self):
|
def commit(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
@ -48,9 +44,7 @@ class Shelve(LoggerMixin, MutableMapping):
|
|||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
class Session(object):
|
class Session(object, metaclass=ABCMeta):
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def store(self, resource):
|
def store(self, resource):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
@ -96,9 +90,7 @@ class Session(object):
|
|||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
class BasicSession(Session, LoggerMixin):
|
class BasicSession(Session, LoggerMixin, metaclass=ABCMeta):
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
def __init__(self, resource_type, *args, **kw):
|
def __init__(self, resource_type, *args, **kw):
|
||||||
super(BasicSession, self).__init__(*args, **kw)
|
super(BasicSession, self).__init__(*args, **kw)
|
||||||
|
|
||||||
@ -129,7 +121,8 @@ class BasicSession(Session, LoggerMixin):
|
|||||||
|
|
||||||
def delete_children(self, resource_type, parent):
|
def delete_children(self, resource_type, parent):
|
||||||
children = self.get_collection(resource_type, parent)
|
children = self.get_collection(resource_type, parent)
|
||||||
map(self.delete, children)
|
for c in children:
|
||||||
|
self.delete(c)
|
||||||
|
|
||||||
def _get_content_instances(self, parent):
|
def _get_content_instances(self, parent):
|
||||||
return self.get_collection(self.cinType, parent)
|
return self.get_collection(self.cinType, parent)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from Queue import Queue, Empty
|
from queue import Queue, Empty
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from openmtc_server.TaskRunner import TaskRunner
|
from openmtc_server.TaskRunner import TaskRunner
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from urllib import quote
|
from urllib.parse import quote
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from mimeparse import parse_mime_type
|
from mimeparse import parse_mime_type
|
||||||
|
@ -77,8 +77,7 @@ CONFIG_DIR = "/etc/openmtc/gevent"
|
|||||||
CONFIG_DIST_FILES = ("openmtc-gevent/etc/conf/config-backend.json.dist",
|
CONFIG_DIST_FILES = ("openmtc-gevent/etc/conf/config-backend.json.dist",
|
||||||
"openmtc-gevent/etc/conf/config-gateway.json.dist")
|
"openmtc-gevent/etc/conf/config-gateway.json.dist")
|
||||||
SSL_CERT_DIR = "/etc/openmtc/certs"
|
SSL_CERT_DIR = "/etc/openmtc/certs"
|
||||||
SSL_CERT_FILES = tuple(map(lambda x: os.path.join('openmtc-gevent/certs/', x),
|
SSL_CERT_FILES = tuple([os.path.join('openmtc-gevent/certs/', x) for x in os.listdir('openmtc-gevent/certs')])
|
||||||
os.listdir('openmtc-gevent/certs')))
|
|
||||||
DATA_FILES = [
|
DATA_FILES = [
|
||||||
(DB_DIR, ""),
|
(DB_DIR, ""),
|
||||||
(LOG_DIR, ""),
|
(LOG_DIR, ""),
|
||||||
|
@ -57,16 +57,16 @@ loops = 1000
|
|||||||
enc_table = []
|
enc_table = []
|
||||||
dec_table = []
|
dec_table = []
|
||||||
|
|
||||||
print "Running tests (%d loops each)" % loops
|
print("Running tests (%d loops each)" % loops)
|
||||||
|
|
||||||
for title, mod, enc, dec in tests:
|
for title, mod, enc, dec in tests:
|
||||||
print title
|
print(title)
|
||||||
|
|
||||||
print " [Encode]", enc
|
print(" [Encode]", enc)
|
||||||
result = timeit(enc, mod, number=loops)
|
result = timeit(enc, mod, number=loops)
|
||||||
enc_table.append([title, result])
|
enc_table.append([title, result])
|
||||||
|
|
||||||
print " [Decode]", dec
|
print(" [Decode]", dec)
|
||||||
result = timeit(dec, mod, number=loops)
|
result = timeit(dec, mod, number=loops)
|
||||||
dec_table.append([title, result])
|
dec_table.append([title, result])
|
||||||
|
|
||||||
@ -76,8 +76,8 @@ enc_table.insert(0, ['Package', 'Seconds'])
|
|||||||
dec_table.sort(key=lambda x: x[1])
|
dec_table.sort(key=lambda x: x[1])
|
||||||
dec_table.insert(0, ['Package', 'Seconds'])
|
dec_table.insert(0, ['Package', 'Seconds'])
|
||||||
|
|
||||||
print "\nEncoding Test (%d loops)" % loops
|
print("\nEncoding Test (%d loops)" % loops)
|
||||||
print tabulate(enc_table, headers="firstrow")
|
print(tabulate(enc_table, headers="firstrow"))
|
||||||
|
|
||||||
print "\nDecoding Test (%d loops)" % loops
|
print("\nDecoding Test (%d loops)" % loops)
|
||||||
print tabulate(dec_table, headers="firstrow")
|
print(tabulate(dec_table, headers="firstrow"))
|
||||||
|
8
utils.py
8
utils.py
@ -35,8 +35,8 @@ def get_packages(package, package_dir, excluded_list=None, included_list=None):
|
|||||||
r_prefix = len(root) + 1
|
r_prefix = len(root) + 1
|
||||||
for path, dirs, files in os.walk(root, onerror=on_error):
|
for path, dirs, files in os.walk(root, onerror=on_error):
|
||||||
is_module = "__init__.py" in files and path != root
|
is_module = "__init__.py" in files and path != root
|
||||||
excluded = any(map(lambda x: x in path, excluded_list))
|
excluded = any([x in path for x in excluded_list])
|
||||||
included = any(map(lambda x: x in path, included_list))
|
included = any([x in path for x in included_list])
|
||||||
if is_module and (not excluded or included):
|
if is_module and (not excluded or included):
|
||||||
packages.append(package + "." + path[r_prefix:].replace("/", "."))
|
packages.append(package + "." + path[r_prefix:].replace("/", "."))
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ def get_pkg_files(base_dir, name):
|
|||||||
|
|
||||||
def enable_init_files(init_dir, init_dist_files):
|
def enable_init_files(init_dir, init_dist_files):
|
||||||
for f in init_dist_files:
|
for f in init_dist_files:
|
||||||
os.chmod(os.path.join(init_dir, os.path.basename(f)), 0755)
|
os.chmod(os.path.join(init_dir, os.path.basename(f)), 0o755)
|
||||||
|
|
||||||
|
|
||||||
def move_config_files(config_dir, config_files):
|
def move_config_files(config_dir, config_files):
|
||||||
@ -74,7 +74,7 @@ def create_openmtc_user(db_dir=None, log_dir=None):
|
|||||||
try:
|
try:
|
||||||
from pwd import getpwnam
|
from pwd import getpwnam
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print "Could not import the 'pwd' module. Skipping user management"
|
print("Could not import the 'pwd' module. Skipping user management")
|
||||||
else:
|
else:
|
||||||
# assuming DB_DIR was created by setup already
|
# assuming DB_DIR was created by setup already
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user