mirror of
https://github.com/tuna/tunasync-scripts.git
synced 2025-04-20 04:12:42 +00:00
anaconda: report error when something is wrong
Signed-off-by: Harry Chen <i@harrychen.xyz>
This commit is contained in:
parent
b9697ced2a
commit
f8afa1f57c
22
anaconda.py
22
anaconda.py
@ -3,6 +3,7 @@ import hashlib
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import errno
|
import errno
|
||||||
import random
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
@ -211,11 +212,7 @@ def sync_repo(repo_url: str, local_dir: Path, tmpdir: Path, delete: bool, remove
|
|||||||
shutil.move(str(tmp_repodata) + ".gz", str(local_dir / "repodata.json.gz"))
|
shutil.move(str(tmp_repodata) + ".gz", str(local_dir / "repodata.json.gz"))
|
||||||
else:
|
else:
|
||||||
# If the gzip file is not generated, remove the dangling gzip archive
|
# If the gzip file is not generated, remove the dangling gzip archive
|
||||||
try:
|
Path(local_dir / "repodata.json.gz").unlink(missing_ok=True)
|
||||||
os.remove(str(local_dir / "repodata.json.gz"))
|
|
||||||
except OSError as e:
|
|
||||||
if e.errno != errno.ENOENT:
|
|
||||||
raise
|
|
||||||
|
|
||||||
shutil.move(str(tmp_repodata), str(local_dir / "repodata.json"))
|
shutil.move(str(tmp_repodata), str(local_dir / "repodata.json"))
|
||||||
shutil.move(str(tmp_bz2_repodata), str(local_dir / "repodata.json.bz2"))
|
shutil.move(str(tmp_bz2_repodata), str(local_dir / "repodata.json.bz2"))
|
||||||
@ -232,12 +229,8 @@ def sync_repo(repo_url: str, local_dir: Path, tmpdir: Path, delete: bool, remove
|
|||||||
shutil.move(str(tmp_current_repodata), str(
|
shutil.move(str(tmp_current_repodata), str(
|
||||||
local_dir / "current_repodata.json"))
|
local_dir / "current_repodata.json"))
|
||||||
if not tmp_current_repodata_gz_gened:
|
if not tmp_current_repodata_gz_gened:
|
||||||
try:
|
# If the gzip file is not generated, remove the dangling gzip archive
|
||||||
# If the gzip file is not generated, remove the dangling gzip archive
|
Path(local_dir / "current_repodata.json.gz").unlink(missing_ok=True)
|
||||||
os.remove(str(local_dir / "current_repodata.json.gz"))
|
|
||||||
except OSError as e:
|
|
||||||
if e.errno != errno.ENOENT:
|
|
||||||
raise
|
|
||||||
|
|
||||||
if delete:
|
if delete:
|
||||||
local_filelist = []
|
local_filelist = []
|
||||||
@ -334,6 +327,8 @@ def main():
|
|||||||
size_statistics = 0
|
size_statistics = 0
|
||||||
random.seed()
|
random.seed()
|
||||||
|
|
||||||
|
success = True
|
||||||
|
|
||||||
logging.info("Syncing installers...")
|
logging.info("Syncing installers...")
|
||||||
for dist in ("archive", "miniconda"):
|
for dist in ("archive", "miniconda"):
|
||||||
remote_url = "{}/{}".format(CONDA_REPO_BASE_URL, dist)
|
remote_url = "{}/{}".format(CONDA_REPO_BASE_URL, dist)
|
||||||
@ -344,6 +339,7 @@ def main():
|
|||||||
f.stat().st_size for f in local_dir.glob('*') if f.is_file())
|
f.stat().st_size for f in local_dir.glob('*') if f.is_file())
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.exception("Failed to sync installers of {}".format(dist))
|
logging.exception("Failed to sync installers of {}".format(dist))
|
||||||
|
success = False
|
||||||
|
|
||||||
for repo in CONDA_REPOS:
|
for repo in CONDA_REPOS:
|
||||||
for arch in CONDA_ARCHES:
|
for arch in CONDA_ARCHES:
|
||||||
@ -356,6 +352,7 @@ def main():
|
|||||||
local_dir, Path(tmpdir), args.delete, args.remove_legacy)
|
local_dir, Path(tmpdir), args.delete, args.remove_legacy)
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.exception("Failed to sync repo: {}/{}".format(repo, arch))
|
logging.exception("Failed to sync repo: {}/{}".format(repo, arch))
|
||||||
|
success = False
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(tmpdir)
|
shutil.rmtree(tmpdir)
|
||||||
|
|
||||||
@ -369,10 +366,13 @@ def main():
|
|||||||
local_dir, Path(tmpdir), args.delete, args.remove_legacy)
|
local_dir, Path(tmpdir), args.delete, args.remove_legacy)
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.exception("Failed to sync repo: {}".format(repo))
|
logging.exception("Failed to sync repo: {}".format(repo))
|
||||||
|
success = False
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(tmpdir)
|
shutil.rmtree(tmpdir)
|
||||||
|
|
||||||
print("Total size is", sizeof_fmt(size_statistics, suffix=""))
|
print("Total size is", sizeof_fmt(size_statistics, suffix=""))
|
||||||
|
if not success:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user