Skip to content

Commit

Permalink
Merge pull request #18 from tahoe-lafs/17.remove-pyutil-dependency
Browse files Browse the repository at this point in the history
remove pyutil dependency

Fixes: ticket:17
  • Loading branch information
exarkun committed Aug 11, 2020
2 parents 08fe3ea + 819ca04 commit 1c6b2bb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
5 changes: 4 additions & 1 deletion setup.py
Expand Up @@ -60,11 +60,14 @@
long_description=open('README.rst', 'rU').read(),
url="https://github.com/tahoe-lafs/zfec",
install_requires=[
"pyutil >= 3.0.0",
"argparse >= 0.8 ; python_version <= '2.7'",
# note to self: single-quotes on the '2.7' are ok:
# https://github.com/pypa/packaging/blob/16.8/packaging/markers.py#L121
],
extras_require={
"bench": ["pyutil >= 3.0.0"],
"test": ["twisted", "setuptools_trial", "pyutil >= 3.0.0"],
},
ext_modules=extensions,
cmdclass=versioneer.get_cmdclass(),
)
4 changes: 1 addition & 3 deletions tox.ini
Expand Up @@ -3,9 +3,7 @@ envlist = py27,py35,py36
skip_missing_interpreters = True

[testenv]
deps = pyutil
twisted
setuptools_trial
deps = .[test]
usedevelop = True

commands =
Expand Down
30 changes: 27 additions & 3 deletions zfec/filefec.py
@@ -1,14 +1,35 @@
from __future__ import print_function
import array, os, struct
from base64 import b32encode
from pyutil import fileutil
from pyutil.mathutil import pad_size, log_ceil

import zfec
from zfec import easyfec

CHUNKSIZE = 4096

def pad_size(n, k):
"""
The smallest number that has to be added to n to equal a multiple of k.
"""
if n%k:
return k - n%k
else:
return 0

def log_ceil(n, b):
"""
The smallest integer k such that b^k >= n.
log_ceil(n, 2) is the number of bits needed to store any of n values, e.g.
the number of bits needed to store any of 128 possible values is 7.
"""
p = 1
k = 0
while p < n:
p *= b
k += 1
return k

def ab(x): # debuggery
if len(x) >= 3:
return "%s:%s" % (len(x), b32encode(x[-3:]),)
Expand Down Expand Up @@ -224,7 +245,10 @@ def cb(blocks, length):
for fn in fns:
if verbose:
print("Cleaning up: trying to remove %r..." % (fn,))
fileutil.remove_if_possible(fn)
try:
os.remove(fn)
except EnvironmentError:
pass
return 1
if verbose:
print()
Expand Down

0 comments on commit 1c6b2bb

Please sign in to comment.