From c5649188c4177bbd2456b1d367b19e30af5aebc8 Mon Sep 17 00:00:00 2001 From: Clement Verna Date: Jan 08 2017 17:39:19 +0000 Subject: Remove Importer class so that we gain flexibility between fedorahosted and github Signed-off-by: Clement Verna --- diff --git a/pagure_importer/utils/__init__.py b/pagure_importer/utils/__init__.py index a81887e..8cab974 100644 --- a/pagure_importer/utils/__init__.py +++ b/pagure_importer/utils/__init__.py @@ -243,28 +243,6 @@ def is_image(filename): return False -class Importer: - ''' Common Class for Github and Feodrahosted importer''' - - def __init__(self, username, password, repo_name, repo_folder, nopush): - self.username = username - self.password = password - self.repo_name = repo_name - self.repo_folder = repo_folder - self.clone_repo_location = os.path.join( - repo_folder, 'clone-' + repo_name) - self.nopush = nopush - - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_val, exc_tb): - ''' Delete the cloned repo where the commits were going ''' - if os.path.exists(self.clone_repo_location): - if not self.nopush: - shutil.rmtree(self.clone_repo_location) - - def issue_to_json(issue, folder): ''' Write the specified issue as a JSON blob on the specified folder. Returns a list of all the files changed or created. diff --git a/pagure_importer/utils/importer_github.py b/pagure_importer/utils/importer_github.py index adcebc2..866c750 100644 --- a/pagure_importer/utils/importer_github.py +++ b/pagure_importer/utils/importer_github.py @@ -1,24 +1,41 @@ import click +import os +import shutil from github import Github from pagure_importer.utils import ( - models, gh_get_user_email, get_auth_token, Importer, issue_to_json + models, gh_get_user_email, get_auth_token, issue_to_json ) -class GithubImporter(Importer): +class GithubImporter(object): ''' Imports from Github using PyGithub and libpagure ''' def __init__(self, username, password, project, repo_name, repo_folder, nopush): ''' Instantiate GithubImporter object ''' - Importer.__init__(self, username, password, repo_name, repo_folder, nopush) + self.username = username + self.password = password + self.repo_name = repo_name + self.repo_folder = repo_folder + self.clone_repo_location = os.path.join( + repo_folder, 'clone-' + repo_name) + self.nopush = nopush self.github_project_name = project self.github = Github(username, password) otp_auth = get_auth_token(self.github) self.github = Github(otp_auth) + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + ''' Delete the cloned repo where the commits were going ''' + if os.path.exists(self.clone_repo_location): + if not self.nopush: + shutil.rmtree(self.clone_repo_location) + def get_issue_assignee(self, github_issue): ''' From the github issue object, return the assignee of the issue if any ''' diff --git a/pagure_importer/utils/importer_trac.py b/pagure_importer/utils/importer_trac.py index eb1d20c..2d731b0 100644 --- a/pagure_importer/utils/importer_trac.py +++ b/pagure_importer/utils/importer_trac.py @@ -3,11 +3,12 @@ import re import time import click import requests +import shutil +import os from base64 import b64decode from datetime import datetime from pagure_importer.utils import ( - get_close_status, is_image, Importer, issue_to_json, - get_secure_filename) + get_close_status, is_image, issue_to_json, get_secure_filename) from pagure_importer.utils.models import User, Issue, IssueComment @@ -20,13 +21,19 @@ def to_timestamp(tm): return ts -class TracImporter(Importer): +class TracImporter(object): ''' Pagure importer for trac instance ''' def __init__(self, project_url, username, password, offset, repo_name, repo_folder, nopush, fasclient=None, tags=False, private=False): ''' Instantiate a TracImporter object ''' - Importer.__init__(self, username, password, repo_name, repo_folder, nopush) + self.username = username + self.password = password + self.repo_name = repo_name + self.repo_folder = repo_folder + self.clone_repo_location = os.path.join( + repo_folder, 'clone-' + repo_name) + self.nopush = nopush self.url = project_url self.fas = fasclient self.tags = tags @@ -37,6 +44,15 @@ class TracImporter(Importer): self.reqid = 0 self.custom_fields = self.get_custom_fields() + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + ''' Delete the cloned repo where the commits were going ''' + if os.path.exists(self.clone_repo_location): + if not self.nopush: + shutil.rmtree(self.clone_repo_location) + def request(self, method, *args): ''' Common method for querying trac '''