Fixed stuff and switched to tar

Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
fly 2021-01-13 20:45:19 +00:00
parent cc6f79b2ff
commit 1c338a0861

View file

@ -82,11 +82,11 @@ def read_index(fname):
index = {} index = {}
with open(fname) as f: with open(fname) as f:
for line in f: for line in f:
match = re.match("(.:.*):(.*)", line) match = re.match("(version|time|path|d:.*):(.*)", line)
if match != None: if match != None:
index[match.group(1)] = match.group(2) index[match.group(1)] = match.group(2)
else: else:
match = re.match("(version|time|path):(.*)", line) match = re.match("(.*:.*):(.*:.*)", line)
if match != None: if match != None:
index[match.group(1)] = match.group(2) index[match.group(1)] = match.group(2)
return index return index
@ -96,35 +96,41 @@ def write_index(fname, index):
for element in index: for element in index:
f.write(element + ":" + str(index[element]) + "\n") f.write(element + ":" + str(index[element]) + "\n")
def update_parent_index(base, path, changed_dir):
def update_index(output, name, name_major): if os.path.isfile(base + "/" + path + "/.dirindex"):
if os.path.isfile(output + "/" + name_major + "/.dirindex"): index = read_index(base + "/" + path + "/.dirindex")
index = read_index(output + "/" + name_major + "/.dirindex")
else: else:
index = {} index = {}
index["version"] = 1 index["version"] = 1
index["path"] = name_major if path != "":
index["path"] = "osm2city/" + path
sha = get_sha1(output + "/" + name_major + "/" + name + ".zip")
if sha != None:
index["z:" + name + ".zip"] = sha
write_index(output + "/" + name_major + "/.dirindex", index)
if os.path.isfile(output + "/.dirindex"):
main_index = read_index(output + "/.dirindex")
else: else:
main_index = {} index["path"] = "osm2city"
main_index["version"] = 1
main_index["path"] = ""
sha = get_sha1(output + "/" + name_major + "/.dirindex") sha = get_sha1(base + "/" + path + "/" + changed_dir + "/.dirindex")
if sha != None: if sha != None:
main_index["d:" + name_major] = sha index["d:" + changed_dir] = sha
write_index(output + "/.dirindex", main_index) write_index(base + "/" + path + "/.dirindex", index)
def update_index(output, part, name, name_major):
if os.path.isfile(output + "/" + part + "/" + name_major + "/.dirindex"):
index = read_index(output + "/" + part + "/" + name_major + "/.dirindex")
else:
index = {}
index["version"] = 1
index["path"] = "osm2city/" + part + "/" + name_major
sha = get_sha1(output + "/" + part + "/" + name_major + "/" + name + ".txz")
if sha != None:
index["t:" + name + ".txz"] = sha + ":" + str(os.path.getsize(output + "/" + part + "/" + name_major + "/" + name + ".txz"))
write_index(output + "/" + part + "/" + name_major + "/.dirindex", index)
update_parent_index(output, part, name_major)
update_parent_index(output, "", part)
running = True running = True
while running: while running:
try: try:
@ -153,22 +159,23 @@ while running:
name_major = ew + norm(ew_val_major, 3) + ns + norm(ns_val_major, 2) name_major = ew + norm(ew_val_major, 3) + ns + norm(ns_val_major, 2)
run("mkdir -p " + output + "/" + name_major, shell=True)
run("rm -f " + output + "/" + name_major + "/" + name + ".zip", shell=True)
print("Packaging " + name + "...") print("Packaging " + name + "...")
cmd = "bash -c 'cd projects/worldbuild/scenery && zip -rq " + output + "/" + name_major + "/" + name + ".zip {Details,Pylons,Buildings,Roads}/" + name_major + "/" + name + "/*'" for part in ["Buildings", "Details", "Pylons", "Roads"]:
with open(os.devnull, 'w') as fp: run("rm -f " + output + "/" + part + "/" + name_major + "/" + name + ".txz", shell=True)
package = Popen(cmd , shell=True, start_new_session=True, stdout=fp) if os.path.exists("projects/worldbuild/scenery/" + part + "/" + name_major + "/" + name):
run("mkdir -p " + output + "/" + part + "/" + name_major, shell=True)
package.wait() cmd = "bash -c 'cd projects/worldbuild/scenery/" + part + "/" + name_major + " && tar -cJf " + output + "/" + part + "/" + name_major + "/" + name + ".txz " + name + "/'"
with open(os.devnull, 'w') as fp:
package = Popen(cmd , shell=True, start_new_session=True, stdout=fp)
package.wait()
update_index(output, part, name, name_major)
print("Packaging " + name + " done") print("Packaging " + name + " done")
update_index(output, name, name_major)
send_status(name, "packaged", host, port) send_status(name, "packaged", host, port)
except KeyboardInterrupt: except KeyboardInterrupt: