-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
36 lines (31 loc) · 953 Bytes
/
utils.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
31
32
33
34
35
36
import os
import shutil
import fnmatch
def copy_repo_files(dest_dir, current_dir):
"""Copies all files in the current repo to the destination directory,
excluding those specified in .gitignore."""
chosen_patterns = [
"environment",
"preprocessing",
"scripts",
"src",
".gitignore",
"README.md",
"train.py",
"utils.py",
]
def chosen_func(_, names):
ignored = []
for pattern in chosen_patterns:
ignored.extend(fnmatch.filter(names, pattern))
return ignored
# Create destination directory if it doesn't exist
os.makedirs(dest_dir, exist_ok=True)
for item in os.listdir("."):
if item in chosen_patterns:
s = os.path.join(".", item)
d = os.path.join(dest_dir, item)
if os.path.isdir(s):
shutil.copytree(s, d)
else:
shutil.copy2(s, d)