summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2012-06-22 13:23:51 +0200
committerFlorian Bruhin <me@the-compiler.org>2012-06-22 13:23:51 +0200
commit9c997feb12d316ba7d6a3f13eb45e35914957bc7 (patch)
tree8e07f7df24bd6ebd0d0e036b4248aa70337644f3
parent3a3207d6d60fb214615ce8fa3d9cfd7943bf665d (diff)
downloadxdd2esi-9c997feb12d316ba7d6a3f13eb45e35914957bc7.tar.gz
xdd2esi-9c997feb12d316ba7d6a3f13eb45e35914957bc7.zip
PEP8
-rw-r--r--canlib.py5
-rw-r--r--esilib.py45
-rw-r--r--setup.py15
-rw-r--r--xdd2esi.py73
-rw-r--r--xdd2esilib.py9
-rw-r--r--xddlib.py9
6 files changed, 66 insertions, 90 deletions
diff --git a/canlib.py b/canlib.py
index f6e839f..393c1cb 100644
--- a/canlib.py
+++ b/canlib.py
@@ -1,11 +1,8 @@
#!/usr/bin/python
# vim: set fileencoding=utf-8 tabstop=8 expandtab shiftwidth=4 softtabstop=4 :
-"""
-canlib.py
-
+""" canlib.py
Represents CAN objects and datatypes
-
Florian Bruhin
"""
diff --git a/esilib.py b/esilib.py
index 91ccf2b..cc718d9 100644
--- a/esilib.py
+++ b/esilib.py
@@ -1,11 +1,8 @@
#!/usr/bin/python
# vim: set fileencoding=utf-8 tabstop=8 expandtab shiftwidth=4 softtabstop=4 :
-"""
-esilib.py
-
+""" esilib.py
Python-library to write the Device Profile part of an ESI XML file
-
Florian Bruhin
"""
@@ -48,8 +45,8 @@ class ESIFile:
""" Represents the device profile part of an ESI XML file """
def __init__(self, versioninfo=None):
self.dicttree = etree.Element("Dictionary")
- infoline = "Generated by {} on {}".format(versioninfo,
- datetime.datetime.now().ctime())
+ infoline = "Generated by {} on {}".format(
+ versioninfo, datetime.datetime.now().ctime())
_append_comment(self.dicttree, infoline)
self.dt_simple = etree.Element("DataTypes")
self.dt_middle = etree.Element("DataTypes")
@@ -108,9 +105,8 @@ class ESIFile:
InvalidESIWarning)
def merge_from_template(self, filename):
- """
- Replaces dicttree with the tree of the template file,
- with the dictionary-part replaced by the new data
+ """ Replaces dicttree with the tree of the template file, with the
+ dictionary-part replaced by the new data
"""
xpath = ("/EtherCATInfo/Descriptions/Devices/Device[1]/Profile[1]/"
"Dictionary")
@@ -146,9 +142,7 @@ class ESIFile:
return (esitype, esisize)
def add_record_datatype(self, esiname):
- """
- Adds a datatype for a record.
-
+ """ Adds a datatype for a record.
esiname: A human readable name like "DT1003"
"""
# Bitsize will be set later
@@ -159,13 +153,10 @@ class ESIFile:
def add_array_datatype(self, esiname, basetype, elements, lbound=0,
octet=False):
- """
- Adds a datatype for an array.
-
+ """ Adds a datatype for an array.
datatype: Basetype of the array
elements: Number of elements
lbound: ???, <LBound>-Tag
-
"""
(esitype, esisize) = type_to_esitype(basetype)
if octet:
@@ -323,14 +314,16 @@ def _esitype_int(datatype):
try:
signstring = signstrings[datatype.signed]
except KeyError:
- warnings.warn("Got datatype {} of type int without sign information, "
- "assuming signed!".format(datatype.name), NoSignInformationWarning)
+ warnings.warn(
+ "Got datatype {} of type int without sign information, assuming "
+ "signed!".format(datatype.name), NoSignInformationWarning)
signstring = ''
try:
sizestring = sizestrings[datatype.size]
except KeyError:
- warnings.warn("Got datatype {} of type int with an invalid size, "
- "assuming 16 bit!".format(datatype.name), InvalidSizeWarning)
+ warnings.warn(
+ "Got datatype {} of type int with an invalid size, assuming 16 "
+ "bit!".format(datatype.name), InvalidSizeWarning)
esisize = 16
sizestring = sizestrings[esisize]
else:
@@ -342,8 +335,9 @@ def _esitype_float(datatype):
""" Converts float-py-datatypes to ESI """
allowed_sizes = [ 32, 64 ]
if datatype.size not in allowed_sizes:
- warnings.warn("Got datatype {} of type float with an invalid size, "
- "assuming 32 bit!".format(datatype.name), InvalidSizeWarning)
+ warnings.warn(
+ "Got datatype {} of type float with an invalid size, assuming 32 "
+ "bit!".format(datatype.name), InvalidSizeWarning)
esisize = 32
else:
esisize = datatype.size
@@ -369,7 +363,7 @@ def _esitype_oct(datatype):
esisize = datatype.size
if datatype.type_ == 'octet':
pybasetype = canlib.Datatype(False, 'integer', 8, "OCTET({})".format(
- esilength), esilength)
+ esilength), esilength)
elif datatype.type_ == 'unicode':
pybasetype = canlib.Datatype(False, 'integer', 16, "UNICODE({})".
format(esilength), esilength)
@@ -382,14 +376,11 @@ def _append_comment(root, comment):
root.append(etree.Comment(comment))
def _append_elements(root, subnode, attrs, force=False):
- """
- Appends new datatype or object to the tree.
-
+ """ Appends new datatype or object to the tree.
root: dttree, objtree, ...
subnode: "DataType", "Object", "SubItem", ...
attrs: [ ("Name", "UDINT"), ("BitSize", 32), ... ]
force: If true, add subnode even if attrs are None
-
An example: If the objtree is empty at the moment, and you do:
_append_elements(objtree, "Object", [("Name", "foobar")]
it gets:
diff --git a/setup.py b/setup.py
index 72a5e7e..801ad5f 100644
--- a/setup.py
+++ b/setup.py
@@ -1,17 +1,10 @@
#!/usr/bin/python
# vim: set fileencoding=utf-8 tabstop=8 expandtab shiftwidth=4 softtabstop=4 :
+""" Builds a standalone executable using cx_freeze """
from cx_Freeze import setup, Executable
includes = ["lxml._elementpath", "gzip", "inspect"]
-
-setup(
- options = {
- "build_exe" : {
- "includes": includes,
- },
- },
- description = "Converter von xdd zu esi",
- executables = [Executable("xdd2esi.py")]
-)
-
+setup(options = { "build_exe" : { "includes": includes, }, },
+ description = "Converter von xdd zu esi",
+ executables = [Executable("xdd2esi.py")])
diff --git a/xdd2esi.py b/xdd2esi.py
index 73f57c1..89bd5a8 100644
--- a/xdd2esi.py
+++ b/xdd2esi.py
@@ -1,11 +1,8 @@
#!/usr/bin/python
# vim: set fileencoding=utf-8 tabstop=8 expandtab shiftwidth=4 softtabstop=4 :
-"""
-xdd2esi.py
-
+""" xdd2esi.py
User interface for xdd2esilib.py
-
30. May 2012
"""
@@ -20,43 +17,49 @@ _versioninfo = "xdd2esi v{}".format(__version__)
def parseargs():
""" Parse the command-line arguments """
parser = argparse.ArgumentParser(
- description='Convert XDD files to ESI files',
- epilog='Florian Bruhin')
-
+ description='Convert XDD files to ESI files',
+ epilog='Florian Bruhin')
# Positional
parser.add_argument('infile', default=None, help='Input file')
- parser.add_argument('outfile', default=None,
- help='Output file (-: stdout)')
- parser.add_argument('-v', '--version', help='Show the version of this '
- 'script', action='version', version="%(prog)s {}".format(__version__))
-
+ parser.add_argument(
+ 'outfile', default=None,
+ help='Output file (-: stdout)')
+ parser.add_argument(
+ '-v', '--version', help='Show the version of this script',
+ action='version', version="%(prog)s {}".format(__version__))
# Conversion
convertopts = parser.add_argument_group("Conversion options")
- convertopts.add_argument('-s', '--shift', default=None, nargs=3,
- metavar=('start_range', 'end_range', 'offset'), action='append',
- help="Shift IDs <startrange> to <endrange> by <offset> (may be used "
- "multiple times)", type=opt_hexint)
- convertopts.add_argument('-t', '--template', metavar='template_file',
- action='store', help="Replace <Dictionary>-Tree in template-file")
- convertopts.add_argument('-f', '--force', help="Don't treat warnings as "
- "errors", action='store_true')
- convertopts.add_argument('-S', '--schema', metavar='xml_schema',
- action='store', help="Verify output with an xml-schema")
+ convertopts.add_argument(
+ '-s', '--shift', default=None, nargs=3,
+ metavar=('start_range', 'end_range', 'offset'), action='append',
+ help="Shift IDs <startrange> to <endrange> by <offset> (may be used "
+ "multiple times)", type=opt_hexint)
+ convertopts.add_argument(
+ '-t', '--template', metavar='template_file', action='store',
+ help="Replace <Dictionary>-Tree in template-file")
+ convertopts.add_argument(
+ '-f', '--force', help="Don't treat warnings as errors",
+ action='store_true')
+ convertopts.add_argument(
+ '-S', '--schema', metavar='xml_schema', action='store',
+ help="Verify output with an xml-schema")
# --ugly and --nobasic store inverted values
- convertopts.add_argument('-u', '--ugly', help="Don't pretty-print",
- action='store_false', default=True, dest='pretty')
- convertopts.add_argument('-n', '--nobasic', help="Don't add basic data "
- "types", action='store_false', default=True, dest='addbasic')
-
+ convertopts.add_argument(
+ '-u', '--ugly', help="Don't pretty-print", action='store_false',
+ default=True, dest='pretty')
+ convertopts.add_argument(
+ '-n', '--nobasic', help="Don't add basic data types",
+ action='store_false', default=True, dest='addbasic')
# Debug
debugopts = parser.add_argument_group("Debugging options")
- debugopts.add_argument('-d', '--dump', help="Dump objects after reading "
- "XDD", action='store_true', default=False)
- debugopts.add_argument('-D', '--dry-run', help="Don't actually convert, "
- "only check input file for errors", action='store_true', default=False,
- dest='dryrun')
- debugopts.add_argument('-l', '--loglevel', default='info',
- type=opt_loglevel)
+ debugopts.add_argument(
+ '-d', '--dump', help="Dump objects after reading XDD",
+ action='store_true', default=False)
+ debugopts.add_argument(
+ '-D', '--dry-run', help="Don't actually convert, only check input "
+ "file for errors", action='store_true', default=False, dest='dryrun')
+ debugopts.add_argument(
+ '-l', '--loglevel', default='info', type=opt_loglevel)
options = parser.parse_args()
return options
@@ -65,7 +68,7 @@ def opt_loglevel(loglevel):
numeric_level = getattr(logging, loglevel.upper(), None)
if not isinstance(numeric_level, int):
raise argparse.ArgumentTypeError('{} is not a valid '
- 'loglevel!'.format(loglevel))
+ 'loglevel!'.format(loglevel))
return numeric_level
def opt_hexint(num):
diff --git a/xdd2esilib.py b/xdd2esilib.py
index 78e9246..26626bc 100644
--- a/xdd2esilib.py
+++ b/xdd2esilib.py
@@ -1,11 +1,8 @@
#!/usr/bin/python
# vim: set fileencoding=utf-8 tabstop=8 expandtab shiftwidth=4 softtabstop=4 :
-"""
-xdd2esilib.py
-
+""" xdd2esilib.py
Converts xdd to esi using xddlib and esilib
-
Florian Bruhin
"""
@@ -288,8 +285,8 @@ def _convert(xdd, addbasic=True):
try:
convfunc = convfuncs[objtype]
except KeyError:
- warnings.warn("I don't know how to convert the object {}!"
- .format(obj.getidentity()), NoConvertFuncWarning)
+ warnings.warn("I don't know how to convert the object {}!".format(
+ obj.getidentity()), NoConvertFuncWarning)
else:
convfunc(obj)
diff --git a/xddlib.py b/xddlib.py
index 77d23e2..6c90e73 100644
--- a/xddlib.py
+++ b/xddlib.py
@@ -1,11 +1,8 @@
#!/usr/bin/python
# vim: set fileencoding=utf-8 tabstop=8 expandtab shiftwidth=4 softtabstop=4 :
-"""
-xddlib.py
-
+""" xddlib.py
Python-library to read the CANopenObject-Part of XDD files
-
Florian Bruhin
"""
@@ -307,9 +304,7 @@ def _convert_cast_attribute(obj, label, units):
setattr(obj, label, newvalue)
def _convert_cast_get_unit(obj, unit, value):
- """
- Gets the unit of an object attribute (from the datatype if needed)
- """
+ """ Gets the unit of an object attribute (from the datatype if needed) """
if unit == 'dt': # If the unit is 'dt', get the real unit from the
# datatype
newunit = obj.datatype.type_