mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-30 00:00:11 +01:00
python: flake8 liniting
This commit is contained in:
parent
c7fd20e478
commit
f6ef7265ce
7 changed files with 177 additions and 142 deletions
|
@ -1,4 +1,3 @@
|
|||
import os
|
||||
from setuptools import setup, find_namespace_packages
|
||||
from glob import glob
|
||||
|
||||
|
@ -20,7 +19,8 @@ setup(
|
|||
classifiers=[
|
||||
'Development Status :: 4 - Beta',
|
||||
'Topic :: Scientific/Engineering',
|
||||
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
|
||||
'License :: OSI Approved :: '
|
||||
'GNU General Public License v3 or later (GPLv3+)',
|
||||
'Operating System :: MacOS :: MacOS X',
|
||||
'Operating System :: Microsoft :: Windows',
|
||||
'Operating System :: POSIX :: Linux',
|
||||
|
@ -35,4 +35,3 @@ setup(
|
|||
],
|
||||
scripts=glob('bin/*')
|
||||
)
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
from message import Message
|
||||
from timestamp import Timestamp
|
||||
from message import Message # noqa F401
|
||||
from timestamp import Timestamp # noqa F401
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import .timestamp
|
||||
import villas.human.timestamp as ts
|
||||
from functools import total_ordering
|
||||
|
||||
|
||||
@total_ordering
|
||||
class Message:
|
||||
"""Parsing a VILLASnode sample from a file (not a UDP package!!)"""
|
||||
|
||||
|
@ -9,7 +12,7 @@ class Message:
|
|||
self.values = values
|
||||
|
||||
@classmethod
|
||||
def parse(self, line, source = None):
|
||||
def parse(cls, line, source=None):
|
||||
csv = line.split()
|
||||
|
||||
t = ts.Timestamp.parse(csv[0])
|
||||
|
@ -20,5 +23,8 @@ class Message:
|
|||
def __str__(self):
|
||||
return '%s %s' % (self.ts, " ".join(map(str, self.values)))
|
||||
|
||||
def __cmp__(self, other):
|
||||
return cmp(self.ts, other.ts)
|
||||
def __eq__(self, other):
|
||||
return self.ts == other.ts
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.ts < other.ts
|
||||
|
|
|
@ -1,19 +1,24 @@
|
|||
import re
|
||||
from functools import total_ordering
|
||||
|
||||
|
||||
@total_ordering
|
||||
class Timestamp:
|
||||
"""Parsing the VILLASnode human-readable timestamp format"""
|
||||
|
||||
def __init__(self, seconds = 0, nanoseconds = None, offset = None, sequence = None):
|
||||
def __init__(self, seconds=0, nanoseconds=None,
|
||||
offset=None, sequence=None):
|
||||
self.seconds = seconds
|
||||
self.nanoseconds = nanoseconds
|
||||
self.offset = offset
|
||||
self.sequence = sequence
|
||||
|
||||
@classmethod
|
||||
def parse(self, ts):
|
||||
m = re.match('(\d+)(?:\.(\d+))?([-+]\d+(?:\.\d+)?(?:e[+-]?\d+)?)?(?:\((\d+)\))?', ts)
|
||||
def parse(cls, ts):
|
||||
m = re.match(r'(\d+)(?:\.(\d+))?([-+]\d+(?:\.\d+)?'
|
||||
r'(?:e[+-]?\d+)?)?(?:\((\d+)\))?', ts)
|
||||
|
||||
seconds = int(m.group(1)); # Mandatory
|
||||
seconds = int(m.group(1)) # Mandatory
|
||||
nanoseconds = int(m.group(2)) if m.group(2) else None
|
||||
offset = float(m.group(3)) if m.group(3) else None
|
||||
sequence = int(m.group(4)) if m.group(4) else None
|
||||
|
@ -42,5 +47,8 @@ class Timestamp:
|
|||
|
||||
return sum
|
||||
|
||||
def __cmp__(self, other):
|
||||
return cmp(float(self), float(other))
|
||||
def __eg__(self, other):
|
||||
return float(self) == float(other)
|
||||
|
||||
def __lt__(self, other):
|
||||
return float(self) < float(other)
|
||||
|
|
|
@ -7,6 +7,7 @@ from threading import Thread
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RecvThread(Thread):
|
||||
|
||||
def __init__(self, cb):
|
||||
|
|
|
@ -9,9 +9,12 @@ import datetime
|
|||
|
||||
LOGGER = logging.getLogger('villas.node')
|
||||
|
||||
|
||||
class Node(object):
|
||||
|
||||
def __init__(self, log_filename = None, config_filename = None, config = { }, api = 'http://localhost:8080', executable = 'villas-node', **kwargs):
|
||||
def __init__(self, log_filename=None, config_filename=None,
|
||||
config={}, api='http://localhost:8080',
|
||||
executable='villas-node', **kwargs):
|
||||
self.config = config
|
||||
self.config_filename = config_filename
|
||||
self.log_filename = log_filename
|
||||
|
@ -21,7 +24,8 @@ class Node(object):
|
|||
self.child = None
|
||||
|
||||
def start(self):
|
||||
self.config_file = tempfile.NamedTemporaryFile(mode='w+', suffix='.json')
|
||||
self.config_file = tempfile.NamedTemporaryFile(mode='w+',
|
||||
suffix='.json')
|
||||
|
||||
if self.config_filename:
|
||||
with open(self.config_filename) as f:
|
||||
|
@ -33,13 +37,16 @@ class Node(object):
|
|||
|
||||
if self.log_filename is None:
|
||||
now = datetime.datetime.now()
|
||||
self.log_filename = now.strftime('villas-node_%Y-%m-%d_%H-%M-%S.log')
|
||||
self.log_filename = now.strftime(
|
||||
'villas-node_%Y-%m-%d_%H-%M-%S.log')
|
||||
|
||||
self.log = open(self.log_filename, 'w+')
|
||||
|
||||
LOGGER.info("Starting VILLASnode instance with config: %s", self.config_file.name)
|
||||
LOGGER.info("Starting VILLASnode instance with config: %s",
|
||||
self.config_file.name)
|
||||
|
||||
self.child = subprocess.Popen([self.executable, self.config_file.name], stdout=self.log, stderr=self.log)
|
||||
self.child = subprocess.Popen([self.executable, self.config_file.name],
|
||||
stdout=self.log, stderr=self.log)
|
||||
|
||||
def pause(self):
|
||||
LOGGER.info("Pausing VILLASnode instance")
|
||||
|
|
|
@ -1,29 +1,35 @@
|
|||
import re
|
||||
from datetime import datetime
|
||||
from functools import total_ordering
|
||||
|
||||
|
||||
@total_ordering
|
||||
class Timestamp:
|
||||
"""Parsing the VILLASnode human-readable timestamp format"""
|
||||
|
||||
def __init__(self, seconds=None, nanoseconds=None, offset=None, sequence=None):
|
||||
def __init__(self, seconds=None, nanoseconds=None,
|
||||
offset=None, sequence=None):
|
||||
self.seconds = seconds
|
||||
self.nanoseconds = nanoseconds
|
||||
self.offset = offset
|
||||
self.sequence = sequence
|
||||
|
||||
@classmethod
|
||||
def now(self, offset=None, sequence=None):
|
||||
def now(cls, offset=None, sequence=None):
|
||||
n = datetime.utcnow()
|
||||
|
||||
secs = int(n.timestamp())
|
||||
nsecs = 1000 * n.microsecond
|
||||
|
||||
return Timestamp(seconds=secs, nanoseconds=nsecs, offset=offset, sequence=sequence)
|
||||
return Timestamp(seconds=secs, nanoseconds=nsecs,
|
||||
offset=offset, sequence=sequence)
|
||||
|
||||
@classmethod
|
||||
def parse(self, ts):
|
||||
m = re.match('(\d+)(?:\.(\d+))?([-+]\d+(?:\.\d+)?(?:e[+-]?\d+)?)?(?:\((\d+)\))?', ts)
|
||||
def parse(cls, ts):
|
||||
m = re.match(r'(\d+)(?:\.(\d+))?([-+]\d+(?:\.\d+)?'
|
||||
r'(?:e[+-]?\d+)?)?(?:\((\d+)\))?', ts)
|
||||
|
||||
seconds = int(m.group(1)); # Mandatory
|
||||
seconds = int(m.group(1)) # Mandatory
|
||||
nanoseconds = int(m.group(2)) if m.group(2) else None
|
||||
offset = float(m.group(3)) if m.group(3) else None
|
||||
sequence = int(m.group(4)) if m.group(4) else None
|
||||
|
@ -52,9 +58,14 @@ class Timestamp:
|
|||
|
||||
return sum
|
||||
|
||||
def __cmp__(self, other):
|
||||
return cmp(float(self), float(other))
|
||||
def __eq__(self, other):
|
||||
return float(self) == float(other)
|
||||
|
||||
def __lt__(self, other):
|
||||
return float(self) < float(other)
|
||||
|
||||
|
||||
@total_ordering
|
||||
class Sample:
|
||||
"""Parsing a VILLASnode sample from a file (not a UDP package!!)"""
|
||||
|
||||
|
@ -63,7 +74,7 @@ class Sample:
|
|||
self.values = values
|
||||
|
||||
@classmethod
|
||||
def parse(self, line):
|
||||
def parse(cls, line):
|
||||
csv = line.split()
|
||||
|
||||
ts = Timestamp.parse(csv[0])
|
||||
|
@ -76,7 +87,7 @@ class Sample:
|
|||
value = value.lower()
|
||||
try:
|
||||
v = complex(value)
|
||||
except:
|
||||
except Exception:
|
||||
if value.endswith('i'):
|
||||
v = complex(value.replace('i', 'j'))
|
||||
else:
|
||||
|
@ -89,5 +100,8 @@ class Sample:
|
|||
def __str__(self):
|
||||
return '%s %s' % (self.ts, " ".join(map(str, self.values)))
|
||||
|
||||
def __cmp__(self, other):
|
||||
return cmp(self.ts, other.ts)
|
||||
def __eq__(self, other):
|
||||
return self.ts == other.ts
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.ts < other.ts
|
||||
|
|
Loading…
Add table
Reference in a new issue