mirror of
https://github.com/tuna/tunasync-scripts.git
synced 2025-04-20 04:12:42 +00:00
flushing output for logging
This commit is contained in:
parent
5b57ea3d14
commit
c5560d6db2
14
apt-sync.py
14
apt-sync.py
@ -69,7 +69,7 @@ def check_and_download(url: str, dst_file: Path)->int:
|
|||||||
os.utime(dst_file, (remote_ts, remote_ts))
|
os.utime(dst_file, (remote_ts, remote_ts))
|
||||||
return 0
|
return 0
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
print(e)
|
print(e, flush=True)
|
||||||
if dst_file.is_file():
|
if dst_file.is_file():
|
||||||
dst_file.unlink()
|
dst_file.unlink()
|
||||||
return 1
|
return 1
|
||||||
@ -95,7 +95,7 @@ def apt_mirror(base_url: str, dist: str, repo: str, arch: str, dest_base_dir: Pa
|
|||||||
if not dest_base_dir.is_dir():
|
if not dest_base_dir.is_dir():
|
||||||
print("Destination directory is empty, cannot continue")
|
print("Destination directory is empty, cannot continue")
|
||||||
return 1
|
return 1
|
||||||
print(f"Started mirroring {base_url} {dist}, {repo}, {arch}!")
|
print(f"Started mirroring {base_url} {dist}, {repo}, {arch}!", flush=True)
|
||||||
|
|
||||||
# download Release files
|
# download Release files
|
||||||
dist_dir,dist_tmp_dir = mkdir_with_dot_tmp(dest_base_dir / "dists" / dist)
|
dist_dir,dist_tmp_dir = mkdir_with_dot_tmp(dest_base_dir / "dists" / dist)
|
||||||
@ -143,7 +143,7 @@ def apt_mirror(base_url: str, dist: str, repo: str, arch: str, dest_base_dir: Pa
|
|||||||
print(f"Invalid checksum of {pkgidx_file}, expected {checksum}")
|
print(f"Invalid checksum of {pkgidx_file}, expected {checksum}")
|
||||||
return 1
|
return 1
|
||||||
if pkgidx_content is None and pkgidx_file.stem == 'Packages':
|
if pkgidx_content is None and pkgidx_file.stem == 'Packages':
|
||||||
print(f"getting packages index content from {pkgidx_file.name}")
|
print(f"getting packages index content from {pkgidx_file.name}", flush=True)
|
||||||
suffix = pkgidx_file.suffix
|
suffix = pkgidx_file.suffix
|
||||||
if suffix == '.xz':
|
if suffix == '.xz':
|
||||||
pkgidx_content = lzma.decompress(content).decode('utf-8')
|
pkgidx_content = lzma.decompress(content).decode('utf-8')
|
||||||
@ -183,7 +183,7 @@ def apt_mirror(base_url: str, dist: str, repo: str, arch: str, dest_base_dir: Pa
|
|||||||
pkg_size = int(pattern_package_size.search(pkg).group(1))
|
pkg_size = int(pattern_package_size.search(pkg).group(1))
|
||||||
pkg_checksum = pattern_package_sha256.search(pkg).group(1)
|
pkg_checksum = pattern_package_sha256.search(pkg).group(1)
|
||||||
except:
|
except:
|
||||||
print("Failed to parse one package description")
|
print("Failed to parse one package description", flush=True)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
err = 1
|
err = 1
|
||||||
continue
|
continue
|
||||||
@ -202,7 +202,7 @@ def apt_mirror(base_url: str, dist: str, repo: str, arch: str, dest_base_dir: Pa
|
|||||||
|
|
||||||
pkg_url=f"{base_url}/{pkg_filename}"
|
pkg_url=f"{base_url}/{pkg_filename}"
|
||||||
for retry in range(MAX_RETRY):
|
for retry in range(MAX_RETRY):
|
||||||
print(f"downloading {pkg_url} to {dest_filename}")
|
print(f"downloading {pkg_url} to {dest_filename}", flush=True)
|
||||||
# break # dry run
|
# break # dry run
|
||||||
if check_and_download(pkg_url, dest_filename) != 0:
|
if check_and_download(pkg_url, dest_filename) != 0:
|
||||||
continue
|
continue
|
||||||
@ -232,7 +232,7 @@ def apt_mirror(base_url: str, dist: str, repo: str, arch: str, dest_base_dir: Pa
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
print(f"Mirroring {base_url} {dist}, {repo}, {arch} done!")
|
print(f"Mirroring {base_url} {dist}, {repo}, {arch} done!")
|
||||||
print(f"{deb_count} packages, {deb_size} bytes in total")
|
print(f"{deb_count} packages, {deb_size} bytes in total", flush=True)
|
||||||
return err
|
return err
|
||||||
|
|
||||||
def apt_delete_old_debs(dest_base_dir: Path, remote_set: Set[str], dry_run: bool):
|
def apt_delete_old_debs(dest_base_dir: Path, remote_set: Set[str], dry_run: bool):
|
||||||
@ -241,7 +241,7 @@ def apt_delete_old_debs(dest_base_dir: Path, remote_set: Set[str], dry_run: bool
|
|||||||
deleting = on_disk - remote_set
|
deleting = on_disk - remote_set
|
||||||
# print(on_disk)
|
# print(on_disk)
|
||||||
# print(remote_set)
|
# print(remote_set)
|
||||||
print(f"Deleting {len(deleting)} packages not in the index{' (dry run)' if dry_run else ''}")
|
print(f"Deleting {len(deleting)} packages not in the index{' (dry run)' if dry_run else ''}", flush=True)
|
||||||
for i in deleting:
|
for i in deleting:
|
||||||
if dry_run:
|
if dry_run:
|
||||||
print("Will delete", i)
|
print("Will delete", i)
|
||||||
|
@ -88,17 +88,20 @@ repo_gpgcheck=0
|
|||||||
gpgcheck=0
|
gpgcheck=0
|
||||||
enabled=1
|
enabled=1
|
||||||
''')
|
''')
|
||||||
dest_dirs.append((args.working_dir / name).absolute())
|
dst = (args.working_dir / name).absolute()
|
||||||
|
dst.mkdir(parents=True, exist_ok=True)
|
||||||
|
dest_dirs.append(dst)
|
||||||
conf.flush()
|
conf.flush()
|
||||||
# sp.run(["cat", conf.name])
|
# sp.run(["cat", conf.name])
|
||||||
# sp.run(["ls", "-la", cache_dir])
|
# sp.run(["ls", "-la", cache_dir])
|
||||||
|
|
||||||
if len(dest_dirs) == 0:
|
if len(dest_dirs) == 0:
|
||||||
print("Nothing to sync")
|
print("Nothing to sync", flush=True)
|
||||||
failed.append(('', arch))
|
failed.append(('', arch))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
cmd_args = ["reposync", "-a", arch, "-c", conf.name, "-d", "-p", str(args.working_dir.absolute()), "-e", cache_dir]
|
cmd_args = ["reposync", "-a", arch, "-c", conf.name, "-d", "-p", str(args.working_dir.absolute()), "-e", cache_dir]
|
||||||
|
print("Launching reposync", flush=True)
|
||||||
# print(cmd_args)
|
# print(cmd_args)
|
||||||
ret = sp.run(cmd_args)
|
ret = sp.run(cmd_args)
|
||||||
if ret.returncode != 0:
|
if ret.returncode != 0:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user