summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyo Nakamura <upa@haeena.net>2022-10-31 22:55:43 +0900
committerRyo Nakamura <upa@haeena.net>2022-10-31 22:55:43 +0900
commit44ed580f4dfc2ece93685c4415b08555c765bc70 (patch)
treed5fc537e63b4a4c386de36c27d43d6568a2c9df6 /src
parent926688e84921c0ba17c39b41b34bbcd391def299 (diff)
add rename-logic.py
Diffstat (limited to 'src')
-rwxr-xr-xsrc/rename-logic.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/rename-logic.py b/src/rename-logic.py
new file mode 100755
index 0000000..9916c96
--- /dev/null
+++ b/src/rename-logic.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python3
+
+from os.path import dirname, basename, isfile, isdir, exists
+from os import listdir
+import sys
+
+"""
+
+This file simply implements the src_path to dst_path conversion logic
+just for test. file_fill() and file_fill_recursive() in file.c
+implements this logic.
+
+"""
+
+
+def recursive(src, rel_path, dst, dst_should_dir, replace_dir_name):
+
+ if isfile(src):
+ if dst_should_dir:
+ print("{} => {}/{}{}".format(src, dst, rel_path, basename(src)))
+ else:
+ print("{} => {}{}".format(src, rel_path, dst))
+ return
+
+ # src is directory
+ for f in listdir(src):
+ next_src = "{}/{}".format(src, f)
+ if replace_dir_name and dst_should_dir:
+ next_rel_path = ""
+ else:
+ next_rel_path = "{}{}/".format(rel_path, basename(src))
+ recursive(next_src, next_rel_path, dst, dst_should_dir, False)
+
+
+def fill_dst(src, dst):
+ dst_should_dir = isdir(src)
+ replace_dir_name = not isdir(dst)
+ recursive(src, "", dst, dst_should_dir, replace_dir_name)
+
+
+def main():
+ fill_dst(sys.argv[1], sys.argv[2])
+
+main()