From edea7f2a662536efba1ef84628aa05218a78822d Mon Sep 17 00:00:00 2001 From: Anthony Delosa Date: Wed, 31 Oct 2018 22:13:08 +1000 Subject: [PATCH 1/3] Remove bitarray dependency and update doco. Add new versions of python to tox tests --- HISTORY.rst | 6 ++++++ docs/installation.rst | 26 ++++++++++++++++++++++++- mciutil/mciutil.py | 45 ++++++++++++++++++++++++++++++++++++------- requirements.txt | 1 - setup.py | 4 +++- tests/test_mideu.py | 3 --- tox.ini | 2 +- 7 files changed, 73 insertions(+), 14 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 8aa51e6..415a191 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,12 @@ History ======= +0.6.0 (2018-10-01) +------------------ +* Removed dependency on bitarray (no binary wheels) +* Added details on installation for non-python users +* 2 years almost since last update! + 0.5.0 (2016-10-03) ------------------ * Fixed version display in release version. diff --git a/docs/installation.rst b/docs/installation.rst index e5fb38d..f214f0f 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -2,9 +2,33 @@ Installation ============ -At the command line:: +mciutil is distributed as a python package. + +You will need a version of python installed to run the tool. + +Python version 2.6, 2.7 or 3.4 and above are supported. + +See https://www.python.org/downloads for instructions on installing python on +your required platform. + +Once you have Python available, at the command line enter:: $ virtualenv mciutil $ source ./mciutil/bin/activate $ pip install mciutil +For Windows platforms:: + + c:> virtualenv mciutil + c:> ./mciutil/Scripts/activate + c:> pip install mciutil + +If you start another command prompt after installing, you can +make the commands available in the new session by activating the +python environment:: + + $ source ./mciutil/bin/activate + +or for windows:: + + c:> ./mciutil/Scripts/activate diff --git a/mciutil/mciutil.py b/mciutil/mciutil.py index 107b968..587cf0e 100644 --- a/mciutil/mciutil.py +++ b/mciutil/mciutil.py @@ -5,21 +5,51 @@ """ from __future__ import print_function -import logging -import sys -import struct +import binascii +import codecs import datetime import decimal -import codecs +import logging import re -import binascii +import struct +import sys +from array import array -import bitarray import hexdump LOGGER = logging.getLogger(__name__) +class BitArray: + """ + This is a minimal native python replacement for the bitarray module that was used to interpret + the file bitmap. The bitarray module is written in c and does not provide binary wheels so + forces users to have compilers installed just to install mciutil. + This small class provides the required functions from that library. + """ + endian = 'big' + bytes = b'' + + def __init__(self, endian='big'): + self.endian = endian + + def frombytes(self, array_bytes): + self.bytes = array_bytes + + def tolist(self): + swap_bytes = array('B', self.bytes) + if self.endian == 'little': + for i, n in enumerate(swap_bytes): + swap_bytes[i] = int('{:08b}'.format(n)[::-1], 2) + width = len(self.bytes)*8 + try: + swapped_bytes = swap_bytes.tobytes() + except AttributeError: # 2.7 does not recognise .tobytes method. 2.6 does! + swapped_bytes = swap_bytes.tostring() + bit_list = '{bytes:0{width}b}'.format(bytes=int(binascii.hexlify(swapped_bytes), 16), width=width) + return [bit == '1' for bit in bit_list] + + def unblock(blocked_data): """ Unblocks a 1014 byte blocked string @@ -478,7 +508,8 @@ def _get_bitmap_list(binary_bitmap): bitmap """ - working_bitmap_list = bitarray.bitarray(endian='big') + # working_bitmap_list = bitarray.bitarray(endian='big') + working_bitmap_list = BitArray(endian='big') working_bitmap_list.frombytes(binary_bitmap) # Add bit 0 -> original binary bitmap diff --git a/requirements.txt b/requirements.txt index 4ba661f..57ea165 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ versioneer wheel==0.23.0 hexdump>=3.2 -bitarray>=0.8.1 PyYAML>=3.10 argparse>=1.4.0 diff --git a/setup.py b/setup.py index 5bdec63..e3dde40 100755 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ history = history_file.read().replace('.. :changelog:', '') requirements = [ - 'PyYAML', 'hexdump', 'bitarray', 'argparse' + 'PyYAML', 'hexdump', 'argparse' ] test_requirements = [ @@ -58,6 +58,8 @@ 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', ], test_suite='tests', tests_require=test_requirements, diff --git a/tests/test_mideu.py b/tests/test_mideu.py index 3affb95..5aabe32 100644 --- a/tests/test_mideu.py +++ b/tests/test_mideu.py @@ -47,9 +47,6 @@ def test_enter_with_no_subcommand(self): try calling standard entry without sub command.. should return help text :return: """ - # run with no parms.. argparse should fail - self.assertRaises(SystemExit, lambda: self.parser.parse_args()) - # run with no parms.. pass none _main(None) diff --git a/tox.ini b/tox.ini index a82e2af..af1a32d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py26, py27, py35 +envlist = py26, py27, py35, py36, py37 [testenv] setenv = From bd335b16e3a59976aa371a2bfbd58d176a84a501 Mon Sep 17 00:00:00 2001 From: Anthony Delosa Date: Wed, 31 Oct 2018 22:25:36 +1000 Subject: [PATCH 2/3] Dropped official 2.6 testing including travis ci and tox --- .travis.yml | 3 ++- docs/installation.rst | 6 ++++-- setup.py | 2 -- tox.ini | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index ec06d83..106683c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,11 @@ language: python python: - - "2.6" - "2.7" - "3.4" - "3.5" + - "3.6" + - "3.7" - "pypy" # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors diff --git a/docs/installation.rst b/docs/installation.rst index f214f0f..24b3452 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -6,10 +6,12 @@ mciutil is distributed as a python package. You will need a version of python installed to run the tool. -Python version 2.6, 2.7 or 3.4 and above are supported. +Python version 2.7 or 3.4 and above are supported. +This will most likely work on Python 2.6 but no testing is done +and no 2.6 fixes will be considered. Its time to move to Py3. See https://www.python.org/downloads for instructions on installing python on -your required platform. +your platform of choice. Once you have Python available, at the command line enter:: diff --git a/setup.py b/setup.py index e3dde40..636ed45 100755 --- a/setup.py +++ b/setup.py @@ -52,10 +52,8 @@ 'License :: OSI Approved :: BSD License', 'Natural Language :: English', 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', diff --git a/tox.ini b/tox.ini index af1a32d..ace1997 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py26, py27, py35, py36, py37 +envlist = py27, py34, py35, py36, py37 [testenv] setenv = From 879725f86f9e96be7548931442b664190a86f8e6 Mon Sep 17 00:00:00 2001 From: Anthony Delosa Date: Wed, 31 Oct 2018 22:36:03 +1000 Subject: [PATCH 3/3] No 3.7 support at Travis yet.. removed --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 106683c..9454893 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ python: - "3.4" - "3.5" - "3.6" - - "3.7" - "pypy" # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors