From abae983829d107df6ef35886ff83d13a89c06497 Mon Sep 17 00:00:00 2001 From: Patrick Uiterwijk Date: Feb 11 2017 10:35:38 +0000 Subject: Allow to import from Fedora Hosted without any git operations Signed-off-by: Patrick Uiterwijk --- diff --git a/pagure_importer/commands/fedorahosted.py b/pagure_importer/commands/fedorahosted.py index 5e22a64..75f3aad 100644 --- a/pagure_importer/commands/fedorahosted.py +++ b/pagure_importer/commands/fedorahosted.py @@ -20,37 +20,48 @@ import pagure_importer.utils.git as gitutils help='Number of issue in pagure before import') @click.option('--nopush', is_flag=True, help="Do not push the result of pagure-importer back") -def fedorahosted( - project_url, tags, private, username, password, offset, nopush): +@click.option('--project', default=None, + help='Project name, as namespace/project') +def fedorahosted(project_url, tags, private, username, password, offset, + nopush, project): fasclient = FASclient(username, password, 'https://admin.fedoraproject.org/accounts') if project_url.endswith('.git'): project_url = project_url.replace('.git', '') project_url += '/login/jsonrpc' repos = pagure_importer.utils.display_repo() - if repos: - repo_index = click.prompt('Choose the import destination repo ', - default=1) + repo_index = click.prompt('Choose the import destination repo ', + default=1) + if repo_index == 'n': + # We create a temporary directory to throw our stuff in + newpath = tempfile.mkdtemp() + print('Creating all issues into %s' % newpath) + new_repo = None + if not project: + raise Exception("With 'n', --project is required") + if not nopush: + raise Exception("With 'n', --nopush is required") + else: repo_name = repos[int(repo_index)-1] newpath, new_repo = gitutils.clone_repo(repo_name, REPO_PATH) - project = get_pagure_namespace(REPO_PATH, repo_name) - with importer_trac.TracImporter(project_url=project_url, - username=username, - password=password, - offset=offset, - repo_name=repo_name, - repo_folder=REPO_PATH, - fasclient=fasclient, - tags=tags, - private=private, - nopush=nopush) as trac_importer: + if not project: + project = get_pagure_namespace(REPO_PATH, repo_name) + with importer_trac.TracImporter(project_url=project_url, + username=username, + password=password, + offset=offset, + repo_name=repo_name, + repo_folder=REPO_PATH, + fasclient=fasclient, + tags=tags, + private=private, + nopush=nopush) as trac_importer: - trac_importer.import_issues(project) + trac_importer.import_issues(project) + if new_repo: # update the local git repo new_repo = gitutils.update_git( new_repo, commit_message='Imported issues from fedorahosted project: %s' % repo_name) - if not nopush: - gitutils.push_repo(new_repo) - else: - click.echo('No ticket repository found. Use pgimport clone command') + if not nopush: + gitutils.push_repo(new_repo) diff --git a/pagure_importer/utils/__init__.py b/pagure_importer/utils/__init__.py index 2e11f18..f4de437 100644 --- a/pagure_importer/utils/__init__.py +++ b/pagure_importer/utils/__init__.py @@ -98,6 +98,7 @@ def display_repo(): index += 1 click.echo(str(index) + ' - ' + file) repo.append(file) + click.echo('n - New') click.echo() return repo