| Index: emcore/trunk/tools/emcore.py |
| — | — | @@ -93,7 +93,7 @@ |
| 94 | 94 | to all functions decorated with @command
|
| 95 | 95 | """
|
| 96 | 96 | cls.cmddict = {}
|
| 97 | | - for attr, value in cls.__dict__.iteritems():
|
| | 97 | + for attr, value in cls.__dict__.items():
|
| 98 | 98 | if getattr(value, 'func', False):
|
| 99 | 99 | if getattr(value.func, '_command', False):
|
| 100 | 100 | cls.cmddict[value.func.__name__] = value
|
| — | — | @@ -125,17 +125,17 @@ |
| 126 | 126 | if func in self.cmddict:
|
| 127 | 127 | try:
|
| 128 | 128 | self.cmddict[func](*args)
|
| 129 | | - except (ArgumentError, libemcore.ArgumentError), e:
|
| | 129 | + except (ArgumentError, libemcore.ArgumentError) as e:
|
| 130 | 130 | usage(e, specific=func)
|
| 131 | 131 | except (ArgumentError, libemcore.ArgumentError):
|
| 132 | 132 | usage("Syntax Error in function '" + func + "'", specific=func)
|
| 133 | | - except ArgumentTypeError, e:
|
| | 133 | + except ArgumentTypeError as e:
|
| 134 | 134 | usage(e, specific=func)
|
| 135 | 135 | except NotImplementedError:
|
| 136 | 136 | self.logger.error("This function is not implemented yet!\n")
|
| 137 | | - except libemcore.DeviceError, e:
|
| | 137 | + except libemcore.DeviceError as e:
|
| 138 | 138 | self.logger.error(str(e) + "\n")
|
| 139 | | - except TypeError, e:
|
| | 139 | + except TypeError as e:
|
| 140 | 140 | # Only act on TypeErrors for the function we called, not on TypeErrors raised by another function.
|
| 141 | 141 | if str(e).split(" ", 1)[0] == func + "()":
|
| 142 | 142 | self.logger.error(usage("Argument Error in '%s': Wrong argument count" % func, specific=func))
|
| Index: emcore/trunk/tools/misc.py |
| — | — | @@ -250,7 +250,9 @@ |
| 251 | 251 | # and split into a list of lines:
|
| 252 | 252 | lines = docstring.expandtabs().splitlines()
|
| 253 | 253 | # Determine minimum indentation (first line doesn't count):
|
| 254 | | - indent = sys.maxint
|
| | 254 | + try: maxsize = sys.maxint
|
| | 255 | + except AttributeError: maxsize = sys.maxsize
|
| | 256 | + indent = maxsize
|
| 255 | 257 | for line in lines[1:]:
|
| 256 | 258 | stripped = line.lstrip()
|
| 257 | 259 | if stripped:
|
| — | — | @@ -257,7 +259,7 @@ |
| 258 | 260 | indent = min(indent, len(line) - len(stripped))
|
| 259 | 261 | # Remove indentation (first line is special):
|
| 260 | 262 | trimmed = [lines[0].strip()]
|
| 261 | | - if indent < sys.maxint:
|
| | 263 | + if indent < maxsize:
|
| 262 | 264 | for line in lines[1:]:
|
| 263 | 265 | trimmed.append(line[indent:].rstrip())
|
| 264 | 266 | # Strip off trailing and leading blank lines:
|
| — | — | @@ -343,6 +345,8 @@ |
| 344 | 346 | """
|
| 345 | 347 | Converts quite everything into bool.
|
| 346 | 348 | """
|
| | 349 | + try: long
|
| | 350 | + except NameError: long = int
|
| 347 | 351 | if type(something) == bool:
|
| 348 | 352 | return something
|
| 349 | 353 | if something is None:
|
| — | — | @@ -362,6 +366,8 @@ |
| 363 | 367 | This works for default arguments too, because it returns
|
| 364 | 368 | None when it found that it got a NoneType object.
|
| 365 | 369 | """
|
| | 370 | + try: long
|
| | 371 | + except NameError: long = int
|
| 366 | 372 | if type(something) == int or type(something) == long:
|
| 367 | 373 | return something
|
| 368 | 374 | elif something is None:
|
| — | — | @@ -377,4 +383,12 @@ |
| 378 | 384 | except ValueError:
|
| 379 | 385 | raise ArgumentTypeError("integer", "'%s'" % something)
|
| 380 | 386 | else:
|
| 381 | | - raise ArgumentTypeError("integer", "'%s'" % something) |
| \ No newline at end of file |
| | 387 | + raise ArgumentTypeError("integer", "'%s'" % something)
|
| | 388 | +
|
| | 389 | +
|
| | 390 | +def majorver():
|
| | 391 | + """
|
| | 392 | + Returns the major version of python
|
| | 393 | + """
|
| | 394 | + import sys
|
| | 395 | + return sys.hexversion // 0x1000000 |
| \ No newline at end of file |
| Index: emcore/trunk/tools/libemcore.py |
| — | — | @@ -30,6 +30,7 @@ |
| 31 | 31 | import struct
|
| 32 | 32 | import ctypes
|
| 33 | 33 | import usb.core
|
| | 34 | +import base64
|
| 34 | 35 |
|
| 35 | 36 | from libemcoredata import *
|
| 36 | 37 | from misc import Logger, Bunch, Error, ArgumentError, gethwname
|
| — | — | @@ -222,7 +223,7 @@ |
| 223 | 224 | """
|
| 224 | 225 | cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
| 225 | 226 | din_maxsize = self.lib.dev.packetsizelimit.din
|
| 226 | | - data = ""
|
| | 227 | + data = b""
|
| 227 | 228 | (headsize, bodysize, tailsize) = self._alignsplit(addr, size, cin_maxsize, 16)
|
| 228 | 229 | self.logger.debug("Downloading %d bytes from 0x%X, split as (%d/%d/%d)\n" % (size, addr, headsize, bodysize, tailsize))
|
| 229 | 230 | if headsize != 0:
|
| — | — | @@ -288,12 +289,12 @@ |
| 289 | 290 | string = ""
|
| 290 | 291 | while (len(string) < maxlength or maxlength < 0):
|
| 291 | 292 | data = self._readmem(addr, min(maxlength - len(string), cin_maxsize))
|
| 292 | | - length = data.find("\0")
|
| | 293 | + length = data.find(b"\0")
|
| 293 | 294 | if length >= 0:
|
| 294 | | - string += data[:length]
|
| | 295 | + string += data[:length].decode("latin_1")
|
| 295 | 296 | break
|
| 296 | 297 | else:
|
| 297 | | - string += data
|
| | 298 | + string += data.decode("latin_1")
|
| 298 | 299 | addr += cin_maxsize
|
| 299 | 300 | return string
|
| 300 | 301 |
|
| — | — | @@ -300,7 +301,7 @@ |
| 301 | 302 | @command()
|
| 302 | 303 | def i2cread(self, index, slaveaddr, startaddr, size):
|
| 303 | 304 | """ Reads data from an i2c slave """
|
| 304 | | - data = ""
|
| | 305 | + data = b""
|
| 305 | 306 | for i in range(size):
|
| 306 | 307 | resp = self.lib.monitorcommand(struct.pack("<IBBBBII", 8, index, slaveaddr, startaddr + i, 1, 0, 0), "III1s", (None, None, None, "data"))
|
| 307 | 308 | data += resp.data
|
| — | — | @@ -318,10 +319,10 @@ |
| 319 | 320 |
|
| 320 | 321 | @command()
|
| 321 | 322 | def usbcread(self):
|
| 322 | | - """ Reads one packet with the maximal cin size """
|
| | 323 | + """ Reads one packet with the maximal cin size from the console """
|
| 323 | 324 | cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
| 324 | 325 | resp = self.lib.monitorcommand(struct.pack("<IIII", 10, cin_maxsize, 0, 0), "III%ds" % cin_maxsize, ("validsize", "buffersize", "queuesize", "data"))
|
| 325 | | - resp.data = resp.data[:resp.validsize]
|
| | 326 | + resp.data = resp.data[:resp.validsize].decode("latin_1")
|
| 326 | 327 | resp.maxsize = cin_maxsize
|
| 327 | 328 | return resp
|
| 328 | 329 |
|
| — | — | @@ -918,7 +919,7 @@ |
| 919 | 920 | self.connected = True
|
| 920 | 921 |
|
| 921 | 922 | def monitorcommand(self, cmd, rcvdatatypes=None, rcvstruct=None):
|
| 922 | | - self.logger.debug("Sending monitorcommand [0x%s]\n" % cmd[3::-1].encode("hex"))
|
| | 923 | + self.logger.debug("Sending monitorcommand [0x%s]\n" % base64.b16encode(cmd[3::-1]).decode("ascii"))
|
| 923 | 924 | writelen = self.dev.cout(cmd)
|
| 924 | 925 | if rcvdatatypes:
|
| 925 | 926 | rcvdatatypes = "I" + rcvdatatypes # add the response
|
| — | — | @@ -1073,7 +1074,7 @@ |
| 1074 | 1075 | from misc import gendoc
|
| 1075 | 1076 | logger.write("Generating documentation\n")
|
| 1076 | 1077 | cmddict = {}
|
| 1077 | | - for attr, value in Emcore.__dict__.iteritems():
|
| | 1078 | + for attr, value in Emcore.__dict__.items():
|
| 1078 | 1079 | if getattr(value, 'func', False):
|
| 1079 | 1080 | if getattr(value.func, '_command', False):
|
| 1080 | 1081 | cmddict[value.func.__name__] = value
|