aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts/filter_zip.py
diff options
context:
space:
mode:
authoralexv-smirnov <alex@ydb.tech>2023-03-15 19:59:12 +0300
committeralexv-smirnov <alex@ydb.tech>2023-03-15 19:59:12 +0300
commit056bb284ccf8dd6793ec3a54ffa36c4fb2b9ad11 (patch)
tree4740980126f32e3af7937ba0ca5f83e59baa4ab0 /build/scripts/filter_zip.py
parent269126dcced1cc8b53eb4398b4a33e5142f10290 (diff)
downloadydb-056bb284ccf8dd6793ec3a54ffa36c4fb2b9ad11.tar.gz
add library/cpp/actors, ymake build to ydb oss export
Diffstat (limited to 'build/scripts/filter_zip.py')
-rw-r--r--build/scripts/filter_zip.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/build/scripts/filter_zip.py b/build/scripts/filter_zip.py
new file mode 100644
index 0000000000..b2121b9c9e
--- /dev/null
+++ b/build/scripts/filter_zip.py
@@ -0,0 +1,71 @@
+import argparse
+import os
+import re
+import uuid
+import zipfile
+
+
+def pattern_to_regexp(p):
+ return re.compile(
+ '^'
+ + re.escape(p)
+ .replace(r'\*\*\/', '[_DIR_]')
+ .replace(r'\*', '[_FILE_]')
+ .replace('[_DIR_]', '(.*/)?')
+ .replace('[_FILE_]', '([^/]*)')
+ + '$'
+ )
+
+
+def is_deathman(positive_filter, negative_filter, candidate):
+ remove = positive_filter
+ for pf in positive_filter:
+ if pf.match(candidate):
+ remove = False
+ break
+ if not negative_filter or remove:
+ return remove
+ for nf in negative_filter:
+ if nf.match(candidate):
+ remove = True
+ break
+ return remove
+
+
+def just_do_it():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--positive', action='append', default=[])
+ parser.add_argument('--negative', action='append', default=[])
+ parser.add_argument('--file', action='store', required=True)
+ args = parser.parse_args()
+ if not args.positive and not args.negative:
+ return
+ pos = [pattern_to_regexp(i) for i in args.positive]
+ neg = [pattern_to_regexp(i) for i in args.negative]
+ temp_dirname = None
+ for _ in range(10):
+ candidate = '__unpacked_{}__'.format(uuid.uuid4())
+ if not os.path.exists(candidate):
+ temp_dirname = candidate
+ os.makedirs(temp_dirname)
+ if not temp_dirname:
+ raise Exception("Can't generate name for temp dir")
+
+ with zipfile.ZipFile(args.file, 'r') as zip_ref:
+ zip_ref.extractall(temp_dirname)
+
+ for root, _, files in os.walk(temp_dirname):
+ for f in files:
+ candidate = os.path.join(root, f).replace('\\', '/')
+ if is_deathman(pos, neg, os.path.relpath(candidate, temp_dirname)):
+ os.remove(candidate)
+
+ with zipfile.ZipFile(args.file, 'w') as zip_ref:
+ for root, _, files in os.walk(temp_dirname):
+ for f in files:
+ realname = os.path.join(root, f)
+ zip_ref.write(realname, os.path.sep.join(os.path.normpath(realname).split(os.path.sep, 2)[1:]))
+
+
+if __name__ == '__main__':
+ just_do_it()