-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEpiTemplate.py
More file actions
65 lines (52 loc) · 1.98 KB
/
Copy pathEpiTemplate.py
File metadata and controls
65 lines (52 loc) · 1.98 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
65
import os
import sys
import shutil
import subprocess
from urllib.parse import urlparse
from distutils.dir_util import copy_tree
def clone_repo(repo_ssh, dir_name):
if os.path.exists(dir_name):
raise Exception(f"Directory '{dir_name}' already exists.")
subprocess.run(['git', 'clone', repo_ssh, dir_name], check=True)
def check_if_repo_empty(dir_name):
return len(os.listdir(dir_name)) <= 1
def clone_repo_without_git(repo_ssh, dir_name):
clone_repo(repo_ssh, dir_name)
shutil.rmtree(os.path.join(dir_name, '.git'))
def move_files(source_dir, dest_dir):
copy_tree(source_dir, dest_dir)
def manage_repo(repo_ssh, repo_name):
# Clone the repo
try:
clone_repo(repo_ssh, repo_name)
except Exception as e:
print(f"Error during cloning: {e}")
return
# Check if the repo is empty
if not check_if_repo_empty(repo_name):
print("Warning: The repository is not empty!")
user_input = input("Do you want to continue? (y/n) ")
if user_input.lower() != 'y':
print("Process terminated by user.")
return
# If warning is accepted, clone the other repo into a temporary directory
try:
clone_repo_without_git('git@github.com:S0ly/EpiTemplate.git', 'temp_repo')
except Exception as e:
print(f"Error during cloning: {e}")
return
# Move everything from temp_repo to the user provided repo
move_files('temp_repo/', repo_name)
# Remove temp_repo
shutil.rmtree('temp_repo')
print(f"Contents of the repo 'git@github.com:S0ly/EpiTemplate.git' have been cloned to '{repo_name}' excluding '.git' directory.")
if __name__ == "__main__":
if len(sys.argv) < 2:
print('Usage: python script_name.py ssh_repo_link [repo_name]')
sys.exit(1)
repo_ssh = sys.argv[1]
if len(sys.argv) > 2:
repo_name = sys.argv[2]
else:
repo_name = os.path.basename(urlparse(repo_ssh).path).replace('.git', '')
manage_repo(repo_ssh, repo_name)