From: zooko Date: Fri, 9 Nov 2007 16:45:23 +0000 (+0530) Subject: zfec: a few debugging and in-line comment tweaks X-Git-Url: https://git.rkrishnan.org/components/%22news.html/listings/somewhere?a=commitdiff_plain;h=dcdce4fe75babfc8155e6a75ebdc9c688d52b00e;p=tahoe-lafs%2Fzfec.git zfec: a few debugging and in-line comment tweaks darcs-hash:3a3ee6328a6ad7de8d8011aa935f4b70d763850e --- diff --git a/zfec/setup.py b/zfec/setup.py index 6f849f9..50210ca 100755 --- a/zfec/setup.py +++ b/zfec/setup.py @@ -31,8 +31,7 @@ use_setuptools(min_version=min_version, download_delay=0) from setuptools import Extension, find_packages, setup -DEBUGMODE=False -# DEBUGMODE=True +DEBUGMODE=("--debug" in sys.argv) extra_compile_args=[] extra_link_args=[] diff --git a/zfec/zfec/easyfec.py b/zfec/zfec/easyfec.py index db39f5b..3ee44c2 100644 --- a/zfec/zfec/easyfec.py +++ b/zfec/zfec/easyfec.py @@ -10,6 +10,17 @@ def div_ceil(n, d): """ return (n/d) + (n%d != 0) +from base64 import b32encode +def ab(x): # debuggery + if len(x) >= 3: + return "%s:%s" % (len(x), b32encode(x[-3:]),) + elif len(x) == 2: + return "%s:%s" % (len(x), b32encode(x[-2:]),) + elif len(x) == 1: + return "%s:%s" % (len(x), b32encode(x[-1:]),) + elif len(x) == 0: + return "%s:%s" % (len(x), "--empty--",) + class Encoder(object): def __init__(self, k, m): self.fec = zfec.Encoder(k, m) diff --git a/zfec/zfec/filefec.py b/zfec/zfec/filefec.py index 135f4a2..80df5b7 100644 --- a/zfec/zfec/filefec.py +++ b/zfec/zfec/filefec.py @@ -6,6 +6,17 @@ import array, os, re, struct, traceback CHUNKSIZE = 4096 +from base64 import b32encode +def ab(x): # debuggery + if len(x) >= 3: + return "%s:%s" % (len(x), b32encode(x[-3:]),) + elif len(x) == 2: + return "%s:%s" % (len(x), b32encode(x[-2:]),) + elif len(x) == 1: + return "%s:%s" % (len(x), b32encode(x[-1:]),) + elif len(x) == 0: + return "%s:%s" % (len(x), "--empty--",) + class InsufficientShareFilesError(zfec.Error): def __init__(self, k, kb, *args, **kwargs): zfec.Error.__init__(self, *args, **kwargs) @@ -216,9 +227,9 @@ def encode_to_files(inf, fsize, dirname, prefix, k, m, suffix=".fec", overwrite= return 0 # Note: if you really prefer base-2 and you change this code, then please -# denote 2^20 as "MiB" instead of "MB" in order to avoid ambiguity. -# Thanks. +# denote 2^20 as "MiB" instead of "MB" in order to avoid ambiguity. See: # http://en.wikipedia.org/wiki/Megabyte +# Thanks. MILLION_BYTES=10**6 def decode_from_files(outf, infiles, verbose=False):