1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-10 06:46:15 +01: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) conf.write_initial_config(e.file, config, True)
print >>sys.stderr, 'done' print >>sys.stderr, 'done'
conf.get_config(override_conffile = self.options.conffile, except oscerr.ConfigMissingApiurl, e:
override_apisrv = self.options.apisrv, print >>sys.stderr, e.msg
override_debug = self.options.debug, import getpass
override_http_debug = self.options.http_debug, user = raw_input('Username: ')
override_traceback = self.options.traceback, passwd = getpass.getpass()
override_post_mortem = self.options.post_mortem) 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 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 cookiejar = None
def parse_apisrv_url(scheme, apisrv): 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? # FIXME: it might be sufficient to just assume defaults?
msg = config_incomplete_text % conffile msg = config_incomplete_text % conffile
msg += new_conf_template % DEFAULTS msg += new_conf_template % DEFAULTS
raise oscerr.ConfigError(msg) raise oscerr.ConfigError(msg, conffile)
config = dict(cp.items('general', raw=1)) config = dict(cp.items('general', raw=1))
@ -285,7 +290,7 @@ def get_config(override_conffile = None,
try: try:
config[i] = cp.getboolean('general', i) config[i] = cp.getboolean('general', i)
except ValueError, e: 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']) 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: # provided that there _are_ credentials for the chosen apisrv:
if config['apisrv'] in config['auth_dict'].keys(): if config['apisrv'] in config['auth_dict'].keys():
config['user'] = config['auth_dict'][config['apisrv']]['user'] 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 # finally, initialize urllib2 for to use the credentials for Basic Authentication
init_basicauth(config) init_basicauth(config)

View File

@ -19,9 +19,16 @@ class UserAbort(OscBaseError):
class ConfigError(OscBaseError): class ConfigError(OscBaseError):
"""Exception raised when there is an error in the config file""" """Exception raised when there is an error in the config file"""
def __init__(self, msg): def __init__(self, msg, file):
OscBaseError.__init__(self) OscBaseError.__init__(self)
self.msg = msg 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): class APIError(OscBaseError):
"""Exception raised when there is an error in the output from the API""" """Exception raised when there is an error in the output from the API"""