1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | import os |
---|
4 | |
---|
5 | from allmydata.util import fileutil, idlib |
---|
6 | from allmydata.storage import storage_index_to_dir |
---|
7 | |
---|
8 | newtopdirs = set() |
---|
9 | for sidir in os.listdir('.'): |
---|
10 | if idlib.could_be_base32_encoded_l(sidir, 128): |
---|
11 | newtopdir = idlib.b2a_l(idlib.a2b(sidir)[:2], 14) |
---|
12 | if not newtopdir in newtopdirs: |
---|
13 | newtopdirs.add(newtopdir) |
---|
14 | fileutil.make_dirs(newtopdir) |
---|
15 | try: |
---|
16 | os.rename(sidir, os.path.join(newtopdir, sidir)) |
---|
17 | except EnvironmentError: |
---|
18 | # Maybe there is already a sidir there and we need to move the |
---|
19 | # contents of this sidir into it. |
---|
20 | for fn in os.listdir(sidir): |
---|
21 | os.rename(os.path.join(sidir, fn), os.path.join(newtopdir, sidir, fn)) |
---|
22 | # Okay, good, now rmdir the old one. |
---|
23 | os.rmdir(sidir) |
---|
24 | |
---|
25 | |
---|