diff --git a/.gitignore b/.gitignore index 3e80c5b..92c5d4c 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,5 @@ venv.bak/ # configuration rt2zammad.json +# cache +rt2zammad.cache diff --git a/migrate.py b/migrate.py index 0227fc3..11d98cc 100755 --- a/migrate.py +++ b/migrate.py @@ -3,13 +3,15 @@ Quick and dirty attempt to migrate issues from Request Tracker to Zammad. """ +import pickle import json import os import sys from requests.exceptions import HTTPError from zammad_py import ZammadAPI -from rt import Rt +from zammad_py.api import TagList +from rt import Rt, ALL_QUEUES TEMPLATE = """{ "zammad_host": "", @@ -43,3 +45,42 @@ source = Rt(config['rt_url'], config['rt_user'], config['rt_pass']) if not source.login(): print('Failed to login to RT!') sys.exit(2) + +if os.path.exists('rt2zammad.cache'): + with open('rt2zammad.cache', 'rb') as handle: + data = pickle.load(handle) + users = data['users'] + queues = data['queues'] + tickets = data['tickets'] + +else: + users = {} + tickets = [] + queues = set() + + def ensure_user(username): + if username not in users: + users[username] = source.get_user(username) + + + for i in range(1, 1000): + print('Loading ticket {}'.format(i)) + ticket = source.get_ticket(i) + if ticket is None: + break + queues.add(ticket['Queue']) + ensure_user(ticket['Creator']) + ensure_user(ticket['Owner']) + history = source.get_history(i) + attachments = [] + for a in source.get_attachments_ids(i): + attachment = source.get_attachment(i, a) + attachments.append(attachments) + ensure_user(attachment['Creator']) + tickets.append({ + 'ticket': ticket, + 'history': history, + 'attachments': attachments, + }) + with open('rt2zammad.cache', 'wb') as handle: + data = pickle.dump({'users': users, 'queues': queues, 'tickets': tickets}, handle)