File size: 1,147 Bytes
a466cca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import os, io, zipfile, shutil, requests
GITHUB_SOURCES=[("RTLucassen","B-line_detection"),("ljhowell","LUS-Segmentation-RT"),("GuoJiaqi-1020","MeDiVLAD")]
def _dl_and_extract(owner, repo, ref):
    url=f"https://github.com/{owner}/{repo}/archive/refs/heads/{ref}.zip"
    r=requests.get(url,timeout=60); r.raise_for_status()
    z=zipfile.ZipFile(io.BytesIO(r.content)); tmp=f"_tmp_{repo}"; os.makedirs(tmp,exist_ok=True); z.extractall(tmp)
    top=[os.path.join(tmp,d) for d in os.listdir(tmp) if os.path.isdir(os.path.join(tmp,d))]
    src=top[0]; dst=os.path.join("external",repo); os.makedirs("external",exist_ok=True)
    if os.path.exists(dst): shutil.rmtree(dst); shutil.move(src,dst); shutil.rmtree(tmp,ignore_errors=True); return dst
def fetch_upstream():
    os.makedirs("external",exist_ok=True); results={}
    for owner,repo in GITHUB_SOURCES:
        if os.path.exists(os.path.join("external",repo)): results[repo]="exists"; continue
        try: _dl_and_extract(owner,repo,"main"); results[repo]="downloaded-main"
        except Exception: _dl_and_extract(owner,repo,"master"); results[repo]="downloaded-master"
    return results