mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-13 17:16:23 +01:00
Refactor config setup dialog
Move logic to conf module in new function interactive_config_setup for new config file and missing apiurl section. Dropped keyring code, because it was never used in write_initial_config()
This commit is contained in:
parent
dbed74a13f
commit
428a81e451
@ -146,27 +146,16 @@ class Osc(cmdln.Cmdln):
|
||||
except oscerr.NoConfigfile as e:
|
||||
print(e.msg, file=sys.stderr)
|
||||
print('Creating osc configuration file %s ...' % e.file, file=sys.stderr)
|
||||
import getpass
|
||||
config = {}
|
||||
config['user'] = raw_input('Username: ')
|
||||
config['pass'] = getpass.getpass()
|
||||
if self.options.no_keyring:
|
||||
config['use_keyring'] = '0'
|
||||
if self.options.no_gnome_keyring:
|
||||
config['gnome_keyring'] = '0'
|
||||
apiurl = conf.DEFAULTS['apiurl']
|
||||
if self.options.apiurl:
|
||||
config['apiurl'] = self.options.apiurl
|
||||
|
||||
conf.write_initial_config(e.file, config)
|
||||
apiurl = self.options.apiurl
|
||||
conf.interactive_config_setup(e.file, apiurl)
|
||||
print('done', file=sys.stderr)
|
||||
if try_again:
|
||||
self.postoptparse(try_again = False)
|
||||
except oscerr.ConfigMissingApiurl as e:
|
||||
print(e.msg, file=sys.stderr)
|
||||
import getpass
|
||||
user = raw_input('Username: ')
|
||||
passwd = getpass.getpass()
|
||||
conf.add_section(e.file, e.url, user, passwd)
|
||||
conf.interactive_config_setup(e.file, e.url, initial=False)
|
||||
if try_again:
|
||||
self.postoptparse(try_again = False)
|
||||
|
||||
|
13
osc/conf.py
13
osc/conf.py
@ -43,6 +43,7 @@ import re
|
||||
import sys
|
||||
import ssl
|
||||
import warnings
|
||||
import getpass
|
||||
|
||||
try:
|
||||
from http.cookiejar import LWPCookieJar, CookieJar
|
||||
@ -1061,4 +1062,16 @@ def identify_conf():
|
||||
|
||||
return conffile
|
||||
|
||||
def interactive_config_setup(conffile, apiurl, initial=True):
|
||||
user = raw_input('Username: ')
|
||||
passwd = getpass.getpass()
|
||||
if initial:
|
||||
config = {'user': user, 'pass': passwd}
|
||||
if apiurl:
|
||||
config['apiurl'] = apiurl
|
||||
write_initial_config(conffile, config)
|
||||
else:
|
||||
add_section(conffile, apiurl, user, passwd)
|
||||
|
||||
|
||||
# vim: sw=4 et
|
||||
|
Loading…
Reference in New Issue
Block a user