[Bf-blender-cvs] [5040c77bdbc] temp-dna-rename: Utility to apply edits
Campbell Barton
noreply at git.blender.org
Tue Feb 12 22:11:27 CET 2019
Commit: 5040c77bdbc9ef94dbc378e4c0606d7c5bb4f7c6
Author: Campbell Barton
Date: Wed Feb 13 00:39:32 2019 +1100
Branches: temp-dna-rename
https://developer.blender.org/rB5040c77bdbc9ef94dbc378e4c0606d7c5bb4f7c6
Utility to apply edits
===================================================================
A version_update_D4342_utility.py
===================================================================
diff --git a/version_update_D4342_utility.py b/version_update_D4342_utility.py
new file mode 100755
index 00000000000..d901c52cf7f
--- /dev/null
+++ b/version_update_D4342_utility.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python3
+
+# Run from Blender's root DIR
+
+SOURCE_DIRS = (
+ "source",
+ )
+
+USE_MULTIPROCESS = True
+
+replace_all = (
+ ("clipsta", "clip_start"),
+ ("clipend", "clip_end"),
+ ("YF_dofdist", "dof_dist"),
+ ("Lamp", "Light"),
+)
+
+replace_tables = (
+ replace_all,
+)
+
+
+replace_tables_re = [
+ [(src, dst) for src, dst in table]
+ for table in replace_tables
+]
+
+
+def replace_all(fn, data_src):
+ import re
+
+ data_dst = data_src
+ for table in replace_tables_re:
+ for src_re, dst in table:
+ data_dst = re.sub(src_re, dst, data_dst)
+ return data_dst
+
+
+operation = replace_all
+
+import os
+
+def source_files(path):
+ for dirpath, dirnames, filenames in os.walk(path):
+ dirnames[:] = [d for d in dirnames if not d.startswith(".")]
+ for filename in filenames:
+ if filename.startswith("."):
+ continue
+ ext = os.path.splitext(filename)[1]
+
+ # XXX weak, don't touch this!
+ if filename.endswith("versioning_dna.c"):
+ continue
+
+ # if ext.lower() in {".py"}:
+ # if ext.lower() in {".c", ".cc", ".cxx", ".cpp", ".h", ".hxx", ".hpp", ".py"}:
+ if ext.lower() in {".c", ".cc", ".cxx", ".cpp", ".h", ".hxx", ".hpp"}:
+ yield os.path.join(dirpath, filename)
+
+def operation_wrap(fn):
+ with open(fn, "r", encoding="utf-8") as f:
+ data_src = f.read()
+ data_dst = operation(fn, data_src)
+
+ if data_dst is None or (data_src == data_dst):
+ return
+
+ with open(fn, "w", encoding="utf-8") as f:
+ f.write(data_dst)
+
+
+def main():
+ if USE_MULTIPROCESS:
+ args = [fn for DIR in SOURCE_DIRS for fn in source_files(DIR)]
+ import multiprocessing
+ job_total = multiprocessing.cpu_count()
+ pool = multiprocessing.Pool(processes=job_total * 2)
+ pool.map(operation_wrap, args)
+ else:
+ for fn in source_files(SOURCE_DIR):
+ operation_wrap(fn)
+
+
+if __name__ == "__main__":
+ main()
More information about the Bf-blender-cvs
mailing list