Some progress towards running crawler on Python 3.
This commit is contained in:
parent
e971ccf58e
commit
ff582c5129
|
@ -1,3 +1,4 @@
|
||||||
|
from future.utils import PY3
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
from allmydata.util import base32
|
from allmydata.util import base32
|
||||||
|
@ -17,5 +18,12 @@ def si_a2b(ascii_storageindex):
|
||||||
return base32.a2b(ascii_storageindex)
|
return base32.a2b(ascii_storageindex)
|
||||||
|
|
||||||
def storage_index_to_dir(storageindex):
|
def storage_index_to_dir(storageindex):
|
||||||
|
"""Convert storage index to directory path.
|
||||||
|
|
||||||
|
Returns native string.
|
||||||
|
"""
|
||||||
sia = si_b2a(storageindex)
|
sia = si_b2a(storageindex)
|
||||||
|
if PY3:
|
||||||
|
# On Python 3 we expect paths to be unicode.
|
||||||
|
sia = sia.decode("ascii")
|
||||||
return os.path.join(sia[:2], sia)
|
return os.path.join(sia[:2], sia)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from future.utils import native_str, PY3
|
||||||
|
|
||||||
import os, time, struct
|
import os, time, struct
|
||||||
try:
|
try:
|
||||||
|
@ -77,6 +78,9 @@ class ShareCrawler(service.MultiService):
|
||||||
self.statefile = statefile
|
self.statefile = statefile
|
||||||
self.prefixes = [si_b2a(struct.pack(">H", i << (16-10)))[:2]
|
self.prefixes = [si_b2a(struct.pack(">H", i << (16-10)))[:2]
|
||||||
for i in range(2**10)]
|
for i in range(2**10)]
|
||||||
|
if PY3:
|
||||||
|
# On Python 3 we expect the paths to be unicode, not bytes.
|
||||||
|
self.prefixes = [p.decode("ascii") for p in self.prefixes]
|
||||||
self.prefixes.sort()
|
self.prefixes.sort()
|
||||||
self.timer = None
|
self.timer = None
|
||||||
self.bucket_cache = (None, [])
|
self.bucket_cache = (None, [])
|
||||||
|
@ -314,7 +318,8 @@ class ShareCrawler(service.MultiService):
|
||||||
try:
|
try:
|
||||||
buckets = os.listdir(prefixdir)
|
buckets = os.listdir(prefixdir)
|
||||||
buckets.sort()
|
buckets.sort()
|
||||||
except EnvironmentError:
|
except EnvironmentError as e:
|
||||||
|
print(e)
|
||||||
buckets = []
|
buckets = []
|
||||||
self.bucket_cache = (i, buckets)
|
self.bucket_cache = (i, buckets)
|
||||||
self.process_prefixdir(cycle, prefix, prefixdir,
|
self.process_prefixdir(cycle, prefix, prefixdir,
|
||||||
|
|
|
@ -8,7 +8,7 @@ class LeaseInfo(object):
|
||||||
self.cancel_secret = cancel_secret
|
self.cancel_secret = cancel_secret
|
||||||
self.expiration_time = expiration_time
|
self.expiration_time = expiration_time
|
||||||
if nodeid is not None:
|
if nodeid is not None:
|
||||||
assert isinstance(nodeid, str)
|
assert isinstance(nodeid, bytes)
|
||||||
assert len(nodeid) == 20
|
assert len(nodeid) == 20
|
||||||
self.nodeid = nodeid
|
self.nodeid = nodeid
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ class StorageServer(service.MultiService, Referenceable):
|
||||||
expiration_cutoff_date=None,
|
expiration_cutoff_date=None,
|
||||||
expiration_sharetypes=("mutable", "immutable")):
|
expiration_sharetypes=("mutable", "immutable")):
|
||||||
service.MultiService.__init__(self)
|
service.MultiService.__init__(self)
|
||||||
assert isinstance(nodeid, str)
|
assert isinstance(nodeid, bytes)
|
||||||
assert len(nodeid) == 20
|
assert len(nodeid) == 20
|
||||||
self.my_nodeid = nodeid
|
self.my_nodeid = nodeid
|
||||||
self.storedir = storedir
|
self.storedir = storedir
|
||||||
|
|
|
@ -100,11 +100,11 @@ class Basic(unittest.TestCase, StallMixin, pollmixin.PollMixin):
|
||||||
return self.s.stopService()
|
return self.s.stopService()
|
||||||
|
|
||||||
def si(self, i):
|
def si(self, i):
|
||||||
return hashutil.storage_index_hash(bytes(i))
|
return hashutil.storage_index_hash(b"%d" % (i,))
|
||||||
def rs(self, i, serverid):
|
def rs(self, i, serverid):
|
||||||
return hashutil.bucket_renewal_secret_hash(bytes(i), serverid)
|
return hashutil.bucket_renewal_secret_hash(b"%d" % (i,), serverid)
|
||||||
def cs(self, i, serverid):
|
def cs(self, i, serverid):
|
||||||
return hashutil.bucket_cancel_secret_hash(bytes(i), serverid)
|
return hashutil.bucket_cancel_secret_hash(b"%d" % (i,), serverid)
|
||||||
|
|
||||||
def write(self, i, ss, serverid, tail=0):
|
def write(self, i, ss, serverid, tail=0):
|
||||||
si = self.si(i)
|
si = self.si(i)
|
||||||
|
|
Loading…
Reference in New Issue