-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompress_files.py
More file actions
64 lines (52 loc) · 2.21 KB
/
compress_files.py
File metadata and controls
64 lines (52 loc) · 2.21 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# import os
# import gzip
# import shutil
# def compress_files(source_dir):
# for root, _, files in os.walk(source_dir):
# for file in files:
# file_path = os.path.join(root, file)
# gz_path = file_path + ".gz"
# with open(file_path, 'rb') as f_in:
# with gzip.open(gz_path, 'wb') as f_out:
# shutil.copyfileobj(f_in, f_out)
# def before_upload(source, target, env):
# data_dir = os.path.join(env['PROJECT_DIR'], 'data')
# compress_files(data_dir)
# import os
# import subprocess
# def compress_files(source_dir):
# # Path to Git Bash executable
# git_bash_path = "C:\\Program Files\\Git\\bin\\bash.exe"
# # Command to recursively gzip all files in the source directory
# gzip_command = f'find "{source_dir}" -type f -exec gzip -k {{}} \\;'
# # Run the command using Git Bash
# try:
# subprocess.run([git_bash_path, "-c", gzip_command], check=True)
# print(f"Successfully compressed files in {source_dir}")
# except subprocess.CalledProcessError as e:
# print(f"Error compressing files: {e}")
# def before_upload(source, target, env):
# # Path to the 'data' directory
# data_dir = os.path.join(env["PROJECT_DIR"], "data")
# compress_files(data_dir)
import os
import subprocess
def compress_files(source_dir):
# Path to Git Bash executable
git_bash_path = "C:\\Program Files\\Git\\bin\\bash.exe"
# Command to recursively gzip all files in the source directory
gzip_command = f'find "{source_dir}" -type f -exec gzip -k {{}} \\;'
# Run the command using Git Bash
try:
print(f"Running gzip command: {gzip_command}")
subprocess.run([git_bash_path, "-c", gzip_command], check=True)
print(f"Successfully compressed files in {source_dir}")
except subprocess.CalledProcessError as e:
print(f"Error compressing files: {e}")
def before_upload(source, target, env):
# Path to the 'data' directory
data_dir = os.path.join(env["PROJECT_DIR"], "data")
if os.path.exists(data_dir):
compress_files(data_dir)
else:
print(f"Data directory not found: {data_dir}")