bupa1018 commited on
Commit
bc25670
·
1 Parent(s): 9a649e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py CHANGED
@@ -48,6 +48,54 @@ def load_project_id(json_file):
48
  data = json.load(f)
49
  return data['project_id']
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  def download_gitlab_repo():
52
  print("Start the upload_gitRepository function")
53
  project_id = load_project_id('repository_ids.json')
 
48
  data = json.load(f)
49
  return data['project_id']
50
 
51
+
52
+ def download_gitlab_project_by_version():
53
+ try:
54
+ # Load the configuration from config.json
55
+ with open("config2.json", "r") as file:
56
+ config = json.load(file)
57
+
58
+ # Extract GitLab project information from the config
59
+ api_url = config['gitlab']['api_url']
60
+ project_id = urllib.parse.quote(config['gitlab']['project']['id'], safe="")
61
+ version = config['gitlab']['project']['version']
62
+
63
+ # Construct the URL for the release's zip file
64
+ url = f"{api_url}/projects/{project_id}/repository/archive.zip?sha={version}"
65
+
66
+ # Send GET request to download the zip file
67
+ response = requests.get(url, stream=True)
68
+
69
+ if response.status_code == 200:
70
+ # Extract filename from content-disposition header
71
+ content_disposition = response.headers.get("content-disposition")
72
+ if content_disposition and "filename=" in content_disposition:
73
+ filename = content_disposition.split("filename=")[-1].strip('"')
74
+
75
+ # target_path = f"{DATA_DIR}/{filename}"
76
+
77
+ # Check if the request was successful
78
+ if response.status_code == 200:
79
+ api.upload_file(
80
+ path_or_fileobj= f"{DATA_DIR}/{filename}",
81
+ path_in_repo= f"{DATA_DIR}/{filename}",
82
+ repo_id=HF_SPACE_NAME,
83
+ repo_type='space'
84
+ )
85
+ print(f"Release {version} downloaded successfully as {file_path}.")
86
+ else:
87
+ print(f"Failed to download the release: {response.status_code} - {response.reason}")
88
+ print(response.text)
89
+
90
+ except FileNotFoundError:
91
+ print("The config.json file was not found. Please ensure it exists in the project directory.")
92
+ except json.JSONDecodeError:
93
+ print("Failed to parse the config.json file. Please ensure it contains valid JSON.")
94
+ except Exception as e:
95
+ print(f"An error occurred: {e}")
96
+
97
+
98
+
99
  def download_gitlab_repo():
100
  print("Start the upload_gitRepository function")
101
  project_id = load_project_id('repository_ids.json')