-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
35 lines (25 loc) · 1.15 KB
/
build.py
File metadata and controls
35 lines (25 loc) · 1.15 KB
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
31
32
33
34
35
import os
import zipfile
def create_zip_from_source(source_dir="src", zip_file="AppModulesAssistor.zip", target_dir="target"):
# Save the current working directory
original_directory = os.getcwd()
# Create the target directory if it does not exist
os.makedirs(target_dir, exist_ok=True)
try:
# Change to the source directory
os.chdir(source_dir)
# Create the zip file from the contents of the source directory, without including the src directory itself
with zipfile.ZipFile(f"../{target_dir}/{zip_file}", 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, dirs, files in os.walk("."):
for file in files:
file_path = os.path.join(root, file)
arcname = os.path.relpath(file_path, ".")
zipf.write(file_path, arcname)
print(f"Success: Created {zip_file} in {target_dir}")
except Exception as e:
print(f"Failed to create zip file: {e}")
finally:
# Return to the original directory regardless of success or failure
os.chdir(original_directory)
if __name__ == "__main__":
create_zip_from_source()