| |
@@ -1,5 +1,6 @@
|
| |
import csv
|
| |
import os
|
| |
+ import sys
|
| |
import json
|
| |
import click
|
| |
import urlparse
|
| |
@@ -10,6 +11,10 @@
|
| |
from pagure_importer.utils.exceptions import FileNotFound, EmailNotFound
|
| |
from pagure_importer.app import REPO_PATH
|
| |
|
| |
+ CFG_PATH = os.path.join(os.environ.get('HOME'), '.pgimport')
|
| |
+ CONFIG = ConfigParser()
|
| |
+ CONFIG.optionxform = str
|
| |
+
|
| |
|
| |
def create_auth_token(github):
|
| |
''' Creates github authentication token. If Two Factor Authentication
|
| |
@@ -27,21 +32,53 @@
|
| |
return otp_auth
|
| |
|
| |
|
| |
+ def create_config():
|
| |
+ '''Create the config file with default close statuses
|
| |
+ and an empty github auth_token'''
|
| |
+
|
| |
+ CONFIG['close_status'] = {'Invalid': ['invalid', 'wontfix', 'worksforme'],
|
| |
+ 'Insufficient data': ['insufficient_info'],
|
| |
+ 'Duplicate': ['duplicate']}
|
| |
+ CONFIG['github'] = {'auth_token': ''}
|
| |
+ if os.path.exists(CFG_PATH):
|
| |
+ if click.confirm('You already have a config file, if you continue '
|
| |
+ 'your custom settings will be lost'):
|
| |
+ with click.open_file(CFG_PATH, 'w+') as config_file:
|
| |
+ CONFIG.write(config_file)
|
| |
+ else:
|
| |
+ sys.exit(1)
|
| |
+ else:
|
| |
+ with click.open_file(CFG_PATH, 'w+') as config_file:
|
| |
+ CONFIG.write(config_file)
|
| |
+
|
| |
+
|
| |
+ def get_close_status():
|
| |
+ ''' Read the config file and returns the close statuses'''
|
| |
+
|
| |
+ close_status = None
|
| |
+ if os.path.exists(CFG_PATH):
|
| |
+ CONFIG.read(CFG_PATH)
|
| |
+ close_status = CONFIG['close_status']
|
| |
+ else:
|
| |
+ create_config()
|
| |
+ CONFIG.read(CFG_PATH)
|
| |
+ close_status = CONFIG['close_status']
|
| |
+ return close_status
|
| |
+
|
| |
+
|
| |
def get_auth_token(github):
|
| |
''' Checks the .pgimport file for github authentication key,
|
| |
if it is not present, creates it. '''
|
| |
|
| |
- cfg_path = os.path.join(os.environ.get('HOME'), '.pgimport')
|
| |
- if os.path.exists(cfg_path):
|
| |
- parser = ConfigParser()
|
| |
- parser.read(cfg_path)
|
| |
- otp_auth = parser['github']['auth_token']
|
| |
- else:
|
| |
- otp_auth = create_auth_token(github)
|
| |
- otp_auth = otp_auth.token
|
| |
- with click.open_file(cfg_path, 'w+') as fp:
|
| |
- fp.write('[github] \nauth_token : %s' % otp_auth)
|
| |
- return otp_auth
|
| |
+ if os.path.exists(CFG_PATH):
|
| |
+ CONFIG.read(CFG_PATH)
|
| |
+ otp_auth = CONFIG['github']['auth_token']
|
| |
+ if not otp_auth:
|
| |
+ otp_auth = create_auth_token(github)
|
| |
+ CONFIG['github']['auth_token'] = otp_auth.token
|
| |
+ with click.open_file(CFG_PATH, 'w+') as config_file:
|
| |
+ CONFIG.write(config_file)
|
| |
+ return otp_auth
|
| |
|
| |
|
| |
def display_repo():
|
| |
Thi will allow a user to change the close status by edting a config file, before running the import.