Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #44 from adelosa/feature/remove-bitarray
Browse files Browse the repository at this point in the history
Remove bitarray dependency
  • Loading branch information
adelosa committed Oct 31, 2018
2 parents 88cddc2 + 879725f commit 35d491f
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -3,10 +3,10 @@
language: python

python:
- "2.6"
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "pypy"

# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
Expand Down
6 changes: 6 additions & 0 deletions HISTORY.rst
Expand Up @@ -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.
Expand Down
28 changes: 27 additions & 1 deletion docs/installation.rst
Expand Up @@ -2,9 +2,35 @@
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.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 platform of choice.

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
45 changes: 38 additions & 7 deletions mciutil/mciutil.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion 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
6 changes: 3 additions & 3 deletions setup.py
Expand Up @@ -15,7 +15,7 @@
history = history_file.read().replace('.. :changelog:', '')

requirements = [
'PyYAML', 'hexdump', 'bitarray', 'argparse'
'PyYAML', 'hexdump', 'argparse'
]

test_requirements = [
Expand Down Expand Up @@ -52,12 +52,12 @@
'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',
'Programming Language :: Python :: 3.7',
],
test_suite='tests',
tests_require=test_requirements,
Expand Down
3 changes: 0 additions & 3 deletions tests/test_mideu.py
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = py26, py27, py35
envlist = py27, py34, py35, py36, py37

[testenv]
setenv =
Expand Down

0 comments on commit 35d491f

Please sign in to comment.