diff options
author | Thomas Tanner <trtanner@btinternet.com> | 2016-03-12 23:28:47 (GMT) |
---|---|---|
committer | Thomas Tanner <trtanner@btinternet.com> | 2016-03-12 23:28:47 (GMT) |
commit | a014c40490ca3353d82476ca6a1db2ad80ca57fe (patch) | |
tree | 45ef50d57013cfb7ea0876f5b860e65fac4a1c6d /src/script | |
parent | 56db17b7c0f733d1b33e07148f927149263bfc02 (diff) | |
download | SCons-a014c40490ca3353d82476ca6a1db2ad80ca57fe.zip SCons-a014c40490ca3353d82476ca6a1db2ad80ca57fe.tar.gz SCons-a014c40490ca3353d82476ca6a1db2ad80ca57fe.tar.bz2 |
improve behaviour
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/scons-rename-cachedirs.py | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/script/scons-rename-cachedirs.py b/src/script/scons-rename-cachedirs.py index dd76a42..24897d1 100644 --- a/src/script/scons-rename-cachedirs.py +++ b/src/script/scons-rename-cachedirs.py @@ -36,6 +36,7 @@ __date__ = "__DATE__" __developer__ = "__DEVELOPER__"
import glob
+import json
import os
# The entire purpose of this script is to rename the files in the specified
@@ -43,20 +44,35 @@ import os # directories.
# You run this in the cache directory.
+
expected = ['{:X}'.format(x) for x in range(0, 16)]
-# check there are 16 directories, 0 - 9, A - F
-if sorted(glob.glob('*')) != [x]:
- raise RuntimeError("This doesn't look like a cache directory")
+
+if not os.path.exists('config'):
+ # check there are 16 directories, 0 - 9, A - F
+ if sorted(glob.glob('*')) != expected:
+ raise RuntimeError("This doesn't look like a (version 1) cache directory")
+ config = { 'prefix_len' : 1 }
+else:
+ with open('config') as conf:
+ config = json.load(conf)
+ if config['prefix_len'] != 1:
+ raise RuntimeError("This doesn't look like a (version 1) cache directory")
+
dirs = set()
for file in glob.iglob(os.path.join('*', '*')):
name = os.path.basename(file)
dir = name[:2].upper()
- print dir, name
if dir not in dirs:
os.mkdir(dir)
dirs.add(dir)
os.rename(file, os.path.join(dir, name))
- # Now delete the original directories
- for dir in expected:
- os.rmdir(dir)
\ No newline at end of file +# Now delete the original directories
+for dir in expected:
+ if os.path.exists(dir):
+ os.rmdir(dir)
+
+# and write a config file
+config['prefix_len'] = 2
+with open('config', 'w') as conf:
+ json.dump(config, conf)
\ No newline at end of file |