Compare commits
No commits in common. "master" and "nilmrun-2.0.0" have entirely different histories.
master
...
nilmrun-2.
2
.gitattributes
vendored
2
.gitattributes
vendored
|
@ -1 +1 @@
|
|||
nilmrun/_version.py export-subst
|
||||
src/_version.py export-subst
|
||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,8 +3,8 @@ build/
|
|||
*.pyc
|
||||
dist/
|
||||
nilmrun.egg-info/
|
||||
.eggs/
|
||||
|
||||
# This gets generated as needed by setup.py
|
||||
MANIFEST.in
|
||||
MANIFEST
|
||||
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
# Root
|
||||
include README.md
|
||||
include setup.py
|
||||
include versioneer.py
|
||||
include Makefile
|
||||
|
||||
# Version
|
||||
include nilmrun/_version.py
|
15
Makefile
15
Makefile
|
@ -1,6 +1,9 @@
|
|||
# By default, run the tests.
|
||||
all: test
|
||||
|
||||
test2:
|
||||
nilmrun/trainola.py data.js
|
||||
|
||||
version:
|
||||
python3 setup.py version
|
||||
|
||||
|
@ -20,11 +23,8 @@ develop:
|
|||
docs:
|
||||
make -C docs
|
||||
|
||||
ctrl: flake
|
||||
flake:
|
||||
flake8 nilmrun
|
||||
lint:
|
||||
pylint3 --rcfile=setup.cfg nilmrun
|
||||
pylint3 --rcfile=.pylintrc nilmdb
|
||||
|
||||
test:
|
||||
ifneq ($(INSIDE_EMACS),)
|
||||
|
@ -37,13 +37,12 @@ else
|
|||
endif
|
||||
|
||||
clean::
|
||||
find . -name '*.pyc' -o -name '__pycache__' -print0 | xargs -0 rm -rf
|
||||
rm -f .coverage
|
||||
rm -rf nilmrun.egg-info/ build/
|
||||
find . -name '*pyc' | xargs rm -f
|
||||
rm -rf nilmtools.egg-info/ build/ MANIFEST.in
|
||||
make -C docs clean
|
||||
|
||||
gitclean::
|
||||
git clean -dXf
|
||||
|
||||
.PHONY: all version dist sdist install docs test
|
||||
.PHONY: ctrl lint flake clean gitclean
|
||||
.PHONY: all version dist sdist install docs lint test clean gitclean
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import nilmrun.processmanager
|
||||
|
||||
from ._version import get_versions
|
||||
__version__ = get_versions()['version']
|
||||
del get_versions
|
||||
|
|
|
@ -41,9 +41,9 @@ def get_config():
|
|||
cfg = VersioneerConfig()
|
||||
cfg.VCS = "git"
|
||||
cfg.style = "pep440"
|
||||
cfg.tag_prefix = "nilmrun-"
|
||||
cfg.parentdir_prefix = "nilmrun-"
|
||||
cfg.versionfile_source = "nilmrun/_version.py"
|
||||
cfg.tag_prefix = "nilmdb-"
|
||||
cfg.parentdir_prefix = "nilmdb-"
|
||||
cfg.versionfile_source = "nilmdb/_version.py"
|
||||
cfg.verbose = False
|
||||
return cfg
|
||||
|
||||
|
@ -86,20 +86,20 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
|
|||
if e.errno == errno.ENOENT:
|
||||
continue
|
||||
if verbose:
|
||||
print("unable to run %s" % dispcmd)
|
||||
print(("unable to run %s" % dispcmd))
|
||||
print(e)
|
||||
return None, None
|
||||
else:
|
||||
if verbose:
|
||||
print("unable to find command, tried %s" % (commands,))
|
||||
print(("unable to find command, tried %s" % (commands,)))
|
||||
return None, None
|
||||
stdout = p.communicate()[0].strip()
|
||||
if sys.version_info[0] >= 3:
|
||||
stdout = stdout.decode()
|
||||
if p.returncode != 0:
|
||||
if verbose:
|
||||
print("unable to run %s (error)" % dispcmd)
|
||||
print("stdout was %s" % stdout)
|
||||
print(("unable to run %s (error)" % dispcmd))
|
||||
print(("stdout was %s" % stdout))
|
||||
return None, p.returncode
|
||||
return stdout, p.returncode
|
||||
|
||||
|
@ -124,8 +124,8 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
|
|||
root = os.path.dirname(root) # up a level
|
||||
|
||||
if verbose:
|
||||
print("Tried directories %s but none started with prefix %s" %
|
||||
(str(rootdirs), parentdir_prefix))
|
||||
print(("Tried directories %s but none started with prefix %s" %
|
||||
(str(rootdirs), parentdir_prefix)))
|
||||
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
|
||||
|
||||
|
||||
|
@ -192,15 +192,15 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
|
|||
# "stabilization", as well as "HEAD" and "master".
|
||||
tags = set([r for r in refs if re.search(r'\d', r)])
|
||||
if verbose:
|
||||
print("discarding '%s', no digits" % ",".join(refs - tags))
|
||||
print(("discarding '%s', no digits" % ",".join(refs - tags)))
|
||||
if verbose:
|
||||
print("likely tags: %s" % ",".join(sorted(tags)))
|
||||
print(("likely tags: %s" % ",".join(sorted(tags))))
|
||||
for ref in sorted(tags):
|
||||
# sorting will prefer e.g. "2.0" over "2.0rc1"
|
||||
if ref.startswith(tag_prefix):
|
||||
r = ref[len(tag_prefix):]
|
||||
if verbose:
|
||||
print("picking %s" % r)
|
||||
print(("picking %s" % r))
|
||||
return {"version": r,
|
||||
"full-revisionid": keywords["full"].strip(),
|
||||
"dirty": False, "error": None,
|
||||
|
@ -229,7 +229,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
|
|||
hide_stderr=True)
|
||||
if rc != 0:
|
||||
if verbose:
|
||||
print("Directory %s not under git control" % root)
|
||||
print(("Directory %s not under git control" % root))
|
||||
raise NotThisMethod("'git rev-parse --git-dir' returned error")
|
||||
|
||||
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
|
||||
|
@ -278,7 +278,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
|
|||
if not full_tag.startswith(tag_prefix):
|
||||
if verbose:
|
||||
fmt = "tag '%s' doesn't start with prefix '%s'"
|
||||
print(fmt % (full_tag, tag_prefix))
|
||||
print((fmt % (full_tag, tag_prefix)))
|
||||
pieces["error"] = ("tag '%s' doesn't start with prefix '%s'"
|
||||
% (full_tag, tag_prefix))
|
||||
return pieces
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
#!/usr/bin/python
|
||||
|
||||
from nilmdb.utils.printf import *
|
||||
|
||||
import threading
|
||||
import subprocess
|
||||
|
@ -13,11 +15,9 @@ import tempfile
|
|||
import atexit
|
||||
import shutil
|
||||
|
||||
|
||||
class ProcessError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class LogReceiver(object):
|
||||
"""Spawn a thread that listens to a pipe for log messages,
|
||||
and stores them locally."""
|
||||
|
@ -41,7 +41,6 @@ class LogReceiver(object):
|
|||
def clear(self):
|
||||
self.log = io.BytesIO()
|
||||
|
||||
|
||||
class Process(object):
|
||||
"""Spawn and manage a subprocess, and capture its output."""
|
||||
def __init__(self, argv, tempfile = None):
|
||||
|
@ -181,7 +180,6 @@ class Process(object):
|
|||
pass
|
||||
return d
|
||||
|
||||
|
||||
class ProcessManager(object):
|
||||
"""Track and manage a collection of Process objects"""
|
||||
def __init__(self):
|
||||
|
@ -262,8 +260,7 @@ class ProcessManager(object):
|
|||
|
||||
def get_info(self):
|
||||
"""Get info about all running PIDs"""
|
||||
info = {
|
||||
"total": Process.get_empty_info(),
|
||||
info = { "total" : Process.get_empty_info(),
|
||||
"pids" : {},
|
||||
"system" : {}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
"""CherryPy-based server for running NILM filters via HTTP"""
|
||||
|
||||
import cherrypy
|
||||
import sys
|
||||
import os
|
||||
import socket
|
||||
import json
|
||||
import traceback
|
||||
import time
|
||||
|
||||
from nilmdb.utils.printf import sprintf
|
||||
import nilmdb
|
||||
from nilmdb.utils.printf import *
|
||||
from nilmdb.server.serverutil import (
|
||||
chunked_response,
|
||||
response_type,
|
||||
exception_to_httperror,
|
||||
CORS_allow,
|
||||
json_to_request_params,
|
||||
|
@ -17,12 +23,10 @@ from nilmdb.server.serverutil import (
|
|||
)
|
||||
from nilmdb.utils import serializer_proxy
|
||||
import nilmrun
|
||||
import nilmrun.processmanager
|
||||
|
||||
# Add CORS_allow tool
|
||||
cherrypy.tools.CORS_allow = cherrypy.Tool('on_start_resource', CORS_allow)
|
||||
|
||||
|
||||
# CherryPy apps
|
||||
class App(object):
|
||||
"""Root application for NILM runner"""
|
||||
|
@ -49,7 +53,6 @@ class App(object):
|
|||
def version(self):
|
||||
return nilmrun.__version__
|
||||
|
||||
|
||||
class AppProcess(object):
|
||||
|
||||
def __init__(self, manager):
|
||||
|
@ -113,7 +116,6 @@ class AppProcess(object):
|
|||
self.manager.remove(pid)
|
||||
return status
|
||||
|
||||
|
||||
class AppRun(object):
|
||||
def __init__(self, manager):
|
||||
self.manager = manager
|
||||
|
@ -152,7 +154,6 @@ class AppRun(object):
|
|||
"args must be a list of strings")
|
||||
return self.manager.run_code(code, args)
|
||||
|
||||
|
||||
class Server(object):
|
||||
def __init__(self, host = '127.0.0.1', port = 8080,
|
||||
force_traceback = False, # include traceback in all errors
|
||||
|
@ -180,10 +181,8 @@ class Server(object):
|
|||
# Set up Cross-Origin Resource Sharing (CORS) handler so we
|
||||
# can correctly respond to browsers' CORS preflight requests.
|
||||
# This also limits verbs to GET and HEAD by default.
|
||||
app_config.update({
|
||||
'tools.CORS_allow.on': True,
|
||||
'tools.CORS_allow.methods': ['GET', 'HEAD']
|
||||
})
|
||||
app_config.update({ 'tools.CORS_allow.on': True,
|
||||
'tools.CORS_allow.methods': ['GET', 'HEAD'] })
|
||||
|
||||
# Configure the 'json_in' tool to also allow other content-types
|
||||
# (like x-www-form-urlencoded), and to treat JSON as a dict that
|
||||
|
@ -227,13 +226,10 @@ class Server(object):
|
|||
def stop(self):
|
||||
cherrypy_stop()
|
||||
|
||||
|
||||
# Multiple processes and threads should be OK here, but we'll still
|
||||
# follow the NilmDB approach of having just one globally initialized
|
||||
# copy of the server object.
|
||||
_wsgi_server = None
|
||||
|
||||
|
||||
def wsgi_application(basepath): # pragma: no cover
|
||||
"""Return a WSGI application object.
|
||||
|
||||
|
@ -251,7 +247,8 @@ def wsgi_application(basepath): # pragma: no cover
|
|||
except Exception:
|
||||
# Build an error message on failure
|
||||
import pprint
|
||||
err = "Initializing nilmrun failed:\n\n"
|
||||
err = sprintf("Initializing nilmrun failed:\n\n",
|
||||
dbpath)
|
||||
err += traceback.format_exc()
|
||||
try:
|
||||
import pwd
|
||||
|
@ -266,10 +263,8 @@ def wsgi_application(basepath): # pragma: no cover
|
|||
err += sprintf("\nEnvironment:\n%s\n", pprint.pformat(environ))
|
||||
if _wsgi_server is None:
|
||||
# Serve up the error with our own mini WSGI app.
|
||||
headers = [
|
||||
('Content-type', 'text/plain'),
|
||||
('Content-length', str(len(err)))
|
||||
]
|
||||
headers = [ ('Content-type', 'text/plain'),
|
||||
('Content-length', str(len(err))) ]
|
||||
start_response("500 Internal Server Error", headers)
|
||||
return [err]
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
nilmdb>=2.0.3
|
||||
psutil==5.7.2
|
||||
nilmdb>=2.0.2
|
||||
psutil>=2.0.0
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
#!/usr/bin/python
|
||||
|
||||
from nilmdb.client.httpclient import HTTPClient, ClientError, ServerError
|
||||
from nilmdb.utils.printf import *
|
||||
|
@ -13,8 +13,7 @@ def main():
|
|||
def_url = os.environ.get("NILMRUN_URL", "http://localhost/nilmrun/")
|
||||
parser = argparse.ArgumentParser(
|
||||
description = 'Kill/remove a process from the NilmRun server',
|
||||
formatter_class = argparse.ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument("-v", "--version", action="version",
|
||||
formatter_class = argparse.ArgumentDefaultsHelpFormatter,
|
||||
version = nilmrun.__version__)
|
||||
group = parser.add_argument_group("Standard options")
|
||||
group.add_argument('-u', '--url',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
#!/usr/bin/python
|
||||
|
||||
import nilmrun.server
|
||||
import argparse
|
||||
|
@ -10,8 +10,7 @@ def main():
|
|||
|
||||
parser = argparse.ArgumentParser(
|
||||
description = 'Run the NilmRun server',
|
||||
formatter_class = argparse.ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument("-v", "--version", action="version",
|
||||
formatter_class = argparse.ArgumentDefaultsHelpFormatter,
|
||||
version = nilmrun.__version__)
|
||||
|
||||
group = parser.add_argument_group("Standard options")
|
||||
|
@ -35,6 +34,7 @@ def main():
|
|||
embedded = False
|
||||
server = nilmrun.server.Server(host = args.address,
|
||||
port = args.port,
|
||||
embedded = embedded,
|
||||
force_traceback = args.traceback)
|
||||
|
||||
# Print info
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
#!/usr/bin/python
|
||||
|
||||
from nilmdb.client.httpclient import HTTPClient, ClientError, ServerError
|
||||
from nilmdb.utils.printf import *
|
||||
import datetime_tz
|
||||
from nilmdb.utils import datetime_tz
|
||||
import nilmrun
|
||||
|
||||
import argparse
|
||||
|
@ -13,8 +13,7 @@ def main():
|
|||
def_url = os.environ.get("NILMRUN_URL", "http://localhost/nilmrun/")
|
||||
parser = argparse.ArgumentParser(
|
||||
description = 'List NilmRun processes',
|
||||
formatter_class = argparse.ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument("-v", "--version", action="version",
|
||||
formatter_class = argparse.ArgumentDefaultsHelpFormatter,
|
||||
version = nilmrun.__version__)
|
||||
group = parser.add_argument_group("Standard options")
|
||||
group.add_argument('-u', '--url',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
#!/usr/bin/python
|
||||
|
||||
from nilmdb.client.httpclient import HTTPClient, ClientError, ServerError
|
||||
from nilmdb.utils.printf import *
|
||||
|
@ -14,8 +14,7 @@ def main():
|
|||
def_url = os.environ.get("NILMRUN_URL", "http://localhost/nilmrun/")
|
||||
parser = argparse.ArgumentParser(
|
||||
description = 'Run a command on the NilmRun server',
|
||||
formatter_class = argparse.ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument("-v", "--version", action="version",
|
||||
formatter_class = argparse.ArgumentDefaultsHelpFormatter,
|
||||
version = nilmrun.__version__)
|
||||
group = parser.add_argument_group("Standard options")
|
||||
group.add_argument('-u', '--url',
|
||||
|
@ -31,8 +30,7 @@ def main():
|
|||
help="Arguments for command")
|
||||
args = parser.parse_args()
|
||||
|
||||
client = HTTPClient(baseurl=args.url, verify_ssl=not args.noverify,
|
||||
post_json=True)
|
||||
client = HTTPClient(baseurl = args.url, verify_ssl = not args.noverify)
|
||||
|
||||
# Run command
|
||||
pid = client.post("run/command", { "argv": [ args.cmd ] + args.arg })
|
||||
|
|
|
@ -28,11 +28,3 @@ versionfile_source=nilmrun/_version.py
|
|||
versionfile_build=nilmrun/_version.py
|
||||
tag_prefix=nilmrun-
|
||||
parentdir_prefix=nilmrun-
|
||||
|
||||
[flake8]
|
||||
exclude=_version.py
|
||||
extend-ignore=E731
|
||||
|
||||
[pylint]
|
||||
ignore=_version.py
|
||||
disable=C0103,C0111,R0913,R0914
|
||||
|
|
2
setup.py
2
setup.py
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
#!/usr/bin/python
|
||||
|
||||
# To release a new version, tag it:
|
||||
# git tag -a nilmrun-1.1 -m "Version 1.1"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
#!/usr/bin/python
|
||||
|
||||
import nose
|
||||
import os
|
||||
|
|
|
@ -276,11 +276,11 @@ https://creativecommons.org/publicdomain/zero/1.0/ .
|
|||
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
try:
|
||||
import configparser
|
||||
except ImportError:
|
||||
import ConfigParser as configparser
|
||||
import configparser as configparser
|
||||
import errno
|
||||
import json
|
||||
import os
|
||||
|
|
Loading…
Reference in New Issue
Block a user