diff --git a/rt2fs b/rt2fs index c841c0d..03098ca 100755 --- a/rt2fs +++ b/rt2fs @@ -52,34 +52,39 @@ os.makedirs("attachments", exist_ok=True) ticket_ids = range(config["rt_start"], config["rt_end"]) -def dump(id): +def dump(id, retries=3): print(f"Dumping RT#{id}") - ticket_dumpfile = f"tickets/{id}" - if not os.path.exists(ticket_dumpfile): - ticket = rt.get_ticket(id) - if ticket is None: - print("Got 'None' while fetching ticket") - os.exit(1) - ticket["original_id"] = str(id) - if ticket["Queue"] != 'spam': - maybe_dump_user(rt, ticket["Creator"]) - maybe_dump_user(rt, ticket["Owner"]) + try: + ticket_dumpfile = f"tickets/{id}" + if not os.path.exists(ticket_dumpfile): + ticket = rt.get_ticket(id) + if ticket is None: + print("Got 'None' while fetching ticket") + os.exit(1) + ticket["original_id"] = str(id) + if ticket["Queue"] != 'spam': + maybe_dump_user(rt, ticket["Creator"]) + maybe_dump_user(rt, ticket["Owner"]) - if ticket["original_id"] != ticket["numerical_id"]: - # Merged ticket - history = [] - else: - history = rt.get_history(id) - for item in history: - for a, title in item["Attachments"]: - attachment = rt.get_attachment(id, a) - os.makedirs(f"attachments/{id}", exist_ok=True) - with open(f"attachments/{id}/{a}", "wb") as handle: - pickle.dump(attachment, handle) - maybe_dump_user(rt, item["Creator"]) - data = {"ticket": ticket, "history": history} - with open(ticket_dumpfile, "wb") as handle: - pickle.dump(data, handle) + if ticket["original_id"] != ticket["numerical_id"]: + # Merged ticket + history = [] + else: + history = rt.get_history(id) + for item in history: + for a, title in item["Attachments"]: + attachment = rt.get_attachment(id, a) + os.makedirs(f"attachments/{id}", exist_ok=True) + with open(f"attachments/{id}/{a}", "wb") as handle: + pickle.dump(attachment, handle) + maybe_dump_user(rt, item["Creator"]) + data = {"ticket": ticket, "history": history} + with open(ticket_dumpfile, "wb") as handle: + pickle.dump(data, handle) + except: + print(f"Failed to dump RT#{id}.. ({retries} retries left)") + if retries > 0: + dump(id, retries - 1) worker_count = 4 with Pool(worker_count) as p: