From 39eb22b5923d63ef1932523f0c2a3fd87e01a10c Mon Sep 17 00:00:00 2001 From: Clement Verna Date: Sep 25 2016 15:43:58 +0000 Subject: [PATCH 1/2] Let click handle the stdout --- diff --git a/pagure_importer/commands/fedorahosted.py b/pagure_importer/commands/fedorahosted.py index 89d4ccb..9acf30a 100644 --- a/pagure_importer/commands/fedorahosted.py +++ b/pagure_importer/commands/fedorahosted.py @@ -1,5 +1,4 @@ import click -import getpass import pagure_importer from pagure_importer.app import app, REPO_PATH from pagure_importer.utils import importer_trac @@ -9,19 +8,24 @@ from pagure_importer.utils.fas import FASclient @app.command() @click.argument('project_url') @click.option('--tags', help="Import pagure tags:", is_flag=True) -@click.option('--private', help="By default make all issues private", is_flag=True) -def fedorahosted(project_url, tags, private): - username = raw_input('Enter you FAS Username: ') - password = getpass.getpass('Enter your FAS password: ') +@click.option('--private', help="By default make all issues private", + is_flag=True) +@click.option('--username', prompt="Enter your FAS Username: ", + help="FAS username") +@click.option('--password', prompt=True, hide_input=True, + help="FAS password") +def fedorahosted(project_url, tags, private, username, password): fasclient = FASclient(username, password, 'https://admin.fedoraproject.org/accounts') project_url = project_url + '/login/jsonrpc' repos = pagure_importer.utils.display_repo() if repos: - repo_index = raw_input('Choose the import destination repo (default 1) : ') or 1 + repo_index = click.prompt('Choose the import destination repo ', + default=1) repo_name = repos[int(repo_index)-1] trac_importer = importer_trac.TracImporter(project_url, username, - password, fasclient, tags, private) + password, fasclient, tags, + private) trac_importer.import_issues(repo_name=repo_name, repo_folder=REPO_PATH) else: click.echo('No ticket repository found. Use pgimport clone command') diff --git a/pagure_importer/commands/push.py b/pagure_importer/commands/push.py index e07fcf4..bc2c3d3 100644 --- a/pagure_importer/commands/push.py +++ b/pagure_importer/commands/push.py @@ -1,22 +1,18 @@ import click import os -import sys import subprocess as sp from pagure_importer.app import app, REPO_PATH @app.command() @click.argument('repo_name') -def push (repo_name): - not_cont = raw_input('Before executing this command, you must have' - ' "Pagure Tickets" enabled from pagure project\'s settings' - ' (Pressing just "Enter" will continue): ') - if not_cont: - sys.exit(1) - repo = os.path.join(REPO_PATH, repo_name) - os.chdir(repo) - cmd = ['git', 'push', 'origin', 'master' ] - proc = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.STDOUT) - output, _ = proc.communicate() - output = output.decode('utf-8') - click.echo(output) +def push(repo_name): + if click.confirm('Before executing this command, you must have' + '"Pagure Tickets" enabled from pagure project\'s settings. Continue?'): + repo = os.path.join(REPO_PATH, repo_name) + os.chdir(repo) + cmd = ['git', 'push', 'origin', 'master'] + proc = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.STDOUT) + output, _ = proc.communicate() + output = output.decode('utf-8') + click.echo(output) diff --git a/pagure_importer/utils/importer_trac.py b/pagure_importer/utils/importer_trac.py index 7ac7042..a4fc751 100644 --- a/pagure_importer/utils/importer_trac.py +++ b/pagure_importer/utils/importer_trac.py @@ -2,6 +2,7 @@ import requests import time import base64 import sys +import click from datetime import datetime from pagure_importer.utils.git import ( clone_repo, get_secure_filename, push_delete_repo, update_git) @@ -32,10 +33,10 @@ class TracImporter(): auth=(self.username, self.password)) resp = resp.json() if resp['id'] != self.reqid: - print('ERROR: Invalid response for request! ID does not match') + click.echo('ERROR: Invalid response for request! ID does not match') sys.exit(1) if resp['error'] != None: - print("ERROR: Error in response: %s" % resp['error']) + click.echo("ERROR: Error in response: %s" % resp['error']) sys.exit(1) return resp['result'] @@ -69,8 +70,8 @@ class TracImporter(): pagure_issue.comments.append(comments[key].to_json()) # update the local git repo new_repo = update_git(pagure_issue, newpath, new_repo) - print 'Updated ' + repo_name + ' with issue :' + str(ticket_id) +\ - '/' + str(tickets_id[-1]) + click.echo('Updated ' + repo_name + ' with issue :' + + str(ticket_id) + '/' + str(tickets_id[-1])) push_delete_repo(newpath, new_repo) def create_issue(self, ticket_id): From 5deebb1f3805cd5b2baa2c476d112091a2e6ed46 Mon Sep 17 00:00:00 2001 From: Clement Verna Date: Sep 25 2016 18:44:15 +0000 Subject: [PATCH 2/2] Removed redundant colon sign --- diff --git a/pagure_importer/commands/fedorahosted.py b/pagure_importer/commands/fedorahosted.py index 9acf30a..923b363 100644 --- a/pagure_importer/commands/fedorahosted.py +++ b/pagure_importer/commands/fedorahosted.py @@ -10,7 +10,7 @@ from pagure_importer.utils.fas import FASclient @click.option('--tags', help="Import pagure tags:", is_flag=True) @click.option('--private', help="By default make all issues private", is_flag=True) -@click.option('--username', prompt="Enter your FAS Username: ", +@click.option('--username', prompt="Enter your FAS Username", help="FAS username") @click.option('--password', prompt=True, hide_input=True, help="FAS password")