mirror of
https://github.com/tuna/tunasync-scripts.git
synced 2025-04-20 04:12:42 +00:00
delete empty folders
This commit is contained in:
parent
71a221c3f7
commit
1e9d0b7329
@ -24,10 +24,10 @@ REPOS = [
|
|||||||
"git-lfs/git-lfs",
|
"git-lfs/git-lfs",
|
||||||
"prometheus/prometheus",
|
"prometheus/prometheus",
|
||||||
"commercialhaskell/stackage-content", # Used by stackage
|
"commercialhaskell/stackage-content", # Used by stackage
|
||||||
{"repo": "xxr3376/Learn-Project", "all_versions": True},
|
{"repo": "xxr3376/Learn-Project", "versions": -1},
|
||||||
{"repo": "robertying/learnX", "all_versions": True},
|
{"repo": "robertying/learnX", "versions": -1},
|
||||||
"rust-analyzer/rust-analyzer",
|
"rust-analyzer/rust-analyzer",
|
||||||
{"repo": "iina/iina", "all_versions": True, "pre_release": True, "flat": True},
|
{"repo": "iina/iina", "versions": -1, "pre_release": True, "flat": True},
|
||||||
]
|
]
|
||||||
|
|
||||||
# connect and read timeout value
|
# connect and read timeout value
|
||||||
@ -167,16 +167,16 @@ def main():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
for cfg in REPOS:
|
for cfg in REPOS:
|
||||||
flat = False
|
flat = False # build a folder for each release
|
||||||
all_versions = False
|
versions = 1 # keep only one release
|
||||||
tarball = False
|
tarball = False # do not download the tarball
|
||||||
prerelease = False
|
prerelease = False # filter out pre-releases
|
||||||
if isinstance(cfg, str):
|
if isinstance(cfg, str):
|
||||||
repo = cfg
|
repo = cfg
|
||||||
else:
|
else:
|
||||||
repo = cfg["repo"]
|
repo = cfg["repo"]
|
||||||
if "all_versions" in cfg:
|
if "versions" in cfg:
|
||||||
all_versions = cfg["all_versions"]
|
versions = cfg["versions"]
|
||||||
if "flat" in cfg:
|
if "flat" in cfg:
|
||||||
flat = cfg["flat"]
|
flat = cfg["flat"]
|
||||||
if "tarball" in cfg:
|
if "tarball" in cfg:
|
||||||
@ -195,7 +195,7 @@ def main():
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
break
|
break
|
||||||
|
|
||||||
nothing = True
|
n_downloaded = 0
|
||||||
for release in releases:
|
for release in releases:
|
||||||
if not release['draft'] and (prerelease or not release['prerelease']):
|
if not release['draft'] and (prerelease or not release['prerelease']):
|
||||||
name = ensure_safe_name(release['name'] or release['tag_name'])
|
name = ensure_safe_name(release['name'] or release['tag_name'])
|
||||||
@ -203,12 +203,13 @@ def main():
|
|||||||
print("Error: Unnamed release")
|
print("Error: Unnamed release")
|
||||||
continue
|
continue
|
||||||
download(release, (repo_dir if flat else repo_dir / name), tarball)
|
download(release, (repo_dir if flat else repo_dir / name), tarball)
|
||||||
if nothing and not flat:
|
if n_downloaded == 0 and not flat:
|
||||||
|
# create a symbolic link to the latest release folder
|
||||||
link_latest(name, repo_dir)
|
link_latest(name, repo_dir)
|
||||||
nothing = False
|
n_downloaded += 1
|
||||||
if not all_versions: # only download the latest release
|
if versions > 0 and n_downloaded >= versions:
|
||||||
break
|
break
|
||||||
if nothing:
|
if n_downloaded == 0:
|
||||||
print(f"Error: No release version found for {repo}")
|
print(f"Error: No release version found for {repo}")
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
@ -231,6 +232,13 @@ def main():
|
|||||||
old_file = working_dir / old_file
|
old_file = working_dir / old_file
|
||||||
old_file.unlink()
|
old_file.unlink()
|
||||||
|
|
||||||
|
for local_dir in working_dir.glob('*/*/*'):
|
||||||
|
if local_dir.is_dir():
|
||||||
|
try:
|
||||||
|
# remove empty dirs only
|
||||||
|
local_dir.rmdir()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user