1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-09-20 09:16:16 +02:00
- added a file attribute to the ConfigError() class
- added new ConfigMissingApiurl() class
This commit is contained in:
Marcus Hüwe 2008-08-07 17:14:26 +00:00
parent 8d055f7990
commit 3359646b02
3 changed files with 37 additions and 9 deletions

View File

@ -78,12 +78,25 @@ class Osc(cmdln.Cmdln):
conf.write_initial_config(e.file, config, True)
print >>sys.stderr, 'done'
conf.get_config(override_conffile = self.options.conffile,
override_apisrv = self.options.apisrv,
override_debug = self.options.debug,
override_http_debug = self.options.http_debug,
override_traceback = self.options.traceback,
override_post_mortem = self.options.post_mortem)
except oscerr.ConfigMissingApiurl, e:
print >>sys.stderr, e.msg
import getpass
user = raw_input('Username: ')
passwd = getpass.getpass()
cp = conf.get_configParser()
cp.add_section(e.url)
cp.set(e.url, 'user', user)
cp.set(e.url, 'pass', passwd)
file = open(e.file, 'w')
cp.write(file, True)
if file: file.close()
conf.get_config(override_conffile = self.options.conffile,
override_apisrv = self.options.apisrv,
override_debug = self.options.debug,
override_http_debug = self.options.http_debug,
override_traceback = self.options.traceback,
override_post_mortem = self.options.post_mortem)
self.conf = conf

View File

@ -130,6 +130,11 @@ Make sure that it has a [general] section.
"""
config_missing_apiurl_text = """
the apiurl \'%s\' does not exist in the config file. Please enter
your credentials for this apiurl.
"""
cookiejar = None
def parse_apisrv_url(scheme, apisrv):
@ -274,7 +279,7 @@ def get_config(override_conffile = None,
# FIXME: it might be sufficient to just assume defaults?
msg = config_incomplete_text % conffile
msg += new_conf_template % DEFAULTS
raise oscerr.ConfigError(msg)
raise oscerr.ConfigError(msg, conffile)
config = dict(cp.items('general', raw=1))
@ -285,7 +290,7 @@ def get_config(override_conffile = None,
try:
config[i] = cp.getboolean('general', i)
except ValueError, e:
raise oscerr.ConfigError('cannot parse \'%s\' setting: ' % i + str(e))
raise oscerr.ConfigError('cannot parse \'%s\' setting: ' % i + str(e), conffile)
config['packagecachedir'] = os.path.expanduser(config['packagecachedir'])
@ -330,6 +335,9 @@ def get_config(override_conffile = None,
# provided that there _are_ credentials for the chosen apisrv:
if config['apisrv'] in config['auth_dict'].keys():
config['user'] = config['auth_dict'][config['apisrv']]['user']
else:
raise oscerr.ConfigMissingApiurl(config_missing_apiurl_text % config['apisrv'],
conffile, config['apiurl'])
# finally, initialize urllib2 for to use the credentials for Basic Authentication
init_basicauth(config)

View File

@ -19,9 +19,16 @@ class UserAbort(OscBaseError):
class ConfigError(OscBaseError):
"""Exception raised when there is an error in the config file"""
def __init__(self, msg):
def __init__(self, msg, file):
OscBaseError.__init__(self)
self.msg = msg
self.file = file
class ConfigMissingApiurl(ConfigError):
"""Exception raised when a apiurl does not exist in the config file"""
def __init__(self, msg, file, url):
ConfigError.__init__(self, msg, file)
self.url = url
class APIError(OscBaseError):
"""Exception raised when there is an error in the output from the API"""