Skip to content

Commit

Permalink
test: trying to fix download issue
Browse files Browse the repository at this point in the history
Signed-off-by: Mike <[email protected]>
  • Loading branch information
mike-sul committed Aug 9, 2023
1 parent 91d50c2 commit 737b772
Showing 1 changed file with 42 additions and 41 deletions.
83 changes: 42 additions & 41 deletions lmp/generate-static-deltas
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,20 @@ class ProgressCb:


def drain(progress: Progress, response, prog_cb: ProgressCb, dst: str):
p = Popen(["tar", "-xj"], cwd=dst, stdin=PIPE)
#p = Popen(["tar", "-xj"], cwd=dst, stdin=PIPE)

for chunk in response.iter_content(chunk_size=1024 * 1024):
if chunk:
p.stdin.write(chunk)
#p.stdin.write(chunk)
status(f"Read {len(chunk)} bytes")
prog_cb(len(chunk))
p.stdin.close()
p.wait()
# p.stdin.close()
# p.wait()
progress.tick()


def _download_extract(progress: Progress, tarurls: List[str], dst: str):
status(f"Downloading: {tarurls} -> {dst}ostree_repo")

total_length = 0
responses = []
for u in tarurls:
Expand Down Expand Up @@ -177,42 +178,42 @@ def main(creds_zip_file: str, deltas: List[Delta], factory: str, tok_secret_name
if len(downloads) > 0:
_download_extract(prog, downloads, "./")

if len(pulls) > 0:
status(f"Pulling: {pulls} -> ./ostree_repo")
for commit in pulls:
pull_ostree_commit(factory, commit, "./ostree_repo", tok_secret_name, ostree_url)

delta_stats = generate_deltas(prog, deltas, "./ostree_repo")

# update summary and generate a new type of delta indexes
cmd("ostree", "summary", "-u", "--repo=./ostree_repo")

# TODO: remove the following code that determines and prints a type of delta indexes been generated
# once we completely switch to the new indexes types. https://foundriesio.atlassian.net/browse/FFTK-1122
if os.path.isdir("./ostree_repo/delta-indexes"):
with open("./ostree_repo/config", "r") as f:
config = f.readlines()
for e in config:
if e == "indexed-deltas=true\n":
status("New type of delta indexes are generated and enabled in the repo config")
break
else:
status("Old type of delta indexes are generated (in-summary type)")

rmtree("./ostree_repo/objects") # We just need to sync deltas
os.remove("./ostree_repo/summary") # summary is generated by the ostree server
cmd("fiopush", "-summary", "-repo=./ostree_repo", "-creds", creds_zip_file)
prog.tick()

for to_sha, s in delta_stats.items():
with open(os.path.join(out_dir, f"{to_sha}.json"), "wb") as f:
f.write(s["canonical-json"])
prog.tick()

upload_delta_stats(prog, factory, delta_stats, tok_secret_name)

add_delta_stat_refs_to_targets(creds_zip_file, delta_stats)
prog.tick()
# if len(pulls) > 0:
# status(f"Pulling: {pulls} -> ./ostree_repo")
# for commit in pulls:
# pull_ostree_commit(factory, commit, "./ostree_repo", tok_secret_name, ostree_url)
#
# delta_stats = generate_deltas(prog, deltas, "./ostree_repo")
#
# # update summary and generate a new type of delta indexes
# cmd("ostree", "summary", "-u", "--repo=./ostree_repo")
#
# # TODO: remove the following code that determines and prints a type of delta indexes been generated
# # once we completely switch to the new indexes types. https://foundriesio.atlassian.net/browse/FFTK-1122
# if os.path.isdir("./ostree_repo/delta-indexes"):
# with open("./ostree_repo/config", "r") as f:
# config = f.readlines()
# for e in config:
# if e == "indexed-deltas=true\n":
# status("New type of delta indexes are generated and enabled in the repo config")
# break
# else:
# status("Old type of delta indexes are generated (in-summary type)")
#
# rmtree("./ostree_repo/objects") # We just need to sync deltas
# os.remove("./ostree_repo/summary") # summary is generated by the ostree server
# cmd("fiopush", "-summary", "-repo=./ostree_repo", "-creds", creds_zip_file)
# prog.tick()
#
# for to_sha, s in delta_stats.items():
# with open(os.path.join(out_dir, f"{to_sha}.json"), "wb") as f:
# f.write(s["canonical-json"])
# prog.tick()
#
# upload_delta_stats(prog, factory, delta_stats, tok_secret_name)
#
# add_delta_stat_refs_to_targets(creds_zip_file, delta_stats)
# prog.tick()


if __name__ == "__main__":
Expand Down

0 comments on commit 737b772

Please sign in to comment.