Remove py2 support

Change-Id: Ieeaeb3b8efcae004e94aea6c1d2703c9782a8650
Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/21320
Tested-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
This commit is contained in:
Enrico Faulhaber
2019-09-25 17:45:26 +02:00
parent 04032079d7
commit 70a9c42a7a
59 changed files with 458 additions and 667 deletions

View File

@ -32,21 +32,20 @@ import subprocess
import sys
import threading
import traceback
import unicodedata
from os import path
repodir = path.abspath(path.join(path.dirname(__file__), u'..', u'..'))
repodir = path.abspath(path.join(path.dirname(__file__), '..', '..'))
CONFIG = {
u'piddir': os.path.join(repodir, u'pid'),
u'logdir': os.path.join(repodir, u'log'),
u'confdir': os.path.join(repodir, u'cfg'),
u'basedir': repodir,
} if os.path.exists(os.path.join(repodir, u'.git')) else {
u'piddir': u'/var/run/secop',
u'logdir': u'/var/log',
u'confdir': u'/etc/secop',
u'basedir': repodir,
'piddir': os.path.join(repodir, 'pid'),
'logdir': os.path.join(repodir, 'log'),
'confdir': os.path.join(repodir, 'etc'),
'basedir': repodir,
} if os.path.exists(os.path.join(repodir, '.git')) else {
'piddir': '/var/run/secop',
'logdir': '/var/log',
'confdir': '/etc/secop',
'basedir': repodir,
}

View File

@ -22,15 +22,9 @@
# *****************************************************************************
"""Enum class"""
from __future__ import division, print_function
__ALL__ = ['Enum']
try:
text_type = unicode # Py2
except NameError:
text_type = str # Py3
unicode = str # pylint: disable=redefined-builtin
class EnumMember(object):
"""represents one member of an Enum
@ -49,7 +43,7 @@ class EnumMember(object):
def __cmp__(self, other):
if isinstance(other, EnumMember):
other = other.value
if isinstance(other, (str, unicode)):
if isinstance(other, str):
if other in self.enum:
other = self.enum[other].value
try:
@ -73,7 +67,7 @@ class EnumMember(object):
if isinstance(other, int):
return other == self.value
# compare by name (for (in)equality only)
if isinstance(other, (str, unicode)):
if isinstance(other, str):
if other in self.enum:
return self.name == other
return False
@ -114,8 +108,6 @@ class EnumMember(object):
return self.value.__sub__(other.value if isinstance(other, EnumMember) else other)
def __mul__(self, other):
return self.value.__mul__(other.value if isinstance(other, EnumMember) else other)
def __div__(self, other):
return self.value.__div__(other.value if isinstance(other, EnumMember) else other)
def __truediv__(self, other):
return self.value.__truediv__(other.value if isinstance(other, EnumMember) else other)
def __floordiv__(self, other):
@ -137,8 +129,6 @@ class EnumMember(object):
return self.value.__rsub__(other.value if isinstance(other, EnumMember) else other)
def __rmul__(self, other):
return self.value.__rmul__(other.value if isinstance(other, EnumMember) else other)
def __rdiv__(self, other):
return self.value.__rdiv__(other.value if isinstance(other, EnumMember) else other)
def __rtruediv__(self, other):
return self.value.__rtruediv__(other.value if isinstance(other, EnumMember) else other)
def __rfloordiv__(self, other):
@ -181,10 +171,6 @@ class EnumMember(object):
def __float__(self):
return self.value.__float__()
#return NotImplemented # makes no sense
def __oct__(self):
return self.value.__oct__()
def __hex__(self):
return self.value.__hex__()
def __index__(self):
return self.value.__index__()
@ -234,7 +220,7 @@ class Enum(dict):
name=parent.name
# else:
# raise TypeError('Enum instances need a name or an Enum parent!')
if not isinstance(name, (str, text_type)):
if not isinstance(name, str):
raise TypeError('1st argument to Enum must be a name or an Enum!')
names = set()

View File

@ -1,44 +0,0 @@
# -*- coding: utf-8 -*-
# *****************************************************************************
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Module authors:
# Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
#
# *****************************************************************************
"""Define metaclass helper"""
from __future__ import division, print_function
try:
# pylint: disable=unused-import
from six import add_metaclass # for py2/3 compat
except ImportError:
# copied from six v1.10.0
def add_metaclass(metaclass):
"""Class decorator for creating a class with a metaclass."""
def wrapper(cls):
orig_vars = cls.__dict__.copy()
slots = orig_vars.get('__slots__')
if slots is not None:
if isinstance(slots, str):
slots = [slots]
for slots_var in slots:
orig_vars.pop(slots_var)
orig_vars.pop('__dict__', None)
orig_vars.pop('__weakref__', None)
return metaclass(cls.__name__, cls.__bases__, orig_vars)
return wrapper

View File

@ -21,7 +21,6 @@
# *****************************************************************************
"""Define parsing helpers"""
from __future__ import division, print_function
import re
import time
@ -144,7 +143,7 @@ def format_args(args):
return ','.join(format_args(arg) for arg in args).join('[]')
if isinstance(args, tuple):
return ','.join(format_args(arg) for arg in args).join('()')
if isinstance(args, (str, unicode)):
if isinstance(args, str):
# XXX: check for 'easy' strings only and omit the ''
return repr(args)
return repr(args) # for floats/ints/...

View File

@ -20,7 +20,6 @@
#
# *****************************************************************************
"""Define pidfile helpers"""
from __future__ import division, print_function
import atexit
import os

View File

@ -23,7 +23,6 @@
"""Utilities for modules that require sequenced actions on value change."""
from __future__ import division, print_function
from time import sleep
@ -74,7 +73,7 @@ class SequencerMixin(object):
self._seq_fault_on_error = fault_on_error
self._seq_fault_on_stop = fault_on_stop
self._seq_stopflag = False
self._seq_phase = u''
self._seq_phase = ''
self._seq_error = None
self._seq_stopped = None
@ -116,7 +115,7 @@ class SequencerMixin(object):
the default is to only go into ALARM.
"""
if self.seq_is_alive():
raise IsBusyError(u'move sequence already in progress')
raise IsBusyError('move sequence already in progress')
self._seq_stopflag = False
self._seq_error = self._seq_stopped = None
@ -129,7 +128,7 @@ class SequencerMixin(object):
def read_status(self):
if self.seq_is_alive():
return self.Status.BUSY, u'moving: ' + self._seq_phase
return self.Status.BUSY, 'moving: ' + self._seq_phase
elif self._seq_error:
if self._seq_fault_on_error:
return self.Status.ERROR, self._seq_error
@ -138,9 +137,9 @@ class SequencerMixin(object):
if self._seq_fault_on_stop:
return self.Status.ERROR, self._seq_stopped
return self.Status.WARN, self._seq_stopped
if hasattr(self, u'read_hw_status'):
if hasattr(self, 'read_hw_status'):
return self.read_hw_status()
return self.Status.IDLE, u''
return self.Status.IDLE, ''
def do_stop(self):
if self.seq_is_alive():
@ -150,7 +149,7 @@ class SequencerMixin(object):
try:
self._seq_thread_inner(seq, store_init)
except Exception as e:
self.log.exception(u'unhandled error in sequence thread: %s', e)
self.log.exception('unhandled error in sequence thread: %s', e)
self._seq_error = str(e)
finally:
self._seq_thread = None
@ -159,11 +158,11 @@ class SequencerMixin(object):
def _seq_thread_inner(self, seq, store_init):
store = Namespace()
store.__dict__.update(store_init)
self.log.debug(u'sequence: starting, values %s', store_init)
self.log.debug('sequence: starting, values %s', store_init)
for step in seq:
self._seq_phase = step.desc
self.log.debug(u'sequence: entering phase: %s', step.desc)
self.log.debug('sequence: entering phase: %s', step.desc)
try:
i = 0
while True:
@ -171,10 +170,10 @@ class SequencerMixin(object):
result = step.func(store, *step.args)
if self._seq_stopflag:
if result:
self._seq_stopped = u'stopped while %s' % step.desc
self._seq_stopped = 'stopped while %s' % step.desc
else:
self._seq_stopped = u'stopped after %s' % step.desc
cleanup_func = step.kwds.get(u'cleanup', None)
self._seq_stopped = 'stopped after %s' % step.desc
cleanup_func = step.kwds.get('cleanup', None)
if callable(cleanup_func):
try:
cleanup_func(store, result, *step.args)
@ -188,6 +187,6 @@ class SequencerMixin(object):
i += 1
except Exception as e:
self.log.exception(
u'error in sequence step %r: %s', step.desc, e)
self._seq_error = u'during %s: %s' % (step.desc, e)
'error in sequence step %r: %s', step.desc, e)
self._seq_error = 'during %s: %s' % (step.desc, e)
break