2009-08-20 21:28:05 +02:00
|
|
|
# Copyright (C) 2006-2009 Novell Inc. All rights reserved.
|
2006-10-10 16:04:34 +02:00
|
|
|
# This program is free software; it may be used, copied, modified
|
|
|
|
# and distributed under the terms of the GNU General Public Licence,
|
2009-08-20 21:28:05 +02:00
|
|
|
# either version 2, or version 3 (at your option).
|
2006-10-10 16:04:34 +02:00
|
|
|
|
2013-04-09 12:51:28 +02:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2006-10-10 16:04:34 +02:00
|
|
|
"""Read osc configuration and store it in a dictionary
|
|
|
|
|
2017-10-27 11:29:00 +02:00
|
|
|
This module reads and parses oscrc. The resulting configuration is stored
|
2009-10-20 16:30:15 +02:00
|
|
|
for later usage in a dictionary named 'config'.
|
2017-10-27 11:29:00 +02:00
|
|
|
The oscrc is kept mode 0600, so that it is not publically readable.
|
2009-10-20 16:30:15 +02:00
|
|
|
This gives no real security for storing passwords.
|
2009-08-20 21:28:05 +02:00
|
|
|
If in doubt, use your favourite keyring.
|
2017-10-27 11:29:00 +02:00
|
|
|
Password is stored on ~/.config/osc/oscrc as bz2 compressed and base64 encoded, so that is fairly
|
2009-08-20 21:28:05 +02:00
|
|
|
large and not to be recognized or remembered easily by an occasional spectator.
|
2006-10-10 16:04:34 +02:00
|
|
|
|
|
|
|
If information is missing, it asks the user questions.
|
|
|
|
|
|
|
|
After reading the config, urllib2 is initialized.
|
|
|
|
|
|
|
|
The configuration dictionary could look like this:
|
|
|
|
|
2007-04-25 12:24:51 +02:00
|
|
|
{'apisrv': 'https://api.opensuse.org/',
|
2009-03-02 15:03:06 +01:00
|
|
|
'user': 'joe',
|
|
|
|
'api_host_options': {'api.opensuse.org': {'user': 'joe', 'pass': 'secret'},
|
|
|
|
'apitest.opensuse.org': {'user': 'joe', 'pass': 'secret',
|
2008-08-20 11:45:49 +02:00
|
|
|
'http_headers':(('Host','api.suse.de'),
|
|
|
|
('User','faye'))},
|
|
|
|
'foo.opensuse.org': {'user': 'foo', 'pass': 'foo'}},
|
2006-10-10 16:04:34 +02:00
|
|
|
'build-cmd': '/usr/bin/build',
|
|
|
|
'build-root': '/abuild/oscbuild-%(repo)s-%(arch)s',
|
|
|
|
'packagecachedir': '/var/cache/osbuild',
|
|
|
|
'su-wrapper': 'sudo',
|
|
|
|
}
|
|
|
|
|
|
|
|
"""
|
2009-10-29 18:27:20 +01:00
|
|
|
|
2014-01-07 10:24:07 +01:00
|
|
|
import bz2
|
2011-08-17 15:33:56 +02:00
|
|
|
import base64
|
2021-10-21 02:44:20 +02:00
|
|
|
import errno
|
2011-08-17 15:33:56 +02:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
2015-11-28 22:32:45 +01:00
|
|
|
import ssl
|
2016-06-15 12:14:41 +02:00
|
|
|
import warnings
|
2019-08-26 11:30:41 +02:00
|
|
|
import getpass
|
2013-04-09 12:36:42 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
from http.cookiejar import LWPCookieJar, CookieJar
|
|
|
|
from http.client import HTTPConnection, HTTPResponse
|
|
|
|
from io import StringIO
|
|
|
|
from urllib.parse import urlsplit
|
2013-04-09 14:03:17 +02:00
|
|
|
from urllib.error import URLError
|
|
|
|
from urllib.request import HTTPBasicAuthHandler, HTTPCookieProcessor, HTTPPasswordMgrWithDefaultRealm, ProxyHandler
|
2015-11-28 22:32:45 +01:00
|
|
|
from urllib.request import AbstractHTTPHandler, build_opener, proxy_bypass, HTTPSHandler
|
2013-04-09 12:36:42 +02:00
|
|
|
except ImportError:
|
|
|
|
#python 2.x
|
|
|
|
from cookielib import LWPCookieJar, CookieJar
|
|
|
|
from httplib import HTTPConnection, HTTPResponse
|
|
|
|
from StringIO import StringIO
|
|
|
|
from urlparse import urlsplit
|
2016-06-15 12:14:41 +02:00
|
|
|
from urllib2 import URLError, HTTPBasicAuthHandler, HTTPCookieProcessor, HTTPPasswordMgrWithDefaultRealm, ProxyHandler, AbstractBasicAuthHandler
|
2015-11-28 22:32:45 +01:00
|
|
|
from urllib2 import AbstractHTTPHandler, build_opener, proxy_bypass, HTTPSHandler
|
2011-07-15 20:10:45 +02:00
|
|
|
|
2013-04-09 11:35:53 +02:00
|
|
|
from . import OscConfigParser
|
Merged revisions 3774-3775,3779,3781-3782,3787,3789-3793,3798,3802,3805,3817-3822,3827,3829-3830,3837-3839,3841-3842,3848-3850 via svnmerge from
https://forgesvn1.novell.com/svn/opensuse/branches/buildservice/osc-exception-handling
........
r3774 | poeml | 2008-04-22 17:39:45 +0200 (Tue, 22 Apr 2008) | 3 lines
A first draft on implement systematic exception handling:
Add errors.py with some exceptions defined, and babysitter.py to handle them
........
r3775 | poeml | 2008-04-22 22:34:12 +0200 (Tue, 22 Apr 2008) | 9 lines
- new global options:
--debugger jump into the debugger before executing anything
--post-mortem jump into the debugger in case of errors
-t, --traceback print call trace in case of errors
- traceback and post_mortem can also be set in .oscrc.
- catch more errors (HTTPError).
- make config accessible from outside of the Osc instance, by making it a class
attribute
........
r3779 | poeml | 2008-04-23 00:55:49 +0200 (Wed, 23 Apr 2008) | 5 lines
- new global option:
-d, --debug print info useful for debugging
- catch some more errors (HTTPError), with OscHTTPError which isn't very
advanced yet.
........
r3781 | Marcus_H | 2008-04-23 01:02:00 +0200 (Wed, 23 Apr 2008) | 2 lines
- added OscConfigError class (just for testing).
- small change in the signature of the OscBaseError constructor (actually we should get rid of the 'args' tuple because it will be deprecated sooner or later
........
r3782 | Marcus_H | 2008-04-23 02:02:13 +0200 (Wed, 23 Apr 2008) | 2 lines
- access the prg.conf.config dict in a save way - this way we avoid AttributeErrors if the prg.conf.config dict doesn't exist
- in case of an configparser error we have to use the prg.options object directly (this was removed in r3781 by accident)
........
r3787 | poeml | 2008-04-23 09:23:56 +0200 (Wed, 23 Apr 2008) | 4 lines
- remove local exception handling from do_req
- for HTTPError, print details (headers and response) when in debug mode
- catch AttributeError
........
r3789 | poeml | 2008-04-23 16:23:14 +0200 (Wed, 23 Apr 2008) | 4 lines
- errors: add two new classes named OscWrongOptionsError and OscWrongArgsError
- commandline: raise instances of the new errors in a number of places
- commandline: add get_cmd_help() to Osc instance which returns the formatted help of a subcommand
........
r3790 | Marcus_H | 2008-04-23 16:48:28 +0200 (Wed, 23 Apr 2008) | 4 lines
- added 2 new exception classes: OscNoConfigfileError and OscIOError
- added new method write_config() to the conf.py module: This method writes osc's configuration file
- minor cleanups in the conf module
........
r3791 | poeml | 2008-04-23 17:11:07 +0200 (Wed, 23 Apr 2008) | 3 lines
small compatibility fix for r3790: try-except-finally isn't supported in
python-2.4.2, thus do the same as try-except inside a try-finally.
........
r3792 | poeml | 2008-04-23 17:37:53 +0200 (Wed, 23 Apr 2008) | 2 lines
fix up the remaining places regarding handling of errors related to commandline parsing
........
r3793 | poeml | 2008-04-23 17:40:34 +0200 (Wed, 23 Apr 2008) | 3 lines
raise a NoWorkingCopyError in osc.core.store_read_project() in case of an
IOError
........
r3798 | Marcus_H | 2008-04-23 23:55:24 +0200 (Wed, 23 Apr 2008) | 1 line
ported -r3797 from trunk
........
r3802 | Marcus_H | 2008-04-24 11:00:55 +0200 (Thu, 24 Apr 2008) | 1 line
ported -r3801 from trunk
........
r3805 | poeml | 2008-04-24 12:52:30 +0200 (Thu, 24 Apr 2008) | 2 lines
raise OscHTTPError in show_pattern_meta(), replacing local error handling
........
r3817 | poeml | 2008-04-24 20:21:32 +0200 (Thu, 24 Apr 2008) | 9 lines
- remove errors.OscHTTPError again.
it seems simpler to use urllib2.HTTPError instead (and just add a specific
error text message where appropriate, and re-raise)
- for 404s, check out _which_ part was not found
it is very ugly, but may be considered Good for pragmatic reasons
- removed local exception handling and workaround for returned 500's from
delete_package() and delete_project(), thereby getting rid of 4 possible exit
points.
........
r3818 | Marcus_H | 2008-04-24 22:36:17 +0200 (Thu, 24 Apr 2008) | 1 line
- this check is superfluous because every HTTPError instance has a code attribute
........
r3819 | poeml | 2008-04-25 00:39:39 +0200 (Fri, 25 Apr 2008) | 1 line
remove a forgotten debug line from core.delete_project()
........
r3820 | poeml | 2008-04-25 10:07:58 +0200 (Fri, 25 Apr 2008) | 2 lines
- ditch local error handling from wipebinaries(), rebuild(), and abortbuild()
........
r3821 | poeml | 2008-04-25 10:56:38 +0200 (Fri, 25 Apr 2008) | 2 lines
It is never needed to import the exception module.
........
r3822 | poeml | 2008-04-25 11:13:39 +0200 (Fri, 25 Apr 2008) | 4 lines
- when going into the debugger with --post-mortem, always print a traceback before
(thus implying -t)
- do not jump into the debugger if not on a TTY, or working in interactive mode
........
r3827 | poeml | 2008-04-25 13:07:46 +0200 (Fri, 25 Apr 2008) | 9 lines
- add errors.OscWorkingCopyOutdated, which takes a tuple with three args:
path to working copy, current rev, expected rev
- add handler for urllib2.URLError errors to the babysitter
- simplify the OscWrongArgsError and OscWrongOptionsError handlers, by removing
the extra line "Sorry, wrong ..." that was printed before the messages given
when the error was raised.
- remove one more errors.OscHTTPError which was still there, and raise
urllib2.HTTPError instead (show_package_meta())
........
r3829 | poeml | 2008-04-25 14:19:10 +0200 (Fri, 25 Apr 2008) | 11 lines
- comment some methods in osc.core which are used by nearly all do_* methods in
osc.commandline
- improve "is not a package/project dir" error messages, by printing the
absolute path tried, instead of '.' for the cwd
- make core.store_read_package() raise a proper NoWorkingCopyError instead of
terminating
- give attribution to things in babysitter.py copied from mercurial
- prefix HTTPError exceptions with 'Server returned an error:'
- remove obsolete local error handling from do_prjresults(), do_importsrcpkg(),
do_repos()
........
r3830 | poeml | 2008-04-25 14:29:35 +0200 (Fri, 25 Apr 2008) | 1 line
catch IOError exceptions in the babysitter
........
r3837 | poeml | 2008-04-25 17:27:36 +0200 (Fri, 25 Apr 2008) | 5 lines
- do_remotebuildlog: raise errors for wrong arguments, remove exits
- raise AttributeError in make_meta_url() instead of exiting
- delete unused method core.delete_server_files()
- replace exit call inside make_meta_url() with an AttributeError
........
r3838 | poeml | 2008-04-25 17:49:18 +0200 (Fri, 25 Apr 2008) | 1 line
simplify the check in do_checkout if a project exists, by using show_project_meta() instead of meta_exists
........
r3839 | poeml | 2008-04-25 18:31:26 +0200 (Fri, 25 Apr 2008) | 6 lines
- commandline do_checkout(): change the order of the two checks, first do the
(cheaper) check for existing directory
- core.core checkout_package(): simplify the check in if the package
exists, by using show_package_meta() instead of meta_exists
Let it throw an exception, instead of using sys.exit().
........
r3841 | Marcus_H | 2008-04-27 15:48:06 +0200 (Sun, 27 Apr 2008) | 5 lines
- added 2 new exception classes: PackageError() and PackageExistsError. The PackageError() class is meant to be the base class for all subsequent package exceptions.
- get rid of 2 sys.exit(1) calls
- make the update() method of the Project() class safer: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- minor fix in delPackage(): use getTransActPath() when printing out the filename
........
r3842 | Marcus_H | 2008-04-27 16:52:55 +0200 (Sun, 27 Apr 2008) | 3 lines
- make the commit() method safe: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- removed another sys.exit(1): raise an exception if a package is missing when doing a commit. For now we use the PackageExistsError() exception but this might change in the future (updated description of PackageExistsError() according to this change)
........
r3848 | poeml | 2008-04-28 12:46:45 +0200 (Mon, 28 Apr 2008) | 3 lines
rename several error classes, dropping the "Osc" prefix, and "Error" suffix in
cases where they don't really make sense.
........
r3849 | poeml | 2008-04-28 12:57:32 +0200 (Mon, 28 Apr 2008) | 3 lines
- rename osc.errors module to osc.oscerr, to make it easier to import it from
other programs and have a crystal clear namespace
........
r3850 | poeml | 2008-04-28 13:26:12 +0200 (Mon, 28 Apr 2008) | 2 lines
split PackageExists exception class into PackageExists and PackageMissing
........
2008-04-28 18:37:44 +02:00
|
|
|
from osc import oscerr
|
2019-08-27 15:08:38 +02:00
|
|
|
from osc.util.helper import raw_input
|
2013-04-09 11:35:53 +02:00
|
|
|
from .oscsslexcp import NoSecureSSLError
|
2019-08-27 15:08:38 +02:00
|
|
|
from osc import credentials
|
2006-10-10 16:04:34 +02:00
|
|
|
|
2009-09-04 19:48:53 +02:00
|
|
|
GENERIC_KEYRING = False
|
|
|
|
GNOME_KEYRING = False
|
|
|
|
|
2009-05-11 09:46:01 +02:00
|
|
|
try:
|
2009-09-04 19:48:53 +02:00
|
|
|
import keyring
|
|
|
|
GENERIC_KEYRING = True
|
|
|
|
except:
|
2009-10-20 16:30:15 +02:00
|
|
|
try:
|
|
|
|
import gobject
|
|
|
|
gobject.set_application_name('osc')
|
|
|
|
import gnomekeyring
|
2019-08-27 17:50:57 +02:00
|
|
|
GNOME_KEYRING = gnomekeyring.is_available()
|
2009-10-20 16:30:15 +02:00
|
|
|
except:
|
|
|
|
pass
|
2006-10-10 16:04:34 +02:00
|
|
|
|
2011-08-17 15:33:56 +02:00
|
|
|
|
2011-02-18 00:34:49 +01:00
|
|
|
def _get_processors():
|
|
|
|
"""
|
|
|
|
get number of processors (online) based on
|
2021-09-03 10:41:43 +02:00
|
|
|
SC_NPROCESSORS_ONLN (returns 1 if config name/os.sysconf does not exist).
|
2011-02-18 00:34:49 +01:00
|
|
|
"""
|
|
|
|
try:
|
|
|
|
return os.sysconf('SC_NPROCESSORS_ONLN')
|
2021-09-03 10:41:43 +02:00
|
|
|
except (AttributeError, ValueError):
|
2011-02-18 00:34:49 +01:00
|
|
|
return 1
|
|
|
|
|
2021-08-12 02:21:11 +02:00
|
|
|
|
|
|
|
def _identify_osccookiejar():
|
|
|
|
if os.path.isfile(os.path.join(os.path.expanduser("~"), '.osc_cookiejar')):
|
|
|
|
# For backwards compatibility, use the old location if it exists
|
|
|
|
return '~/.osc_cookiejar'
|
|
|
|
|
|
|
|
if os.getenv('XDG_STATE_HOME', '') != '':
|
|
|
|
osc_state_dir = os.path.join(os.getenv('XDG_STATE_HOME'), 'osc')
|
|
|
|
else:
|
|
|
|
osc_state_dir = os.path.join(os.path.expanduser("~"), '.local', 'state', 'osc')
|
|
|
|
|
|
|
|
return os.path.join(osc_state_dir, 'cookiejar')
|
|
|
|
|
2011-08-17 15:33:56 +02:00
|
|
|
DEFAULTS = {'apiurl': 'https://api.opensuse.org',
|
2019-08-27 15:08:38 +02:00
|
|
|
'user': None,
|
|
|
|
'pass': None,
|
|
|
|
'passx': None,
|
2011-08-17 15:33:56 +02:00
|
|
|
'packagecachedir': '/var/tmp/osbuild-packagecache',
|
|
|
|
'su-wrapper': 'sudo',
|
|
|
|
|
|
|
|
# build type settings
|
|
|
|
'build-cmd': '/usr/bin/build',
|
|
|
|
'build-type': '', # may be empty for chroot, kvm or xen
|
2013-03-20 15:42:48 +01:00
|
|
|
'build-root': '/var/tmp/build-root/%(repo)s-%(arch)s',
|
2011-08-17 15:33:56 +02:00
|
|
|
'build-uid': '', # use the default provided by build
|
|
|
|
'build-device': '', # required for VM builds
|
|
|
|
'build-memory': '', # required for VM builds
|
2021-02-11 10:58:40 +01:00
|
|
|
'build-shell-after-fail': '0', # optional for VM builds
|
2011-08-17 15:33:56 +02:00
|
|
|
'build-swap': '', # optional for VM builds
|
|
|
|
'build-vmdisk-rootsize': '', # optional for VM builds
|
|
|
|
'build-vmdisk-swapsize': '', # optional for VM builds
|
2012-02-04 17:02:18 +01:00
|
|
|
'build-vmdisk-filesystem': '', # optional for VM builds
|
2016-02-18 11:31:59 +01:00
|
|
|
'build-vm-user': '', # optional for VM builds
|
2014-11-20 17:09:53 +01:00
|
|
|
'build-kernel': '', # optional for VM builds
|
|
|
|
'build-initrd': '', # optional for VM builds
|
2011-08-17 15:33:56 +02:00
|
|
|
|
2018-01-24 14:00:02 +01:00
|
|
|
'build-jobs': str(_get_processors()),
|
2011-08-17 15:33:56 +02:00
|
|
|
'builtin_signature_check': '1', # by default use builtin check for verify pkgs
|
|
|
|
'icecream': '0',
|
2020-04-14 06:50:24 +02:00
|
|
|
'ccache': '0',
|
2021-04-08 12:09:33 +02:00
|
|
|
'sccache': '0',
|
|
|
|
'sccache_uri': '',
|
2011-08-17 15:33:56 +02:00
|
|
|
|
2012-12-15 01:50:24 +01:00
|
|
|
'buildlog_strip_time': '0', # strips the build time from the build log
|
|
|
|
|
2011-08-17 15:33:56 +02:00
|
|
|
'debug': '0',
|
|
|
|
'http_debug': '0',
|
|
|
|
'http_full_debug': '0',
|
|
|
|
'http_retries': '3',
|
|
|
|
'verbose': '1',
|
2016-06-09 16:24:30 +02:00
|
|
|
'no_preinstallimage': '0',
|
2011-08-17 15:33:56 +02:00
|
|
|
'traceback': '0',
|
|
|
|
'post_mortem': '0',
|
2013-01-31 16:03:31 +01:00
|
|
|
'use_keyring': '0',
|
|
|
|
'gnome_keyring': '0',
|
2021-08-12 02:21:11 +02:00
|
|
|
'cookiejar': _identify_osccookiejar(),
|
2011-08-17 15:33:56 +02:00
|
|
|
# fallback for osc build option --no-verify
|
|
|
|
'no_verify': '0',
|
|
|
|
# enable project tracking by default
|
|
|
|
'do_package_tracking': '1',
|
|
|
|
# default for osc build
|
|
|
|
'extra-pkgs': '',
|
|
|
|
# default repository
|
|
|
|
'build_repository': 'openSUSE_Factory',
|
|
|
|
# default project for branch or bco
|
|
|
|
'getpac_default_project': 'openSUSE:Factory',
|
|
|
|
# alternate filesystem layout: have multiple subdirs, where colons were.
|
|
|
|
'checkout_no_colon': '0',
|
|
|
|
# change filesystem layout: avoid checkout from within a proj or package dir.
|
|
|
|
'checkout_rooted': '0',
|
|
|
|
# local files to ignore with status, addremove, ....
|
|
|
|
'exclude_glob': '.osc CVS .svn .* _linkerror *~ #*# *.orig *.bak *.changes.vctmp.*',
|
2019-08-27 10:33:36 +02:00
|
|
|
# whether to keep passwords in plaintext (deprecated (see creds manager)).
|
|
|
|
'plaintext_passwd': '0',
|
2020-01-23 13:48:20 +01:00
|
|
|
# whether to print Web UI links to directly insert in browser (where possible)
|
|
|
|
'print_web_links': '0',
|
2011-08-17 15:33:56 +02:00
|
|
|
# limit the age of requests shown with 'osc req list'.
|
|
|
|
# this is a default only, can be overridden by 'osc req list -D NNN'
|
|
|
|
# Use 0 for unlimted.
|
|
|
|
'request_list_days': 0,
|
|
|
|
# check for unversioned/removed files before commit
|
|
|
|
'check_filelist': '1',
|
|
|
|
# check for pending requests after executing an action (e.g. checkout, update, commit)
|
2019-09-18 15:36:01 +02:00
|
|
|
'check_for_request_on_action': '1',
|
2011-08-17 15:33:56 +02:00
|
|
|
# what to do with the source package if the submitrequest has been accepted
|
|
|
|
'submitrequest_on_accept_action': '',
|
|
|
|
'request_show_interactive': '0',
|
2016-02-10 18:27:35 +01:00
|
|
|
'request_show_source_buildstatus': '0',
|
2012-04-27 15:04:06 +02:00
|
|
|
# if a review is accepted in interactive mode and a group
|
|
|
|
# was specified the review will be accepted for this group
|
|
|
|
'review_inherit_group': '0',
|
2011-08-17 15:33:56 +02:00
|
|
|
'submitrequest_accepted_template': '',
|
|
|
|
'submitrequest_declined_template': '',
|
|
|
|
'linkcontrol': '0',
|
|
|
|
'include_request_from_project': '1',
|
2011-09-07 15:19:54 +02:00
|
|
|
'local_service_run': '1',
|
2011-08-17 15:33:56 +02:00
|
|
|
|
|
|
|
# Maintenance defaults to OBS instance defaults
|
|
|
|
'maintained_attribute': 'OBS:Maintained',
|
|
|
|
'maintenance_attribute': 'OBS:MaintenanceProject',
|
|
|
|
'maintained_update_project_attribute': 'OBS:UpdateProject',
|
|
|
|
'show_download_progress': '0',
|
2014-10-01 14:45:48 +02:00
|
|
|
# path to the vc script
|
2017-08-15 13:31:10 +02:00
|
|
|
'vc-cmd': '/usr/lib/build/vc',
|
|
|
|
|
|
|
|
# heuristic to speedup Package.status
|
|
|
|
'status_mtime_heuristic': '0'
|
2006-10-10 16:04:34 +02:00
|
|
|
}
|
2009-08-21 14:03:09 +02:00
|
|
|
|
2017-07-07 18:47:43 +02:00
|
|
|
# some distros like Debian rename and move build to obs-build
|
|
|
|
if not os.path.isfile('/usr/bin/build') and os.path.isfile('/usr/bin/obs-build'):
|
|
|
|
DEFAULTS['build-cmd'] = '/usr/bin/obs-build'
|
|
|
|
if not os.path.isfile('/usr/lib/build/vc') and os.path.isfile('/usr/lib/obs-build/vc'):
|
|
|
|
DEFAULTS['vc-cmd'] = '/usr/lib/obs-build/vc'
|
|
|
|
|
2009-08-21 14:03:09 +02:00
|
|
|
# being global to this module, this dict can be accessed from outside
|
|
|
|
# it will hold the parsed configuration
|
|
|
|
config = DEFAULTS.copy()
|
|
|
|
|
2009-08-22 00:22:12 +02:00
|
|
|
boolean_opts = ['debug', 'do_package_tracking', 'http_debug', 'post_mortem', 'traceback', 'check_filelist', 'plaintext_passwd',
|
2010-12-27 23:03:17 +01:00
|
|
|
'checkout_no_colon', 'checkout_rooted', 'check_for_request_on_action', 'linkcontrol', 'show_download_progress', 'request_show_interactive',
|
2016-02-10 18:27:35 +01:00
|
|
|
'request_show_source_buildstatus', 'review_inherit_group', 'use_keyring', 'gnome_keyring', 'no_verify', 'builtin_signature_check',
|
2017-08-15 13:31:10 +02:00
|
|
|
'http_full_debug', 'include_request_from_project', 'local_service_run', 'buildlog_strip_time', 'no_preinstallimage',
|
2021-04-08 12:09:33 +02:00
|
|
|
'status_mtime_heuristic', 'print_web_links', 'ccache', 'sccache', 'build-shell-after-fail']
|
2018-01-23 12:28:55 +01:00
|
|
|
integer_opts = ['build-jobs']
|
2006-10-10 16:04:34 +02:00
|
|
|
|
2018-07-25 16:19:50 +02:00
|
|
|
api_host_options = ['user', 'pass', 'passx', 'aliases', 'http_headers', 'realname', 'email', 'sslcertck', 'cafile', 'capath', 'trusted_prj']
|
2010-03-06 20:14:51 +01:00
|
|
|
|
2006-10-10 16:04:34 +02:00
|
|
|
new_conf_template = """
|
|
|
|
[general]
|
|
|
|
|
2009-02-24 00:29:32 +01:00
|
|
|
# URL to access API server, e.g. %(apiurl)s
|
|
|
|
# you also need a section [%(apiurl)s] with the credentials
|
|
|
|
apiurl = %(apiurl)s
|
2007-04-25 12:24:51 +02:00
|
|
|
|
2006-10-10 16:04:34 +02:00
|
|
|
# Downloaded packages are cached here. Must be writable by you.
|
|
|
|
#packagecachedir = %(packagecachedir)s
|
|
|
|
|
|
|
|
# Wrapper to call build as root (sudo, su -, ...)
|
|
|
|
#su-wrapper = %(su-wrapper)s
|
2021-03-19 12:51:56 +01:00
|
|
|
# set it empty to run build script as user (works only with KVM atm):
|
|
|
|
#su-wrapper =
|
2006-10-10 16:04:34 +02:00
|
|
|
|
|
|
|
# rootdir to setup the chroot environment
|
2011-03-15 18:45:36 +01:00
|
|
|
# can contain %%(repo)s, %%(arch)s, %%(project)s, %%(package)s and %%(apihost)s (apihost is the hostname
|
|
|
|
# extracted from currently used apiurl) for replacement, e.g.
|
2009-01-09 17:12:45 +01:00
|
|
|
# /srv/oscbuild/%%(repo)s-%%(arch)s or
|
|
|
|
# /srv/oscbuild/%%(repo)s-%%(arch)s-%%(project)s-%%(package)s
|
2006-10-10 16:04:34 +02:00
|
|
|
#build-root = %(build-root)s
|
|
|
|
|
2010-01-09 14:56:55 +01:00
|
|
|
# compile with N jobs (default: "getconf _NPROCESSORS_ONLN")
|
|
|
|
#build-jobs = N
|
|
|
|
|
2010-03-28 21:13:04 +02:00
|
|
|
# build-type to use - values can be (depending on the capabilities of the 'build' script)
|
|
|
|
# empty - chroot build
|
|
|
|
# kvm - kvm VM build (needs build-device, build-swap, build-memory)
|
|
|
|
# xen - xen VM build (needs build-device, build-swap, build-memory)
|
|
|
|
# experimental:
|
|
|
|
# qemu - qemu VM build
|
|
|
|
# lxc - lxc build
|
|
|
|
#build-type =
|
|
|
|
|
2021-02-11 10:58:40 +01:00
|
|
|
# Execute always a shell prompt on build failure inside of the build environment
|
|
|
|
#build-shell-after-fail = 1
|
|
|
|
|
2010-03-28 21:13:04 +02:00
|
|
|
# build-device is the disk-image file to use as root for VM builds
|
|
|
|
# e.g. /var/tmp/FILE.root
|
|
|
|
#build-device = /var/tmp/FILE.root
|
|
|
|
|
|
|
|
# build-swap is the disk-image to use as swap for VM builds
|
|
|
|
# e.g. /var/tmp/FILE.swap
|
|
|
|
#build-swap = /var/tmp/FILE.swap
|
|
|
|
|
2014-11-20 17:09:53 +01:00
|
|
|
# build-kernel is the boot kernel used for VM builds
|
|
|
|
#build-kernel = /boot/vmlinuz
|
|
|
|
|
|
|
|
# build-initrd is the boot initrd used for VM builds
|
|
|
|
#build-initrd = /boot/initrd
|
|
|
|
|
2010-03-28 21:13:04 +02:00
|
|
|
# build-memory is the amount of memory used in the VM
|
|
|
|
# value in MB - e.g. 512
|
|
|
|
#build-memory = 512
|
|
|
|
|
|
|
|
# build-vmdisk-rootsize is the size of the disk-image used as root in a VM build
|
|
|
|
# values in MB - e.g. 4096
|
|
|
|
#build-vmdisk-rootsize = 4096
|
|
|
|
|
|
|
|
# build-vmdisk-swapsize is the size of the disk-image used as swap in a VM build
|
|
|
|
# values in MB - e.g. 1024
|
|
|
|
#build-vmdisk-swapsize = 1024
|
|
|
|
|
2012-02-04 17:02:18 +01:00
|
|
|
# build-vmdisk-filesystem is the file system type of the disk-image used in a VM build
|
|
|
|
# values are ext3(default) ext4 xfs reiserfs btrfs
|
|
|
|
#build-vmdisk-filesystem = ext4
|
|
|
|
|
2010-02-12 22:54:39 +01:00
|
|
|
# Numeric uid:gid to assign to the "abuild" user in the build-root
|
|
|
|
# or "caller" to use the current users uid:gid
|
|
|
|
# This is convenient when sharing the buildroot with ordinary userids
|
|
|
|
# on the host.
|
|
|
|
# This should not be 0
|
2010-02-28 02:30:13 +01:00
|
|
|
# build-uid =
|
2010-02-12 22:54:39 +01:00
|
|
|
|
2012-12-15 01:50:24 +01:00
|
|
|
# strip leading build time information from the build log
|
|
|
|
# buildlog_strip_time = 1
|
|
|
|
|
2020-04-14 06:50:24 +02:00
|
|
|
# Enable ccache in build roots.
|
|
|
|
# ccache = 1
|
|
|
|
|
2021-04-08 12:09:33 +02:00
|
|
|
# Enable sccache in build roots. Conflicts with ccache.
|
|
|
|
# sccache = 1
|
|
|
|
|
|
|
|
# Optional remote URI for sccache storage.
|
|
|
|
# sccache_uri = redis://127.0.0.1:6379
|
|
|
|
|
2008-07-12 14:06:23 +02:00
|
|
|
# extra packages to install when building packages locally (osc build)
|
|
|
|
# this corresponds to osc build's -x option and can be overridden with that
|
|
|
|
# -x '' can also be given on the command line to override this setting, or
|
2019-12-03 15:05:48 +01:00
|
|
|
# you can have an empty setting here. This global setting may leads to
|
|
|
|
# dependency problems when the base distro is not providing the package.
|
|
|
|
# => using server side definition via cli_debug_packages substitute rule is
|
|
|
|
# recommended therefore.
|
|
|
|
#extra-pkgs =
|
2008-07-12 14:06:23 +02:00
|
|
|
|
2008-07-30 18:45:00 +02:00
|
|
|
# build platform is used if the platform argument is omitted to osc build
|
2009-09-08 10:14:27 +02:00
|
|
|
#build_repository = %(build_repository)s
|
2009-08-20 21:28:05 +02:00
|
|
|
|
2009-09-03 20:08:43 +02:00
|
|
|
# default project for getpac or bco
|
|
|
|
#getpac_default_project = %(getpac_default_project)s
|
|
|
|
|
2009-08-20 21:28:05 +02:00
|
|
|
# alternate filesystem layout: have multiple subdirs, where colons were.
|
|
|
|
#checkout_no_colon = %(checkout_no_colon)s
|
|
|
|
|
2010-12-27 23:03:17 +01:00
|
|
|
# change filesystem layout: avoid checkout within a project or package dir.
|
|
|
|
#checkout_rooted = %(checkout_rooted)s
|
|
|
|
|
2009-08-20 21:28:05 +02:00
|
|
|
# local files to ignore with status, addremove, ....
|
|
|
|
#exclude_glob = %(exclude_glob)s
|
2008-07-30 18:45:00 +02:00
|
|
|
|
2009-08-20 21:28:05 +02:00
|
|
|
# limit the age of requests shown with 'osc req list'.
|
|
|
|
# this is a default only, can be overridden by 'osc req list -D NNN'
|
|
|
|
# Use 0 for unlimted.
|
|
|
|
#request_list_days = %(request_list_days)s
|
|
|
|
|
|
|
|
# show info useful for debugging
|
Merged revisions 3774-3775,3779,3781-3782,3787,3789-3793,3798,3802,3805,3817-3822,3827,3829-3830,3837-3839,3841-3842,3848-3850 via svnmerge from
https://forgesvn1.novell.com/svn/opensuse/branches/buildservice/osc-exception-handling
........
r3774 | poeml | 2008-04-22 17:39:45 +0200 (Tue, 22 Apr 2008) | 3 lines
A first draft on implement systematic exception handling:
Add errors.py with some exceptions defined, and babysitter.py to handle them
........
r3775 | poeml | 2008-04-22 22:34:12 +0200 (Tue, 22 Apr 2008) | 9 lines
- new global options:
--debugger jump into the debugger before executing anything
--post-mortem jump into the debugger in case of errors
-t, --traceback print call trace in case of errors
- traceback and post_mortem can also be set in .oscrc.
- catch more errors (HTTPError).
- make config accessible from outside of the Osc instance, by making it a class
attribute
........
r3779 | poeml | 2008-04-23 00:55:49 +0200 (Wed, 23 Apr 2008) | 5 lines
- new global option:
-d, --debug print info useful for debugging
- catch some more errors (HTTPError), with OscHTTPError which isn't very
advanced yet.
........
r3781 | Marcus_H | 2008-04-23 01:02:00 +0200 (Wed, 23 Apr 2008) | 2 lines
- added OscConfigError class (just for testing).
- small change in the signature of the OscBaseError constructor (actually we should get rid of the 'args' tuple because it will be deprecated sooner or later
........
r3782 | Marcus_H | 2008-04-23 02:02:13 +0200 (Wed, 23 Apr 2008) | 2 lines
- access the prg.conf.config dict in a save way - this way we avoid AttributeErrors if the prg.conf.config dict doesn't exist
- in case of an configparser error we have to use the prg.options object directly (this was removed in r3781 by accident)
........
r3787 | poeml | 2008-04-23 09:23:56 +0200 (Wed, 23 Apr 2008) | 4 lines
- remove local exception handling from do_req
- for HTTPError, print details (headers and response) when in debug mode
- catch AttributeError
........
r3789 | poeml | 2008-04-23 16:23:14 +0200 (Wed, 23 Apr 2008) | 4 lines
- errors: add two new classes named OscWrongOptionsError and OscWrongArgsError
- commandline: raise instances of the new errors in a number of places
- commandline: add get_cmd_help() to Osc instance which returns the formatted help of a subcommand
........
r3790 | Marcus_H | 2008-04-23 16:48:28 +0200 (Wed, 23 Apr 2008) | 4 lines
- added 2 new exception classes: OscNoConfigfileError and OscIOError
- added new method write_config() to the conf.py module: This method writes osc's configuration file
- minor cleanups in the conf module
........
r3791 | poeml | 2008-04-23 17:11:07 +0200 (Wed, 23 Apr 2008) | 3 lines
small compatibility fix for r3790: try-except-finally isn't supported in
python-2.4.2, thus do the same as try-except inside a try-finally.
........
r3792 | poeml | 2008-04-23 17:37:53 +0200 (Wed, 23 Apr 2008) | 2 lines
fix up the remaining places regarding handling of errors related to commandline parsing
........
r3793 | poeml | 2008-04-23 17:40:34 +0200 (Wed, 23 Apr 2008) | 3 lines
raise a NoWorkingCopyError in osc.core.store_read_project() in case of an
IOError
........
r3798 | Marcus_H | 2008-04-23 23:55:24 +0200 (Wed, 23 Apr 2008) | 1 line
ported -r3797 from trunk
........
r3802 | Marcus_H | 2008-04-24 11:00:55 +0200 (Thu, 24 Apr 2008) | 1 line
ported -r3801 from trunk
........
r3805 | poeml | 2008-04-24 12:52:30 +0200 (Thu, 24 Apr 2008) | 2 lines
raise OscHTTPError in show_pattern_meta(), replacing local error handling
........
r3817 | poeml | 2008-04-24 20:21:32 +0200 (Thu, 24 Apr 2008) | 9 lines
- remove errors.OscHTTPError again.
it seems simpler to use urllib2.HTTPError instead (and just add a specific
error text message where appropriate, and re-raise)
- for 404s, check out _which_ part was not found
it is very ugly, but may be considered Good for pragmatic reasons
- removed local exception handling and workaround for returned 500's from
delete_package() and delete_project(), thereby getting rid of 4 possible exit
points.
........
r3818 | Marcus_H | 2008-04-24 22:36:17 +0200 (Thu, 24 Apr 2008) | 1 line
- this check is superfluous because every HTTPError instance has a code attribute
........
r3819 | poeml | 2008-04-25 00:39:39 +0200 (Fri, 25 Apr 2008) | 1 line
remove a forgotten debug line from core.delete_project()
........
r3820 | poeml | 2008-04-25 10:07:58 +0200 (Fri, 25 Apr 2008) | 2 lines
- ditch local error handling from wipebinaries(), rebuild(), and abortbuild()
........
r3821 | poeml | 2008-04-25 10:56:38 +0200 (Fri, 25 Apr 2008) | 2 lines
It is never needed to import the exception module.
........
r3822 | poeml | 2008-04-25 11:13:39 +0200 (Fri, 25 Apr 2008) | 4 lines
- when going into the debugger with --post-mortem, always print a traceback before
(thus implying -t)
- do not jump into the debugger if not on a TTY, or working in interactive mode
........
r3827 | poeml | 2008-04-25 13:07:46 +0200 (Fri, 25 Apr 2008) | 9 lines
- add errors.OscWorkingCopyOutdated, which takes a tuple with three args:
path to working copy, current rev, expected rev
- add handler for urllib2.URLError errors to the babysitter
- simplify the OscWrongArgsError and OscWrongOptionsError handlers, by removing
the extra line "Sorry, wrong ..." that was printed before the messages given
when the error was raised.
- remove one more errors.OscHTTPError which was still there, and raise
urllib2.HTTPError instead (show_package_meta())
........
r3829 | poeml | 2008-04-25 14:19:10 +0200 (Fri, 25 Apr 2008) | 11 lines
- comment some methods in osc.core which are used by nearly all do_* methods in
osc.commandline
- improve "is not a package/project dir" error messages, by printing the
absolute path tried, instead of '.' for the cwd
- make core.store_read_package() raise a proper NoWorkingCopyError instead of
terminating
- give attribution to things in babysitter.py copied from mercurial
- prefix HTTPError exceptions with 'Server returned an error:'
- remove obsolete local error handling from do_prjresults(), do_importsrcpkg(),
do_repos()
........
r3830 | poeml | 2008-04-25 14:29:35 +0200 (Fri, 25 Apr 2008) | 1 line
catch IOError exceptions in the babysitter
........
r3837 | poeml | 2008-04-25 17:27:36 +0200 (Fri, 25 Apr 2008) | 5 lines
- do_remotebuildlog: raise errors for wrong arguments, remove exits
- raise AttributeError in make_meta_url() instead of exiting
- delete unused method core.delete_server_files()
- replace exit call inside make_meta_url() with an AttributeError
........
r3838 | poeml | 2008-04-25 17:49:18 +0200 (Fri, 25 Apr 2008) | 1 line
simplify the check in do_checkout if a project exists, by using show_project_meta() instead of meta_exists
........
r3839 | poeml | 2008-04-25 18:31:26 +0200 (Fri, 25 Apr 2008) | 6 lines
- commandline do_checkout(): change the order of the two checks, first do the
(cheaper) check for existing directory
- core.core checkout_package(): simplify the check in if the package
exists, by using show_package_meta() instead of meta_exists
Let it throw an exception, instead of using sys.exit().
........
r3841 | Marcus_H | 2008-04-27 15:48:06 +0200 (Sun, 27 Apr 2008) | 5 lines
- added 2 new exception classes: PackageError() and PackageExistsError. The PackageError() class is meant to be the base class for all subsequent package exceptions.
- get rid of 2 sys.exit(1) calls
- make the update() method of the Project() class safer: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- minor fix in delPackage(): use getTransActPath() when printing out the filename
........
r3842 | Marcus_H | 2008-04-27 16:52:55 +0200 (Sun, 27 Apr 2008) | 3 lines
- make the commit() method safe: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- removed another sys.exit(1): raise an exception if a package is missing when doing a commit. For now we use the PackageExistsError() exception but this might change in the future (updated description of PackageExistsError() according to this change)
........
r3848 | poeml | 2008-04-28 12:46:45 +0200 (Mon, 28 Apr 2008) | 3 lines
rename several error classes, dropping the "Osc" prefix, and "Error" suffix in
cases where they don't really make sense.
........
r3849 | poeml | 2008-04-28 12:57:32 +0200 (Mon, 28 Apr 2008) | 3 lines
- rename osc.errors module to osc.oscerr, to make it easier to import it from
other programs and have a crystal clear namespace
........
r3850 | poeml | 2008-04-28 13:26:12 +0200 (Mon, 28 Apr 2008) | 2 lines
split PackageExists exception class into PackageExists and PackageMissing
........
2008-04-28 18:37:44 +02:00
|
|
|
#debug = 1
|
2009-08-20 21:28:05 +02:00
|
|
|
|
|
|
|
# show HTTP traffic useful for debugging
|
2007-04-25 12:24:51 +02:00
|
|
|
#http_debug = 1
|
2009-08-20 21:28:05 +02:00
|
|
|
|
2010-12-01 10:22:53 +01:00
|
|
|
# number of retries on HTTP transfer
|
|
|
|
#http_retries = 3
|
|
|
|
|
2010-08-12 21:34:08 +02:00
|
|
|
# Skip signature verification of packages used for build.
|
|
|
|
#no_verify = 1
|
|
|
|
|
Merged revisions 3774-3775,3779,3781-3782,3787,3789-3793,3798,3802,3805,3817-3822,3827,3829-3830,3837-3839,3841-3842,3848-3850 via svnmerge from
https://forgesvn1.novell.com/svn/opensuse/branches/buildservice/osc-exception-handling
........
r3774 | poeml | 2008-04-22 17:39:45 +0200 (Tue, 22 Apr 2008) | 3 lines
A first draft on implement systematic exception handling:
Add errors.py with some exceptions defined, and babysitter.py to handle them
........
r3775 | poeml | 2008-04-22 22:34:12 +0200 (Tue, 22 Apr 2008) | 9 lines
- new global options:
--debugger jump into the debugger before executing anything
--post-mortem jump into the debugger in case of errors
-t, --traceback print call trace in case of errors
- traceback and post_mortem can also be set in .oscrc.
- catch more errors (HTTPError).
- make config accessible from outside of the Osc instance, by making it a class
attribute
........
r3779 | poeml | 2008-04-23 00:55:49 +0200 (Wed, 23 Apr 2008) | 5 lines
- new global option:
-d, --debug print info useful for debugging
- catch some more errors (HTTPError), with OscHTTPError which isn't very
advanced yet.
........
r3781 | Marcus_H | 2008-04-23 01:02:00 +0200 (Wed, 23 Apr 2008) | 2 lines
- added OscConfigError class (just for testing).
- small change in the signature of the OscBaseError constructor (actually we should get rid of the 'args' tuple because it will be deprecated sooner or later
........
r3782 | Marcus_H | 2008-04-23 02:02:13 +0200 (Wed, 23 Apr 2008) | 2 lines
- access the prg.conf.config dict in a save way - this way we avoid AttributeErrors if the prg.conf.config dict doesn't exist
- in case of an configparser error we have to use the prg.options object directly (this was removed in r3781 by accident)
........
r3787 | poeml | 2008-04-23 09:23:56 +0200 (Wed, 23 Apr 2008) | 4 lines
- remove local exception handling from do_req
- for HTTPError, print details (headers and response) when in debug mode
- catch AttributeError
........
r3789 | poeml | 2008-04-23 16:23:14 +0200 (Wed, 23 Apr 2008) | 4 lines
- errors: add two new classes named OscWrongOptionsError and OscWrongArgsError
- commandline: raise instances of the new errors in a number of places
- commandline: add get_cmd_help() to Osc instance which returns the formatted help of a subcommand
........
r3790 | Marcus_H | 2008-04-23 16:48:28 +0200 (Wed, 23 Apr 2008) | 4 lines
- added 2 new exception classes: OscNoConfigfileError and OscIOError
- added new method write_config() to the conf.py module: This method writes osc's configuration file
- minor cleanups in the conf module
........
r3791 | poeml | 2008-04-23 17:11:07 +0200 (Wed, 23 Apr 2008) | 3 lines
small compatibility fix for r3790: try-except-finally isn't supported in
python-2.4.2, thus do the same as try-except inside a try-finally.
........
r3792 | poeml | 2008-04-23 17:37:53 +0200 (Wed, 23 Apr 2008) | 2 lines
fix up the remaining places regarding handling of errors related to commandline parsing
........
r3793 | poeml | 2008-04-23 17:40:34 +0200 (Wed, 23 Apr 2008) | 3 lines
raise a NoWorkingCopyError in osc.core.store_read_project() in case of an
IOError
........
r3798 | Marcus_H | 2008-04-23 23:55:24 +0200 (Wed, 23 Apr 2008) | 1 line
ported -r3797 from trunk
........
r3802 | Marcus_H | 2008-04-24 11:00:55 +0200 (Thu, 24 Apr 2008) | 1 line
ported -r3801 from trunk
........
r3805 | poeml | 2008-04-24 12:52:30 +0200 (Thu, 24 Apr 2008) | 2 lines
raise OscHTTPError in show_pattern_meta(), replacing local error handling
........
r3817 | poeml | 2008-04-24 20:21:32 +0200 (Thu, 24 Apr 2008) | 9 lines
- remove errors.OscHTTPError again.
it seems simpler to use urllib2.HTTPError instead (and just add a specific
error text message where appropriate, and re-raise)
- for 404s, check out _which_ part was not found
it is very ugly, but may be considered Good for pragmatic reasons
- removed local exception handling and workaround for returned 500's from
delete_package() and delete_project(), thereby getting rid of 4 possible exit
points.
........
r3818 | Marcus_H | 2008-04-24 22:36:17 +0200 (Thu, 24 Apr 2008) | 1 line
- this check is superfluous because every HTTPError instance has a code attribute
........
r3819 | poeml | 2008-04-25 00:39:39 +0200 (Fri, 25 Apr 2008) | 1 line
remove a forgotten debug line from core.delete_project()
........
r3820 | poeml | 2008-04-25 10:07:58 +0200 (Fri, 25 Apr 2008) | 2 lines
- ditch local error handling from wipebinaries(), rebuild(), and abortbuild()
........
r3821 | poeml | 2008-04-25 10:56:38 +0200 (Fri, 25 Apr 2008) | 2 lines
It is never needed to import the exception module.
........
r3822 | poeml | 2008-04-25 11:13:39 +0200 (Fri, 25 Apr 2008) | 4 lines
- when going into the debugger with --post-mortem, always print a traceback before
(thus implying -t)
- do not jump into the debugger if not on a TTY, or working in interactive mode
........
r3827 | poeml | 2008-04-25 13:07:46 +0200 (Fri, 25 Apr 2008) | 9 lines
- add errors.OscWorkingCopyOutdated, which takes a tuple with three args:
path to working copy, current rev, expected rev
- add handler for urllib2.URLError errors to the babysitter
- simplify the OscWrongArgsError and OscWrongOptionsError handlers, by removing
the extra line "Sorry, wrong ..." that was printed before the messages given
when the error was raised.
- remove one more errors.OscHTTPError which was still there, and raise
urllib2.HTTPError instead (show_package_meta())
........
r3829 | poeml | 2008-04-25 14:19:10 +0200 (Fri, 25 Apr 2008) | 11 lines
- comment some methods in osc.core which are used by nearly all do_* methods in
osc.commandline
- improve "is not a package/project dir" error messages, by printing the
absolute path tried, instead of '.' for the cwd
- make core.store_read_package() raise a proper NoWorkingCopyError instead of
terminating
- give attribution to things in babysitter.py copied from mercurial
- prefix HTTPError exceptions with 'Server returned an error:'
- remove obsolete local error handling from do_prjresults(), do_importsrcpkg(),
do_repos()
........
r3830 | poeml | 2008-04-25 14:29:35 +0200 (Fri, 25 Apr 2008) | 1 line
catch IOError exceptions in the babysitter
........
r3837 | poeml | 2008-04-25 17:27:36 +0200 (Fri, 25 Apr 2008) | 5 lines
- do_remotebuildlog: raise errors for wrong arguments, remove exits
- raise AttributeError in make_meta_url() instead of exiting
- delete unused method core.delete_server_files()
- replace exit call inside make_meta_url() with an AttributeError
........
r3838 | poeml | 2008-04-25 17:49:18 +0200 (Fri, 25 Apr 2008) | 1 line
simplify the check in do_checkout if a project exists, by using show_project_meta() instead of meta_exists
........
r3839 | poeml | 2008-04-25 18:31:26 +0200 (Fri, 25 Apr 2008) | 6 lines
- commandline do_checkout(): change the order of the two checks, first do the
(cheaper) check for existing directory
- core.core checkout_package(): simplify the check in if the package
exists, by using show_package_meta() instead of meta_exists
Let it throw an exception, instead of using sys.exit().
........
r3841 | Marcus_H | 2008-04-27 15:48:06 +0200 (Sun, 27 Apr 2008) | 5 lines
- added 2 new exception classes: PackageError() and PackageExistsError. The PackageError() class is meant to be the base class for all subsequent package exceptions.
- get rid of 2 sys.exit(1) calls
- make the update() method of the Project() class safer: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- minor fix in delPackage(): use getTransActPath() when printing out the filename
........
r3842 | Marcus_H | 2008-04-27 16:52:55 +0200 (Sun, 27 Apr 2008) | 3 lines
- make the commit() method safe: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- removed another sys.exit(1): raise an exception if a package is missing when doing a commit. For now we use the PackageExistsError() exception but this might change in the future (updated description of PackageExistsError() according to this change)
........
r3848 | poeml | 2008-04-28 12:46:45 +0200 (Mon, 28 Apr 2008) | 3 lines
rename several error classes, dropping the "Osc" prefix, and "Error" suffix in
cases where they don't really make sense.
........
r3849 | poeml | 2008-04-28 12:57:32 +0200 (Mon, 28 Apr 2008) | 3 lines
- rename osc.errors module to osc.oscerr, to make it easier to import it from
other programs and have a crystal clear namespace
........
r3850 | poeml | 2008-04-28 13:26:12 +0200 (Mon, 28 Apr 2008) | 2 lines
split PackageExists exception class into PackageExists and PackageMissing
........
2008-04-28 18:37:44 +02:00
|
|
|
# jump into the debugger in case of errors
|
|
|
|
#post_mortem = 1
|
2009-08-20 21:28:05 +02:00
|
|
|
|
Merged revisions 3774-3775,3779,3781-3782,3787,3789-3793,3798,3802,3805,3817-3822,3827,3829-3830,3837-3839,3841-3842,3848-3850 via svnmerge from
https://forgesvn1.novell.com/svn/opensuse/branches/buildservice/osc-exception-handling
........
r3774 | poeml | 2008-04-22 17:39:45 +0200 (Tue, 22 Apr 2008) | 3 lines
A first draft on implement systematic exception handling:
Add errors.py with some exceptions defined, and babysitter.py to handle them
........
r3775 | poeml | 2008-04-22 22:34:12 +0200 (Tue, 22 Apr 2008) | 9 lines
- new global options:
--debugger jump into the debugger before executing anything
--post-mortem jump into the debugger in case of errors
-t, --traceback print call trace in case of errors
- traceback and post_mortem can also be set in .oscrc.
- catch more errors (HTTPError).
- make config accessible from outside of the Osc instance, by making it a class
attribute
........
r3779 | poeml | 2008-04-23 00:55:49 +0200 (Wed, 23 Apr 2008) | 5 lines
- new global option:
-d, --debug print info useful for debugging
- catch some more errors (HTTPError), with OscHTTPError which isn't very
advanced yet.
........
r3781 | Marcus_H | 2008-04-23 01:02:00 +0200 (Wed, 23 Apr 2008) | 2 lines
- added OscConfigError class (just for testing).
- small change in the signature of the OscBaseError constructor (actually we should get rid of the 'args' tuple because it will be deprecated sooner or later
........
r3782 | Marcus_H | 2008-04-23 02:02:13 +0200 (Wed, 23 Apr 2008) | 2 lines
- access the prg.conf.config dict in a save way - this way we avoid AttributeErrors if the prg.conf.config dict doesn't exist
- in case of an configparser error we have to use the prg.options object directly (this was removed in r3781 by accident)
........
r3787 | poeml | 2008-04-23 09:23:56 +0200 (Wed, 23 Apr 2008) | 4 lines
- remove local exception handling from do_req
- for HTTPError, print details (headers and response) when in debug mode
- catch AttributeError
........
r3789 | poeml | 2008-04-23 16:23:14 +0200 (Wed, 23 Apr 2008) | 4 lines
- errors: add two new classes named OscWrongOptionsError and OscWrongArgsError
- commandline: raise instances of the new errors in a number of places
- commandline: add get_cmd_help() to Osc instance which returns the formatted help of a subcommand
........
r3790 | Marcus_H | 2008-04-23 16:48:28 +0200 (Wed, 23 Apr 2008) | 4 lines
- added 2 new exception classes: OscNoConfigfileError and OscIOError
- added new method write_config() to the conf.py module: This method writes osc's configuration file
- minor cleanups in the conf module
........
r3791 | poeml | 2008-04-23 17:11:07 +0200 (Wed, 23 Apr 2008) | 3 lines
small compatibility fix for r3790: try-except-finally isn't supported in
python-2.4.2, thus do the same as try-except inside a try-finally.
........
r3792 | poeml | 2008-04-23 17:37:53 +0200 (Wed, 23 Apr 2008) | 2 lines
fix up the remaining places regarding handling of errors related to commandline parsing
........
r3793 | poeml | 2008-04-23 17:40:34 +0200 (Wed, 23 Apr 2008) | 3 lines
raise a NoWorkingCopyError in osc.core.store_read_project() in case of an
IOError
........
r3798 | Marcus_H | 2008-04-23 23:55:24 +0200 (Wed, 23 Apr 2008) | 1 line
ported -r3797 from trunk
........
r3802 | Marcus_H | 2008-04-24 11:00:55 +0200 (Thu, 24 Apr 2008) | 1 line
ported -r3801 from trunk
........
r3805 | poeml | 2008-04-24 12:52:30 +0200 (Thu, 24 Apr 2008) | 2 lines
raise OscHTTPError in show_pattern_meta(), replacing local error handling
........
r3817 | poeml | 2008-04-24 20:21:32 +0200 (Thu, 24 Apr 2008) | 9 lines
- remove errors.OscHTTPError again.
it seems simpler to use urllib2.HTTPError instead (and just add a specific
error text message where appropriate, and re-raise)
- for 404s, check out _which_ part was not found
it is very ugly, but may be considered Good for pragmatic reasons
- removed local exception handling and workaround for returned 500's from
delete_package() and delete_project(), thereby getting rid of 4 possible exit
points.
........
r3818 | Marcus_H | 2008-04-24 22:36:17 +0200 (Thu, 24 Apr 2008) | 1 line
- this check is superfluous because every HTTPError instance has a code attribute
........
r3819 | poeml | 2008-04-25 00:39:39 +0200 (Fri, 25 Apr 2008) | 1 line
remove a forgotten debug line from core.delete_project()
........
r3820 | poeml | 2008-04-25 10:07:58 +0200 (Fri, 25 Apr 2008) | 2 lines
- ditch local error handling from wipebinaries(), rebuild(), and abortbuild()
........
r3821 | poeml | 2008-04-25 10:56:38 +0200 (Fri, 25 Apr 2008) | 2 lines
It is never needed to import the exception module.
........
r3822 | poeml | 2008-04-25 11:13:39 +0200 (Fri, 25 Apr 2008) | 4 lines
- when going into the debugger with --post-mortem, always print a traceback before
(thus implying -t)
- do not jump into the debugger if not on a TTY, or working in interactive mode
........
r3827 | poeml | 2008-04-25 13:07:46 +0200 (Fri, 25 Apr 2008) | 9 lines
- add errors.OscWorkingCopyOutdated, which takes a tuple with three args:
path to working copy, current rev, expected rev
- add handler for urllib2.URLError errors to the babysitter
- simplify the OscWrongArgsError and OscWrongOptionsError handlers, by removing
the extra line "Sorry, wrong ..." that was printed before the messages given
when the error was raised.
- remove one more errors.OscHTTPError which was still there, and raise
urllib2.HTTPError instead (show_package_meta())
........
r3829 | poeml | 2008-04-25 14:19:10 +0200 (Fri, 25 Apr 2008) | 11 lines
- comment some methods in osc.core which are used by nearly all do_* methods in
osc.commandline
- improve "is not a package/project dir" error messages, by printing the
absolute path tried, instead of '.' for the cwd
- make core.store_read_package() raise a proper NoWorkingCopyError instead of
terminating
- give attribution to things in babysitter.py copied from mercurial
- prefix HTTPError exceptions with 'Server returned an error:'
- remove obsolete local error handling from do_prjresults(), do_importsrcpkg(),
do_repos()
........
r3830 | poeml | 2008-04-25 14:29:35 +0200 (Fri, 25 Apr 2008) | 1 line
catch IOError exceptions in the babysitter
........
r3837 | poeml | 2008-04-25 17:27:36 +0200 (Fri, 25 Apr 2008) | 5 lines
- do_remotebuildlog: raise errors for wrong arguments, remove exits
- raise AttributeError in make_meta_url() instead of exiting
- delete unused method core.delete_server_files()
- replace exit call inside make_meta_url() with an AttributeError
........
r3838 | poeml | 2008-04-25 17:49:18 +0200 (Fri, 25 Apr 2008) | 1 line
simplify the check in do_checkout if a project exists, by using show_project_meta() instead of meta_exists
........
r3839 | poeml | 2008-04-25 18:31:26 +0200 (Fri, 25 Apr 2008) | 6 lines
- commandline do_checkout(): change the order of the two checks, first do the
(cheaper) check for existing directory
- core.core checkout_package(): simplify the check in if the package
exists, by using show_package_meta() instead of meta_exists
Let it throw an exception, instead of using sys.exit().
........
r3841 | Marcus_H | 2008-04-27 15:48:06 +0200 (Sun, 27 Apr 2008) | 5 lines
- added 2 new exception classes: PackageError() and PackageExistsError. The PackageError() class is meant to be the base class for all subsequent package exceptions.
- get rid of 2 sys.exit(1) calls
- make the update() method of the Project() class safer: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- minor fix in delPackage(): use getTransActPath() when printing out the filename
........
r3842 | Marcus_H | 2008-04-27 16:52:55 +0200 (Sun, 27 Apr 2008) | 3 lines
- make the commit() method safe: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- removed another sys.exit(1): raise an exception if a package is missing when doing a commit. For now we use the PackageExistsError() exception but this might change in the future (updated description of PackageExistsError() according to this change)
........
r3848 | poeml | 2008-04-28 12:46:45 +0200 (Mon, 28 Apr 2008) | 3 lines
rename several error classes, dropping the "Osc" prefix, and "Error" suffix in
cases where they don't really make sense.
........
r3849 | poeml | 2008-04-28 12:57:32 +0200 (Mon, 28 Apr 2008) | 3 lines
- rename osc.errors module to osc.oscerr, to make it easier to import it from
other programs and have a crystal clear namespace
........
r3850 | poeml | 2008-04-28 13:26:12 +0200 (Mon, 28 Apr 2008) | 2 lines
split PackageExists exception class into PackageExists and PackageMissing
........
2008-04-28 18:37:44 +02:00
|
|
|
# print call traces in case of errors
|
|
|
|
#traceback = 1
|
2009-08-20 21:28:05 +02:00
|
|
|
|
2009-08-04 16:12:45 +02:00
|
|
|
# check for unversioned/removed files before commit
|
|
|
|
#check_filelist = 1
|
2009-09-18 03:10:41 +02:00
|
|
|
|
|
|
|
# check for pending requests after executing an action (e.g. checkout, update, commit)
|
2019-09-18 15:36:01 +02:00
|
|
|
#check_for_request_on_action = 1
|
2009-09-18 03:10:41 +02:00
|
|
|
|
2009-12-19 14:44:51 +01:00
|
|
|
# what to do with the source package if the submitrequest has been accepted. If
|
|
|
|
# nothing is specified the API default is used
|
|
|
|
#submitrequest_on_accept_action = cleanup|update|noupdate
|
|
|
|
|
2010-11-14 18:32:02 +01:00
|
|
|
# template for an accepted submitrequest
|
2010-11-14 18:53:14 +01:00
|
|
|
#submitrequest_accepted_template = Hi %%(who)s,\\n
|
2010-12-30 20:58:00 +01:00
|
|
|
# thanks for working on:\\t%%(tgt_project)s/%%(tgt_package)s.
|
2010-11-14 18:53:14 +01:00
|
|
|
# SR %%(reqid)s has been accepted.\\n\\nYour maintainers
|
2010-11-14 18:32:02 +01:00
|
|
|
|
|
|
|
# template for a declined submitrequest
|
2010-11-14 18:53:14 +01:00
|
|
|
#submitrequest_declined_template = Hi %%(who)s,\\n
|
|
|
|
# sorry your SR %%(reqid)s (request type: %%(type)s) for
|
2010-12-30 20:58:00 +01:00
|
|
|
# %%(tgt_project)s/%%(tgt_package)s has been declined because...
|
2010-11-14 18:32:02 +01:00
|
|
|
|
2010-02-11 01:47:47 +01:00
|
|
|
#review requests interactively (default: off)
|
|
|
|
#request_show_review = 1
|
|
|
|
|
2012-04-27 15:04:06 +02:00
|
|
|
# if a review is accepted in interactive mode and a group
|
|
|
|
# was specified the review will be accepted for this group (default: off)
|
|
|
|
#review_inherit_group = 1
|
|
|
|
|
2009-02-24 00:29:32 +01:00
|
|
|
[%(apiurl)s]
|
2009-02-24 22:35:59 +01:00
|
|
|
# set aliases for this apiurl
|
|
|
|
# aliases = foo, bar
|
2018-07-25 16:19:50 +02:00
|
|
|
# real name used in .changes, unless the one from osc meta prj <user> will be used
|
|
|
|
# realname =
|
2009-04-20 15:40:33 +02:00
|
|
|
# email used in .changes, unless the one from osc meta prj <user> will be used
|
2009-08-20 21:28:05 +02:00
|
|
|
# email =
|
2008-08-20 11:45:49 +02:00
|
|
|
# additional headers to pass to a request, e.g. for special authentication
|
2008-08-21 20:17:40 +02:00
|
|
|
#http_headers = Host: foofoobar,
|
|
|
|
# User: mumblegack
|
2011-01-05 16:51:02 +01:00
|
|
|
# Plain text password
|
|
|
|
#pass =
|
2006-10-10 16:04:34 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
2011-08-17 15:33:56 +02:00
|
|
|
account_not_configured_text = """
|
2006-10-10 16:04:34 +02:00
|
|
|
Your user account / password are not configured yet.
|
|
|
|
You will be asked for them below, and they will be stored in
|
|
|
|
%s for future use.
|
|
|
|
"""
|
|
|
|
|
|
|
|
config_incomplete_text = """
|
|
|
|
|
|
|
|
Your configuration file %s is not complete.
|
|
|
|
Make sure that it has a [general] section.
|
|
|
|
(You can copy&paste the below. Some commented defaults are shown.)
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2008-08-07 19:14:26 +02:00
|
|
|
config_missing_apiurl_text = """
|
|
|
|
the apiurl \'%s\' does not exist in the config file. Please enter
|
|
|
|
your credentials for this apiurl.
|
|
|
|
"""
|
|
|
|
|
2007-04-19 12:40:18 +02:00
|
|
|
cookiejar = None
|
2006-10-10 16:04:34 +02:00
|
|
|
|
2011-08-17 15:33:56 +02:00
|
|
|
|
2007-04-25 12:24:51 +02:00
|
|
|
def parse_apisrv_url(scheme, apisrv):
|
|
|
|
if apisrv.startswith('http://') or apisrv.startswith('https://'):
|
2015-08-20 14:45:02 +02:00
|
|
|
url = apisrv
|
2009-02-24 02:29:17 +01:00
|
|
|
elif scheme != None:
|
2015-08-20 14:45:02 +02:00
|
|
|
url = scheme + apisrv
|
2009-02-24 02:29:17 +01:00
|
|
|
else:
|
|
|
|
msg = 'invalid apiurl \'%s\' (specify the protocol (http:// or https://))' % apisrv
|
2013-04-09 14:03:17 +02:00
|
|
|
raise URLError(msg)
|
2015-08-20 14:45:02 +02:00
|
|
|
scheme, url, path = urlsplit(url)[0:3]
|
|
|
|
return scheme, url, path.rstrip('/')
|
2011-08-17 15:33:56 +02:00
|
|
|
|
2007-04-25 12:24:51 +02:00
|
|
|
|
2013-10-26 01:15:18 +02:00
|
|
|
def urljoin(scheme, apisrv, path=''):
|
|
|
|
return '://'.join([scheme, apisrv]) + path
|
2009-02-24 00:29:32 +01:00
|
|
|
|
2011-08-17 15:33:56 +02:00
|
|
|
|
2010-09-01 15:53:37 +02:00
|
|
|
def is_known_apiurl(url):
|
|
|
|
"""returns true if url is a known apiurl"""
|
|
|
|
apiurl = urljoin(*parse_apisrv_url(None, url))
|
2011-08-17 15:33:56 +02:00
|
|
|
return apiurl in config['api_host_options']
|
|
|
|
|
2010-09-01 15:53:37 +02:00
|
|
|
|
2013-10-26 01:15:18 +02:00
|
|
|
def extract_known_apiurl(url):
|
|
|
|
"""
|
|
|
|
Return longest prefix of given url that is known apiurl,
|
|
|
|
None if there is no known apiurl that is prefix of given url.
|
|
|
|
"""
|
|
|
|
scheme, host, path = parse_apisrv_url(None, url)
|
|
|
|
p = path.split('/')
|
|
|
|
while p:
|
|
|
|
apiurl = urljoin(scheme, host, '/'.join(p))
|
|
|
|
if apiurl in config['api_host_options']:
|
|
|
|
return apiurl
|
|
|
|
p.pop()
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2008-08-20 12:41:10 +02:00
|
|
|
def get_apiurl_api_host_options(apiurl):
|
|
|
|
"""
|
|
|
|
Returns all apihost specific options for the given apiurl, None if
|
|
|
|
no such specific optiosn exist.
|
|
|
|
"""
|
|
|
|
# FIXME: in A Better World (tm) there was a config object which
|
|
|
|
# knows this instead of having to extract it from a url where it
|
|
|
|
# had been mingled into before. But this works fine for now.
|
2009-02-24 00:29:32 +01:00
|
|
|
|
|
|
|
apiurl = urljoin(*parse_apisrv_url(None, apiurl))
|
2010-09-01 15:53:37 +02:00
|
|
|
if is_known_apiurl(apiurl):
|
2009-02-24 00:29:32 +01:00
|
|
|
return config['api_host_options'][apiurl]
|
2010-09-01 15:53:37 +02:00
|
|
|
raise oscerr.ConfigMissingApiurl('missing credentials for apiurl: \'%s\'' % apiurl,
|
|
|
|
'', apiurl)
|
2008-08-20 12:41:10 +02:00
|
|
|
|
2011-08-17 15:33:56 +02:00
|
|
|
|
2008-03-15 23:51:37 +01:00
|
|
|
def get_apiurl_usr(apiurl):
|
|
|
|
"""
|
|
|
|
returns the user for this host - if this host does not exist in the
|
2008-08-20 11:45:49 +02:00
|
|
|
internal api_host_options the default user is returned.
|
2008-03-15 23:51:37 +01:00
|
|
|
"""
|
2008-08-20 12:41:10 +02:00
|
|
|
# FIXME: maybe there should be defaults not just for the user but
|
|
|
|
# for all apihost specific options. The ConfigParser class
|
|
|
|
# actually even does this but for some reason we don't use it
|
|
|
|
# (yet?).
|
|
|
|
|
|
|
|
try:
|
|
|
|
return get_apiurl_api_host_options(apiurl)['user']
|
|
|
|
except KeyError:
|
2013-04-09 12:51:28 +02:00
|
|
|
print('no specific section found in config file for host of [\'%s\'] - using default user: \'%s\'' \
|
|
|
|
% (apiurl, config['user']), file=sys.stderr)
|
2008-03-18 14:51:57 +01:00
|
|
|
return config['user']
|
2008-03-15 23:51:37 +01:00
|
|
|
|
2011-08-17 15:33:56 +02:00
|
|
|
|
2010-08-26 13:06:00 +02:00
|
|
|
# workaround m2crypto issue:
|
|
|
|
# if multiple SSL.Context objects are created
|
|
|
|
# m2crypto only uses the last object which was created.
|
|
|
|
# So we need to build a new opener everytime we switch the
|
|
|
|
# apiurl (because different apiurls may have different
|
|
|
|
# cafile/capath locations)
|
2013-10-26 01:15:18 +02:00
|
|
|
def _build_opener(apiurl):
|
2006-10-10 16:04:34 +02:00
|
|
|
from osc.core import __version__
|
2010-08-26 13:06:00 +02:00
|
|
|
global config
|
Support an arbitrary sized file in core.http_request
The old code only supports a file whose size is less then or equal
to INT_MAX (due to a reasonable(!) limit in M2Crypto). The actual
issue is in core.http_request which mmap(...)s the file, wraps it
into a memoryview/buffer and then passes the memoryview/buffer to
urlopen. Eventually, the whole memoryview/buffer is read into memory
(see m2_PyObject_GetBufferInt). If the file is too large (> INT_MAX),
m2_PyObject_GetBufferInt raises a ValueError (which is perfectly
fine!).
Reading a whole file into memory is completely insane. In order to
avoid this, we now simply pass a file-like object to urlopen (more
precisely, the file-like object is associated with the Request
instance that is passed to urlopen). The advantange is that the
file-like object is processed in chunks of 8192 bytes (see
http.client.HTTPConnection) (that is, only 8192 bytes are read into
memory (instead of the whole file)).
There are two pitfalls when passing a file-like object to urlopen:
* By default, a chunked Transfer-Encoding is applied. It seems that
some servers (like api.o.o) do not like this (PUTing a file with
a chunked Transfer-Encoding to api.o.o results in status 400). In
order to avoid a chunked Transfer-Encoding, we explicitly set a
Content-Length header (we also do this in the non-file case (just
for the sake of completeness)).
* If the request fails with status 401, it is retried with an
appropriate Authorization header. When retrying the request, the
file's offset has to be repositioned to the beginning of the file
(otherwise, a 0-length body is sent which most likely does not
match the Content-Length header).
Note: core.http_request's "data" and "file" parameters are now mutually
exclusive because specifying both makes no sense (only one of them
is considered) and it simplifies the implementation a bit.
Fixes: #202 ("osc user authentification seems to be broken with last
commit")
Fixes: #304 ("osc ci - cannot handle more than 2 GB file uploads")
2021-04-09 15:57:00 +02:00
|
|
|
|
|
|
|
class OscHTTPBasicAuthHandler(HTTPBasicAuthHandler, object):
|
|
|
|
# python2: inherit from object in order to make it a new-style class
|
|
|
|
# (HTTPBasicAuthHandler is not a new-style class)
|
|
|
|
def _rewind_request(self, req):
|
|
|
|
if hasattr(req.data, 'seek'):
|
|
|
|
# if the request is issued again (this time with an
|
|
|
|
# Authorization header), the file's offset has to be
|
|
|
|
# repositioned to the beginning of the file (otherwise,
|
|
|
|
# a 0-length body is sent which most likely does not match
|
|
|
|
# the Content-Length header (if present))
|
|
|
|
req.data.seek(0)
|
|
|
|
|
|
|
|
def retry_http_basic_auth(self, host, req, realm):
|
|
|
|
self._rewind_request(req)
|
|
|
|
return super(self.__class__, self).retry_http_basic_auth(host, req,
|
|
|
|
realm)
|
|
|
|
|
|
|
|
|
2011-08-17 15:33:56 +02:00
|
|
|
if 'last_opener' not in _build_opener.__dict__:
|
2010-08-26 13:06:00 +02:00
|
|
|
_build_opener.last_opener = (None, None)
|
|
|
|
if apiurl == _build_opener.last_opener[0]:
|
|
|
|
return _build_opener.last_opener[1]
|
2007-08-08 15:24:52 +02:00
|
|
|
|
2011-07-15 20:10:45 +02:00
|
|
|
# respect no_proxy env variable
|
2013-04-09 14:03:17 +02:00
|
|
|
if proxy_bypass(apiurl):
|
2011-07-15 20:10:45 +02:00
|
|
|
# initialize with empty dict
|
2013-04-09 14:03:17 +02:00
|
|
|
proxyhandler = ProxyHandler({})
|
2011-07-15 20:10:45 +02:00
|
|
|
else:
|
|
|
|
# read proxies from env
|
2013-04-09 14:03:17 +02:00
|
|
|
proxyhandler = ProxyHandler()
|
2011-07-15 20:10:45 +02:00
|
|
|
|
Support an arbitrary sized file in core.http_request
The old code only supports a file whose size is less then or equal
to INT_MAX (due to a reasonable(!) limit in M2Crypto). The actual
issue is in core.http_request which mmap(...)s the file, wraps it
into a memoryview/buffer and then passes the memoryview/buffer to
urlopen. Eventually, the whole memoryview/buffer is read into memory
(see m2_PyObject_GetBufferInt). If the file is too large (> INT_MAX),
m2_PyObject_GetBufferInt raises a ValueError (which is perfectly
fine!).
Reading a whole file into memory is completely insane. In order to
avoid this, we now simply pass a file-like object to urlopen (more
precisely, the file-like object is associated with the Request
instance that is passed to urlopen). The advantange is that the
file-like object is processed in chunks of 8192 bytes (see
http.client.HTTPConnection) (that is, only 8192 bytes are read into
memory (instead of the whole file)).
There are two pitfalls when passing a file-like object to urlopen:
* By default, a chunked Transfer-Encoding is applied. It seems that
some servers (like api.o.o) do not like this (PUTing a file with
a chunked Transfer-Encoding to api.o.o results in status 400). In
order to avoid a chunked Transfer-Encoding, we explicitly set a
Content-Length header (we also do this in the non-file case (just
for the sake of completeness)).
* If the request fails with status 401, it is retried with an
appropriate Authorization header. When retrying the request, the
file's offset has to be repositioned to the beginning of the file
(otherwise, a 0-length body is sent which most likely does not
match the Content-Length header).
Note: core.http_request's "data" and "file" parameters are now mutually
exclusive because specifying both makes no sense (only one of them
is considered) and it simplifies the implementation a bit.
Fixes: #202 ("osc user authentification seems to be broken with last
commit")
Fixes: #304 ("osc ci - cannot handle more than 2 GB file uploads")
2021-04-09 15:57:00 +02:00
|
|
|
authhandler_class = OscHTTPBasicAuthHandler
|
2010-08-19 13:00:10 +02:00
|
|
|
# workaround for http://bugs.python.org/issue9639
|
2016-06-15 12:14:41 +02:00
|
|
|
if sys.version_info >= (2, 6, 6) and sys.version_info < (2, 7, 9):
|
Support an arbitrary sized file in core.http_request
The old code only supports a file whose size is less then or equal
to INT_MAX (due to a reasonable(!) limit in M2Crypto). The actual
issue is in core.http_request which mmap(...)s the file, wraps it
into a memoryview/buffer and then passes the memoryview/buffer to
urlopen. Eventually, the whole memoryview/buffer is read into memory
(see m2_PyObject_GetBufferInt). If the file is too large (> INT_MAX),
m2_PyObject_GetBufferInt raises a ValueError (which is perfectly
fine!).
Reading a whole file into memory is completely insane. In order to
avoid this, we now simply pass a file-like object to urlopen (more
precisely, the file-like object is associated with the Request
instance that is passed to urlopen). The advantange is that the
file-like object is processed in chunks of 8192 bytes (see
http.client.HTTPConnection) (that is, only 8192 bytes are read into
memory (instead of the whole file)).
There are two pitfalls when passing a file-like object to urlopen:
* By default, a chunked Transfer-Encoding is applied. It seems that
some servers (like api.o.o) do not like this (PUTing a file with
a chunked Transfer-Encoding to api.o.o results in status 400). In
order to avoid a chunked Transfer-Encoding, we explicitly set a
Content-Length header (we also do this in the non-file case (just
for the sake of completeness)).
* If the request fails with status 401, it is retried with an
appropriate Authorization header. When retrying the request, the
file's offset has to be repositioned to the beginning of the file
(otherwise, a 0-length body is sent which most likely does not
match the Content-Length header).
Note: core.http_request's "data" and "file" parameters are now mutually
exclusive because specifying both makes no sense (only one of them
is considered) and it simplifies the implementation a bit.
Fixes: #202 ("osc user authentification seems to be broken with last
commit")
Fixes: #304 ("osc ci - cannot handle more than 2 GB file uploads")
2021-04-09 15:57:00 +02:00
|
|
|
class OscHTTPBasicAuthHandlerCompat(OscHTTPBasicAuthHandler):
|
2016-06-15 12:14:41 +02:00
|
|
|
# The following two functions were backported from upstream 2.7.
|
|
|
|
def http_error_auth_reqed(self, authreq, host, req, headers):
|
|
|
|
authreq = headers.get(authreq, None)
|
|
|
|
|
|
|
|
if authreq:
|
|
|
|
mo = AbstractBasicAuthHandler.rx.search(authreq)
|
|
|
|
if mo:
|
|
|
|
scheme, quote, realm = mo.groups()
|
|
|
|
if quote not in ['"', "'"]:
|
|
|
|
warnings.warn("Basic Auth Realm was unquoted",
|
|
|
|
UserWarning, 2)
|
|
|
|
if scheme.lower() == 'basic':
|
|
|
|
return self.retry_http_basic_auth(host, req, realm)
|
2011-04-06 17:23:48 +02:00
|
|
|
|
2010-09-14 23:10:23 +02:00
|
|
|
def retry_http_basic_auth(self, host, req, realm):
|
Support an arbitrary sized file in core.http_request
The old code only supports a file whose size is less then or equal
to INT_MAX (due to a reasonable(!) limit in M2Crypto). The actual
issue is in core.http_request which mmap(...)s the file, wraps it
into a memoryview/buffer and then passes the memoryview/buffer to
urlopen. Eventually, the whole memoryview/buffer is read into memory
(see m2_PyObject_GetBufferInt). If the file is too large (> INT_MAX),
m2_PyObject_GetBufferInt raises a ValueError (which is perfectly
fine!).
Reading a whole file into memory is completely insane. In order to
avoid this, we now simply pass a file-like object to urlopen (more
precisely, the file-like object is associated with the Request
instance that is passed to urlopen). The advantange is that the
file-like object is processed in chunks of 8192 bytes (see
http.client.HTTPConnection) (that is, only 8192 bytes are read into
memory (instead of the whole file)).
There are two pitfalls when passing a file-like object to urlopen:
* By default, a chunked Transfer-Encoding is applied. It seems that
some servers (like api.o.o) do not like this (PUTing a file with
a chunked Transfer-Encoding to api.o.o results in status 400). In
order to avoid a chunked Transfer-Encoding, we explicitly set a
Content-Length header (we also do this in the non-file case (just
for the sake of completeness)).
* If the request fails with status 401, it is retried with an
appropriate Authorization header. When retrying the request, the
file's offset has to be repositioned to the beginning of the file
(otherwise, a 0-length body is sent which most likely does not
match the Content-Length header).
Note: core.http_request's "data" and "file" parameters are now mutually
exclusive because specifying both makes no sense (only one of them
is considered) and it simplifies the implementation a bit.
Fixes: #202 ("osc user authentification seems to be broken with last
commit")
Fixes: #304 ("osc ci - cannot handle more than 2 GB file uploads")
2021-04-09 15:57:00 +02:00
|
|
|
self._rewind_request(req)
|
2016-06-15 12:14:41 +02:00
|
|
|
user, pw = self.passwd.find_user_password(realm, host)
|
|
|
|
if pw is not None:
|
|
|
|
raw = "%s:%s" % (user, pw)
|
|
|
|
auth = 'Basic %s' % base64.b64encode(raw).strip()
|
|
|
|
if req.get_header(self.auth_header, None) == auth:
|
|
|
|
return None
|
|
|
|
req.add_unredirected_header(self.auth_header, auth)
|
|
|
|
return self.parent.open(req, timeout=req.timeout)
|
|
|
|
else:
|
2010-09-14 23:10:23 +02:00
|
|
|
return None
|
|
|
|
|
Support an arbitrary sized file in core.http_request
The old code only supports a file whose size is less then or equal
to INT_MAX (due to a reasonable(!) limit in M2Crypto). The actual
issue is in core.http_request which mmap(...)s the file, wraps it
into a memoryview/buffer and then passes the memoryview/buffer to
urlopen. Eventually, the whole memoryview/buffer is read into memory
(see m2_PyObject_GetBufferInt). If the file is too large (> INT_MAX),
m2_PyObject_GetBufferInt raises a ValueError (which is perfectly
fine!).
Reading a whole file into memory is completely insane. In order to
avoid this, we now simply pass a file-like object to urlopen (more
precisely, the file-like object is associated with the Request
instance that is passed to urlopen). The advantange is that the
file-like object is processed in chunks of 8192 bytes (see
http.client.HTTPConnection) (that is, only 8192 bytes are read into
memory (instead of the whole file)).
There are two pitfalls when passing a file-like object to urlopen:
* By default, a chunked Transfer-Encoding is applied. It seems that
some servers (like api.o.o) do not like this (PUTing a file with
a chunked Transfer-Encoding to api.o.o results in status 400). In
order to avoid a chunked Transfer-Encoding, we explicitly set a
Content-Length header (we also do this in the non-file case (just
for the sake of completeness)).
* If the request fails with status 401, it is retried with an
appropriate Authorization header. When retrying the request, the
file's offset has to be repositioned to the beginning of the file
(otherwise, a 0-length body is sent which most likely does not
match the Content-Length header).
Note: core.http_request's "data" and "file" parameters are now mutually
exclusive because specifying both makes no sense (only one of them
is considered) and it simplifies the implementation a bit.
Fixes: #202 ("osc user authentification seems to be broken with last
commit")
Fixes: #304 ("osc ci - cannot handle more than 2 GB file uploads")
2021-04-09 15:57:00 +02:00
|
|
|
authhandler_class = OscHTTPBasicAuthHandlerCompat
|
2010-08-19 13:00:10 +02:00
|
|
|
|
2010-08-26 13:06:00 +02:00
|
|
|
options = config['api_host_options'][apiurl]
|
|
|
|
# with None as first argument, it will always use this username/password
|
|
|
|
# combination for urls for which arg2 (apisrv) is a super-url
|
2010-08-19 13:00:10 +02:00
|
|
|
authhandler = authhandler_class( \
|
2013-04-09 14:03:17 +02:00
|
|
|
HTTPPasswordMgrWithDefaultRealm())
|
2010-08-26 13:06:00 +02:00
|
|
|
authhandler.add_password(None, apiurl, options['user'], options['pass'])
|
2006-10-10 16:04:34 +02:00
|
|
|
|
2010-08-26 13:06:00 +02:00
|
|
|
if options['sslcertck']:
|
2007-04-19 12:40:18 +02:00
|
|
|
try:
|
2013-04-09 11:35:53 +02:00
|
|
|
from . import oscssl
|
2010-08-26 13:06:00 +02:00
|
|
|
from M2Crypto import m2urllib2
|
2013-04-09 11:27:02 +02:00
|
|
|
except ImportError as e:
|
2013-04-09 12:51:28 +02:00
|
|
|
print(e)
|
2010-08-26 13:06:00 +02:00
|
|
|
raise NoSecureSSLError('M2Crypto is needed to access %s in a secure way.\nPlease install python-m2crypto.' % apiurl)
|
2009-10-02 13:25:59 +02:00
|
|
|
|
2010-08-26 13:06:00 +02:00
|
|
|
cafile = options.get('cafile', None)
|
|
|
|
capath = options.get('capath', None)
|
2009-10-02 13:25:59 +02:00
|
|
|
if not cafile and not capath:
|
2011-08-17 15:33:56 +02:00
|
|
|
for i in ['/etc/pki/tls/cert.pem', '/etc/ssl/certs']:
|
2009-11-10 01:56:52 +01:00
|
|
|
if os.path.isfile(i):
|
|
|
|
cafile = i
|
|
|
|
break
|
|
|
|
elif os.path.isdir(i):
|
|
|
|
capath = i
|
|
|
|
break
|
2013-02-06 00:50:18 +01:00
|
|
|
if not cafile and not capath:
|
2018-01-26 09:46:52 +01:00
|
|
|
raise oscerr.OscIOError(None, 'No CA certificates found. (You may want to install ca-certificates-mozilla package)')
|
2009-11-13 11:46:23 +01:00
|
|
|
ctx = oscssl.mySSLContext()
|
2011-08-17 15:33:56 +02:00
|
|
|
if ctx.load_verify_locations(capath=capath, cafile=cafile) != 1:
|
2018-01-26 09:46:52 +01:00
|
|
|
raise oscerr.OscIOError(None, 'No CA certificates found. (You may want to install ca-certificates-mozilla package)')
|
2013-04-09 14:03:17 +02:00
|
|
|
opener = m2urllib2.build_opener(ctx, oscssl.myHTTPSHandler(ssl_context=ctx, appname='osc'), HTTPCookieProcessor(cookiejar), authhandler, proxyhandler)
|
2009-10-02 13:25:59 +02:00
|
|
|
else:
|
2015-11-28 22:32:45 +01:00
|
|
|
handlers = [HTTPCookieProcessor(cookiejar), authhandler, proxyhandler]
|
|
|
|
try:
|
|
|
|
# disable ssl cert check in python >= 2.7.9
|
|
|
|
ctx = ssl._create_unverified_context()
|
|
|
|
handlers.append(HTTPSHandler(context=ctx))
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2013-04-09 12:51:28 +02:00
|
|
|
print("WARNING: SSL certificate checks disabled. Connection is insecure!\n", file=sys.stderr)
|
2015-11-28 22:32:45 +01:00
|
|
|
opener = build_opener(*handlers)
|
2010-08-26 13:06:00 +02:00
|
|
|
opener.addheaders = [('User-agent', 'osc/%s' % __version__)]
|
|
|
|
_build_opener.last_opener = (apiurl, opener)
|
|
|
|
return opener
|
2009-10-02 13:25:59 +02:00
|
|
|
|
2011-08-17 15:33:56 +02:00
|
|
|
|
2016-11-19 13:01:05 +01:00
|
|
|
def init_basicauth(config, config_mtime):
|
2010-08-26 13:06:00 +02:00
|
|
|
"""initialize urllib2 with the credentials for Basic Authentication"""
|
2006-10-10 16:04:34 +02:00
|
|
|
|
2010-09-01 15:38:08 +02:00
|
|
|
def filterhdrs(meth, ishdr, *hdrs):
|
|
|
|
# this is so ugly but httplib doesn't use
|
|
|
|
# a logger object or such
|
2013-06-15 08:53:26 +02:00
|
|
|
def new_method(self, *args, **kwargs):
|
2014-03-11 19:40:27 +01:00
|
|
|
# check if this is a recursive call (note: we do not
|
|
|
|
# have to care about thread safety)
|
|
|
|
is_rec_call = getattr(self, '_orig_stdout', None) is not None
|
|
|
|
try:
|
|
|
|
if not is_rec_call:
|
|
|
|
self._orig_stdout = sys.stdout
|
|
|
|
sys.stdout = StringIO()
|
|
|
|
meth(self, *args, **kwargs)
|
|
|
|
hdr = sys.stdout.getvalue()
|
|
|
|
finally:
|
|
|
|
# restore original stdout
|
|
|
|
if not is_rec_call:
|
|
|
|
sys.stdout = self._orig_stdout
|
|
|
|
del self._orig_stdout
|
2010-09-01 15:38:08 +02:00
|
|
|
for i in hdrs:
|
|
|
|
if ishdr:
|
|
|
|
hdr = re.sub(r'%s:[^\\r]*\\r\\n' % i, '', hdr)
|
|
|
|
else:
|
|
|
|
hdr = re.sub(i, '', hdr)
|
|
|
|
sys.stdout.write(hdr)
|
|
|
|
new_method.__name__ = meth.__name__
|
|
|
|
return new_method
|
|
|
|
|
|
|
|
if config['http_debug'] and not config['http_full_debug']:
|
2013-04-09 12:36:42 +02:00
|
|
|
HTTPConnection.send = filterhdrs(HTTPConnection.send, True, 'Cookie', 'Authorization')
|
|
|
|
HTTPResponse.begin = filterhdrs(HTTPResponse.begin, False, 'header: Set-Cookie.*\n')
|
2007-04-19 10:47:22 +02:00
|
|
|
|
2010-08-26 13:06:00 +02:00
|
|
|
if config['http_debug']:
|
|
|
|
# brute force
|
|
|
|
def urllib2_debug_init(self, debuglevel=0):
|
|
|
|
self._debuglevel = 1
|
2013-04-09 14:03:17 +02:00
|
|
|
AbstractHTTPHandler.__init__ = urllib2_debug_init
|
2010-08-26 13:06:00 +02:00
|
|
|
|
|
|
|
cookie_file = os.path.expanduser(config['cookiejar'])
|
2021-08-12 02:21:11 +02:00
|
|
|
if not os.path.exists(os.path.dirname(cookie_file)):
|
|
|
|
os.makedirs(os.path.dirname(cookie_file), mode=0o700)
|
2010-08-26 13:06:00 +02:00
|
|
|
global cookiejar
|
2013-04-09 12:36:42 +02:00
|
|
|
cookiejar = LWPCookieJar(cookie_file)
|
2010-08-26 13:06:00 +02:00
|
|
|
try:
|
|
|
|
cookiejar.load(ignore_discard=True)
|
2016-11-19 13:01:05 +01:00
|
|
|
if int(round(config_mtime)) > int(os.stat(cookie_file).st_mtime):
|
|
|
|
cookiejar.clear()
|
|
|
|
cookiejar.save()
|
2010-08-26 13:06:00 +02:00
|
|
|
except IOError:
|
|
|
|
try:
|
2014-03-10 22:36:56 +01:00
|
|
|
fd = os.open(cookie_file, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o600)
|
2014-01-06 11:12:02 +01:00
|
|
|
os.close(fd)
|
2014-03-10 22:36:56 +01:00
|
|
|
except IOError:
|
|
|
|
# hmm is any good reason why we should catch the IOError?
|
2010-08-26 13:06:00 +02:00
|
|
|
#print 'Unable to create cookiejar file: \'%s\'. Using RAM-based cookies.' % cookie_file
|
2013-04-09 12:36:42 +02:00
|
|
|
cookiejar = CookieJar()
|
2006-10-10 16:04:34 +02:00
|
|
|
|
|
|
|
|
2008-03-15 23:51:37 +01:00
|
|
|
def get_configParser(conffile=None, force_read=False):
|
|
|
|
"""
|
|
|
|
Returns an ConfigParser() object. After its first invocation the
|
|
|
|
ConfigParser object is stored in a method attribute and this attribute
|
|
|
|
is returned unless you pass force_read=True.
|
|
|
|
"""
|
2017-10-27 11:29:00 +02:00
|
|
|
if not conffile:
|
|
|
|
conffile = identify_conf()
|
|
|
|
|
2008-03-15 23:51:37 +01:00
|
|
|
conffile = os.path.expanduser(conffile)
|
2011-08-17 15:33:56 +02:00
|
|
|
if 'conffile' not in get_configParser.__dict__:
|
2010-03-07 22:50:11 +01:00
|
|
|
get_configParser.conffile = conffile
|
2011-08-17 15:33:56 +02:00
|
|
|
if force_read or 'cp' not in get_configParser.__dict__ or conffile != get_configParser.conffile:
|
2008-08-07 18:40:55 +02:00
|
|
|
get_configParser.cp = OscConfigParser.OscConfigParser(DEFAULTS)
|
2008-03-15 23:51:37 +01:00
|
|
|
get_configParser.cp.read(conffile)
|
2010-03-07 22:50:11 +01:00
|
|
|
get_configParser.conffile = conffile
|
2008-03-15 23:51:37 +01:00
|
|
|
return get_configParser.cp
|
|
|
|
|
2011-08-17 15:33:56 +02:00
|
|
|
|
2011-11-18 22:27:38 +01:00
|
|
|
def write_config(fname, cp):
|
|
|
|
"""write new configfile in a safe way"""
|
2011-11-18 22:32:10 +01:00
|
|
|
if os.path.exists(fname) and not os.path.isfile(fname):
|
|
|
|
# only write to a regular file
|
|
|
|
return
|
2021-12-06 14:23:51 +01:00
|
|
|
|
|
|
|
# config file is behind a symlink
|
|
|
|
# resolve the symlink and continue writing the config as usual
|
|
|
|
if os.path.islink(fname):
|
|
|
|
fname = os.readlink(fname)
|
|
|
|
|
|
|
|
# create directories to the config file (if they don't exist already)
|
2017-10-27 11:29:00 +02:00
|
|
|
if not os.path.exists(os.path.dirname(fname)):
|
2021-12-06 14:23:51 +01:00
|
|
|
try:
|
|
|
|
os.makedirs(os.path.dirname(fname), mode=0o700)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.EEXIST:
|
|
|
|
raise
|
|
|
|
|
2011-11-18 22:27:38 +01:00
|
|
|
with open(fname + '.new', 'w') as f:
|
|
|
|
cp.write(f, comments=True)
|
|
|
|
try:
|
|
|
|
os.rename(fname + '.new', fname)
|
2013-04-09 12:45:16 +02:00
|
|
|
os.chmod(fname, 0o600)
|
2011-11-18 22:27:38 +01:00
|
|
|
except:
|
|
|
|
if os.path.exists(fname + '.new'):
|
|
|
|
os.unlink(fname + '.new')
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
2019-08-29 11:35:34 +02:00
|
|
|
def config_set_option(section, opt, val=None, delete=False, update=True, creds_mgr_descr=None, **kwargs):
|
2010-03-07 22:50:11 +01:00
|
|
|
"""
|
|
|
|
Sets a config option. If val is not specified the current/default value is
|
|
|
|
returned. If val is specified, opt is set to val and the new value is returned.
|
|
|
|
If an option was modified get_config is called with **kwargs unless update is set
|
|
|
|
to False (override_conffile defaults to config['conffile']).
|
|
|
|
If val is not specified and delete is True then the option is removed from the
|
|
|
|
config/reset to the default value.
|
|
|
|
"""
|
|
|
|
cp = get_configParser(config['conffile'])
|
|
|
|
# don't allow "internal" options
|
|
|
|
general_opts = [i for i in DEFAULTS.keys() if not i in ['user', 'pass', 'passx']]
|
2010-06-23 14:20:56 +02:00
|
|
|
if section != 'general':
|
|
|
|
section = config['apiurl_aliases'].get(section, section)
|
2013-10-26 01:15:18 +02:00
|
|
|
scheme, host, path = \
|
2010-06-23 14:20:56 +02:00
|
|
|
parse_apisrv_url(config.get('scheme', 'https'), section)
|
2013-10-26 01:15:18 +02:00
|
|
|
section = urljoin(scheme, host, path)
|
2010-06-23 14:20:56 +02:00
|
|
|
|
|
|
|
sections = {}
|
|
|
|
for url in cp.sections():
|
|
|
|
if url == 'general':
|
|
|
|
sections[url] = url
|
|
|
|
else:
|
2013-10-26 01:15:18 +02:00
|
|
|
scheme, host, path = \
|
2010-06-23 14:20:56 +02:00
|
|
|
parse_apisrv_url(config.get('scheme', 'https'), url)
|
2013-10-26 01:15:18 +02:00
|
|
|
apiurl = urljoin(scheme, host, path)
|
2010-06-23 14:20:56 +02:00
|
|
|
sections[apiurl] = url
|
|
|
|
|
2010-03-08 14:09:15 +01:00
|
|
|
section = sections.get(section.rstrip('/'), section)
|
2010-03-07 22:50:11 +01:00
|
|
|
if not section in cp.sections():
|
|
|
|
raise oscerr.ConfigError('unknown section \'%s\'' % section, config['conffile'])
|
|
|
|
if section == 'general' and not opt in general_opts or \
|
|
|
|
section != 'general' and not opt in api_host_options:
|
|
|
|
raise oscerr.ConfigError('unknown config option \'%s\'' % opt, config['conffile'])
|
2021-07-14 11:19:08 +02:00
|
|
|
|
|
|
|
if not val and not delete and opt == 'pass' and creds_mgr_descr is not None:
|
|
|
|
# change password store
|
|
|
|
creds_mgr = _get_credentials_manager(section, cp)
|
|
|
|
user = _extract_user_compat(cp, section, creds_mgr)
|
|
|
|
val = creds_mgr.get_password(section, user)
|
|
|
|
|
2010-03-07 22:50:11 +01:00
|
|
|
run = False
|
|
|
|
if val:
|
2019-08-29 11:35:34 +02:00
|
|
|
if opt == 'pass':
|
|
|
|
creds_mgr = _get_credentials_manager(section, cp)
|
2019-08-29 14:27:30 +02:00
|
|
|
user = _extract_user_compat(cp, section, creds_mgr)
|
2019-08-29 11:35:34 +02:00
|
|
|
old_pw = creds_mgr.get_password(section, user, defer=False)
|
|
|
|
try:
|
|
|
|
creds_mgr.delete_password(section, user)
|
|
|
|
if creds_mgr_descr:
|
|
|
|
creds_mgr_new = creds_mgr_descr.create(cp)
|
|
|
|
else:
|
|
|
|
creds_mgr_new = creds_mgr
|
|
|
|
creds_mgr_new.set_password(section, user, val)
|
|
|
|
write_config(config['conffile'], cp)
|
|
|
|
opt = credentials.AbstractCredentialsManager.config_entry
|
|
|
|
old_pw = None
|
|
|
|
finally:
|
|
|
|
if old_pw is not None:
|
|
|
|
creds_mgr.set_password(section, user, old_pw)
|
|
|
|
# not nice, but needed if the Credentials Manager will change
|
|
|
|
# something in cp
|
|
|
|
write_config(config['conffile'], cp)
|
|
|
|
else:
|
|
|
|
cp.set(section, opt, val)
|
|
|
|
write_config(config['conffile'], cp)
|
2010-03-07 22:50:11 +01:00
|
|
|
run = True
|
2019-08-29 11:35:34 +02:00
|
|
|
elif delete and (cp.has_option(section, opt) or opt == 'pass'):
|
|
|
|
if opt == 'pass':
|
|
|
|
creds_mgr = _get_credentials_manager(section, cp)
|
2021-07-14 11:31:56 +02:00
|
|
|
user = _extract_user_compat(cp, section, creds_mgr)
|
2019-08-29 11:35:34 +02:00
|
|
|
creds_mgr.delete_password(section, user)
|
|
|
|
else:
|
|
|
|
cp.remove_option(section, opt)
|
2010-03-07 22:50:11 +01:00
|
|
|
write_config(config['conffile'], cp)
|
|
|
|
run = True
|
|
|
|
if run and update:
|
2011-09-21 01:52:04 +02:00
|
|
|
kw = {'override_conffile': config['conffile'],
|
|
|
|
'override_no_keyring': config['use_keyring'],
|
|
|
|
'override_no_gnome_keyring': config['gnome_keyring']}
|
2010-03-07 22:50:11 +01:00
|
|
|
kw.update(kwargs)
|
|
|
|
get_config(**kw)
|
|
|
|
if cp.has_option(section, opt):
|
|
|
|
return (opt, cp.get(section, opt, raw=True))
|
|
|
|
return (opt, None)
|
2008-03-15 23:51:37 +01:00
|
|
|
|
2019-08-29 14:27:30 +02:00
|
|
|
def _extract_user_compat(cp, section, creds_mgr):
|
|
|
|
"""
|
|
|
|
This extracts the user either from the ConfigParser or
|
|
|
|
the creds_mgr. Only needed for deprecated Gnome Keyring
|
|
|
|
"""
|
|
|
|
user = cp.get(section, 'user')
|
|
|
|
if user is None and hasattr(creds_mgr, 'get_user'):
|
|
|
|
user = creds_mgr.get_user(section)
|
|
|
|
return user
|
|
|
|
|
2019-08-27 15:08:38 +02:00
|
|
|
def write_initial_config(conffile, entries, custom_template='', creds_mgr_descriptor=None):
|
Merged revisions 3774-3775,3779,3781-3782,3787,3789-3793,3798,3802,3805,3817-3822,3827,3829-3830,3837-3839,3841-3842,3848-3850 via svnmerge from
https://forgesvn1.novell.com/svn/opensuse/branches/buildservice/osc-exception-handling
........
r3774 | poeml | 2008-04-22 17:39:45 +0200 (Tue, 22 Apr 2008) | 3 lines
A first draft on implement systematic exception handling:
Add errors.py with some exceptions defined, and babysitter.py to handle them
........
r3775 | poeml | 2008-04-22 22:34:12 +0200 (Tue, 22 Apr 2008) | 9 lines
- new global options:
--debugger jump into the debugger before executing anything
--post-mortem jump into the debugger in case of errors
-t, --traceback print call trace in case of errors
- traceback and post_mortem can also be set in .oscrc.
- catch more errors (HTTPError).
- make config accessible from outside of the Osc instance, by making it a class
attribute
........
r3779 | poeml | 2008-04-23 00:55:49 +0200 (Wed, 23 Apr 2008) | 5 lines
- new global option:
-d, --debug print info useful for debugging
- catch some more errors (HTTPError), with OscHTTPError which isn't very
advanced yet.
........
r3781 | Marcus_H | 2008-04-23 01:02:00 +0200 (Wed, 23 Apr 2008) | 2 lines
- added OscConfigError class (just for testing).
- small change in the signature of the OscBaseError constructor (actually we should get rid of the 'args' tuple because it will be deprecated sooner or later
........
r3782 | Marcus_H | 2008-04-23 02:02:13 +0200 (Wed, 23 Apr 2008) | 2 lines
- access the prg.conf.config dict in a save way - this way we avoid AttributeErrors if the prg.conf.config dict doesn't exist
- in case of an configparser error we have to use the prg.options object directly (this was removed in r3781 by accident)
........
r3787 | poeml | 2008-04-23 09:23:56 +0200 (Wed, 23 Apr 2008) | 4 lines
- remove local exception handling from do_req
- for HTTPError, print details (headers and response) when in debug mode
- catch AttributeError
........
r3789 | poeml | 2008-04-23 16:23:14 +0200 (Wed, 23 Apr 2008) | 4 lines
- errors: add two new classes named OscWrongOptionsError and OscWrongArgsError
- commandline: raise instances of the new errors in a number of places
- commandline: add get_cmd_help() to Osc instance which returns the formatted help of a subcommand
........
r3790 | Marcus_H | 2008-04-23 16:48:28 +0200 (Wed, 23 Apr 2008) | 4 lines
- added 2 new exception classes: OscNoConfigfileError and OscIOError
- added new method write_config() to the conf.py module: This method writes osc's configuration file
- minor cleanups in the conf module
........
r3791 | poeml | 2008-04-23 17:11:07 +0200 (Wed, 23 Apr 2008) | 3 lines
small compatibility fix for r3790: try-except-finally isn't supported in
python-2.4.2, thus do the same as try-except inside a try-finally.
........
r3792 | poeml | 2008-04-23 17:37:53 +0200 (Wed, 23 Apr 2008) | 2 lines
fix up the remaining places regarding handling of errors related to commandline parsing
........
r3793 | poeml | 2008-04-23 17:40:34 +0200 (Wed, 23 Apr 2008) | 3 lines
raise a NoWorkingCopyError in osc.core.store_read_project() in case of an
IOError
........
r3798 | Marcus_H | 2008-04-23 23:55:24 +0200 (Wed, 23 Apr 2008) | 1 line
ported -r3797 from trunk
........
r3802 | Marcus_H | 2008-04-24 11:00:55 +0200 (Thu, 24 Apr 2008) | 1 line
ported -r3801 from trunk
........
r3805 | poeml | 2008-04-24 12:52:30 +0200 (Thu, 24 Apr 2008) | 2 lines
raise OscHTTPError in show_pattern_meta(), replacing local error handling
........
r3817 | poeml | 2008-04-24 20:21:32 +0200 (Thu, 24 Apr 2008) | 9 lines
- remove errors.OscHTTPError again.
it seems simpler to use urllib2.HTTPError instead (and just add a specific
error text message where appropriate, and re-raise)
- for 404s, check out _which_ part was not found
it is very ugly, but may be considered Good for pragmatic reasons
- removed local exception handling and workaround for returned 500's from
delete_package() and delete_project(), thereby getting rid of 4 possible exit
points.
........
r3818 | Marcus_H | 2008-04-24 22:36:17 +0200 (Thu, 24 Apr 2008) | 1 line
- this check is superfluous because every HTTPError instance has a code attribute
........
r3819 | poeml | 2008-04-25 00:39:39 +0200 (Fri, 25 Apr 2008) | 1 line
remove a forgotten debug line from core.delete_project()
........
r3820 | poeml | 2008-04-25 10:07:58 +0200 (Fri, 25 Apr 2008) | 2 lines
- ditch local error handling from wipebinaries(), rebuild(), and abortbuild()
........
r3821 | poeml | 2008-04-25 10:56:38 +0200 (Fri, 25 Apr 2008) | 2 lines
It is never needed to import the exception module.
........
r3822 | poeml | 2008-04-25 11:13:39 +0200 (Fri, 25 Apr 2008) | 4 lines
- when going into the debugger with --post-mortem, always print a traceback before
(thus implying -t)
- do not jump into the debugger if not on a TTY, or working in interactive mode
........
r3827 | poeml | 2008-04-25 13:07:46 +0200 (Fri, 25 Apr 2008) | 9 lines
- add errors.OscWorkingCopyOutdated, which takes a tuple with three args:
path to working copy, current rev, expected rev
- add handler for urllib2.URLError errors to the babysitter
- simplify the OscWrongArgsError and OscWrongOptionsError handlers, by removing
the extra line "Sorry, wrong ..." that was printed before the messages given
when the error was raised.
- remove one more errors.OscHTTPError which was still there, and raise
urllib2.HTTPError instead (show_package_meta())
........
r3829 | poeml | 2008-04-25 14:19:10 +0200 (Fri, 25 Apr 2008) | 11 lines
- comment some methods in osc.core which are used by nearly all do_* methods in
osc.commandline
- improve "is not a package/project dir" error messages, by printing the
absolute path tried, instead of '.' for the cwd
- make core.store_read_package() raise a proper NoWorkingCopyError instead of
terminating
- give attribution to things in babysitter.py copied from mercurial
- prefix HTTPError exceptions with 'Server returned an error:'
- remove obsolete local error handling from do_prjresults(), do_importsrcpkg(),
do_repos()
........
r3830 | poeml | 2008-04-25 14:29:35 +0200 (Fri, 25 Apr 2008) | 1 line
catch IOError exceptions in the babysitter
........
r3837 | poeml | 2008-04-25 17:27:36 +0200 (Fri, 25 Apr 2008) | 5 lines
- do_remotebuildlog: raise errors for wrong arguments, remove exits
- raise AttributeError in make_meta_url() instead of exiting
- delete unused method core.delete_server_files()
- replace exit call inside make_meta_url() with an AttributeError
........
r3838 | poeml | 2008-04-25 17:49:18 +0200 (Fri, 25 Apr 2008) | 1 line
simplify the check in do_checkout if a project exists, by using show_project_meta() instead of meta_exists
........
r3839 | poeml | 2008-04-25 18:31:26 +0200 (Fri, 25 Apr 2008) | 6 lines
- commandline do_checkout(): change the order of the two checks, first do the
(cheaper) check for existing directory
- core.core checkout_package(): simplify the check in if the package
exists, by using show_package_meta() instead of meta_exists
Let it throw an exception, instead of using sys.exit().
........
r3841 | Marcus_H | 2008-04-27 15:48:06 +0200 (Sun, 27 Apr 2008) | 5 lines
- added 2 new exception classes: PackageError() and PackageExistsError. The PackageError() class is meant to be the base class for all subsequent package exceptions.
- get rid of 2 sys.exit(1) calls
- make the update() method of the Project() class safer: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- minor fix in delPackage(): use getTransActPath() when printing out the filename
........
r3842 | Marcus_H | 2008-04-27 16:52:55 +0200 (Sun, 27 Apr 2008) | 3 lines
- make the commit() method safe: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- removed another sys.exit(1): raise an exception if a package is missing when doing a commit. For now we use the PackageExistsError() exception but this might change in the future (updated description of PackageExistsError() according to this change)
........
r3848 | poeml | 2008-04-28 12:46:45 +0200 (Mon, 28 Apr 2008) | 3 lines
rename several error classes, dropping the "Osc" prefix, and "Error" suffix in
cases where they don't really make sense.
........
r3849 | poeml | 2008-04-28 12:57:32 +0200 (Mon, 28 Apr 2008) | 3 lines
- rename osc.errors module to osc.oscerr, to make it easier to import it from
other programs and have a crystal clear namespace
........
r3850 | poeml | 2008-04-28 13:26:12 +0200 (Mon, 28 Apr 2008) | 2 lines
split PackageExists exception class into PackageExists and PackageMissing
........
2008-04-28 18:37:44 +02:00
|
|
|
"""
|
2008-08-07 18:40:55 +02:00
|
|
|
write osc's intial configuration file. entries is a dict which contains values
|
Merged revisions 3774-3775,3779,3781-3782,3787,3789-3793,3798,3802,3805,3817-3822,3827,3829-3830,3837-3839,3841-3842,3848-3850 via svnmerge from
https://forgesvn1.novell.com/svn/opensuse/branches/buildservice/osc-exception-handling
........
r3774 | poeml | 2008-04-22 17:39:45 +0200 (Tue, 22 Apr 2008) | 3 lines
A first draft on implement systematic exception handling:
Add errors.py with some exceptions defined, and babysitter.py to handle them
........
r3775 | poeml | 2008-04-22 22:34:12 +0200 (Tue, 22 Apr 2008) | 9 lines
- new global options:
--debugger jump into the debugger before executing anything
--post-mortem jump into the debugger in case of errors
-t, --traceback print call trace in case of errors
- traceback and post_mortem can also be set in .oscrc.
- catch more errors (HTTPError).
- make config accessible from outside of the Osc instance, by making it a class
attribute
........
r3779 | poeml | 2008-04-23 00:55:49 +0200 (Wed, 23 Apr 2008) | 5 lines
- new global option:
-d, --debug print info useful for debugging
- catch some more errors (HTTPError), with OscHTTPError which isn't very
advanced yet.
........
r3781 | Marcus_H | 2008-04-23 01:02:00 +0200 (Wed, 23 Apr 2008) | 2 lines
- added OscConfigError class (just for testing).
- small change in the signature of the OscBaseError constructor (actually we should get rid of the 'args' tuple because it will be deprecated sooner or later
........
r3782 | Marcus_H | 2008-04-23 02:02:13 +0200 (Wed, 23 Apr 2008) | 2 lines
- access the prg.conf.config dict in a save way - this way we avoid AttributeErrors if the prg.conf.config dict doesn't exist
- in case of an configparser error we have to use the prg.options object directly (this was removed in r3781 by accident)
........
r3787 | poeml | 2008-04-23 09:23:56 +0200 (Wed, 23 Apr 2008) | 4 lines
- remove local exception handling from do_req
- for HTTPError, print details (headers and response) when in debug mode
- catch AttributeError
........
r3789 | poeml | 2008-04-23 16:23:14 +0200 (Wed, 23 Apr 2008) | 4 lines
- errors: add two new classes named OscWrongOptionsError and OscWrongArgsError
- commandline: raise instances of the new errors in a number of places
- commandline: add get_cmd_help() to Osc instance which returns the formatted help of a subcommand
........
r3790 | Marcus_H | 2008-04-23 16:48:28 +0200 (Wed, 23 Apr 2008) | 4 lines
- added 2 new exception classes: OscNoConfigfileError and OscIOError
- added new method write_config() to the conf.py module: This method writes osc's configuration file
- minor cleanups in the conf module
........
r3791 | poeml | 2008-04-23 17:11:07 +0200 (Wed, 23 Apr 2008) | 3 lines
small compatibility fix for r3790: try-except-finally isn't supported in
python-2.4.2, thus do the same as try-except inside a try-finally.
........
r3792 | poeml | 2008-04-23 17:37:53 +0200 (Wed, 23 Apr 2008) | 2 lines
fix up the remaining places regarding handling of errors related to commandline parsing
........
r3793 | poeml | 2008-04-23 17:40:34 +0200 (Wed, 23 Apr 2008) | 3 lines
raise a NoWorkingCopyError in osc.core.store_read_project() in case of an
IOError
........
r3798 | Marcus_H | 2008-04-23 23:55:24 +0200 (Wed, 23 Apr 2008) | 1 line
ported -r3797 from trunk
........
r3802 | Marcus_H | 2008-04-24 11:00:55 +0200 (Thu, 24 Apr 2008) | 1 line
ported -r3801 from trunk
........
r3805 | poeml | 2008-04-24 12:52:30 +0200 (Thu, 24 Apr 2008) | 2 lines
raise OscHTTPError in show_pattern_meta(), replacing local error handling
........
r3817 | poeml | 2008-04-24 20:21:32 +0200 (Thu, 24 Apr 2008) | 9 lines
- remove errors.OscHTTPError again.
it seems simpler to use urllib2.HTTPError instead (and just add a specific
error text message where appropriate, and re-raise)
- for 404s, check out _which_ part was not found
it is very ugly, but may be considered Good for pragmatic reasons
- removed local exception handling and workaround for returned 500's from
delete_package() and delete_project(), thereby getting rid of 4 possible exit
points.
........
r3818 | Marcus_H | 2008-04-24 22:36:17 +0200 (Thu, 24 Apr 2008) | 1 line
- this check is superfluous because every HTTPError instance has a code attribute
........
r3819 | poeml | 2008-04-25 00:39:39 +0200 (Fri, 25 Apr 2008) | 1 line
remove a forgotten debug line from core.delete_project()
........
r3820 | poeml | 2008-04-25 10:07:58 +0200 (Fri, 25 Apr 2008) | 2 lines
- ditch local error handling from wipebinaries(), rebuild(), and abortbuild()
........
r3821 | poeml | 2008-04-25 10:56:38 +0200 (Fri, 25 Apr 2008) | 2 lines
It is never needed to import the exception module.
........
r3822 | poeml | 2008-04-25 11:13:39 +0200 (Fri, 25 Apr 2008) | 4 lines
- when going into the debugger with --post-mortem, always print a traceback before
(thus implying -t)
- do not jump into the debugger if not on a TTY, or working in interactive mode
........
r3827 | poeml | 2008-04-25 13:07:46 +0200 (Fri, 25 Apr 2008) | 9 lines
- add errors.OscWorkingCopyOutdated, which takes a tuple with three args:
path to working copy, current rev, expected rev
- add handler for urllib2.URLError errors to the babysitter
- simplify the OscWrongArgsError and OscWrongOptionsError handlers, by removing
the extra line "Sorry, wrong ..." that was printed before the messages given
when the error was raised.
- remove one more errors.OscHTTPError which was still there, and raise
urllib2.HTTPError instead (show_package_meta())
........
r3829 | poeml | 2008-04-25 14:19:10 +0200 (Fri, 25 Apr 2008) | 11 lines
- comment some methods in osc.core which are used by nearly all do_* methods in
osc.commandline
- improve "is not a package/project dir" error messages, by printing the
absolute path tried, instead of '.' for the cwd
- make core.store_read_package() raise a proper NoWorkingCopyError instead of
terminating
- give attribution to things in babysitter.py copied from mercurial
- prefix HTTPError exceptions with 'Server returned an error:'
- remove obsolete local error handling from do_prjresults(), do_importsrcpkg(),
do_repos()
........
r3830 | poeml | 2008-04-25 14:29:35 +0200 (Fri, 25 Apr 2008) | 1 line
catch IOError exceptions in the babysitter
........
r3837 | poeml | 2008-04-25 17:27:36 +0200 (Fri, 25 Apr 2008) | 5 lines
- do_remotebuildlog: raise errors for wrong arguments, remove exits
- raise AttributeError in make_meta_url() instead of exiting
- delete unused method core.delete_server_files()
- replace exit call inside make_meta_url() with an AttributeError
........
r3838 | poeml | 2008-04-25 17:49:18 +0200 (Fri, 25 Apr 2008) | 1 line
simplify the check in do_checkout if a project exists, by using show_project_meta() instead of meta_exists
........
r3839 | poeml | 2008-04-25 18:31:26 +0200 (Fri, 25 Apr 2008) | 6 lines
- commandline do_checkout(): change the order of the two checks, first do the
(cheaper) check for existing directory
- core.core checkout_package(): simplify the check in if the package
exists, by using show_package_meta() instead of meta_exists
Let it throw an exception, instead of using sys.exit().
........
r3841 | Marcus_H | 2008-04-27 15:48:06 +0200 (Sun, 27 Apr 2008) | 5 lines
- added 2 new exception classes: PackageError() and PackageExistsError. The PackageError() class is meant to be the base class for all subsequent package exceptions.
- get rid of 2 sys.exit(1) calls
- make the update() method of the Project() class safer: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- minor fix in delPackage(): use getTransActPath() when printing out the filename
........
r3842 | Marcus_H | 2008-04-27 16:52:55 +0200 (Sun, 27 Apr 2008) | 3 lines
- make the commit() method safe: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- removed another sys.exit(1): raise an exception if a package is missing when doing a commit. For now we use the PackageExistsError() exception but this might change in the future (updated description of PackageExistsError() according to this change)
........
r3848 | poeml | 2008-04-28 12:46:45 +0200 (Mon, 28 Apr 2008) | 3 lines
rename several error classes, dropping the "Osc" prefix, and "Error" suffix in
cases where they don't really make sense.
........
r3849 | poeml | 2008-04-28 12:57:32 +0200 (Mon, 28 Apr 2008) | 3 lines
- rename osc.errors module to osc.oscerr, to make it easier to import it from
other programs and have a crystal clear namespace
........
r3850 | poeml | 2008-04-28 13:26:12 +0200 (Mon, 28 Apr 2008) | 2 lines
split PackageExists exception class into PackageExists and PackageMissing
........
2008-04-28 18:37:44 +02:00
|
|
|
for the config file (e.g. { 'user' : 'username', 'pass' : 'password' } ).
|
2008-08-07 18:40:55 +02:00
|
|
|
custom_template is an optional configuration template.
|
Merged revisions 3774-3775,3779,3781-3782,3787,3789-3793,3798,3802,3805,3817-3822,3827,3829-3830,3837-3839,3841-3842,3848-3850 via svnmerge from
https://forgesvn1.novell.com/svn/opensuse/branches/buildservice/osc-exception-handling
........
r3774 | poeml | 2008-04-22 17:39:45 +0200 (Tue, 22 Apr 2008) | 3 lines
A first draft on implement systematic exception handling:
Add errors.py with some exceptions defined, and babysitter.py to handle them
........
r3775 | poeml | 2008-04-22 22:34:12 +0200 (Tue, 22 Apr 2008) | 9 lines
- new global options:
--debugger jump into the debugger before executing anything
--post-mortem jump into the debugger in case of errors
-t, --traceback print call trace in case of errors
- traceback and post_mortem can also be set in .oscrc.
- catch more errors (HTTPError).
- make config accessible from outside of the Osc instance, by making it a class
attribute
........
r3779 | poeml | 2008-04-23 00:55:49 +0200 (Wed, 23 Apr 2008) | 5 lines
- new global option:
-d, --debug print info useful for debugging
- catch some more errors (HTTPError), with OscHTTPError which isn't very
advanced yet.
........
r3781 | Marcus_H | 2008-04-23 01:02:00 +0200 (Wed, 23 Apr 2008) | 2 lines
- added OscConfigError class (just for testing).
- small change in the signature of the OscBaseError constructor (actually we should get rid of the 'args' tuple because it will be deprecated sooner or later
........
r3782 | Marcus_H | 2008-04-23 02:02:13 +0200 (Wed, 23 Apr 2008) | 2 lines
- access the prg.conf.config dict in a save way - this way we avoid AttributeErrors if the prg.conf.config dict doesn't exist
- in case of an configparser error we have to use the prg.options object directly (this was removed in r3781 by accident)
........
r3787 | poeml | 2008-04-23 09:23:56 +0200 (Wed, 23 Apr 2008) | 4 lines
- remove local exception handling from do_req
- for HTTPError, print details (headers and response) when in debug mode
- catch AttributeError
........
r3789 | poeml | 2008-04-23 16:23:14 +0200 (Wed, 23 Apr 2008) | 4 lines
- errors: add two new classes named OscWrongOptionsError and OscWrongArgsError
- commandline: raise instances of the new errors in a number of places
- commandline: add get_cmd_help() to Osc instance which returns the formatted help of a subcommand
........
r3790 | Marcus_H | 2008-04-23 16:48:28 +0200 (Wed, 23 Apr 2008) | 4 lines
- added 2 new exception classes: OscNoConfigfileError and OscIOError
- added new method write_config() to the conf.py module: This method writes osc's configuration file
- minor cleanups in the conf module
........
r3791 | poeml | 2008-04-23 17:11:07 +0200 (Wed, 23 Apr 2008) | 3 lines
small compatibility fix for r3790: try-except-finally isn't supported in
python-2.4.2, thus do the same as try-except inside a try-finally.
........
r3792 | poeml | 2008-04-23 17:37:53 +0200 (Wed, 23 Apr 2008) | 2 lines
fix up the remaining places regarding handling of errors related to commandline parsing
........
r3793 | poeml | 2008-04-23 17:40:34 +0200 (Wed, 23 Apr 2008) | 3 lines
raise a NoWorkingCopyError in osc.core.store_read_project() in case of an
IOError
........
r3798 | Marcus_H | 2008-04-23 23:55:24 +0200 (Wed, 23 Apr 2008) | 1 line
ported -r3797 from trunk
........
r3802 | Marcus_H | 2008-04-24 11:00:55 +0200 (Thu, 24 Apr 2008) | 1 line
ported -r3801 from trunk
........
r3805 | poeml | 2008-04-24 12:52:30 +0200 (Thu, 24 Apr 2008) | 2 lines
raise OscHTTPError in show_pattern_meta(), replacing local error handling
........
r3817 | poeml | 2008-04-24 20:21:32 +0200 (Thu, 24 Apr 2008) | 9 lines
- remove errors.OscHTTPError again.
it seems simpler to use urllib2.HTTPError instead (and just add a specific
error text message where appropriate, and re-raise)
- for 404s, check out _which_ part was not found
it is very ugly, but may be considered Good for pragmatic reasons
- removed local exception handling and workaround for returned 500's from
delete_package() and delete_project(), thereby getting rid of 4 possible exit
points.
........
r3818 | Marcus_H | 2008-04-24 22:36:17 +0200 (Thu, 24 Apr 2008) | 1 line
- this check is superfluous because every HTTPError instance has a code attribute
........
r3819 | poeml | 2008-04-25 00:39:39 +0200 (Fri, 25 Apr 2008) | 1 line
remove a forgotten debug line from core.delete_project()
........
r3820 | poeml | 2008-04-25 10:07:58 +0200 (Fri, 25 Apr 2008) | 2 lines
- ditch local error handling from wipebinaries(), rebuild(), and abortbuild()
........
r3821 | poeml | 2008-04-25 10:56:38 +0200 (Fri, 25 Apr 2008) | 2 lines
It is never needed to import the exception module.
........
r3822 | poeml | 2008-04-25 11:13:39 +0200 (Fri, 25 Apr 2008) | 4 lines
- when going into the debugger with --post-mortem, always print a traceback before
(thus implying -t)
- do not jump into the debugger if not on a TTY, or working in interactive mode
........
r3827 | poeml | 2008-04-25 13:07:46 +0200 (Fri, 25 Apr 2008) | 9 lines
- add errors.OscWorkingCopyOutdated, which takes a tuple with three args:
path to working copy, current rev, expected rev
- add handler for urllib2.URLError errors to the babysitter
- simplify the OscWrongArgsError and OscWrongOptionsError handlers, by removing
the extra line "Sorry, wrong ..." that was printed before the messages given
when the error was raised.
- remove one more errors.OscHTTPError which was still there, and raise
urllib2.HTTPError instead (show_package_meta())
........
r3829 | poeml | 2008-04-25 14:19:10 +0200 (Fri, 25 Apr 2008) | 11 lines
- comment some methods in osc.core which are used by nearly all do_* methods in
osc.commandline
- improve "is not a package/project dir" error messages, by printing the
absolute path tried, instead of '.' for the cwd
- make core.store_read_package() raise a proper NoWorkingCopyError instead of
terminating
- give attribution to things in babysitter.py copied from mercurial
- prefix HTTPError exceptions with 'Server returned an error:'
- remove obsolete local error handling from do_prjresults(), do_importsrcpkg(),
do_repos()
........
r3830 | poeml | 2008-04-25 14:29:35 +0200 (Fri, 25 Apr 2008) | 1 line
catch IOError exceptions in the babysitter
........
r3837 | poeml | 2008-04-25 17:27:36 +0200 (Fri, 25 Apr 2008) | 5 lines
- do_remotebuildlog: raise errors for wrong arguments, remove exits
- raise AttributeError in make_meta_url() instead of exiting
- delete unused method core.delete_server_files()
- replace exit call inside make_meta_url() with an AttributeError
........
r3838 | poeml | 2008-04-25 17:49:18 +0200 (Fri, 25 Apr 2008) | 1 line
simplify the check in do_checkout if a project exists, by using show_project_meta() instead of meta_exists
........
r3839 | poeml | 2008-04-25 18:31:26 +0200 (Fri, 25 Apr 2008) | 6 lines
- commandline do_checkout(): change the order of the two checks, first do the
(cheaper) check for existing directory
- core.core checkout_package(): simplify the check in if the package
exists, by using show_package_meta() instead of meta_exists
Let it throw an exception, instead of using sys.exit().
........
r3841 | Marcus_H | 2008-04-27 15:48:06 +0200 (Sun, 27 Apr 2008) | 5 lines
- added 2 new exception classes: PackageError() and PackageExistsError. The PackageError() class is meant to be the base class for all subsequent package exceptions.
- get rid of 2 sys.exit(1) calls
- make the update() method of the Project() class safer: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- minor fix in delPackage(): use getTransActPath() when printing out the filename
........
r3842 | Marcus_H | 2008-04-27 16:52:55 +0200 (Sun, 27 Apr 2008) | 3 lines
- make the commit() method safe: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- removed another sys.exit(1): raise an exception if a package is missing when doing a commit. For now we use the PackageExistsError() exception but this might change in the future (updated description of PackageExistsError() according to this change)
........
r3848 | poeml | 2008-04-28 12:46:45 +0200 (Mon, 28 Apr 2008) | 3 lines
rename several error classes, dropping the "Osc" prefix, and "Error" suffix in
cases where they don't really make sense.
........
r3849 | poeml | 2008-04-28 12:57:32 +0200 (Mon, 28 Apr 2008) | 3 lines
- rename osc.errors module to osc.oscerr, to make it easier to import it from
other programs and have a crystal clear namespace
........
r3850 | poeml | 2008-04-28 13:26:12 +0200 (Mon, 28 Apr 2008) | 2 lines
split PackageExists exception class into PackageExists and PackageMissing
........
2008-04-28 18:37:44 +02:00
|
|
|
"""
|
|
|
|
conf_template = custom_template or new_conf_template
|
|
|
|
config = DEFAULTS.copy()
|
|
|
|
config.update(entries)
|
2013-04-09 12:36:42 +02:00
|
|
|
sio = StringIO(conf_template.strip() % config)
|
2008-08-07 18:40:55 +02:00
|
|
|
cp = OscConfigParser.OscConfigParser(DEFAULTS)
|
|
|
|
cp.readfp(sio)
|
2019-08-27 15:08:38 +02:00
|
|
|
cp.set(config['apiurl'], 'user', config['user'])
|
|
|
|
if creds_mgr_descriptor:
|
|
|
|
creds_mgr = creds_mgr_descriptor.create(cp)
|
|
|
|
else:
|
|
|
|
creds_mgr = _get_credentials_manager(config['apiurl'], cp)
|
|
|
|
creds_mgr.set_password(config['apiurl'], config['user'], config['pass'])
|
2011-11-18 22:27:38 +01:00
|
|
|
write_config(conffile, cp)
|
2011-08-17 15:33:56 +02:00
|
|
|
|
Merged revisions 3774-3775,3779,3781-3782,3787,3789-3793,3798,3802,3805,3817-3822,3827,3829-3830,3837-3839,3841-3842,3848-3850 via svnmerge from
https://forgesvn1.novell.com/svn/opensuse/branches/buildservice/osc-exception-handling
........
r3774 | poeml | 2008-04-22 17:39:45 +0200 (Tue, 22 Apr 2008) | 3 lines
A first draft on implement systematic exception handling:
Add errors.py with some exceptions defined, and babysitter.py to handle them
........
r3775 | poeml | 2008-04-22 22:34:12 +0200 (Tue, 22 Apr 2008) | 9 lines
- new global options:
--debugger jump into the debugger before executing anything
--post-mortem jump into the debugger in case of errors
-t, --traceback print call trace in case of errors
- traceback and post_mortem can also be set in .oscrc.
- catch more errors (HTTPError).
- make config accessible from outside of the Osc instance, by making it a class
attribute
........
r3779 | poeml | 2008-04-23 00:55:49 +0200 (Wed, 23 Apr 2008) | 5 lines
- new global option:
-d, --debug print info useful for debugging
- catch some more errors (HTTPError), with OscHTTPError which isn't very
advanced yet.
........
r3781 | Marcus_H | 2008-04-23 01:02:00 +0200 (Wed, 23 Apr 2008) | 2 lines
- added OscConfigError class (just for testing).
- small change in the signature of the OscBaseError constructor (actually we should get rid of the 'args' tuple because it will be deprecated sooner or later
........
r3782 | Marcus_H | 2008-04-23 02:02:13 +0200 (Wed, 23 Apr 2008) | 2 lines
- access the prg.conf.config dict in a save way - this way we avoid AttributeErrors if the prg.conf.config dict doesn't exist
- in case of an configparser error we have to use the prg.options object directly (this was removed in r3781 by accident)
........
r3787 | poeml | 2008-04-23 09:23:56 +0200 (Wed, 23 Apr 2008) | 4 lines
- remove local exception handling from do_req
- for HTTPError, print details (headers and response) when in debug mode
- catch AttributeError
........
r3789 | poeml | 2008-04-23 16:23:14 +0200 (Wed, 23 Apr 2008) | 4 lines
- errors: add two new classes named OscWrongOptionsError and OscWrongArgsError
- commandline: raise instances of the new errors in a number of places
- commandline: add get_cmd_help() to Osc instance which returns the formatted help of a subcommand
........
r3790 | Marcus_H | 2008-04-23 16:48:28 +0200 (Wed, 23 Apr 2008) | 4 lines
- added 2 new exception classes: OscNoConfigfileError and OscIOError
- added new method write_config() to the conf.py module: This method writes osc's configuration file
- minor cleanups in the conf module
........
r3791 | poeml | 2008-04-23 17:11:07 +0200 (Wed, 23 Apr 2008) | 3 lines
small compatibility fix for r3790: try-except-finally isn't supported in
python-2.4.2, thus do the same as try-except inside a try-finally.
........
r3792 | poeml | 2008-04-23 17:37:53 +0200 (Wed, 23 Apr 2008) | 2 lines
fix up the remaining places regarding handling of errors related to commandline parsing
........
r3793 | poeml | 2008-04-23 17:40:34 +0200 (Wed, 23 Apr 2008) | 3 lines
raise a NoWorkingCopyError in osc.core.store_read_project() in case of an
IOError
........
r3798 | Marcus_H | 2008-04-23 23:55:24 +0200 (Wed, 23 Apr 2008) | 1 line
ported -r3797 from trunk
........
r3802 | Marcus_H | 2008-04-24 11:00:55 +0200 (Thu, 24 Apr 2008) | 1 line
ported -r3801 from trunk
........
r3805 | poeml | 2008-04-24 12:52:30 +0200 (Thu, 24 Apr 2008) | 2 lines
raise OscHTTPError in show_pattern_meta(), replacing local error handling
........
r3817 | poeml | 2008-04-24 20:21:32 +0200 (Thu, 24 Apr 2008) | 9 lines
- remove errors.OscHTTPError again.
it seems simpler to use urllib2.HTTPError instead (and just add a specific
error text message where appropriate, and re-raise)
- for 404s, check out _which_ part was not found
it is very ugly, but may be considered Good for pragmatic reasons
- removed local exception handling and workaround for returned 500's from
delete_package() and delete_project(), thereby getting rid of 4 possible exit
points.
........
r3818 | Marcus_H | 2008-04-24 22:36:17 +0200 (Thu, 24 Apr 2008) | 1 line
- this check is superfluous because every HTTPError instance has a code attribute
........
r3819 | poeml | 2008-04-25 00:39:39 +0200 (Fri, 25 Apr 2008) | 1 line
remove a forgotten debug line from core.delete_project()
........
r3820 | poeml | 2008-04-25 10:07:58 +0200 (Fri, 25 Apr 2008) | 2 lines
- ditch local error handling from wipebinaries(), rebuild(), and abortbuild()
........
r3821 | poeml | 2008-04-25 10:56:38 +0200 (Fri, 25 Apr 2008) | 2 lines
It is never needed to import the exception module.
........
r3822 | poeml | 2008-04-25 11:13:39 +0200 (Fri, 25 Apr 2008) | 4 lines
- when going into the debugger with --post-mortem, always print a traceback before
(thus implying -t)
- do not jump into the debugger if not on a TTY, or working in interactive mode
........
r3827 | poeml | 2008-04-25 13:07:46 +0200 (Fri, 25 Apr 2008) | 9 lines
- add errors.OscWorkingCopyOutdated, which takes a tuple with three args:
path to working copy, current rev, expected rev
- add handler for urllib2.URLError errors to the babysitter
- simplify the OscWrongArgsError and OscWrongOptionsError handlers, by removing
the extra line "Sorry, wrong ..." that was printed before the messages given
when the error was raised.
- remove one more errors.OscHTTPError which was still there, and raise
urllib2.HTTPError instead (show_package_meta())
........
r3829 | poeml | 2008-04-25 14:19:10 +0200 (Fri, 25 Apr 2008) | 11 lines
- comment some methods in osc.core which are used by nearly all do_* methods in
osc.commandline
- improve "is not a package/project dir" error messages, by printing the
absolute path tried, instead of '.' for the cwd
- make core.store_read_package() raise a proper NoWorkingCopyError instead of
terminating
- give attribution to things in babysitter.py copied from mercurial
- prefix HTTPError exceptions with 'Server returned an error:'
- remove obsolete local error handling from do_prjresults(), do_importsrcpkg(),
do_repos()
........
r3830 | poeml | 2008-04-25 14:29:35 +0200 (Fri, 25 Apr 2008) | 1 line
catch IOError exceptions in the babysitter
........
r3837 | poeml | 2008-04-25 17:27:36 +0200 (Fri, 25 Apr 2008) | 5 lines
- do_remotebuildlog: raise errors for wrong arguments, remove exits
- raise AttributeError in make_meta_url() instead of exiting
- delete unused method core.delete_server_files()
- replace exit call inside make_meta_url() with an AttributeError
........
r3838 | poeml | 2008-04-25 17:49:18 +0200 (Fri, 25 Apr 2008) | 1 line
simplify the check in do_checkout if a project exists, by using show_project_meta() instead of meta_exists
........
r3839 | poeml | 2008-04-25 18:31:26 +0200 (Fri, 25 Apr 2008) | 6 lines
- commandline do_checkout(): change the order of the two checks, first do the
(cheaper) check for existing directory
- core.core checkout_package(): simplify the check in if the package
exists, by using show_package_meta() instead of meta_exists
Let it throw an exception, instead of using sys.exit().
........
r3841 | Marcus_H | 2008-04-27 15:48:06 +0200 (Sun, 27 Apr 2008) | 5 lines
- added 2 new exception classes: PackageError() and PackageExistsError. The PackageError() class is meant to be the base class for all subsequent package exceptions.
- get rid of 2 sys.exit(1) calls
- make the update() method of the Project() class safer: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- minor fix in delPackage(): use getTransActPath() when printing out the filename
........
r3842 | Marcus_H | 2008-04-27 16:52:55 +0200 (Sun, 27 Apr 2008) | 3 lines
- make the commit() method safe: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- removed another sys.exit(1): raise an exception if a package is missing when doing a commit. For now we use the PackageExistsError() exception but this might change in the future (updated description of PackageExistsError() according to this change)
........
r3848 | poeml | 2008-04-28 12:46:45 +0200 (Mon, 28 Apr 2008) | 3 lines
rename several error classes, dropping the "Osc" prefix, and "Error" suffix in
cases where they don't really make sense.
........
r3849 | poeml | 2008-04-28 12:57:32 +0200 (Mon, 28 Apr 2008) | 3 lines
- rename osc.errors module to osc.oscerr, to make it easier to import it from
other programs and have a crystal clear namespace
........
r3850 | poeml | 2008-04-28 13:26:12 +0200 (Mon, 28 Apr 2008) | 2 lines
split PackageExists exception class into PackageExists and PackageMissing
........
2008-04-28 18:37:44 +02:00
|
|
|
|
2019-08-27 15:08:38 +02:00
|
|
|
def add_section(filename, url, user, passwd, creds_mgr_descriptor=None):
|
2009-05-11 09:46:01 +02:00
|
|
|
"""
|
|
|
|
Add a section to config file for new api url.
|
|
|
|
"""
|
|
|
|
global config
|
|
|
|
cp = get_configParser(filename)
|
|
|
|
try:
|
|
|
|
cp.add_section(url)
|
correctly refer to exception
this is left-over from 87d354e1a013806ef37f11e22f015e5cc43e533d
Addressing:
Traceback (most recent call last):
File "/usr/bin/osc", line 26, in <module>
r = babysitter.run(osccli)
File "/usr/lib/python2.7/site-packages/osc/babysitter.py", line 60, in run
return prg.main()
File "/usr/lib/python2.7/site-packages/osc/cmdln.py", line 335, in main
self.postoptparse()
File "/usr/lib/python2.7/site-packages/osc/commandline.py", line 136, in postoptparse
override_verbose = self.options.verbose)
File "/usr/lib/python2.7/site-packages/osc/conf.py", line 873, in get_config
add_section(conffile, url, user, passwordx)
File "/usr/lib/python2.7/site-packages/osc/conf.py", line 712, in add_section
except OscConfigParser.ConfigParser.DuplicateSectionError:
AttributeError: class OscConfigParser has no attribute 'ConfigParser'
2013-07-17 10:18:10 +02:00
|
|
|
except OscConfigParser.configparser.DuplicateSectionError:
|
2009-05-11 09:46:01 +02:00
|
|
|
# Section might have existed, but was empty
|
|
|
|
pass
|
2019-08-27 15:08:38 +02:00
|
|
|
cp.set(url, 'user', user)
|
|
|
|
if creds_mgr_descriptor:
|
|
|
|
creds_mgr = creds_mgr_descriptor.create(cp)
|
2009-05-11 09:46:01 +02:00
|
|
|
else:
|
2019-08-27 15:08:38 +02:00
|
|
|
creds_mgr = _get_credentials_manager(url, cp)
|
|
|
|
creds_mgr.set_password(url, user, passwd)
|
2011-11-18 22:27:38 +01:00
|
|
|
write_config(filename, cp)
|
2011-08-17 15:33:56 +02:00
|
|
|
|
|
|
|
|
2019-08-27 15:08:38 +02:00
|
|
|
def _get_credentials_manager(url, cp):
|
|
|
|
if cp.has_option(url, credentials.AbstractCredentialsManager.config_entry):
|
2019-10-16 10:41:06 +02:00
|
|
|
creds_mgr = credentials.create_credentials_manager(url, cp)
|
|
|
|
if creds_mgr is None:
|
|
|
|
msg = 'Unable to instantiate creds mgr (section: %s)' % url
|
|
|
|
conffile = get_configParser.conffile
|
|
|
|
raise oscerr.ConfigMissingCredentialsError(msg, conffile, url)
|
|
|
|
return creds_mgr
|
2019-08-27 15:08:38 +02:00
|
|
|
if config['use_keyring'] and GENERIC_KEYRING:
|
|
|
|
return credentials.get_keyring_credentials_manager(cp)
|
|
|
|
elif config['gnome_keyring'] and GNOME_KEYRING:
|
|
|
|
protocol, host, path = parse_apisrv_url(None, url)
|
|
|
|
return credentials.GnomeKeyringCredentialsManager(cp, None)
|
|
|
|
elif cp.get(url, 'passx') is not None:
|
|
|
|
return credentials.ObfuscatedConfigFileCredentialsManager(cp, None)
|
|
|
|
return credentials.PlaintextConfigFileCredentialsManager(cp, None)
|
|
|
|
|
2019-08-27 16:26:20 +02:00
|
|
|
|
|
|
|
class APIHostOptionsEntry(dict):
|
|
|
|
def __getitem__(self, key, *args, **kwargs):
|
|
|
|
value = super(self.__class__, self).__getitem__(key, *args, **kwargs)
|
|
|
|
if key == 'pass' and callable(value):
|
|
|
|
value = value()
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
2011-08-17 15:33:56 +02:00
|
|
|
def get_config(override_conffile=None,
|
|
|
|
override_apiurl=None,
|
|
|
|
override_debug=None,
|
|
|
|
override_http_debug=None,
|
|
|
|
override_http_full_debug=None,
|
|
|
|
override_traceback=None,
|
|
|
|
override_post_mortem=None,
|
|
|
|
override_no_keyring=None,
|
|
|
|
override_no_gnome_keyring=None,
|
|
|
|
override_verbose=None):
|
2006-10-10 16:04:34 +02:00
|
|
|
"""do the actual work (see module documentation)"""
|
|
|
|
global config
|
|
|
|
|
2017-10-27 11:29:00 +02:00
|
|
|
if not override_conffile:
|
|
|
|
conffile = identify_conf()
|
|
|
|
else:
|
|
|
|
conffile = override_conffile
|
2006-10-10 16:04:34 +02:00
|
|
|
|
2017-10-27 11:29:00 +02:00
|
|
|
conffile = os.path.expanduser(conffile)
|
2006-10-10 16:04:34 +02:00
|
|
|
if not os.path.exists(conffile):
|
2008-08-07 18:40:55 +02:00
|
|
|
raise oscerr.NoConfigfile(conffile, \
|
|
|
|
account_not_configured_text % conffile)
|
2006-10-10 16:04:34 +02:00
|
|
|
|
2017-10-27 11:29:00 +02:00
|
|
|
# okay, we made sure that oscrc exists
|
2006-10-10 16:04:34 +02:00
|
|
|
|
2009-08-20 21:28:05 +02:00
|
|
|
# make sure it is not world readable, it may contain a password.
|
2021-10-21 02:44:20 +02:00
|
|
|
conffile_stat = os.stat(conffile)
|
|
|
|
if conffile_stat.st_mode != 0o600:
|
|
|
|
try:
|
|
|
|
os.chmod(conffile, 0o600)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno == errno.EROFS:
|
|
|
|
print('Warning: file \'%s\' may have an insecure mode.', conffile)
|
|
|
|
else:
|
|
|
|
raise e
|
2009-08-20 21:28:05 +02:00
|
|
|
|
2008-03-15 23:51:37 +01:00
|
|
|
cp = get_configParser(conffile)
|
2006-10-10 16:04:34 +02:00
|
|
|
|
|
|
|
if not cp.has_section('general'):
|
|
|
|
# FIXME: it might be sufficient to just assume defaults?
|
Merged revisions 3774-3775,3779,3781-3782,3787,3789-3793,3798,3802,3805,3817-3822,3827,3829-3830,3837-3839,3841-3842,3848-3850 via svnmerge from
https://forgesvn1.novell.com/svn/opensuse/branches/buildservice/osc-exception-handling
........
r3774 | poeml | 2008-04-22 17:39:45 +0200 (Tue, 22 Apr 2008) | 3 lines
A first draft on implement systematic exception handling:
Add errors.py with some exceptions defined, and babysitter.py to handle them
........
r3775 | poeml | 2008-04-22 22:34:12 +0200 (Tue, 22 Apr 2008) | 9 lines
- new global options:
--debugger jump into the debugger before executing anything
--post-mortem jump into the debugger in case of errors
-t, --traceback print call trace in case of errors
- traceback and post_mortem can also be set in .oscrc.
- catch more errors (HTTPError).
- make config accessible from outside of the Osc instance, by making it a class
attribute
........
r3779 | poeml | 2008-04-23 00:55:49 +0200 (Wed, 23 Apr 2008) | 5 lines
- new global option:
-d, --debug print info useful for debugging
- catch some more errors (HTTPError), with OscHTTPError which isn't very
advanced yet.
........
r3781 | Marcus_H | 2008-04-23 01:02:00 +0200 (Wed, 23 Apr 2008) | 2 lines
- added OscConfigError class (just for testing).
- small change in the signature of the OscBaseError constructor (actually we should get rid of the 'args' tuple because it will be deprecated sooner or later
........
r3782 | Marcus_H | 2008-04-23 02:02:13 +0200 (Wed, 23 Apr 2008) | 2 lines
- access the prg.conf.config dict in a save way - this way we avoid AttributeErrors if the prg.conf.config dict doesn't exist
- in case of an configparser error we have to use the prg.options object directly (this was removed in r3781 by accident)
........
r3787 | poeml | 2008-04-23 09:23:56 +0200 (Wed, 23 Apr 2008) | 4 lines
- remove local exception handling from do_req
- for HTTPError, print details (headers and response) when in debug mode
- catch AttributeError
........
r3789 | poeml | 2008-04-23 16:23:14 +0200 (Wed, 23 Apr 2008) | 4 lines
- errors: add two new classes named OscWrongOptionsError and OscWrongArgsError
- commandline: raise instances of the new errors in a number of places
- commandline: add get_cmd_help() to Osc instance which returns the formatted help of a subcommand
........
r3790 | Marcus_H | 2008-04-23 16:48:28 +0200 (Wed, 23 Apr 2008) | 4 lines
- added 2 new exception classes: OscNoConfigfileError and OscIOError
- added new method write_config() to the conf.py module: This method writes osc's configuration file
- minor cleanups in the conf module
........
r3791 | poeml | 2008-04-23 17:11:07 +0200 (Wed, 23 Apr 2008) | 3 lines
small compatibility fix for r3790: try-except-finally isn't supported in
python-2.4.2, thus do the same as try-except inside a try-finally.
........
r3792 | poeml | 2008-04-23 17:37:53 +0200 (Wed, 23 Apr 2008) | 2 lines
fix up the remaining places regarding handling of errors related to commandline parsing
........
r3793 | poeml | 2008-04-23 17:40:34 +0200 (Wed, 23 Apr 2008) | 3 lines
raise a NoWorkingCopyError in osc.core.store_read_project() in case of an
IOError
........
r3798 | Marcus_H | 2008-04-23 23:55:24 +0200 (Wed, 23 Apr 2008) | 1 line
ported -r3797 from trunk
........
r3802 | Marcus_H | 2008-04-24 11:00:55 +0200 (Thu, 24 Apr 2008) | 1 line
ported -r3801 from trunk
........
r3805 | poeml | 2008-04-24 12:52:30 +0200 (Thu, 24 Apr 2008) | 2 lines
raise OscHTTPError in show_pattern_meta(), replacing local error handling
........
r3817 | poeml | 2008-04-24 20:21:32 +0200 (Thu, 24 Apr 2008) | 9 lines
- remove errors.OscHTTPError again.
it seems simpler to use urllib2.HTTPError instead (and just add a specific
error text message where appropriate, and re-raise)
- for 404s, check out _which_ part was not found
it is very ugly, but may be considered Good for pragmatic reasons
- removed local exception handling and workaround for returned 500's from
delete_package() and delete_project(), thereby getting rid of 4 possible exit
points.
........
r3818 | Marcus_H | 2008-04-24 22:36:17 +0200 (Thu, 24 Apr 2008) | 1 line
- this check is superfluous because every HTTPError instance has a code attribute
........
r3819 | poeml | 2008-04-25 00:39:39 +0200 (Fri, 25 Apr 2008) | 1 line
remove a forgotten debug line from core.delete_project()
........
r3820 | poeml | 2008-04-25 10:07:58 +0200 (Fri, 25 Apr 2008) | 2 lines
- ditch local error handling from wipebinaries(), rebuild(), and abortbuild()
........
r3821 | poeml | 2008-04-25 10:56:38 +0200 (Fri, 25 Apr 2008) | 2 lines
It is never needed to import the exception module.
........
r3822 | poeml | 2008-04-25 11:13:39 +0200 (Fri, 25 Apr 2008) | 4 lines
- when going into the debugger with --post-mortem, always print a traceback before
(thus implying -t)
- do not jump into the debugger if not on a TTY, or working in interactive mode
........
r3827 | poeml | 2008-04-25 13:07:46 +0200 (Fri, 25 Apr 2008) | 9 lines
- add errors.OscWorkingCopyOutdated, which takes a tuple with three args:
path to working copy, current rev, expected rev
- add handler for urllib2.URLError errors to the babysitter
- simplify the OscWrongArgsError and OscWrongOptionsError handlers, by removing
the extra line "Sorry, wrong ..." that was printed before the messages given
when the error was raised.
- remove one more errors.OscHTTPError which was still there, and raise
urllib2.HTTPError instead (show_package_meta())
........
r3829 | poeml | 2008-04-25 14:19:10 +0200 (Fri, 25 Apr 2008) | 11 lines
- comment some methods in osc.core which are used by nearly all do_* methods in
osc.commandline
- improve "is not a package/project dir" error messages, by printing the
absolute path tried, instead of '.' for the cwd
- make core.store_read_package() raise a proper NoWorkingCopyError instead of
terminating
- give attribution to things in babysitter.py copied from mercurial
- prefix HTTPError exceptions with 'Server returned an error:'
- remove obsolete local error handling from do_prjresults(), do_importsrcpkg(),
do_repos()
........
r3830 | poeml | 2008-04-25 14:29:35 +0200 (Fri, 25 Apr 2008) | 1 line
catch IOError exceptions in the babysitter
........
r3837 | poeml | 2008-04-25 17:27:36 +0200 (Fri, 25 Apr 2008) | 5 lines
- do_remotebuildlog: raise errors for wrong arguments, remove exits
- raise AttributeError in make_meta_url() instead of exiting
- delete unused method core.delete_server_files()
- replace exit call inside make_meta_url() with an AttributeError
........
r3838 | poeml | 2008-04-25 17:49:18 +0200 (Fri, 25 Apr 2008) | 1 line
simplify the check in do_checkout if a project exists, by using show_project_meta() instead of meta_exists
........
r3839 | poeml | 2008-04-25 18:31:26 +0200 (Fri, 25 Apr 2008) | 6 lines
- commandline do_checkout(): change the order of the two checks, first do the
(cheaper) check for existing directory
- core.core checkout_package(): simplify the check in if the package
exists, by using show_package_meta() instead of meta_exists
Let it throw an exception, instead of using sys.exit().
........
r3841 | Marcus_H | 2008-04-27 15:48:06 +0200 (Sun, 27 Apr 2008) | 5 lines
- added 2 new exception classes: PackageError() and PackageExistsError. The PackageError() class is meant to be the base class for all subsequent package exceptions.
- get rid of 2 sys.exit(1) calls
- make the update() method of the Project() class safer: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- minor fix in delPackage(): use getTransActPath() when printing out the filename
........
r3842 | Marcus_H | 2008-04-27 16:52:55 +0200 (Sun, 27 Apr 2008) | 3 lines
- make the commit() method safe: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- removed another sys.exit(1): raise an exception if a package is missing when doing a commit. For now we use the PackageExistsError() exception but this might change in the future (updated description of PackageExistsError() according to this change)
........
r3848 | poeml | 2008-04-28 12:46:45 +0200 (Mon, 28 Apr 2008) | 3 lines
rename several error classes, dropping the "Osc" prefix, and "Error" suffix in
cases where they don't really make sense.
........
r3849 | poeml | 2008-04-28 12:57:32 +0200 (Mon, 28 Apr 2008) | 3 lines
- rename osc.errors module to osc.oscerr, to make it easier to import it from
other programs and have a crystal clear namespace
........
r3850 | poeml | 2008-04-28 13:26:12 +0200 (Mon, 28 Apr 2008) | 2 lines
split PackageExists exception class into PackageExists and PackageMissing
........
2008-04-28 18:37:44 +02:00
|
|
|
msg = config_incomplete_text % conffile
|
|
|
|
msg += new_conf_template % DEFAULTS
|
2008-08-07 19:14:26 +02:00
|
|
|
raise oscerr.ConfigError(msg, conffile)
|
2006-10-10 16:04:34 +02:00
|
|
|
|
|
|
|
config = dict(cp.items('general', raw=1))
|
2010-03-07 22:50:11 +01:00
|
|
|
config['conffile'] = conffile
|
2007-04-25 12:24:51 +02:00
|
|
|
|
2018-01-23 12:28:55 +01:00
|
|
|
typed_opts = ((boolean_opts, cp.getboolean), (integer_opts, cp.getint))
|
|
|
|
for opts, meth in typed_opts:
|
|
|
|
for opt in opts:
|
|
|
|
try:
|
|
|
|
config[opt] = meth('general', opt)
|
|
|
|
except ValueError as e:
|
|
|
|
msg = 'cannot parse \'%s\' setting: %s' % (opt, str(e))
|
|
|
|
raise oscerr.ConfigError(msg, conffile)
|
2007-04-25 01:00:12 +02:00
|
|
|
|
2008-07-12 14:06:23 +02:00
|
|
|
config['packagecachedir'] = os.path.expanduser(config['packagecachedir'])
|
2009-08-21 21:39:12 +02:00
|
|
|
config['exclude_glob'] = config['exclude_glob'].split()
|
2008-07-12 14:06:23 +02:00
|
|
|
|
2008-07-18 14:08:03 +02:00
|
|
|
re_clist = re.compile('[, ]+')
|
2011-08-17 15:33:56 +02:00
|
|
|
config['extra-pkgs'] = [i.strip() for i in re_clist.split(config['extra-pkgs'].strip()) if i]
|
2007-07-24 12:46:03 +02:00
|
|
|
|
2008-08-20 16:07:11 +02:00
|
|
|
# collect the usernames, passwords and additional options for each api host
|
2009-02-24 00:29:32 +01:00
|
|
|
api_host_options = {}
|
2008-08-20 16:07:11 +02:00
|
|
|
|
|
|
|
# Regexp to split extra http headers into a dictionary
|
|
|
|
# the text to be matched looks essentially looks this:
|
|
|
|
# "Attribute1: value1, Attribute2: value2, ..."
|
|
|
|
# there may be arbitray leading and intermitting whitespace.
|
|
|
|
# the following regexp does _not_ support quoted commas within the value.
|
|
|
|
http_header_regexp = re.compile(r"\s*(.*?)\s*:\s*(.*?)\s*(?:,\s*|\Z)")
|
|
|
|
|
2009-05-11 09:46:01 +02:00
|
|
|
# override values which we were called with
|
|
|
|
# This needs to be done before processing API sections as it might be already used there
|
2009-09-04 19:48:53 +02:00
|
|
|
if override_no_keyring:
|
|
|
|
config['use_keyring'] = False
|
2009-08-20 21:28:05 +02:00
|
|
|
if override_no_gnome_keyring:
|
2009-05-11 09:46:01 +02:00
|
|
|
config['gnome_keyring'] = False
|
|
|
|
|
2009-02-24 22:35:59 +01:00
|
|
|
aliases = {}
|
2011-08-17 15:33:56 +02:00
|
|
|
for url in [x for x in cp.sections() if x != 'general']:
|
2009-02-24 00:29:32 +01:00
|
|
|
# backward compatiblity
|
2013-10-26 01:15:18 +02:00
|
|
|
scheme, host, path = parse_apisrv_url(config.get('scheme', 'https'), url)
|
|
|
|
apiurl = urljoin(scheme, host, path)
|
2019-08-27 15:08:38 +02:00
|
|
|
creds_mgr = _get_credentials_manager(url, cp)
|
2019-08-29 14:27:30 +02:00
|
|
|
# if the deprecated gnomekeyring is used we should use the apiurl instead of url
|
|
|
|
# (that's what the old code did), but this makes things more complex
|
|
|
|
# (also, it is very unlikely that url and apiurl differ)
|
|
|
|
user = _extract_user_compat(cp, url, creds_mgr)
|
2009-05-11 09:46:01 +02:00
|
|
|
if user is None:
|
2019-08-29 11:35:34 +02:00
|
|
|
raise oscerr.ConfigMissingCredentialsError('No user found in section %s' % url, conffile, url)
|
2019-08-27 15:08:38 +02:00
|
|
|
password = creds_mgr.get_password(url, user)
|
|
|
|
if password is None:
|
2019-08-29 11:35:34 +02:00
|
|
|
raise oscerr.ConfigMissingCredentialsError('No password found in section %s' % url, conffile, url)
|
2010-12-18 02:17:40 +01:00
|
|
|
|
2008-08-20 16:07:11 +02:00
|
|
|
if cp.has_option(url, 'http_headers'):
|
|
|
|
http_headers = cp.get(url, 'http_headers')
|
|
|
|
http_headers = http_header_regexp.findall(http_headers)
|
|
|
|
else:
|
|
|
|
http_headers = []
|
2009-02-24 22:35:59 +01:00
|
|
|
if cp.has_option(url, 'aliases'):
|
|
|
|
for i in cp.get(url, 'aliases').split(','):
|
|
|
|
key = i.strip()
|
|
|
|
if key == '':
|
|
|
|
continue
|
2011-08-17 15:33:56 +02:00
|
|
|
if key in aliases:
|
2009-02-24 22:35:59 +01:00
|
|
|
msg = 'duplicate alias entry: \'%s\' is already used for another apiurl' % key
|
|
|
|
raise oscerr.ConfigError(msg, conffile)
|
|
|
|
aliases[key] = url
|
2008-08-20 16:07:11 +02:00
|
|
|
|
2019-08-27 16:26:20 +02:00
|
|
|
entry = {'user': user,
|
|
|
|
'pass': password,
|
|
|
|
'http_headers': http_headers}
|
|
|
|
api_host_options[apiurl] = APIHostOptionsEntry(entry)
|
2009-10-02 13:25:59 +02:00
|
|
|
|
2018-08-17 22:09:51 +02:00
|
|
|
optional = ('realname', 'email', 'sslcertck', 'cafile', 'capath')
|
2009-10-02 13:25:59 +02:00
|
|
|
for key in optional:
|
|
|
|
if cp.has_option(url, key):
|
2009-10-06 19:10:31 +02:00
|
|
|
if key == 'sslcertck':
|
|
|
|
api_host_options[apiurl][key] = cp.getboolean(url, key)
|
|
|
|
else:
|
|
|
|
api_host_options[apiurl][key] = cp.get(url, key)
|
2014-06-04 15:33:30 +02:00
|
|
|
if cp.has_option(url, 'build-root', proper=True):
|
|
|
|
api_host_options[apiurl]['build-root'] = cp.get(url, 'build-root', raw=True)
|
2009-10-02 13:25:59 +02:00
|
|
|
|
|
|
|
if not 'sslcertck' in api_host_options[apiurl]:
|
2009-10-06 19:10:31 +02:00
|
|
|
api_host_options[apiurl]['sslcertck'] = True
|
2007-04-25 12:24:51 +02:00
|
|
|
|
2010-09-01 12:04:46 +02:00
|
|
|
if scheme == 'http':
|
|
|
|
api_host_options[apiurl]['sslcertck'] = False
|
|
|
|
|
2010-02-24 20:02:52 +01:00
|
|
|
if cp.has_option(url, 'trusted_prj'):
|
2010-06-23 14:40:55 +02:00
|
|
|
api_host_options[apiurl]['trusted_prj'] = cp.get(url, 'trusted_prj').split(' ')
|
2010-02-24 20:02:52 +01:00
|
|
|
else:
|
|
|
|
api_host_options[apiurl]['trusted_prj'] = []
|
2009-11-11 15:48:25 +01:00
|
|
|
|
2006-10-10 16:04:34 +02:00
|
|
|
# add the auth data we collected to the config dict
|
2008-08-20 11:45:49 +02:00
|
|
|
config['api_host_options'] = api_host_options
|
2009-12-15 17:24:25 +01:00
|
|
|
config['apiurl_aliases'] = aliases
|
2008-08-20 11:45:49 +02:00
|
|
|
|
2009-10-16 17:03:12 +02:00
|
|
|
apiurl = aliases.get(config['apiurl'], config['apiurl'])
|
|
|
|
config['apiurl'] = urljoin(*parse_apisrv_url(None, apiurl))
|
|
|
|
# backward compatibility
|
2012-03-08 14:42:52 +01:00
|
|
|
if 'apisrv' in config:
|
2009-10-16 17:03:12 +02:00
|
|
|
apisrv = config['apisrv'].lstrip('http://')
|
|
|
|
apisrv = apisrv.lstrip('https://')
|
|
|
|
scheme = config.get('scheme', 'https')
|
|
|
|
config['apiurl'] = urljoin(scheme, apisrv)
|
2011-08-17 15:33:56 +02:00
|
|
|
if 'apisrc' in config or 'scheme' in config:
|
2017-10-27 11:29:00 +02:00
|
|
|
print('Warning: Use of the \'scheme\' or \'apisrv\' in oscrc is deprecated!\n' \
|
2013-04-09 12:51:28 +02:00
|
|
|
'Warning: See README for migration details.', file=sys.stderr)
|
2011-08-17 15:33:56 +02:00
|
|
|
if 'build_platform' in config:
|
2013-04-09 12:51:28 +02:00
|
|
|
print('Warning: Use of \'build_platform\' config option is deprecated! (use \'build_repository\' instead)', file=sys.stderr)
|
2009-10-16 17:03:12 +02:00
|
|
|
config['build_repository'] = config['build_platform']
|
2019-08-27 10:33:36 +02:00
|
|
|
if config['plaintext_passwd']:
|
|
|
|
print('The \'plaintext_passwd\' option is deprecated and will be ignored', file=sys.stderr)
|
2009-10-16 17:03:12 +02:00
|
|
|
|
2010-03-06 20:14:51 +01:00
|
|
|
config['verbose'] = int(config['verbose'])
|
2007-08-22 12:18:25 +02:00
|
|
|
# override values which we were called with
|
2009-08-20 21:28:05 +02:00
|
|
|
if override_verbose:
|
|
|
|
config['verbose'] = override_verbose + 1
|
|
|
|
|
|
|
|
if override_debug:
|
Merged revisions 3774-3775,3779,3781-3782,3787,3789-3793,3798,3802,3805,3817-3822,3827,3829-3830,3837-3839,3841-3842,3848-3850 via svnmerge from
https://forgesvn1.novell.com/svn/opensuse/branches/buildservice/osc-exception-handling
........
r3774 | poeml | 2008-04-22 17:39:45 +0200 (Tue, 22 Apr 2008) | 3 lines
A first draft on implement systematic exception handling:
Add errors.py with some exceptions defined, and babysitter.py to handle them
........
r3775 | poeml | 2008-04-22 22:34:12 +0200 (Tue, 22 Apr 2008) | 9 lines
- new global options:
--debugger jump into the debugger before executing anything
--post-mortem jump into the debugger in case of errors
-t, --traceback print call trace in case of errors
- traceback and post_mortem can also be set in .oscrc.
- catch more errors (HTTPError).
- make config accessible from outside of the Osc instance, by making it a class
attribute
........
r3779 | poeml | 2008-04-23 00:55:49 +0200 (Wed, 23 Apr 2008) | 5 lines
- new global option:
-d, --debug print info useful for debugging
- catch some more errors (HTTPError), with OscHTTPError which isn't very
advanced yet.
........
r3781 | Marcus_H | 2008-04-23 01:02:00 +0200 (Wed, 23 Apr 2008) | 2 lines
- added OscConfigError class (just for testing).
- small change in the signature of the OscBaseError constructor (actually we should get rid of the 'args' tuple because it will be deprecated sooner or later
........
r3782 | Marcus_H | 2008-04-23 02:02:13 +0200 (Wed, 23 Apr 2008) | 2 lines
- access the prg.conf.config dict in a save way - this way we avoid AttributeErrors if the prg.conf.config dict doesn't exist
- in case of an configparser error we have to use the prg.options object directly (this was removed in r3781 by accident)
........
r3787 | poeml | 2008-04-23 09:23:56 +0200 (Wed, 23 Apr 2008) | 4 lines
- remove local exception handling from do_req
- for HTTPError, print details (headers and response) when in debug mode
- catch AttributeError
........
r3789 | poeml | 2008-04-23 16:23:14 +0200 (Wed, 23 Apr 2008) | 4 lines
- errors: add two new classes named OscWrongOptionsError and OscWrongArgsError
- commandline: raise instances of the new errors in a number of places
- commandline: add get_cmd_help() to Osc instance which returns the formatted help of a subcommand
........
r3790 | Marcus_H | 2008-04-23 16:48:28 +0200 (Wed, 23 Apr 2008) | 4 lines
- added 2 new exception classes: OscNoConfigfileError and OscIOError
- added new method write_config() to the conf.py module: This method writes osc's configuration file
- minor cleanups in the conf module
........
r3791 | poeml | 2008-04-23 17:11:07 +0200 (Wed, 23 Apr 2008) | 3 lines
small compatibility fix for r3790: try-except-finally isn't supported in
python-2.4.2, thus do the same as try-except inside a try-finally.
........
r3792 | poeml | 2008-04-23 17:37:53 +0200 (Wed, 23 Apr 2008) | 2 lines
fix up the remaining places regarding handling of errors related to commandline parsing
........
r3793 | poeml | 2008-04-23 17:40:34 +0200 (Wed, 23 Apr 2008) | 3 lines
raise a NoWorkingCopyError in osc.core.store_read_project() in case of an
IOError
........
r3798 | Marcus_H | 2008-04-23 23:55:24 +0200 (Wed, 23 Apr 2008) | 1 line
ported -r3797 from trunk
........
r3802 | Marcus_H | 2008-04-24 11:00:55 +0200 (Thu, 24 Apr 2008) | 1 line
ported -r3801 from trunk
........
r3805 | poeml | 2008-04-24 12:52:30 +0200 (Thu, 24 Apr 2008) | 2 lines
raise OscHTTPError in show_pattern_meta(), replacing local error handling
........
r3817 | poeml | 2008-04-24 20:21:32 +0200 (Thu, 24 Apr 2008) | 9 lines
- remove errors.OscHTTPError again.
it seems simpler to use urllib2.HTTPError instead (and just add a specific
error text message where appropriate, and re-raise)
- for 404s, check out _which_ part was not found
it is very ugly, but may be considered Good for pragmatic reasons
- removed local exception handling and workaround for returned 500's from
delete_package() and delete_project(), thereby getting rid of 4 possible exit
points.
........
r3818 | Marcus_H | 2008-04-24 22:36:17 +0200 (Thu, 24 Apr 2008) | 1 line
- this check is superfluous because every HTTPError instance has a code attribute
........
r3819 | poeml | 2008-04-25 00:39:39 +0200 (Fri, 25 Apr 2008) | 1 line
remove a forgotten debug line from core.delete_project()
........
r3820 | poeml | 2008-04-25 10:07:58 +0200 (Fri, 25 Apr 2008) | 2 lines
- ditch local error handling from wipebinaries(), rebuild(), and abortbuild()
........
r3821 | poeml | 2008-04-25 10:56:38 +0200 (Fri, 25 Apr 2008) | 2 lines
It is never needed to import the exception module.
........
r3822 | poeml | 2008-04-25 11:13:39 +0200 (Fri, 25 Apr 2008) | 4 lines
- when going into the debugger with --post-mortem, always print a traceback before
(thus implying -t)
- do not jump into the debugger if not on a TTY, or working in interactive mode
........
r3827 | poeml | 2008-04-25 13:07:46 +0200 (Fri, 25 Apr 2008) | 9 lines
- add errors.OscWorkingCopyOutdated, which takes a tuple with three args:
path to working copy, current rev, expected rev
- add handler for urllib2.URLError errors to the babysitter
- simplify the OscWrongArgsError and OscWrongOptionsError handlers, by removing
the extra line "Sorry, wrong ..." that was printed before the messages given
when the error was raised.
- remove one more errors.OscHTTPError which was still there, and raise
urllib2.HTTPError instead (show_package_meta())
........
r3829 | poeml | 2008-04-25 14:19:10 +0200 (Fri, 25 Apr 2008) | 11 lines
- comment some methods in osc.core which are used by nearly all do_* methods in
osc.commandline
- improve "is not a package/project dir" error messages, by printing the
absolute path tried, instead of '.' for the cwd
- make core.store_read_package() raise a proper NoWorkingCopyError instead of
terminating
- give attribution to things in babysitter.py copied from mercurial
- prefix HTTPError exceptions with 'Server returned an error:'
- remove obsolete local error handling from do_prjresults(), do_importsrcpkg(),
do_repos()
........
r3830 | poeml | 2008-04-25 14:29:35 +0200 (Fri, 25 Apr 2008) | 1 line
catch IOError exceptions in the babysitter
........
r3837 | poeml | 2008-04-25 17:27:36 +0200 (Fri, 25 Apr 2008) | 5 lines
- do_remotebuildlog: raise errors for wrong arguments, remove exits
- raise AttributeError in make_meta_url() instead of exiting
- delete unused method core.delete_server_files()
- replace exit call inside make_meta_url() with an AttributeError
........
r3838 | poeml | 2008-04-25 17:49:18 +0200 (Fri, 25 Apr 2008) | 1 line
simplify the check in do_checkout if a project exists, by using show_project_meta() instead of meta_exists
........
r3839 | poeml | 2008-04-25 18:31:26 +0200 (Fri, 25 Apr 2008) | 6 lines
- commandline do_checkout(): change the order of the two checks, first do the
(cheaper) check for existing directory
- core.core checkout_package(): simplify the check in if the package
exists, by using show_package_meta() instead of meta_exists
Let it throw an exception, instead of using sys.exit().
........
r3841 | Marcus_H | 2008-04-27 15:48:06 +0200 (Sun, 27 Apr 2008) | 5 lines
- added 2 new exception classes: PackageError() and PackageExistsError. The PackageError() class is meant to be the base class for all subsequent package exceptions.
- get rid of 2 sys.exit(1) calls
- make the update() method of the Project() class safer: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- minor fix in delPackage(): use getTransActPath() when printing out the filename
........
r3842 | Marcus_H | 2008-04-27 16:52:55 +0200 (Sun, 27 Apr 2008) | 3 lines
- make the commit() method safe: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- removed another sys.exit(1): raise an exception if a package is missing when doing a commit. For now we use the PackageExistsError() exception but this might change in the future (updated description of PackageExistsError() according to this change)
........
r3848 | poeml | 2008-04-28 12:46:45 +0200 (Mon, 28 Apr 2008) | 3 lines
rename several error classes, dropping the "Osc" prefix, and "Error" suffix in
cases where they don't really make sense.
........
r3849 | poeml | 2008-04-28 12:57:32 +0200 (Mon, 28 Apr 2008) | 3 lines
- rename osc.errors module to osc.oscerr, to make it easier to import it from
other programs and have a crystal clear namespace
........
r3850 | poeml | 2008-04-28 13:26:12 +0200 (Mon, 28 Apr 2008) | 2 lines
split PackageExists exception class into PackageExists and PackageMissing
........
2008-04-28 18:37:44 +02:00
|
|
|
config['debug'] = override_debug
|
2009-02-24 00:29:32 +01:00
|
|
|
if override_http_debug:
|
2007-08-22 12:18:25 +02:00
|
|
|
config['http_debug'] = override_http_debug
|
2010-09-01 15:38:08 +02:00
|
|
|
if override_http_full_debug:
|
|
|
|
config['http_debug'] = override_http_full_debug or config['http_debug']
|
|
|
|
config['http_full_debug'] = override_http_full_debug
|
Merged revisions 3774-3775,3779,3781-3782,3787,3789-3793,3798,3802,3805,3817-3822,3827,3829-3830,3837-3839,3841-3842,3848-3850 via svnmerge from
https://forgesvn1.novell.com/svn/opensuse/branches/buildservice/osc-exception-handling
........
r3774 | poeml | 2008-04-22 17:39:45 +0200 (Tue, 22 Apr 2008) | 3 lines
A first draft on implement systematic exception handling:
Add errors.py with some exceptions defined, and babysitter.py to handle them
........
r3775 | poeml | 2008-04-22 22:34:12 +0200 (Tue, 22 Apr 2008) | 9 lines
- new global options:
--debugger jump into the debugger before executing anything
--post-mortem jump into the debugger in case of errors
-t, --traceback print call trace in case of errors
- traceback and post_mortem can also be set in .oscrc.
- catch more errors (HTTPError).
- make config accessible from outside of the Osc instance, by making it a class
attribute
........
r3779 | poeml | 2008-04-23 00:55:49 +0200 (Wed, 23 Apr 2008) | 5 lines
- new global option:
-d, --debug print info useful for debugging
- catch some more errors (HTTPError), with OscHTTPError which isn't very
advanced yet.
........
r3781 | Marcus_H | 2008-04-23 01:02:00 +0200 (Wed, 23 Apr 2008) | 2 lines
- added OscConfigError class (just for testing).
- small change in the signature of the OscBaseError constructor (actually we should get rid of the 'args' tuple because it will be deprecated sooner or later
........
r3782 | Marcus_H | 2008-04-23 02:02:13 +0200 (Wed, 23 Apr 2008) | 2 lines
- access the prg.conf.config dict in a save way - this way we avoid AttributeErrors if the prg.conf.config dict doesn't exist
- in case of an configparser error we have to use the prg.options object directly (this was removed in r3781 by accident)
........
r3787 | poeml | 2008-04-23 09:23:56 +0200 (Wed, 23 Apr 2008) | 4 lines
- remove local exception handling from do_req
- for HTTPError, print details (headers and response) when in debug mode
- catch AttributeError
........
r3789 | poeml | 2008-04-23 16:23:14 +0200 (Wed, 23 Apr 2008) | 4 lines
- errors: add two new classes named OscWrongOptionsError and OscWrongArgsError
- commandline: raise instances of the new errors in a number of places
- commandline: add get_cmd_help() to Osc instance which returns the formatted help of a subcommand
........
r3790 | Marcus_H | 2008-04-23 16:48:28 +0200 (Wed, 23 Apr 2008) | 4 lines
- added 2 new exception classes: OscNoConfigfileError and OscIOError
- added new method write_config() to the conf.py module: This method writes osc's configuration file
- minor cleanups in the conf module
........
r3791 | poeml | 2008-04-23 17:11:07 +0200 (Wed, 23 Apr 2008) | 3 lines
small compatibility fix for r3790: try-except-finally isn't supported in
python-2.4.2, thus do the same as try-except inside a try-finally.
........
r3792 | poeml | 2008-04-23 17:37:53 +0200 (Wed, 23 Apr 2008) | 2 lines
fix up the remaining places regarding handling of errors related to commandline parsing
........
r3793 | poeml | 2008-04-23 17:40:34 +0200 (Wed, 23 Apr 2008) | 3 lines
raise a NoWorkingCopyError in osc.core.store_read_project() in case of an
IOError
........
r3798 | Marcus_H | 2008-04-23 23:55:24 +0200 (Wed, 23 Apr 2008) | 1 line
ported -r3797 from trunk
........
r3802 | Marcus_H | 2008-04-24 11:00:55 +0200 (Thu, 24 Apr 2008) | 1 line
ported -r3801 from trunk
........
r3805 | poeml | 2008-04-24 12:52:30 +0200 (Thu, 24 Apr 2008) | 2 lines
raise OscHTTPError in show_pattern_meta(), replacing local error handling
........
r3817 | poeml | 2008-04-24 20:21:32 +0200 (Thu, 24 Apr 2008) | 9 lines
- remove errors.OscHTTPError again.
it seems simpler to use urllib2.HTTPError instead (and just add a specific
error text message where appropriate, and re-raise)
- for 404s, check out _which_ part was not found
it is very ugly, but may be considered Good for pragmatic reasons
- removed local exception handling and workaround for returned 500's from
delete_package() and delete_project(), thereby getting rid of 4 possible exit
points.
........
r3818 | Marcus_H | 2008-04-24 22:36:17 +0200 (Thu, 24 Apr 2008) | 1 line
- this check is superfluous because every HTTPError instance has a code attribute
........
r3819 | poeml | 2008-04-25 00:39:39 +0200 (Fri, 25 Apr 2008) | 1 line
remove a forgotten debug line from core.delete_project()
........
r3820 | poeml | 2008-04-25 10:07:58 +0200 (Fri, 25 Apr 2008) | 2 lines
- ditch local error handling from wipebinaries(), rebuild(), and abortbuild()
........
r3821 | poeml | 2008-04-25 10:56:38 +0200 (Fri, 25 Apr 2008) | 2 lines
It is never needed to import the exception module.
........
r3822 | poeml | 2008-04-25 11:13:39 +0200 (Fri, 25 Apr 2008) | 4 lines
- when going into the debugger with --post-mortem, always print a traceback before
(thus implying -t)
- do not jump into the debugger if not on a TTY, or working in interactive mode
........
r3827 | poeml | 2008-04-25 13:07:46 +0200 (Fri, 25 Apr 2008) | 9 lines
- add errors.OscWorkingCopyOutdated, which takes a tuple with three args:
path to working copy, current rev, expected rev
- add handler for urllib2.URLError errors to the babysitter
- simplify the OscWrongArgsError and OscWrongOptionsError handlers, by removing
the extra line "Sorry, wrong ..." that was printed before the messages given
when the error was raised.
- remove one more errors.OscHTTPError which was still there, and raise
urllib2.HTTPError instead (show_package_meta())
........
r3829 | poeml | 2008-04-25 14:19:10 +0200 (Fri, 25 Apr 2008) | 11 lines
- comment some methods in osc.core which are used by nearly all do_* methods in
osc.commandline
- improve "is not a package/project dir" error messages, by printing the
absolute path tried, instead of '.' for the cwd
- make core.store_read_package() raise a proper NoWorkingCopyError instead of
terminating
- give attribution to things in babysitter.py copied from mercurial
- prefix HTTPError exceptions with 'Server returned an error:'
- remove obsolete local error handling from do_prjresults(), do_importsrcpkg(),
do_repos()
........
r3830 | poeml | 2008-04-25 14:29:35 +0200 (Fri, 25 Apr 2008) | 1 line
catch IOError exceptions in the babysitter
........
r3837 | poeml | 2008-04-25 17:27:36 +0200 (Fri, 25 Apr 2008) | 5 lines
- do_remotebuildlog: raise errors for wrong arguments, remove exits
- raise AttributeError in make_meta_url() instead of exiting
- delete unused method core.delete_server_files()
- replace exit call inside make_meta_url() with an AttributeError
........
r3838 | poeml | 2008-04-25 17:49:18 +0200 (Fri, 25 Apr 2008) | 1 line
simplify the check in do_checkout if a project exists, by using show_project_meta() instead of meta_exists
........
r3839 | poeml | 2008-04-25 18:31:26 +0200 (Fri, 25 Apr 2008) | 6 lines
- commandline do_checkout(): change the order of the two checks, first do the
(cheaper) check for existing directory
- core.core checkout_package(): simplify the check in if the package
exists, by using show_package_meta() instead of meta_exists
Let it throw an exception, instead of using sys.exit().
........
r3841 | Marcus_H | 2008-04-27 15:48:06 +0200 (Sun, 27 Apr 2008) | 5 lines
- added 2 new exception classes: PackageError() and PackageExistsError. The PackageError() class is meant to be the base class for all subsequent package exceptions.
- get rid of 2 sys.exit(1) calls
- make the update() method of the Project() class safer: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- minor fix in delPackage(): use getTransActPath() when printing out the filename
........
r3842 | Marcus_H | 2008-04-27 16:52:55 +0200 (Sun, 27 Apr 2008) | 3 lines
- make the commit() method safe: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- removed another sys.exit(1): raise an exception if a package is missing when doing a commit. For now we use the PackageExistsError() exception but this might change in the future (updated description of PackageExistsError() according to this change)
........
r3848 | poeml | 2008-04-28 12:46:45 +0200 (Mon, 28 Apr 2008) | 3 lines
rename several error classes, dropping the "Osc" prefix, and "Error" suffix in
cases where they don't really make sense.
........
r3849 | poeml | 2008-04-28 12:57:32 +0200 (Mon, 28 Apr 2008) | 3 lines
- rename osc.errors module to osc.oscerr, to make it easier to import it from
other programs and have a crystal clear namespace
........
r3850 | poeml | 2008-04-28 13:26:12 +0200 (Mon, 28 Apr 2008) | 2 lines
split PackageExists exception class into PackageExists and PackageMissing
........
2008-04-28 18:37:44 +02:00
|
|
|
if override_traceback:
|
|
|
|
config['traceback'] = override_traceback
|
|
|
|
if override_post_mortem:
|
|
|
|
config['post_mortem'] = override_post_mortem
|
2009-02-24 00:29:32 +01:00
|
|
|
if override_apiurl:
|
2009-02-24 22:35:59 +01:00
|
|
|
apiurl = aliases.get(override_apiurl, override_apiurl)
|
|
|
|
# check if apiurl is a valid url
|
2009-11-18 21:31:08 +01:00
|
|
|
config['apiurl'] = urljoin(*parse_apisrv_url(None, apiurl))
|
2007-08-22 12:18:25 +02:00
|
|
|
|
2009-08-20 21:28:05 +02:00
|
|
|
# XXX unless config['user'] goes away (and is replaced with a handy function, or
|
2008-03-13 17:15:41 +01:00
|
|
|
# config becomes an object, even better), set the global 'user' here as well,
|
2009-02-24 00:29:32 +01:00
|
|
|
# provided that there _are_ credentials for the chosen apiurl:
|
|
|
|
try:
|
2009-02-24 21:17:23 +01:00
|
|
|
config['user'] = get_apiurl_usr(config['apiurl'])
|
2013-04-09 11:27:02 +02:00
|
|
|
except oscerr.ConfigMissingApiurl as e:
|
2009-02-24 00:29:32 +01:00
|
|
|
e.msg = config_missing_apiurl_text % config['apiurl']
|
|
|
|
e.file = conffile
|
|
|
|
raise e
|
2007-08-22 12:18:25 +02:00
|
|
|
|
|
|
|
# finally, initialize urllib2 for to use the credentials for Basic Authentication
|
2016-11-19 13:01:05 +01:00
|
|
|
init_basicauth(config, os.stat(conffile).st_mtime)
|
2007-08-22 12:18:25 +02:00
|
|
|
|
2017-10-27 11:29:00 +02:00
|
|
|
def identify_conf():
|
|
|
|
# needed for compat reasons(users may have their oscrc still in ~
|
|
|
|
if 'OSC_CONFIG' in os.environ:
|
|
|
|
return os.environ.get('OSC_CONFIG')
|
|
|
|
if os.path.exists(os.path.expanduser('~/.oscrc')):
|
2021-08-14 00:55:48 +02:00
|
|
|
return '~/.oscrc'
|
|
|
|
|
|
|
|
if os.environ.get('XDG_CONFIG_HOME', '') != '':
|
|
|
|
conffile = os.environ.get('XDG_CONFIG_HOME') + '/osc/oscrc'
|
2017-10-27 11:29:00 +02:00
|
|
|
else:
|
2021-08-14 00:55:48 +02:00
|
|
|
conffile = '~/.config/osc/oscrc'
|
2017-10-27 11:29:00 +02:00
|
|
|
|
|
|
|
return conffile
|
2011-08-17 15:33:56 +02:00
|
|
|
|
2019-08-26 11:30:41 +02:00
|
|
|
def interactive_config_setup(conffile, apiurl, initial=True):
|
|
|
|
user = raw_input('Username: ')
|
|
|
|
passwd = getpass.getpass()
|
2019-08-29 11:35:34 +02:00
|
|
|
creds_mgr_descr = select_credentials_manager_descr()
|
|
|
|
if initial:
|
|
|
|
config = {'user': user, 'pass': passwd}
|
|
|
|
if apiurl:
|
|
|
|
config['apiurl'] = apiurl
|
|
|
|
write_initial_config(conffile, config, creds_mgr_descriptor=creds_mgr_descr)
|
|
|
|
else:
|
|
|
|
add_section(conffile, apiurl, user, passwd, creds_mgr_descriptor=creds_mgr_descr)
|
|
|
|
|
|
|
|
def select_credentials_manager_descr():
|
2019-08-27 15:08:38 +02:00
|
|
|
if not credentials.has_keyring_support():
|
2020-02-29 01:28:20 +01:00
|
|
|
print('To use keyrings please install python%d-keyring.' % sys.version_info.major)
|
2019-08-27 15:08:38 +02:00
|
|
|
creds_mgr_descriptors = credentials.get_credentials_manager_descriptors()
|
|
|
|
for i, creds_mgr_descr in enumerate(creds_mgr_descriptors, 1):
|
|
|
|
print('%d) %s (%s)' % (i, creds_mgr_descr.name(), creds_mgr_descr.description()))#
|
|
|
|
i = raw_input('Select credentials manager: ')
|
|
|
|
if not i.isdigit():
|
|
|
|
sys.exit('Invalid selection')
|
|
|
|
i = int(i) - 1
|
|
|
|
if i < 0 or i >= len(creds_mgr_descriptors):
|
|
|
|
sys.exit('Invalid selection')
|
2019-08-29 11:35:34 +02:00
|
|
|
return creds_mgr_descriptors[i]
|
2019-08-26 11:30:41 +02:00
|
|
|
|
2009-11-13 11:46:23 +01:00
|
|
|
# vim: sw=4 et
|