forked from ziqin/SUSTech-CS307-Project2-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.py
More file actions
executable file
·28 lines (20 loc) · 787 Bytes
/
Copy pathbundle.py
File metadata and controls
executable file
·28 lines (20 loc) · 787 Bytes
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
#!/usr/bin/env python3
from pathlib import Path
import tarfile
ignored_files = ['src.tar.gz', '.DS_Store', 'Desktop.ini', 'desktop.ini', '.directory']
ignored_types = ['.pyc', '.pyo', '.pyd']
ignored_dirs = ['.git', '__pycache__', '.venv', 'venv', 'env', 'ENV', '.idea', '.vscode', 'data']
def bundle_filter(info: tarfile.TarInfo):
path = Path(info.name)
if info.isfile() and (path.name in ignored_files or path.suffix in ignored_types):
return None
elif info.isdir() and path.name in ignored_dirs:
return None
else:
return info
def bundle():
project_dir = Path(__file__).parent
with tarfile.open('src.tar.gz', 'w:gz') as tar:
tar.add(project_dir, arcname='.', filter=bundle_filter)
if __name__ == '__main__':
bundle()