i0110 commited on
Commit
db88506
Β·
verified Β·
1 Parent(s): 576f616

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -17,6 +17,7 @@ def download_github_files(repo_url, file_paths):
17
  repo_name = repo_url.split('/')[-1].replace(".git", "")
18
  local_repo_path = os.path.join(temp_dir, repo_name)
19
 
 
20
  # ε…‹ιš†δ»“εΊ“
21
  Repo.clone_from(repo_url, local_repo_path)
22
 
@@ -24,21 +25,24 @@ def download_github_files(repo_url, file_paths):
24
  with zipfile.ZipFile(zip_file_path, 'w', zipfile.ZIP_DEFLATED) as zf:
25
  for file_path in file_paths:
26
  abs_file_path = os.path.join(local_repo_path, file_path)
 
27
  if os.path.exists(abs_file_path) and os.path.isfile(abs_file_path):
28
- zf.write(abs_file_path, os.path.basename(abs_file_path))
29
  elif os.path.exists(abs_file_path) and os.path.isdir(abs_file_path):
30
  for root, dirs, files in os.walk(abs_file_path):
31
  for file in files:
32
  file_abs_path = os.path.join(root, file)
33
  zf.write(file_abs_path, os.path.relpath(file_abs_path, local_repo_path))
34
 
 
35
  shutil.rmtree(local_repo_path) # εˆ ι™€ε…‹ιš†ηš„δ»“εΊ“
36
  if os.path.exists(zip_file_path) and os.path.getsize(zip_file_path) > 0:
37
  return zip_file_path, f"{repo_name}_files.zip"
38
  else:
39
- return None, None
 
40
  except Exception as e:
41
- print(f"Error during download: {e}")
42
  return None, None
43
 
44
 
@@ -49,8 +53,10 @@ def parse_github_url(url):
49
  owner, repo, branch, path = match.groups()
50
  repo_url = f'https://github.com/{owner}/{repo}.git'
51
  file_paths = [path.lstrip('/')] if path else []
 
52
  return repo_url, file_paths
53
  else:
 
54
  return None, None
55
 
56
 
 
17
  repo_name = repo_url.split('/')[-1].replace(".git", "")
18
  local_repo_path = os.path.join(temp_dir, repo_name)
19
 
20
+ print(f"Cloning repo: {repo_url} to {local_repo_path}") # 打印
21
  # ε…‹ιš†δ»“εΊ“
22
  Repo.clone_from(repo_url, local_repo_path)
23
 
 
25
  with zipfile.ZipFile(zip_file_path, 'w', zipfile.ZIP_DEFLATED) as zf:
26
  for file_path in file_paths:
27
  abs_file_path = os.path.join(local_repo_path, file_path)
28
+ print(f"Checking file path: {abs_file_path}") # 打印
29
  if os.path.exists(abs_file_path) and os.path.isfile(abs_file_path):
30
+ zf.write(abs_file_path, os.path.basename(abs_file_path))
31
  elif os.path.exists(abs_file_path) and os.path.isdir(abs_file_path):
32
  for root, dirs, files in os.walk(abs_file_path):
33
  for file in files:
34
  file_abs_path = os.path.join(root, file)
35
  zf.write(file_abs_path, os.path.relpath(file_abs_path, local_repo_path))
36
 
37
+
38
  shutil.rmtree(local_repo_path) # εˆ ι™€ε…‹ιš†ηš„δ»“εΊ“
39
  if os.path.exists(zip_file_path) and os.path.getsize(zip_file_path) > 0:
40
  return zip_file_path, f"{repo_name}_files.zip"
41
  else:
42
+ print(f"Zip file is empty or not created.")# 打印
43
+ return None, None
44
  except Exception as e:
45
+ print(f"Error during download: {e}") # 打印
46
  return None, None
47
 
48
 
 
53
  owner, repo, branch, path = match.groups()
54
  repo_url = f'https://github.com/{owner}/{repo}.git'
55
  file_paths = [path.lstrip('/')] if path else []
56
+ print(f"Parsed repo_url: {repo_url}, file_paths: {file_paths}") # 打印
57
  return repo_url, file_paths
58
  else:
59
+ print(f"Invalid URL: {url}") # 打印
60
  return None, None
61
 
62