-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_downloader.py
More file actions
42 lines (31 loc) · 1.63 KB
/
github_downloader.py
File metadata and controls
42 lines (31 loc) · 1.63 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
import subprocess
import os
import argparse
def github_downloader(repo_url, destination_path, folders):
try:
# Step 1: Initialize a new Git repository
subprocess.run(["git", "init", destination_path], check=True)
os.chdir(destination_path)
# Step 2: Set the remote origin
subprocess.run(["git", "remote", "add", "origin", repo_url], check=True)
# Step 3: Enable sparse-checkout
subprocess.run(["git", "sparse-checkout", "init", "--cone"], check=True)
# Step 4: Specify the folders to include
subprocess.run(["git", "sparse-checkout", "set"] + folders, check=True)
# Step 5: Pull the repository
subprocess.run(["git", "pull", "origin", "main"], check=True)
print(f"Cloned specific folders {folders} to {destination_path}")
except subprocess.CalledProcessError as e:
print(f"Error during cloning: {e}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Clone specific filders from github repository.")
parser.add_argument("repo_url", help="GitHub repository URL")
parser.add_argument("destination_path",help="Destination path for the cloned repository")
parser.add_argument("folders", nargs="+", help="Folders to clone from the repository")
args = parser.parse_args()
github_downloader(args.repo_url, args.destination_path, args.folders)
# # Example usage
# repo_url = "https://github.com/SkyentificGit/Moteus.git"
# destination_path = "./github_downloader/git/"
# folders = ["MJBotsPythonLibrary"] # Specify the folders you want to clone
# github_downloader(repo_url, destination_path, folders)