def generate_issue(self, **kwds): issue = Issue() issue.project = kwds.get("project", self.project) issue.summary = kwds.get("summary", random_string(32)) issue.description = kwds.get("description", random_string()) issue.steps_to_reproduce = kwds.get("steps_to_reproduce", random_string()) issue.priority = Priority.objects.get(short_name=kwds.get("priority", random_priority())) issue.issue_type = IssueType.objects.get(short_name=kwds.get("issue_type", random_issue_type())) issue.status = kwds.get("status", random_status()) issue.resolution = kwds.get("resolution", random_resolution()) if issue.status == "OPEN" and not "resolution" in kwds: issue.resolution = Issue.RESOLUTION_CHOICES[0][0] issue.milestone = kwds.get("milestone", self.milestone) issue.reporter = kwds.get("reporter", self.user) issue.assignee = kwds.get("assignee", self.user) issue.save() issue.components = kwds.get("components", [self.component_two]) issue.affects_versions = kwds.get("affects_versions", [self.version_one]) issue.fix_versions = kwds.get("fix_versions", [self.version_one]) return issue
def handle(self, *args, **options): def log(msg): sys.stdout.write(msg) sys.stdout.flush() print(args, options) print("Setting up project key maps.") project_key_map_args = options.get("project_key_map") or [] project_key_map = self.split_key_value_pairs(project_key_map_args) print(project_key_map) print("Initializing username mappings") user_name_map = self.split_key_value_pairs(options.get("user_map") or []) user_map = {} print("Initializing priority mappings.") priority_name_map = self.default_priority_map priority_map = {k: Priority.objects.get(short_name=v) for k, v in priority_name_map.items()} print("Initializing resolution mappings.") resolution_map = self.default_resolution_map status_map = self.default_status_map print("Initializing issue type mappings.") issue_type_name_map = self.default_issue_type_map issue_type_map = {k: IssueType.objects.get(short_name=v) for k, v in issue_type_name_map.items()} default_issue_type = issue_type_map[self.default_issue_type] log_dot = DotLogger() cur = None try: self.create_temporary_tables() print("Acquiring connection.") conn = connections[options.get("database")] cur = conn.cursor() print("Importing users.") cur.execute("SELECT userid, login_name FROM profiles") for row in cur: username = user_name_map.get(row[1]) or row[1] try: user = User.objects.get(username=username) except User.DoesNotExist: try: user = User.objects.get(email=username) except User.DoesNotExist: user = User(username=username, email=row[1], password=username) user.save() user_map[row[0]] = user.pk print("Importing products as projects.") cur.execute("SELECT id, name, description FROM products") all_projects = {row[0]: Project(name=row[1], description=row[2]) for row in cur} import_projects(all_projects.values(), project_key_map) print("Importing versions.") cur.execute("SELECT id, value, product_id from versions") for row in cur: project = all_projects.get(row[2]) version = Version(name=row[1], description="Autoimport from bugzilla.", project=project) version.save() print("Importing components.") cur.execute("SELECT id, name, description, product_id from components") for row in cur: project = all_projects.get(row[-1]) component = Component(name=row[1], description=row[2], project=project) component.save() print("Importing issues.") print("starting query") issue_type_field_clause = ", cf_issue_type AS issue_type" cur.execute(""" SELECT bug.bug_id AS id, assignee.login_name AS assignee, bug.product_id AS product_id, bug.bug_severity AS priority, bug.bug_status AS status, bug.creation_ts AS creation_time, bug.delta_ts AS delta_time, bug.short_desc AS summary, reporter.login_name AS reporter, bug.version AS version_name, c.name AS component_name, bug.lastdiffed AS last_changed, bug.resolution AS resolution {0} FROM bugs bug JOIN profiles assignee ON bug.assigned_to = assignee.userid JOIN profiles reporter ON bug.reporter = reporter.userid LEFT JOIN components c ON bug.component_id = c.id """.format(issue_type_field_clause)) print("query done") for row in rowdict_cursor(cur): assignee = User.objects.get(email=row["assignee"]) project = all_projects[row["product_id"]] priority = priority_map[row["priority"]] status = status_map[row["status"]] creation_time = row["creation_time"] delta_time = row["delta_time"] summary = row["summary"] reporter = User.objects.get(email=row["reporter"]) version = project.version_set.get(name=row["version_name"]) component = project.component_set.get(name=row["component_name"]) last_changed = row["last_changed"] resolution = resolution_map[row["resolution"]] issue_type = issue_type_map.get(row["issue_type"], default_issue_type) issue = Issue() issue.project = project issue.issue_type = issue_type issue.assignee = assignee issue.reporter = reporter issue.priority = priority issue.summary = summary issue.status = status issue.resolution = resolution issue.reported = creation_time issue.last_updated = last_changed issue.save(update_timestamps=False) issue.affects_versions = [version] issue.fix_versions = [version] issue.components = [component] bugzilla_map = BugzillaIssueMap() bugzilla_map.issue = issue bugzilla_map.bugzilla_id = row["id"] bugzilla_map.save() log_dot() print("") print("Importing comments.") cur.execute(""" SELECT d.bug_id AS bug, p.login_name AS user_email, d.bug_when AS timestamp, d.thetext AS description FROM longdescs d JOIN profiles p ON d.who = p.userid ORDER BY bug """) for row in rowdict_cursor(cur): bugzilla_map = BugzillaIssueMap.objects.get(bugzilla_id=row["bug"]) author = User.objects.get(email=row["user_email"]) timestamp = row["timestamp"] text = row["description"] if text: if timestamp == bugzilla_map.issue.reported: bugzilla_map.issue.description += text bugzilla_map.issue.save(update_timestamps=False) else: comment = Comment() comment.content = bugzilla_map.issue comment.text = text comment.author = author comment.created = timestamp comment.updated = timestamp comment.save(update_timestamps=False) log_dot() finally: if cur is not None: cur.close()