-
Notifications
You must be signed in to change notification settings - Fork 5
/
make_package.py
executable file
·30 lines (25 loc) · 1008 Bytes
/
make_package.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python
import glob
import sys
import os
import shutil
import tempfile
if len(sys.argv) > 1:
outzip = "./" + sys.argv[1]
else:
outzip = "appsec-submission"
with open("allowed_files.txt", "rt") as f:
file_patterns = [file.strip() for file in f.readlines()]
with tempfile.TemporaryDirectory() as tmp_dir:
current_dir = os.getcwd()
for pattern in file_patterns:
print(pattern)
base_dir = os.path.commonpath(glob.glob(pattern, recursive=True)) # Dynamic base for each pattern
for file in glob.glob(pattern, recursive=True):
if os.path.isfile(file):
# Create the destination path inside the temporary directory
dest_path = os.path.join(tmp_dir, os.path.relpath(file, current_dir))
os.makedirs(os.path.dirname(dest_path), exist_ok=True)
shutil.copy(file, dest_path)
# Create a zip archive from the temporary directory
shutil.make_archive(outzip, 'zip', tmp_dir)