2009-03-02 15:03:06 +01:00
# Copyright (C) 2006 Novell Inc. All rights reserved.
2006-04-20 16:26:50 +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-04-20 16:26:50 +02:00
2013-04-09 12:51:28 +02:00
from __future__ import print_function
2006-05-23 15:48:58 +02:00
2013-04-09 11:35:53 +02:00
from . import cmdln
from . import conf
from . import oscerr
2011-01-05 16:31:02 +01:00
import sys
2011-07-08 16:09:44 +02:00
import time
2013-06-13 19:57:34 +02:00
import imp
import inspect
2013-04-09 12:36:42 +02:00
try :
from urllib . parse import urlsplit
2013-04-09 14:03:17 +02:00
from urllib . error import HTTPError
2013-04-10 11:34:59 +02:00
ET_ENCODING = " unicode "
2013-04-09 12:36:42 +02:00
except ImportError :
#python 2.x
from urlparse import urlsplit
2013-04-09 14:03:17 +02:00
from urllib2 import HTTPError
2013-04-10 11:34:59 +02:00
ET_ENCODING = " utf-8 "
2011-07-08 16:09:44 +02:00
2010-01-20 09:15:17 +01:00
from optparse import SUPPRESS_HELP
2006-04-20 16:26:50 +02:00
2013-04-09 11:35:53 +02:00
from . core import *
from . util import safewriter
2011-07-08 16:09:44 +02:00
2009-05-06 15:20:15 +02:00
MAN_HEADER = r """ .TH %(ucname)s " 1 " " %(date)s " " %(name)s %(version)s " " User Commands "
. SH NAME
2009-06-17 20:19:45 +02:00
% ( name ) s \- openSUSE build service command - line tool .
2009-05-06 15:20:15 +02:00
. SH SYNOPSIS
. B % ( name ) s
[ \fIGLOBALOPTS \fR ] \fISUBCOMMAND \fR [ \fIOPTS \fR ] [ \fIARGS \fR . . . ]
. br
. B % ( name ) s
\fIhelp SUBCOMMAND \fR
. SH DESCRIPTION
2009-06-17 20:19:45 +02:00
openSUSE build service command - line tool .
2009-05-06 15:20:15 +02:00
"""
MAN_FOOTER = r """
. SH " SEE ALSO "
Type ' osc help <subcommand> ' for more detailed help on a specific subcommand .
. PP
For additional information , see
2010-07-27 15:20:35 +02:00
* http : / / en . opensuse . org / openSUSE : Build_Service_Tutorial
* http : / / en . opensuse . org / openSUSE : OSC
2009-05-06 15:20:15 +02:00
. PP
2015-02-21 08:49:56 +01:00
You can modify osc commands , or roll your own , via the plugin API :
2010-07-27 15:20:35 +02:00
* http : / / en . opensuse . org / openSUSE : OSC_plugins
2009-05-06 15:20:15 +02:00
. SH AUTHOR
osc was written by several authors . This man page is automatically generated .
"""
2007-04-25 01:00:12 +02:00
class Osc ( cmdln . Cmdln ) :
2009-05-05 16:13:22 +02:00
""" Usage: osc [GLOBALOPTS] SUBCOMMAND [OPTS] [ARGS...]
or : osc help SUBCOMMAND
2009-06-17 20:19:45 +02:00
openSUSE build service command - line tool .
2007-04-25 01:00:12 +02:00
Type ' osc help <subcommand> ' for help on a specific subcommand .
2006-12-12 03:01:39 +01:00
2007-04-25 01:00:12 +02:00
$ { command_list }
$ { help_list }
global $ { option_list }
2009-05-18 16:50:43 +02:00
For additional information , see
2010-07-27 15:20:35 +02:00
* http : / / en . opensuse . org / openSUSE : Build_Service_Tutorial
* http : / / en . opensuse . org / openSUSE : OSC
2008-09-24 14:23:56 +02:00
2015-02-21 08:49:56 +01:00
You can modify osc commands , or roll your own , via the plugin API :
2010-07-27 15:20:35 +02:00
* http : / / en . opensuse . org / openSUSE : OSC_plugins
2007-04-25 01:00:12 +02:00
"""
name = ' osc '
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 = None
2006-12-12 03:01:39 +01:00
2009-05-06 15:20:15 +02:00
man_header = MAN_HEADER
man_footer = MAN_FOOTER
2007-05-16 12:55:05 +02:00
2007-04-25 01:00:12 +02:00
def __init__ ( self , * args , * * kwargs ) :
2013-06-13 19:57:34 +02:00
# the plugins have to be loaded before the
# superclass' __init__ method is called
self . _load_plugins ( )
2007-04-25 01:00:12 +02:00
cmdln . Cmdln . __init__ ( self , * args , * * kwargs )
cmdln . Cmdln . do_help . aliases . append ( ' h ' )
2011-02-11 02:43:10 +01:00
sys . stderr = safewriter . SafeWriter ( sys . stderr )
sys . stdout = safewriter . SafeWriter ( sys . stdout )
2006-05-23 15:48:58 +02:00
2009-05-06 15:20:15 +02:00
def get_version ( self ) :
return get_osc_version ( )
2007-05-16 12:55:05 +02:00
def get_optparser ( self ) :
""" this is the parser for " global " options (not specific to subcommand) """
optparser = cmdln . CmdlnOptionParser ( self , version = get_osc_version ( ) )
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
optparser . add_option ( ' --debugger ' , action = ' store_true ' ,
help = ' jump into the debugger before executing anything ' )
optparser . add_option ( ' --post-mortem ' , action = ' store_true ' ,
help = ' jump into the debugger in case of errors ' )
optparser . add_option ( ' -t ' , ' --traceback ' , action = ' store_true ' ,
help = ' print call trace in case of errors ' )
2007-05-16 12:55:05 +02:00
optparser . add_option ( ' -H ' , ' --http-debug ' , action = ' store_true ' ,
2010-09-01 15:38:08 +02:00
help = ' debug HTTP traffic (filters some headers) ' )
optparser . add_option ( ' --http-full-debug ' , action = ' store_true ' ,
2013-05-27 13:06:01 +02:00
help = ' debug HTTP traffic (filters no headers) ' )
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
optparser . add_option ( ' -d ' , ' --debug ' , action = ' store_true ' ,
help = ' print info useful for debugging ' )
2009-02-24 00:29:32 +01:00
optparser . add_option ( ' -A ' , ' --apiurl ' , dest = ' apiurl ' ,
2009-03-31 15:29:16 +02:00
metavar = ' URL/alias ' ,
help = ' specify URL to access API server at or an alias ' )
2007-08-22 12:18:25 +02:00
optparser . add_option ( ' -c ' , ' --config ' , dest = ' conffile ' ,
metavar = ' FILE ' ,
help = ' specify alternate configuration file ' )
2009-09-04 19:48:53 +02:00
optparser . add_option ( ' --no-keyring ' , action = ' store_true ' ,
help = ' disable usage of desktop keyring system ' )
2009-05-11 09:46:01 +02:00
optparser . add_option ( ' --no-gnome-keyring ' , action = ' store_true ' ,
help = ' disable usage of GNOME Keyring ' )
2009-08-20 21:28:05 +02:00
optparser . add_option ( ' -v ' , ' --verbose ' , dest = ' verbose ' , action = ' count ' , default = 0 ,
help = ' increase verbosity ' )
optparser . add_option ( ' -q ' , ' --quiet ' , dest = ' verbose ' , action = ' store_const ' , const = - 1 ,
help = ' be quiet, not verbose ' )
2007-05-16 12:55:05 +02:00
return optparser
2006-05-23 15:48:58 +02:00
2008-08-20 11:40:00 +02:00
def postoptparse ( self , try_again = True ) :
2007-05-16 12:55:05 +02:00
""" merge commandline options into the config """
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
try :
conf . get_config ( override_conffile = self . options . conffile ,
2009-02-24 00:29:32 +01:00
override_apiurl = self . options . apiurl ,
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
override_debug = self . options . debug ,
override_http_debug = self . options . http_debug ,
2010-09-01 15:38:08 +02:00
override_http_full_debug = self . options . 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
override_traceback = self . options . traceback ,
2009-05-11 09:46:01 +02:00
override_post_mortem = self . options . post_mortem ,
2009-09-04 19:48:53 +02:00
override_no_keyring = self . options . no_keyring ,
2009-08-20 21:28:05 +02:00
override_no_gnome_keyring = self . options . no_gnome_keyring ,
override_verbose = self . options . verbose )
2013-04-09 11:27:02 +02:00
except oscerr . NoConfigfile as e :
2013-04-09 12:51:28 +02:00
print ( e . msg , file = sys . stderr )
print ( ' Creating osc configuration file %s ... ' % e . file , file = sys . stderr )
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
import getpass
config = { }
config [ ' user ' ] = raw_input ( ' Username: ' )
config [ ' pass ' ] = getpass . getpass ( )
2010-02-25 14:13:02 +01:00
if self . options . no_keyring :
config [ ' use_keyring ' ] = ' 0 '
if self . options . no_gnome_keyring :
config [ ' gnome_keyring ' ] = ' 0 '
2009-02-24 00:29:32 +01:00
if self . options . apiurl :
config [ ' apiurl ' ] = self . options . apiurl
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-21 20:17:40 +02:00
conf . write_initial_config ( e . file , config )
2013-04-09 12:51:28 +02:00
print ( ' done ' , file = sys . stderr )
2014-08-12 15:01:16 +02:00
if try_again :
2013-05-27 13:38:49 +02:00
self . postoptparse ( try_again = False )
2013-04-09 11:27:02 +02:00
except oscerr . ConfigMissingApiurl as e :
2013-04-09 12:51:28 +02:00
print ( e . msg , file = sys . stderr )
2008-08-07 19:14:26 +02:00
import getpass
user = raw_input ( ' Username: ' )
passwd = getpass . getpass ( )
2009-05-11 09:46:01 +02:00
conf . add_section ( e . file , e . url , user , passwd )
2014-08-12 15:01:16 +02:00
if try_again :
2013-05-27 13:38:49 +02:00
self . postoptparse ( try_again = False )
2008-08-07 19:14:26 +02:00
2009-08-20 21:28:05 +02:00
self . options . verbose = conf . config [ ' verbose ' ]
2010-02-09 20:57:10 +01:00
self . download_progress = None
if conf . config . get ( ' show_download_progress ' , False ) :
2013-04-09 11:35:53 +02:00
from . meter import TextMeter
2010-02-25 10:43:05 +01:00
self . download_progress = TextMeter ( hide_finished = True )
2006-05-23 15:48:58 +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
def get_cmd_help ( self , cmdname ) :
doc = self . _get_cmd_handler ( cmdname ) . __doc__
doc = self . _help_reindent ( doc )
doc = self . _help_preprocess ( doc , cmdname )
doc = doc . rstrip ( ) + ' \n ' # trim down trailing space
return self . _str ( doc )
2006-04-20 16:26:50 +02:00
2010-04-30 17:13:21 +02:00
def get_api_url ( self ) :
2011-04-06 15:31:36 +02:00
try :
localdir = os . getcwd ( )
2013-04-09 11:27:02 +02:00
except Exception as e :
2011-04-06 15:31:36 +02:00
## check for Stale NFS file handle: '.'
2013-05-27 13:38:49 +02:00
try :
os . stat ( ' . ' )
2014-08-12 15:01:16 +02:00
except Exception as ee :
2013-05-27 13:38:49 +02:00
e = ee
2013-04-09 12:51:28 +02:00
print ( " os.getcwd() failed: " , e , file = sys . stderr )
2011-04-06 15:31:36 +02:00
sys . exit ( 1 )
2010-04-30 17:13:21 +02:00
if ( is_package_dir ( localdir ) or is_project_dir ( localdir ) ) and not self . options . apiurl :
2013-05-27 12:16:44 +02:00
return store_read_apiurl ( os . curdir )
2010-04-30 17:13:21 +02:00
else :
2013-05-27 12:16:44 +02:00
return conf . config [ ' apiurl ' ]
2009-08-21 16:55:26 +02:00
# overridden from class Cmdln() to use config variables in help texts
def _help_preprocess ( self , help , cmdname ) :
2010-08-20 14:34:41 +02:00
help_msg = cmdln . Cmdln . _help_preprocess ( self , help , cmdname )
return help_msg % conf . config
2006-04-20 16:26:50 +02:00
2009-08-21 16:55:26 +02:00
2008-08-08 17:19:54 +02:00
def do_init ( self , subcmd , opts , project , package = None ) :
2009-05-18 16:50:43 +02:00
""" $ {cmd_name} : Initialize a directory as working copy
2006-05-23 15:48:58 +02:00
2008-05-21 18:10:20 +02:00
Initialize an existing directory to be a working copy of an
2009-05-18 16:50:43 +02:00
( already existing ) buildservice project / package .
2008-05-21 18:10:20 +02:00
( This is the same as checking out a package and then copying sources
into the directory . It does NOT create a new package . To create a
package , use ' osc meta pkg ... ... ' )
2006-05-23 15:48:58 +02:00
2008-05-21 18:10:20 +02:00
You wouldn ' t normally use this command.
To get a working copy of a package ( e . g . for building it or working on
it , you would normally use the checkout command . Use " osc help
checkout " to get help for it.
2009-05-18 16:50:43 +02:00
usage :
2008-08-01 15:58:49 +02:00
osc init PRJ
2007-06-21 11:40:47 +02:00
osc init PRJ PAC
2007-04-25 01:00:12 +02:00
$ { cmd_option_list }
"""
2009-05-18 16:50:43 +02:00
2010-07-29 17:29:07 +02:00
apiurl = self . get_api_url ( )
2008-08-08 17:19:54 +02:00
if not package :
2010-10-09 16:26:55 +02:00
Project . init_project ( apiurl , os . curdir , project , conf . config [ ' do_package_tracking ' ] )
2013-04-09 12:51:28 +02:00
print ( ' Initializing %s (Project: %s ) ' % ( os . curdir , project ) )
2008-08-01 15:58:49 +02:00
else :
2010-08-30 13:46:49 +02:00
Package . init_package ( apiurl , project , package , os . curdir )
2010-08-30 14:20:12 +02:00
store_write_string ( os . curdir , ' _files ' , show_files_meta ( apiurl , project , package ) + ' \n ' )
2013-04-09 12:51:28 +02:00
print ( ' Initializing %s (Project: %s , Package: %s ) ' % ( os . curdir , project , package ) )
2007-04-25 01:00:12 +02:00
@cmdln.alias ( ' ls ' )
2009-08-20 21:28:05 +02:00
@cmdln.alias ( ' ll ' )
@cmdln.alias ( ' lL ' )
@cmdln.alias ( ' LL ' )
2007-08-16 20:15:08 +02:00
@cmdln.option ( ' -a ' , ' --arch ' , metavar = ' ARCH ' ,
2010-01-12 13:31:25 +01:00
help = ' specify architecture (only for binaries) ' )
2007-08-16 20:15:08 +02:00
@cmdln.option ( ' -r ' , ' --repo ' , metavar = ' REPO ' ,
2010-01-12 13:31:25 +01:00
help = ' specify repository (only for binaries) ' )
2007-08-16 20:15:08 +02:00
@cmdln.option ( ' -b ' , ' --binaries ' , action = ' store_true ' ,
2010-01-12 13:31:25 +01:00
help = ' list built binaries instead of sources ' )
@cmdln.option ( ' -e ' , ' --expand ' , action = ' store_true ' ,
help = ' expand linked package (only for sources) ' )
2010-03-08 23:52:51 +01:00
@cmdln.option ( ' -u ' , ' --unexpand ' , action = ' store_true ' ,
help = ' always work with unexpanded (source) packages ' )
2007-06-26 15:17:38 +02:00
@cmdln.option ( ' -v ' , ' --verbose ' , action = ' store_true ' ,
help = ' print extra information ' )
2009-08-20 21:28:05 +02:00
@cmdln.option ( ' -l ' , ' --long ' , action = ' store_true ' , dest = ' verbose ' ,
help = ' print extra information ' )
2010-05-22 08:22:12 +02:00
@cmdln.option ( ' -D ' , ' --deleted ' , action = ' store_true ' ,
help = ' show only the former deleted projects or packages ' )
2011-06-08 10:25:15 +02:00
@cmdln.option ( ' -M ' , ' --meta ' , action = ' store_true ' ,
help = ' list meta data files ' )
@cmdln.option ( ' -R ' , ' --revision ' , metavar = ' REVISION ' ,
help = ' specify revision (only for sources) ' )
2007-04-25 01:00:12 +02:00
def do_list ( self , subcmd , opts , * args ) :
2010-01-12 13:31:25 +01:00
""" $ {cmd_name} : List sources or binaries on the server
2007-08-16 20:15:08 +02:00
2010-01-12 13:31:25 +01:00
Examples for listing sources :
2010-12-02 23:36:40 +01:00
ls # list all projects (deprecated)
2010-12-02 23:52:38 +01:00
ls / # list all projects
2011-04-11 15:07:56 +02:00
ls . # take PROJECT/PACKAGE from current dir.
2010-01-12 13:31:25 +01:00
ls PROJECT # list packages in a project
ls PROJECT PACKAGE # list source files of package of a project
ls PROJECT PACKAGE < file > # list <file> if this file exists
ls - v PROJECT PACKAGE # verbosely list source files of package
ls - l PROJECT PACKAGE # verbosely list source files of package
ll PROJECT PACKAGE # verbosely list source files of package
LL PROJECT PACKAGE # verbosely list source files of expanded link
2007-06-26 15:17:38 +02:00
With - - verbose , the following fields will be shown for each item :
MD5 hash of file
Revision number of the last commit
Size ( in bytes )
Date and time of the last commit
2007-04-25 01:00:12 +02:00
2010-01-12 13:31:25 +01:00
Examples for listing binaries :
ls - b PROJECT # list all binaries of a project
ls - b PROJECT - a ARCH # list ARCH binaries of a project
ls - b PROJECT - r REPO # list binaries in REPO
ls - b PROJECT PACKAGE REPO ARCH
Usage :
$ { cmd_name } [ PROJECT [ PACKAGE ] ]
$ { cmd_name } - b [ PROJECT [ PACKAGE [ REPO [ ARCH ] ] ] ]
2007-04-25 01:00:12 +02:00
$ { cmd_option_list }
"""
2007-06-26 15:17:38 +02:00
args = slash_split ( args )
2009-08-21 21:39:12 +02:00
if subcmd == ' ll ' :
opts . verbose = True
if subcmd == ' lL ' or subcmd == ' LL ' :
opts . verbose = True
opts . expand = True
2007-06-26 15:17:38 +02:00
2009-11-17 14:39:46 +01:00
project = None
package = None
2010-01-12 13:31:25 +01:00
fname = None
2010-12-02 23:52:38 +01:00
if len ( args ) == 0 :
# For consistency with *all* other commands
2011-04-11 15:07:56 +02:00
# this lists what the server has in the current wd.
2010-12-02 23:52:38 +01:00
# CAUTION: 'osc ls -b' already works like this.
pass
2010-01-12 13:31:25 +01:00
if len ( args ) > 0 :
2007-04-25 01:00:12 +02:00
project = args [ 0 ]
2014-08-12 15:01:16 +02:00
if project == ' / ' :
2013-05-27 13:38:49 +02:00
project = None
2011-04-11 15:07:56 +02:00
if project == ' . ' :
cwd = os . getcwd ( )
if is_project_dir ( cwd ) :
project = store_read_project ( cwd )
elif is_package_dir ( cwd ) :
project = store_read_project ( cwd )
package = store_read_package ( cwd )
2010-01-12 13:31:25 +01:00
if len ( args ) > 1 :
2007-04-25 01:00:12 +02:00
package = args [ 1 ]
2010-01-12 13:31:25 +01:00
if len ( args ) > 2 :
2010-05-22 08:22:12 +02:00
if opts . deleted :
raise oscerr . WrongArgs ( " Too many arguments when listing deleted packages " )
2010-01-12 13:31:25 +01:00
if opts . binaries :
if opts . repo :
if opts . repo != args [ 2 ] :
raise oscerr . WrongArgs ( " conflicting repos specified ( ' %s ' vs ' %s ' ) " % ( opts . repo , args [ 2 ] ) )
else :
opts . repo = args [ 2 ]
else :
2008-11-20 13:56:16 +01:00
fname = args [ 2 ]
2010-01-12 13:31:25 +01:00
if len ( args ) > 3 :
if not opts . binaries :
raise oscerr . WrongArgs ( ' Too many arguments ' )
if opts . arch :
if opts . arch != args [ 3 ] :
raise oscerr . WrongArgs ( " conflicting archs specified ( ' %s ' vs ' %s ' ) " % ( opts . arch , args [ 3 ] ) )
else :
opts . arch = args [ 3 ]
2007-08-16 20:15:08 +02:00
2009-03-31 00:28:26 +02:00
if opts . binaries and opts . expand :
raise oscerr . WrongOptions ( ' Sorry, --binaries and --expand are mutual exclusive. ' )
2007-08-16 20:15:08 +02:00
2014-08-12 15:01:16 +02:00
apiurl = self . get_api_url ( )
2010-07-29 17:29:07 +02:00
2007-08-16 20:15:08 +02:00
# list binaries
if opts . binaries :
2009-11-17 14:39:46 +01:00
# ls -b toplevel doesn't make sense, so use info from
# current dir if available
if len ( args ) == 0 :
2010-08-20 14:34:41 +02:00
cwd = os . getcwd ( )
if is_project_dir ( cwd ) :
project = store_read_project ( cwd )
elif is_package_dir ( cwd ) :
project = store_read_project ( cwd )
package = store_read_package ( cwd )
2010-04-30 17:13:21 +02:00
2009-11-17 14:39:46 +01:00
if not project :
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
raise oscerr . WrongArgs ( ' There are no binaries to list above project level. ' )
2009-04-09 10:21:12 +02:00
if opts . revision :
raise oscerr . WrongOptions ( ' Sorry, the --revision option is not supported for binaries. ' )
2007-08-16 20:15:08 +02:00
2009-11-17 14:39:46 +01:00
repos = [ ]
if opts . repo and opts . arch :
repos . append ( Repo ( opts . repo , opts . arch ) )
elif opts . repo and not opts . arch :
2010-04-09 03:37:04 +02:00
repos = [ repo for repo in get_repos_of_project ( apiurl , project ) if repo . name == opts . repo ]
2009-11-17 14:39:46 +01:00
elif opts . arch and not opts . repo :
2010-04-09 03:37:04 +02:00
repos = [ repo for repo in get_repos_of_project ( apiurl , project ) if repo . arch == opts . arch ]
2009-11-17 14:39:46 +01:00
else :
repos = get_repos_of_project ( apiurl , project )
2009-11-04 15:31:20 +01:00
2009-11-17 14:39:46 +01:00
results = [ ]
for repo in repos :
results . append ( ( repo , get_binarylist ( apiurl , project , repo . name , repo . arch , package = package , verbose = opts . verbose ) ) )
2007-08-16 20:15:08 +02:00
2009-11-17 14:39:46 +01:00
for result in results :
indent = ' '
if len ( results ) > 1 :
2013-04-09 12:51:28 +02:00
print ( ' %s / %s ' % ( result [ 0 ] . name , result [ 0 ] . arch ) )
2009-11-17 14:39:46 +01:00
indent = ' '
2009-11-04 15:31:20 +01:00
2009-11-17 14:39:46 +01:00
if opts . verbose :
for f in result [ 1 ] :
2013-04-09 12:51:28 +02:00
print ( " %9d %s %-40s " % ( f . size , shorttime ( f . mtime ) , f . name ) )
2009-11-17 14:39:46 +01:00
else :
for f in result [ 1 ] :
2013-04-09 12:51:28 +02:00
print ( indent + f )
2007-08-16 20:15:08 +02:00
# list sources
elif not opts . binaries :
if not args :
2011-01-05 10:11:55 +01:00
for prj in meta_get_project_list ( apiurl , opts . deleted ) :
2013-04-09 12:51:28 +02:00
print ( prj )
2007-08-16 20:15:08 +02:00
elif len ( args ) == 1 :
if opts . verbose :
2009-08-20 21:28:05 +02:00
if self . options . verbose :
2013-04-09 12:51:28 +02:00
print ( ' Sorry, the --verbose option is not implemented for projects. ' , file = sys . stderr )
2014-08-11 16:59:40 +02:00
for pkg in meta_get_packagelist ( apiurl , project , deleted = opts . deleted , expand = opts . expand ) :
2013-04-09 12:51:28 +02:00
print ( pkg )
2007-08-16 20:15:08 +02:00
2008-11-20 13:56:16 +01:00
elif len ( args ) == 2 or len ( args ) == 3 :
2010-03-08 23:52:51 +01:00
link_seen = False
print_not_found = True
2010-04-09 01:22:26 +02:00
rev = opts . revision
2010-03-08 23:52:51 +01:00
for i in [ 1 , 2 ] :
2010-07-29 17:29:07 +02:00
l = meta_get_filelist ( apiurl ,
2009-05-18 16:50:43 +02:00
project ,
2007-08-16 20:15:08 +02:00
package ,
2009-03-31 00:28:26 +02:00
verbose = opts . verbose ,
2009-04-09 10:21:12 +02:00
expand = opts . expand ,
2011-06-08 10:25:15 +02:00
meta = opts . meta ,
2013-05-17 10:37:51 +02:00
deleted = opts . deleted ,
2010-04-09 01:22:26 +02:00
revision = rev )
2010-04-06 10:57:49 +02:00
link_seen = ' _link ' in l
2010-03-08 23:52:51 +01:00
if opts . verbose :
out = [ ' %s %7s %9d %s %s ' % ( i . md5 , i . rev , i . size , shorttime ( i . mtime ) , i . name ) \
2008-11-20 13:56:16 +01:00
for i in l if not fname or fname == i . name ]
2010-03-08 23:52:51 +01:00
if len ( out ) > 0 :
print_not_found = False
2013-04-09 12:51:28 +02:00
print ( ' \n ' . join ( out ) )
2010-04-09 03:37:04 +02:00
elif fname :
if fname in l :
2013-04-09 12:51:28 +02:00
print ( fname )
2010-04-09 03:37:04 +02:00
print_not_found = False
2008-11-20 13:56:16 +01:00
else :
2013-04-09 12:51:28 +02:00
print ( ' \n ' . join ( l ) )
2014-08-12 15:01:16 +02:00
if opts . expand or opts . unexpand or not link_seen :
2013-05-27 13:38:49 +02:00
break
2010-07-29 17:29:07 +02:00
m = show_files_meta ( apiurl , project , package )
2010-04-09 01:22:26 +02:00
li = Linkinfo ( )
li . read ( ET . fromstring ( ' ' . join ( m ) ) . find ( ' linkinfo ' ) )
if li . haserror ( ) :
raise oscerr . LinkExpandError ( project , package , li . error )
project , package , rev = li . project , li . package , li . rev
if rev :
2013-04-09 12:51:28 +02:00
print ( ' # -> %s %s ( %s ) ' % ( project , package , rev ) )
2010-04-09 01:22:26 +02:00
else :
2013-04-09 12:51:28 +02:00
print ( ' # -> %s %s (latest) ' % ( project , package ) )
2010-03-08 23:52:51 +01:00
opts . expand = True
if fname and print_not_found :
2013-04-09 12:51:28 +02:00
print ( ' file \' %s \' does not exist ' % fname )
2007-04-25 01:00:12 +02:00
2015-07-14 16:03:35 +02:00
@cmdln.option ( ' -s ' , ' --skip-disabled ' , action = ' store_true ' ,
help = ' Skip disabled channels. Otherwise the source gets added, but not the repositories. ' )
@cmdln.option ( ' -e ' , ' --enable-all ' , action = ' store_true ' ,
help = ' Enable all added channels including the ones disabled by default. ' )
def do_addchannels ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Add channels to project.
2016-05-15 17:50:31 +02:00
The command adds all channels which are defined to be used for a given source package .
2015-10-21 17:17:05 +02:00
The source link target is used to lookup the channels . The command can be
used for a certain package or for all in the specified project .
In case no channel is defined the operation is just returning .
2015-07-14 16:03:35 +02:00
Examples :
2015-10-21 17:17:05 +02:00
osc addchannels [ PROJECT [ PACKAGE ] ]
2015-07-14 16:03:35 +02:00
$ { cmd_option_list }
"""
apiurl = self . get_api_url ( )
2015-07-15 20:41:31 +02:00
localdir = os . getcwd ( )
2015-07-14 16:03:35 +02:00
channel = None
2015-07-15 20:41:31 +02:00
if not args :
2015-10-21 17:17:05 +02:00
if is_project_dir ( localdir ) or is_package_dir ( localdir ) :
2015-07-14 16:03:35 +02:00
project = store_read_project ( localdir )
elif is_package_dir ( localdir ) :
project = store_read_project ( localdir )
channel = store_read_package ( localdir )
2015-07-15 20:46:38 +02:00
else :
raise oscerr . WrongArgs ( ' Either specify project [package] or call it from a project/package working copy ' )
2015-07-14 16:03:35 +02:00
else :
project = args [ 0 ]
2015-07-15 20:41:31 +02:00
query = { ' cmd ' : ' addchannels ' }
2015-09-04 11:09:40 +02:00
if opts . enable_all and opts . skip_disabled :
raise oscerr . WrongOptions ( ' --enable-all and --skip-disabled options are mutually exclusive ' )
elif opts . enable_all :
2015-10-21 17:17:05 +02:00
query [ ' mode ' ] = ' enable_all '
2015-09-04 11:09:40 +02:00
elif opts . skip_disabled :
2015-10-21 17:17:05 +02:00
query [ ' mode ' ] = ' skip_disabled '
2015-09-04 11:09:40 +02:00
2015-07-14 16:03:35 +02:00
print ( " Looking for channels... " )
url = makeurl ( apiurl , [ ' source ' , project ] , query = query )
if channel :
2015-07-15 20:41:31 +02:00
url = makeurl ( apiurl , [ ' source ' , project , channel ] , query = query )
2015-07-14 16:03:35 +02:00
f = http_POST ( url )
2015-10-21 17:17:05 +02:00
@cmdln.alias ( ' enablechannel ' )
def do_enablechannels ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Enables channels
Enables existing channel packages in a project . Enabling means adding the
needed repositories for building .
The command can be used to enable a specific one or all channels of a project .
Examples :
osc enablechannels [ PROJECT [ CHANNEL_PACKAGE ] ]
$ { cmd_option_list }
"""
apiurl = self . get_api_url ( )
localdir = os . getcwd ( )
channel = None
if not args :
if is_project_dir ( localdir ) :
project = store_read_project ( localdir )
elif is_package_dir ( localdir ) :
project = store_read_project ( localdir )
channel = store_read_package ( localdir )
else :
raise oscerr . WrongArgs ( ' Either specify project [package] or call it from a project/package working copy ' )
else :
project = args [ 0 ]
if len ( args ) > 1 :
channel = args [ 1 ]
query = { }
if channel :
query [ ' cmd ' ] = ' enablechannel '
else :
query = { ' cmd ' : ' modifychannels ' , ' mode ' : ' enable_all ' }
print ( " Enable channel(s)... " )
url = makeurl ( apiurl , [ ' source ' , project ] , query = query )
if channel :
url = makeurl ( apiurl , [ ' source ' , project , channel ] , query = query )
f = http_POST ( url )
2009-11-10 10:56:34 +01:00
@cmdln.option ( ' -f ' , ' --force ' , action = ' store_true ' ,
2011-11-30 10:52:50 +01:00
help = ' force generation of new patchinfo file, do not update existing one. ' )
2009-11-10 10:56:34 +01:00
def do_patchinfo ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Generate and edit a patchinfo file.
A patchinfo file describes the packages for an update and the kind of
problem it solves .
2011-11-30 10:52:50 +01:00
This command either creates a new _patchinfo or updates an existing one .
2009-11-10 10:56:34 +01:00
Examples :
osc patchinfo
2012-01-09 11:29:11 +01:00
osc patchinfo [ PROJECT [ PATCH_NAME ] ]
2009-11-10 10:56:34 +01:00
$ { cmd_option_list }
"""
2014-08-12 15:01:16 +02:00
apiurl = self . get_api_url ( )
2009-11-10 10:56:34 +01:00
project_dir = localdir = os . getcwd ( )
2012-01-09 11:29:11 +01:00
patchinfo = ' patchinfo '
if len ( args ) == 0 :
if is_project_dir ( localdir ) :
project = store_read_project ( localdir )
apiurl = self . get_api_url ( )
for p in meta_get_packagelist ( apiurl , project ) :
if p . startswith ( " _patchinfo " ) or p . startswith ( " patchinfo " ) :
patchinfo = p
2011-11-30 10:52:50 +01:00
else :
2012-01-09 11:29:11 +01:00
if is_package_dir ( localdir ) :
2013-05-27 12:16:44 +02:00
project = store_read_project ( localdir )
patchinfo = store_read_package ( localdir )
apiurl = self . get_api_url ( )
if not os . path . exists ( ' _patchinfo ' ) :
2012-03-23 09:37:08 +01:00
sys . exit ( ' Current checked out package has no _patchinfo. Either call it from project level or specify patch name. ' )
2012-01-09 11:29:11 +01:00
else :
2013-05-27 12:16:44 +02:00
sys . exit ( ' This command must be called in a checked out project or patchinfo package. ' )
2012-01-09 11:29:11 +01:00
else :
project = args [ 0 ]
if len ( args ) > 1 :
patchinfo = args [ 1 ]
2010-02-28 02:30:13 +01:00
2011-12-16 15:29:54 +01:00
filelist = None
if patchinfo :
2012-01-09 11:29:11 +01:00
try :
filelist = meta_get_filelist ( apiurl , project , patchinfo )
2013-04-09 14:03:17 +02:00
except HTTPError :
2012-01-09 11:29:11 +01:00
pass
if opts . force or not filelist or not ' _patchinfo ' in filelist :
2013-04-09 12:51:28 +02:00
print ( " Creating new patchinfo... " )
2013-05-27 12:41:50 +02:00
query = ' cmd=createpatchinfo&name= ' + patchinfo
2011-12-16 15:29:54 +01:00
if opts . force :
query + = " &force=1 "
2009-11-10 10:56:34 +01:00
url = makeurl ( apiurl , [ ' source ' , project ] , query = query )
f = http_POST ( url )
2010-02-24 20:02:52 +01:00
for p in meta_get_packagelist ( apiurl , project ) :
2011-03-11 11:07:35 +01:00
if p . startswith ( " _patchinfo " ) or p . startswith ( " patchinfo " ) :
2010-02-24 20:02:52 +01:00
patchinfo = p
2011-11-30 10:52:50 +01:00
else :
2013-04-09 12:51:28 +02:00
print ( " Update existing _patchinfo file... " )
2013-05-27 12:41:50 +02:00
query = ' cmd=updatepatchinfo '
2011-11-30 10:52:50 +01:00
url = makeurl ( apiurl , [ ' source ' , project , patchinfo ] , query = query )
f = http_POST ( url )
2009-11-10 10:56:34 +01:00
2010-12-27 23:03:17 +01:00
# CAUTION:
2014-08-12 15:01:16 +02:00
# Both conf.config['checkout_no_colon'] and conf.config['checkout_rooted']
2010-12-27 23:03:17 +01:00
# fool this test:
2011-11-30 10:52:50 +01:00
if is_package_dir ( localdir ) :
pac = Package ( localdir )
pac . update ( )
filename = " _patchinfo "
else :
2009-11-10 10:56:34 +01:00
checkout_package ( apiurl , project , patchinfo , prj_dir = project_dir )
2011-11-30 10:52:50 +01:00
filename = project_dir + " / " + patchinfo + " /_patchinfo "
2009-11-10 10:56:34 +01:00
2010-05-05 09:03:51 +02:00
run_editor ( filename )
2009-11-10 10:56:34 +01:00
2011-03-08 19:23:04 +01:00
@cmdln.alias ( ' bsdevelproject ' )
2013-10-07 13:12:58 +02:00
@cmdln.alias ( ' dp ' )
@cmdln.option ( ' -r ' , ' --raw ' , action = ' store_true ' , help = ' deprecated option ' )
2011-03-08 19:23:04 +01:00
def do_develproject ( self , subcmd , opts , * args ) :
2013-10-07 13:12:58 +02:00
""" $ {cmd_name} : print the devel project / package of a package
2011-03-08 19:23:04 +01:00
Examples :
osc develproject PRJ PKG
osc develproject
$ { cmd_option_list }
"""
args = slash_split ( args )
apiurl = self . get_api_url ( )
2011-03-08 19:47:54 +01:00
if len ( args ) == 0 :
project = store_read_project ( os . curdir )
package = store_read_package ( os . curdir )
elif len ( args ) == 2 :
project = args [ 0 ]
package = args [ 1 ]
else :
raise oscerr . WrongArgs ( ' need Project and Package ' )
2013-10-07 13:12:58 +02:00
devprj , devpkg = show_devel_project ( apiurl , project , package )
if devprj is None :
print ( ' %s / %s has no devel project ' % ( project , package ) )
elif devpkg and devpkg != package :
print ( " %s %s " % ( devprj , devpkg ) )
2011-03-08 19:23:04 +01:00
else :
2013-10-07 13:12:58 +02:00
print ( devprj )
@cmdln.alias ( ' sdp ' )
2013-10-18 11:50:07 +02:00
@cmdln.option ( ' -u ' , ' --unset ' , action = ' store_true ' ,
help = ' remove devel project ' )
2013-10-07 13:12:58 +02:00
def do_setdevelproject ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Set the devel project / package of a package
Examples :
osc setdevelproject [ PRJ PKG ] DEVPRJ [ DEVPKG ]
$ { cmd_option_list }
"""
args = slash_split ( args )
apiurl = self . get_api_url ( )
devprj , devpkg = None , None
if len ( args ) == 3 or len ( args ) == 4 :
project , package = args [ 0 ] , args [ 1 ]
devprj = args [ 2 ]
if len ( args ) == 4 :
devpkg = args [ 3 ]
elif len ( args ) > = 1 and len ( args ) < = 2 :
project , package = store_read_project ( os . curdir ) , store_read_package ( os . curdir )
devprj = args [ 0 ]
if len ( args ) == 2 :
devpkg = args [ 1 ]
else :
2013-10-18 11:50:07 +02:00
if opts . unset :
project , package = store_read_project ( os . curdir ) , store_read_package ( os . curdir )
else :
raise oscerr . WrongArgs ( ' need at least DEVPRJ (and possibly DEVPKG) ' )
2013-10-07 13:12:58 +02:00
set_devel_project ( apiurl , project , package , devprj , devpkg )
2011-03-08 19:23:04 +01:00
2009-11-10 10:56:34 +01:00
2013-10-31 09:12:17 +01:00
@cmdln.option ( ' -c ' , ' --create ' , action = ' store_true ' ,
help = ' Create a new token ' )
@cmdln.option ( ' -d ' , ' --delete ' , metavar = ' TOKENID ' ,
help = ' Create a new token ' )
2013-11-13 18:23:44 +01:00
@cmdln.option ( ' -t ' , ' --trigger ' , metavar = ' TOKENID ' ,
help = ' Trigger the action of a token ' )
2013-10-31 09:12:17 +01:00
def do_token ( self , subcmd , opts , * args ) :
2013-12-09 19:26:15 +01:00
""" $ {cmd_name} : Show and manage authentication token
2013-10-31 09:12:17 +01:00
2013-12-09 19:26:15 +01:00
Authentication token can be used to run specific commands without
2013-10-31 09:12:17 +01:00
sending credentials .
Usage :
osc token
osc token - - create [ < PROJECT > < PACKAGE > ]
osc token - - delete < TOKENID >
2013-11-13 18:23:44 +01:00
osc token - - trigger < TOKENID >
2013-10-31 09:12:17 +01:00
$ { cmd_option_list }
"""
args = slash_split ( args )
apiurl = self . get_api_url ( )
url = apiurl + " /person/ " + conf . get_apiurl_usr ( apiurl ) + " /token "
if opts . create :
print ( " Create a new token " )
url + = " ?cmd=create "
if len ( args ) > 1 :
url + = " &project= " + args [ 0 ]
url + = " &package= " + args [ 1 ]
f = http_POST ( url )
while True :
buf = f . read ( 16384 )
if not buf :
break
sys . stdout . write ( buf )
elif opts . delete :
print ( " Delete token " )
url + = " / " + opts . delete
http_DELETE ( url )
2013-11-13 18:23:44 +01:00
elif opts . trigger :
print ( " Trigger token " )
url = apiurl + " /trigger/runservice "
req = URLRequest ( url )
req . get_method = lambda : " POST "
req . add_header ( ' Content-Type ' , ' application/octet-stream ' )
req . add_header ( ' Authorization ' , " Token " + opts . trigger )
fd = urlopen ( req , data = None )
print ( fd . read ( ) )
2013-10-31 09:12:17 +01:00
else :
# just list token
for data in streamfile ( url , http_GET ) :
sys . stdout . write ( data )
2009-10-30 10:40:46 +01:00
@cmdln.option ( ' -a ' , ' --attribute ' , metavar = ' ATTRIBUTE ' ,
help = ' affect only a given attribute ' )
2009-10-30 11:18:44 +01:00
@cmdln.option ( ' --attribute-defaults ' , action = ' store_true ' ,
help = ' include defined attribute defaults ' )
@cmdln.option ( ' --attribute-project ' , action = ' store_true ' ,
help = ' include project values, if missing in packages ' )
2011-03-16 10:20:38 +01:00
@cmdln.option ( ' -f ' , ' --force ' , action = ' store_true ' ,
2011-04-28 11:14:38 +02:00
help = ' force the save operation, allows one to ignores some errors like depending repositories. For prj meta only. ' )
2007-07-13 18:01:02 +02:00
@cmdln.option ( ' -F ' , ' --file ' , metavar = ' FILE ' ,
2007-07-16 12:58:11 +02:00
help = ' read metadata from FILE, instead of opening an editor. '
' \' - \' denotes standard input. ' )
2016-06-01 14:00:37 +02:00
@cmdln.option ( ' -r ' , ' --revision ' , metavar = ' REV ' ,
help = ' checkout given revision instead of head revision. For prj and prjconf meta only ' )
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify log message TEXT. For prj and prjconf meta only ' )
2007-07-16 18:20:09 +02:00
@cmdln.option ( ' -e ' , ' --edit ' , action = ' store_true ' ,
help = ' edit metadata ' )
2009-10-30 10:40:46 +01:00
@cmdln.option ( ' -c ' , ' --create ' , action = ' store_true ' ,
help = ' create attribute without values ' )
2012-12-06 14:07:02 +01:00
@cmdln.option ( ' -R ' , ' --remove-linking-repositories ' , action = ' store_true ' ,
help = ' Try to remove also all repositories building against remove ones. ' )
2009-10-30 10:40:46 +01:00
@cmdln.option ( ' -s ' , ' --set ' , metavar = ' ATTRIBUTE_VALUES ' ,
help = ' set attribute values ' )
2007-07-19 14:23:42 +02:00
@cmdln.option ( ' --delete ' , action = ' store_true ' ,
2009-10-30 10:40:46 +01:00
help = ' delete a pattern or attribute ' )
2007-04-25 01:00:12 +02:00
def do_meta ( self , subcmd , opts , * args ) :
2007-07-13 18:01:02 +02:00
""" $ {cmd_name} : Show meta information, or edit it
2006-09-15 12:53:44 +02:00
2007-07-19 12:08:42 +02:00
Show or edit build service metadata of type < prj | pkg | prjconf | user | pattern > .
2007-07-16 12:58:11 +02:00
This command displays metadata on buildservice objects like projects ,
packages , or users . The type of metadata is specified by the word after
" meta " , like e . g . " meta prj " .
2007-07-16 15:40:58 +02:00
prj denotes metadata of a buildservice project .
prjconf denotes the ( build ) configuration of a project .
pkg denotes metadata of a buildservice package .
user denotes the metadata of a user .
2007-07-19 12:14:10 +02:00
pattern denotes installation patterns defined for a project .
To list patterns , use ' osc meta pattern PRJ ' . An additional argument
will be the pattern file to view or edit .
2007-07-16 15:40:58 +02:00
2007-07-16 12:58:11 +02:00
With the - - edit switch , the metadata can be edited . Per default , osc
opens the program specified by the environmental variable EDITOR with a
temporary file . Alternatively , content to be saved can be supplied via
2007-07-16 18:20:09 +02:00
the - - file switch . If the argument is ' - ' , input is taken from stdin :
2009-03-02 15:03:06 +01:00
osc meta prjconf home : user | sed . . . | osc meta prjconf home : user - F -
2007-07-16 12:58:11 +02:00
2016-06-01 14:00:37 +02:00
For meta prj and prjconf updates optional commit messages can be applied with - - message .
2009-05-27 14:09:50 +02:00
When trying to edit a non - existing resource , it is created implicitly .
2006-09-15 12:53:44 +02:00
2007-08-09 18:15:13 +02:00
Examples :
osc meta prj PRJ
osc meta pkg PRJ PKG
osc meta pkg PRJ PKG - e
Usage :
2016-06-01 14:00:37 +02:00
osc meta < prj | prjconf > [ - r | - - revision REV ] ARGS . . .
2014-10-27 01:31:47 +01:00
osc meta < prj | pkg | prjconf | user | pattern > ARGS . . .
2016-06-01 14:00:37 +02:00
osc meta < prj | pkg | prjconf | user | pattern > [ - m | - - message TEXT ] - e | - - edit ARGS . . .
osc meta < prj | pkg | prjconf | user | pattern > [ - m | - - message TEXT ] - F | - - file ARGS . . .
2007-07-19 14:23:42 +02:00
osc meta pattern - - delete PRJ PATTERN
2014-10-27 01:31:47 +01:00
osc meta attribute PRJ [ PKG [ SUBPACKAGE ] ] [ - - attribute ATTRIBUTE ] [ - - create | - - delete | - - set [ value_list ] ]
2007-04-25 01:00:12 +02:00
$ { cmd_option_list }
"""
2006-05-23 17:27:43 +02:00
2007-07-13 18:01:02 +02:00
args = slash_split ( args )
2006-05-23 17:27:43 +02:00
2007-07-13 18:01:02 +02:00
if not args or args [ 0 ] not in metatypes . keys ( ) :
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
raise oscerr . WrongArgs ( ' Unknown meta type. Choose one of %s . ' \
% ' , ' . join ( metatypes ) )
2006-10-12 15:22:56 +02:00
2007-07-13 18:01:02 +02:00
cmd = args [ 0 ]
del args [ 0 ]
2007-06-26 15:17:38 +02:00
2007-07-19 12:08:42 +02:00
if cmd in [ ' pkg ' ] :
2010-04-28 10:52:32 +02:00
min_args , max_args = 0 , 2
2007-07-19 12:08:42 +02:00
elif cmd in [ ' pattern ' ] :
min_args , max_args = 1 , 2
2009-10-30 10:40:46 +01:00
elif cmd in [ ' attribute ' ] :
min_args , max_args = 1 , 3
2010-04-28 10:52:32 +02:00
elif cmd in [ ' prj ' , ' prjconf ' ] :
min_args , max_args = 0 , 1
2007-07-13 18:01:02 +02:00
else :
2007-07-19 12:08:42 +02:00
min_args , max_args = 1 , 1
2010-04-28 10:52:32 +02:00
2007-07-19 12:08:42 +02:00
if len ( args ) < min_args :
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
raise oscerr . WrongArgs ( ' Too few arguments. ' )
2007-07-19 12:08:42 +02:00
if len ( args ) > max_args :
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
raise oscerr . WrongArgs ( ' Too many arguments. ' )
2006-10-12 15:22:56 +02:00
2012-04-02 13:38:06 +02:00
apiurl = self . get_api_url ( )
2014-01-10 13:04:45 +01:00
# Specific arguments
#
# If project or package arguments missing, assume to work
# with project and/or package in current local directory.
2009-10-30 10:40:46 +01:00
attributepath = [ ]
2014-01-10 13:04:45 +01:00
if cmd in [ ' prj ' , ' prjconf ' ] :
if len ( args ) < 1 :
apiurl = store_read_apiurl ( os . curdir )
2010-05-05 09:03:51 +02:00
project = store_read_project ( os . curdir )
else :
project = args [ 0 ]
2014-01-10 13:04:45 +01:00
elif cmd == ' pkg ' :
if len ( args ) < 2 :
apiurl = store_read_apiurl ( os . curdir )
project = store_read_project ( os . curdir )
if len ( args ) < 1 :
2010-05-05 09:03:51 +02:00
package = store_read_package ( os . curdir )
else :
2014-01-10 13:04:45 +01:00
package = args [ 0 ]
else :
project = args [ 0 ]
package = args [ 1 ]
2010-04-28 10:52:32 +02:00
2009-10-30 10:40:46 +01:00
elif cmd == ' attribute ' :
project = args [ 0 ]
if len ( args ) > 1 :
2009-12-30 15:10:11 +01:00
package = args [ 1 ]
2009-10-30 10:40:46 +01:00
else :
2009-12-30 15:10:11 +01:00
package = None
if opts . attribute_project :
raise oscerr . WrongOptions ( ' --attribute-project works only when also a package is given ' )
2009-10-30 10:40:46 +01:00
if len ( args ) > 2 :
2009-12-30 15:10:11 +01:00
subpackage = args [ 2 ]
2009-10-30 10:40:46 +01:00
else :
2009-12-30 15:10:11 +01:00
subpackage = None
2009-10-30 10:40:46 +01:00
attributepath . append ( ' source ' )
attributepath . append ( project )
if package :
2009-12-30 15:10:11 +01:00
attributepath . append ( package )
2009-10-30 10:40:46 +01:00
if subpackage :
2009-12-30 15:10:11 +01:00
attributepath . append ( subpackage )
2009-10-30 10:40:46 +01:00
attributepath . append ( ' _attribute ' )
2007-07-13 18:01:02 +02:00
elif cmd == ' user ' :
2007-04-25 01:00:12 +02:00
user = args [ 0 ]
2007-07-19 12:08:42 +02:00
elif cmd == ' pattern ' :
project = args [ 0 ]
if len ( args ) > 1 :
pattern = args [ 1 ]
else :
pattern = None
2007-07-19 13:54:13 +02:00
# enforce pattern argument if needed
if opts . edit or opts . file :
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
raise oscerr . WrongArgs ( ' A pattern file argument is required. ' )
2007-07-16 18:20:09 +02:00
2016-06-01 14:00:37 +02:00
if cmd not in [ ' prj ' , ' prjconf ' ] and ( opts . message or opts . revision ) :
raise oscerr . WrongOptions ( ' options --revision and --message are only supported for the prj or prjconf subcommand ' )
2009-05-18 16:50:43 +02:00
# show
2009-10-30 10:40:46 +01:00
if not opts . edit and not opts . file and not opts . delete and not opts . create and not opts . set :
2007-07-16 18:20:09 +02:00
if cmd == ' prj ' :
2016-06-01 14:00:37 +02:00
sys . stdout . write ( ' ' . join ( show_project_meta ( apiurl , project , opts . revision ) ) )
2007-07-16 18:20:09 +02:00
elif cmd == ' pkg ' :
2010-06-18 16:06:01 +02:00
sys . stdout . write ( ' ' . join ( show_package_meta ( apiurl , project , package ) ) )
2009-10-30 10:40:46 +01:00
elif cmd == ' attribute ' :
2014-08-12 15:01:16 +02:00
sys . stdout . write ( ' ' . join ( show_attribute_meta ( apiurl , project , package , subpackage ,
2013-05-27 13:03:46 +02:00
opts . attribute , opts . attribute_defaults , opts . attribute_project ) ) )
2007-07-16 18:20:09 +02:00
elif cmd == ' prjconf ' :
2016-06-01 14:00:37 +02:00
sys . stdout . write ( ' ' . join ( show_project_conf ( apiurl , project , opts . revision ) ) )
2007-07-16 18:20:09 +02:00
elif cmd == ' user ' :
2010-06-18 16:06:01 +02:00
r = get_user_meta ( apiurl , user )
2007-07-13 18:01:02 +02:00
if r :
sys . stdout . write ( ' ' . join ( r ) )
2007-07-19 12:08:42 +02:00
elif cmd == ' pattern ' :
if pattern :
2010-06-18 16:06:01 +02:00
r = show_pattern_meta ( apiurl , project , pattern )
2007-07-19 12:08:42 +02:00
if r :
sys . stdout . write ( ' ' . join ( r ) )
else :
2010-06-18 16:06:01 +02:00
r = show_pattern_metalist ( apiurl , project )
2007-07-19 12:08:42 +02:00
if r :
sys . stdout . write ( ' \n ' . join ( r ) + ' \n ' )
2007-07-16 18:20:09 +02:00
# edit
if opts . edit and not opts . file :
if cmd == ' prj ' :
2009-05-18 16:50:43 +02:00
edit_meta ( metatype = ' prj ' ,
2007-07-16 18:20:09 +02:00
edit = True ,
2011-03-16 10:20:38 +01:00
force = opts . force ,
2012-12-06 14:07:02 +01:00
remove_linking_repositories = opts . remove_linking_repositories ,
2007-07-16 18:20:09 +02:00
path_args = quote_plus ( project ) ,
2010-06-18 16:06:01 +02:00
apiurl = apiurl ,
2016-06-01 14:00:37 +02:00
msg = opts . message ,
2008-03-07 10:13:30 +01:00
template_args = ( {
' name ' : project ,
2010-08-20 13:25:32 +02:00
' user ' : conf . get_apiurl_usr ( apiurl ) } ) )
2007-07-16 18:20:09 +02:00
elif cmd == ' pkg ' :
2009-05-18 16:50:43 +02:00
edit_meta ( metatype = ' pkg ' ,
2007-07-16 18:20:09 +02:00
edit = True ,
path_args = ( quote_plus ( project ) , quote_plus ( package ) ) ,
2010-06-18 16:06:01 +02:00
apiurl = apiurl ,
2008-03-07 10:13:30 +01:00
template_args = ( {
' name ' : package ,
2010-08-20 13:25:32 +02:00
' user ' : conf . get_apiurl_usr ( apiurl ) } ) )
2007-07-16 18:20:09 +02:00
elif cmd == ' prjconf ' :
2009-05-18 16:50:43 +02:00
edit_meta ( metatype = ' prjconf ' ,
2007-07-16 18:20:09 +02:00
edit = True ,
path_args = quote_plus ( project ) ,
2010-06-18 16:06:01 +02:00
apiurl = apiurl ,
2016-06-01 14:00:37 +02:00
msg = opts . message ,
2007-07-16 18:20:09 +02:00
template_args = None )
elif cmd == ' user ' :
2009-05-18 16:50:43 +02:00
edit_meta ( metatype = ' user ' ,
2007-07-16 18:20:09 +02:00
edit = True ,
path_args = ( quote_plus ( user ) ) ,
2010-06-18 16:06:01 +02:00
apiurl = apiurl ,
2008-03-07 10:13:30 +01:00
template_args = ( { ' user ' : user } ) )
2007-07-19 12:08:42 +02:00
elif cmd == ' pattern ' :
2009-05-18 16:50:43 +02:00
edit_meta ( metatype = ' pattern ' ,
2007-07-19 12:08:42 +02:00
edit = True ,
path_args = ( project , pattern ) ,
2010-06-18 16:06:01 +02:00
apiurl = apiurl ,
2007-07-19 12:08:42 +02:00
template_args = None )
2007-07-16 18:20:09 +02:00
2009-10-30 10:40:46 +01:00
# create attribute entry
2009-12-30 15:10:11 +01:00
if ( opts . create or opts . set ) and cmd == ' attribute ' :
if not opts . attribute :
raise oscerr . WrongOptions ( ' no attribute given to create ' )
values = ' '
if opts . set :
opts . set = opts . set . replace ( ' & ' , ' & ' ) . replace ( ' < ' , ' < ' ) . replace ( ' > ' , ' > ' )
for i in opts . set . split ( ' , ' ) :
values + = ' <value> %s </value> ' % i
2010-01-21 10:31:53 +01:00
aname = opts . attribute . split ( " : " )
2012-02-21 12:41:06 +01:00
if len ( aname ) != 2 :
raise oscerr . WrongOptions ( ' Given attribute is not in " NAMESPACE:NAME " style ' )
2010-01-21 10:31:53 +01:00
d = ' <attributes><attribute namespace= \' %s \' name= \' %s \' > %s </attribute></attributes> ' % ( aname [ 0 ] , aname [ 1 ] , values )
2010-06-18 16:06:01 +02:00
url = makeurl ( apiurl , attributepath )
2009-12-30 15:10:11 +01:00
for data in streamfile ( url , http_POST , data = d ) :
sys . stdout . write ( data )
2009-10-30 10:40:46 +01:00
2007-07-16 18:20:09 +02:00
# upload file
if opts . file :
if opts . file == ' - ' :
f = sys . stdin . read ( )
2007-07-13 18:01:02 +02:00
else :
2007-07-16 18:20:09 +02:00
try :
f = open ( opts . file ) . read ( )
except :
sys . exit ( ' could not open file \' %s \' . ' % opts . file )
if cmd == ' prj ' :
2009-05-18 16:50:43 +02:00
edit_meta ( metatype = ' prj ' ,
2007-07-16 18:20:09 +02:00
data = f ,
edit = opts . edit ,
2011-03-16 10:20:38 +01:00
force = opts . force ,
2012-12-06 14:07:02 +01:00
remove_linking_repositories = opts . remove_linking_repositories ,
2010-06-18 16:06:01 +02:00
apiurl = apiurl ,
2016-06-01 14:00:37 +02:00
msg = opts . message ,
2007-07-16 18:20:09 +02:00
path_args = quote_plus ( project ) )
elif cmd == ' pkg ' :
2009-05-18 16:50:43 +02:00
edit_meta ( metatype = ' pkg ' ,
2007-07-16 18:20:09 +02:00
data = f ,
edit = opts . edit ,
2010-06-18 16:06:01 +02:00
apiurl = apiurl ,
2007-07-16 18:20:09 +02:00
path_args = ( quote_plus ( project ) , quote_plus ( package ) ) )
elif cmd == ' prjconf ' :
2009-05-18 16:50:43 +02:00
edit_meta ( metatype = ' prjconf ' ,
2007-07-16 18:20:09 +02:00
data = f ,
edit = opts . edit ,
2010-06-18 16:06:01 +02:00
apiurl = apiurl ,
2016-06-01 14:00:37 +02:00
msg = opts . message ,
2007-07-16 18:20:09 +02:00
path_args = quote_plus ( project ) )
elif cmd == ' user ' :
2009-05-18 16:50:43 +02:00
edit_meta ( metatype = ' user ' ,
2007-07-16 18:20:09 +02:00
data = f ,
edit = opts . edit ,
2010-06-18 16:06:01 +02:00
apiurl = apiurl ,
2007-07-16 18:20:09 +02:00
path_args = ( quote_plus ( user ) ) )
2007-07-19 12:08:42 +02:00
elif cmd == ' pattern ' :
2009-05-18 16:50:43 +02:00
edit_meta ( metatype = ' pattern ' ,
2007-07-19 12:08:42 +02:00
data = f ,
edit = opts . edit ,
2010-06-18 16:06:01 +02:00
apiurl = apiurl ,
2007-07-19 12:08:42 +02:00
path_args = ( project , pattern ) )
2007-07-16 18:20:09 +02:00
2007-07-13 18:01:02 +02:00
2007-07-19 14:23:42 +02:00
# delete
if opts . delete :
path = metatypes [ cmd ] [ ' path ' ]
if cmd == ' pattern ' :
path = path % ( project , pattern )
2010-06-18 16:06:01 +02:00
u = makeurl ( apiurl , [ path ] )
2008-04-10 23:04:17 +02:00
http_DELETE ( u )
2009-10-30 10:40:46 +01:00
elif cmd == ' attribute ' :
if not opts . attribute :
2009-12-30 15:10:11 +01:00
raise oscerr . WrongOptions ( ' no attribute given to create ' )
2009-10-30 10:40:46 +01:00
attributepath . append ( opts . attribute )
2010-06-18 16:06:01 +02:00
u = makeurl ( apiurl , attributepath )
2009-12-30 15:10:11 +01:00
for data in streamfile ( u , http_DELETE ) :
sys . stdout . write ( data )
2007-07-19 14:23:42 +02:00
else :
2009-12-30 15:10:11 +01:00
raise oscerr . WrongOptions ( ' The --delete switch is only for pattern metadata or attributes. ' )
2007-07-19 14:23:42 +02:00
2010-12-30 03:14:24 +01:00
# TODO: rewrite and consolidate the current submitrequest/createrequest "mess"
2008-03-05 00:41:00 +01:00
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify message TEXT ' )
2008-03-13 00:37:35 +01:00
@cmdln.option ( ' -r ' , ' --revision ' , metavar = ' REV ' ,
2010-08-31 18:42:52 +02:00
help = ' specify a certain source revision ID (the md5 sum) for the source package ' )
2009-11-17 17:59:17 +01:00
@cmdln.option ( ' -s ' , ' --supersede ' , metavar = ' SUPERSEDE ' ,
help = ' Superseding another request by this one ' )
2008-06-03 17:01:01 +02:00
@cmdln.option ( ' --nodevelproject ' , action = ' store_true ' ,
help = ' do not follow a defined devel project ' \
' (primary project where a package is developed) ' )
2016-08-16 17:40:34 +02:00
@cmdln.option ( ' --separate-requests ' , action = ' store_true ' ,
help = ' Create multiple requests instead of a single one (when command is used for entire project) ' )
2016-08-17 01:43:19 +02:00
@cmdln.option ( ' --seperate-requests ' , action = ' store_true ' ,
help = ' Deprecated (wrong spelling - see --separate-requests) ' )
2009-09-05 15:46:55 +02:00
@cmdln.option ( ' --cleanup ' , action = ' store_true ' ,
help = ' remove package if submission gets accepted (default for home:<id>:branch projects) ' )
@cmdln.option ( ' --no-cleanup ' , action = ' store_true ' ,
help = ' never remove source package on accept, but update its content ' )
@cmdln.option ( ' --no-update ' , action = ' store_true ' ,
help = ' never touch source package on accept (will break source links) ' )
2015-03-09 08:44:12 +01:00
@cmdln.option ( ' --update-link ' , action = ' store_true ' ,
help = ' This transfers the source including the _link file. ' )
2009-08-28 09:33:16 +02:00
@cmdln.option ( ' -d ' , ' --diff ' , action = ' store_true ' ,
help = ' show diff only instead of creating the actual request ' )
2009-11-13 09:58:37 +01:00
@cmdln.option ( ' --yes ' , action = ' store_true ' ,
help = ' proceed without asking. ' )
2008-07-09 22:38:49 +02:00
@cmdln.alias ( " sr " )
2009-06-02 16:57:42 +02:00
@cmdln.alias ( " submitreq " )
2009-08-20 21:28:05 +02:00
@cmdln.alias ( " submitpac " )
2009-06-02 16:57:42 +02:00
def do_submitrequest ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Create request to submit source into another Project
2008-03-05 00:41:00 +01:00
2010-07-27 15:20:35 +02:00
[ See http : / / en . opensuse . org / openSUSE : Build_Service_Collaboration for information
2008-06-06 14:04:34 +02:00
on this topic . ]
2009-06-02 16:57:42 +02:00
See the " request " command for showing and modifing existing requests .
2009-06-02 15:14:46 +02:00
2009-06-02 16:57:42 +02:00
usage :
2009-07-13 11:36:19 +02:00
osc submitreq [ OPTIONS ]
osc submitreq [ OPTIONS ] DESTPRJ [ DESTPKG ]
osc submitreq [ OPTIONS ] SOURCEPRJ SOURCEPKG DESTPRJ [ DESTPKG ]
2010-11-26 12:39:09 +01:00
osc submitpac . . . is a shorthand for osc submitreq - - cleanup . . .
2009-06-02 16:57:42 +02:00
$ { cmd_option_list }
2009-06-02 15:14:46 +02:00
"""
2017-01-31 23:35:43 +01:00
def _check_service ( root ) :
serviceinfo = root . find ( ' serviceinfo ' )
if serviceinfo is not None :
# code "running" is ok, because the api will choke when trying
# to create the sr (if it is still running)
if serviceinfo . get ( ' code ' ) not in ( ' running ' , ' succeeded ' ) :
print ( ' A service run for package %s %s : '
% ( root . get ( ' name ' ) , serviceinfo . get ( ' code ' ) ) ,
file = sys . stderr )
error = serviceinfo . find ( ' error ' )
if error is not None :
print ( ' \n ' . join ( error . text . split ( ' \\ n ' ) ) )
sys . exit ( ' \n Please fix this first ' )
2009-06-02 15:14:46 +02:00
2010-11-26 14:53:30 +01:00
if opts . cleanup and opts . no_cleanup :
raise oscerr . WrongOptions ( ' \' --cleanup \' and \' --no-cleanup \' are mutually exclusive ' )
2016-08-17 01:43:19 +02:00
if opts . seperate_requests :
# compatibility option will be removed in the future
print ( ' --seperate-requests is deprecated (use '
' --separate-requests) ' , file = sys . stderr )
2010-11-26 14:53:30 +01:00
2009-12-19 14:44:51 +01:00
src_update = conf . config [ ' submitrequest_on_accept_action ' ] or None
2009-09-05 15:46:55 +02:00
# we should check here for home:<id>:branch and default to update, but that would require OBS 1.7 server
2010-11-26 12:39:09 +01:00
2010-11-26 14:51:07 +01:00
if subcmd == ' submitpac ' and not opts . no_cleanup :
2013-05-27 12:18:43 +02:00
opts . cleanup = True
2010-11-26 12:39:09 +01:00
2009-09-05 15:46:55 +02:00
if opts . cleanup :
2009-10-20 16:30:15 +02:00
src_update = " cleanup "
2009-09-05 15:46:55 +02:00
elif opts . no_cleanup :
2009-10-20 16:30:15 +02:00
src_update = " update "
2009-09-05 15:46:55 +02:00
elif opts . no_update :
2009-10-20 16:30:15 +02:00
src_update = " noupdate "
2009-09-05 15:46:55 +02:00
2013-01-31 16:03:16 +01:00
myreqs = [ ]
if opts . supersede :
myreqs = [ opts . supersede ]
2009-06-02 16:57:42 +02:00
args = slash_split ( args )
2009-06-02 15:14:46 +02:00
2009-06-05 07:46:20 +02:00
# remove this block later again
oldcmds = [ ' create ' , ' list ' , ' log ' , ' show ' , ' decline ' , ' accept ' , ' delete ' , ' revoke ' ]
if args and args [ 0 ] in oldcmds :
2013-04-09 12:51:28 +02:00
print ( " ************************************************************************ " , file = sys . stderr )
print ( " * WARNING: It looks that you are using this command with a * " , file = sys . stderr )
print ( " * deprecated syntax. * " , file = sys . stderr )
print ( " * Please run \" osc sr --help \" and \" osc rq --help \" * " , file = sys . stderr )
print ( " * to see the new syntax. * " , file = sys . stderr )
print ( " ************************************************************************ " , file = sys . stderr )
2009-06-05 23:45:29 +02:00
if args [ 0 ] == ' create ' :
args . pop ( 0 )
else :
sys . exit ( 1 )
2009-06-05 07:46:20 +02:00
2009-06-02 16:57:42 +02:00
if len ( args ) > 4 :
2009-06-02 15:14:46 +02:00
raise oscerr . WrongArgs ( ' Too many arguments. ' )
2013-01-31 16:03:16 +01:00
if len ( args ) == 2 and is_project_dir ( os . getcwd ( ) ) :
sys . exit ( ' You can not specify a target package when submitting an entire project \n ' )
2009-11-13 09:58:37 +01:00
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2009-11-16 10:42:58 +01:00
2013-01-31 16:03:16 +01:00
if len ( args ) < 2 and is_project_dir ( os . getcwd ( ) ) :
2013-05-02 22:18:14 +02:00
if opts . diff :
raise oscerr . WrongOptions ( ' \' --diff \' is not supported in a project working copy ' )
2009-11-13 09:58:37 +01:00
import cgi
2009-12-21 23:47:25 +01:00
project = store_read_project ( os . curdir )
2009-11-13 09:58:37 +01:00
sr_ids = [ ]
2013-01-31 16:03:16 +01:00
# for single request
actionxml = " "
2015-03-09 08:44:12 +01:00
options_block = " <options> "
2013-01-31 16:03:16 +01:00
if src_update :
2015-03-09 08:44:12 +01:00
options_block + = """ <sourceupdate> %s </sourceupdate> """ % ( src_update )
if opts . update_link :
options_block + """ <updatelink>true</updatelink></options> """
options_block + = " </options> "
2013-01-31 16:03:16 +01:00
2009-11-13 09:58:37 +01:00
# loop via all packages for checking their state
2009-12-21 23:47:25 +01:00
for p in meta_get_packagelist ( apiurl , project ) :
2013-01-31 16:03:16 +01:00
# get _link info from server, that knows about the local state ...
u = makeurl ( apiurl , [ ' source ' , project , p ] )
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
2013-02-14 15:36:04 +01:00
target_project = None
2013-01-31 16:03:16 +01:00
if len ( args ) == 1 :
target_project = args [ 0 ]
linkinfo = root . find ( ' linkinfo ' )
if linkinfo == None :
if len ( args ) < 1 :
2013-04-09 12:51:28 +02:00
print ( " Package " , p , " is not a source link and no target specified. " )
2010-02-24 20:02:52 +01:00
sys . exit ( " This is currently not supported. " )
2013-01-31 16:03:16 +01:00
else :
2010-02-24 20:02:52 +01:00
if linkinfo . get ( ' error ' ) :
2013-04-09 12:51:28 +02:00
print ( " Package " , p , " is a broken source link. " )
2010-02-24 20:02:52 +01:00
sys . exit ( " Please fix this first " )
t = linkinfo . get ( ' project ' )
if t :
2013-01-31 16:03:16 +01:00
if target_project == None :
target_project = t
2010-02-24 20:02:52 +01:00
if len ( root . findall ( ' entry ' ) ) > 1 : # This is not really correct, but should work mostly
# Real fix is to ask the api if sources are modificated
# but there is no such call yet.
2013-04-09 12:51:28 +02:00
print ( " Submitting package " , p )
2010-02-24 20:02:52 +01:00
else :
2013-04-09 12:51:28 +02:00
print ( " Skipping not modified package " , p )
2014-04-28 15:09:29 +02:00
continue
2010-02-24 20:02:52 +01:00
else :
2013-04-09 12:51:28 +02:00
print ( " Skipping package " , p , " since it is a source link pointing inside the project. " )
2014-04-28 15:09:29 +02:00
continue
2009-11-13 09:58:37 +01:00
2017-01-31 23:35:43 +01:00
# check for failed source service
_check_service ( root )
2009-11-13 09:58:37 +01:00
2013-01-31 16:03:16 +01:00
# submitting this package
2016-08-17 01:43:19 +02:00
if opts . separate_requests or opts . seperate_requests :
2013-01-31 16:03:16 +01:00
# create a single request
result = create_submit_request ( apiurl , project , p )
if not result :
sys . exit ( " submit request creation failed " )
sr_ids . append ( result )
else :
2009-11-13 09:58:37 +01:00
s = """ <action type= " submit " > <source project= " %s " package= " %s " /> <target project= " %s " package= " %s " /> %s </action> """ % \
2013-01-31 16:03:16 +01:00
( project , p , t , p , options_block )
2009-11-13 09:58:37 +01:00
actionxml + = s
if actionxml != " " :
xml = """ <request> %s <state name= " new " /> <description> %s </description> </request> """ % \
( actionxml , cgi . escape ( opts . message or " " ) )
2013-02-25 15:22:00 +01:00
u = makeurl ( apiurl , [ ' request ' ] , query = ' cmd=create&addrevision=1 ' )
2009-11-13 09:58:37 +01:00
f = http_POST ( u , data = xml )
2010-02-28 02:30:13 +01:00
2009-11-13 09:58:37 +01:00
root = ET . parse ( f ) . getroot ( )
sr_ids . append ( root . get ( ' id ' ) )
2013-04-09 12:51:28 +02:00
print ( " Request created: " , end = ' ' )
2009-11-13 09:58:37 +01:00
for i in sr_ids :
2013-04-09 12:51:28 +02:00
print ( i , end = ' ' )
2010-08-05 17:00:45 +02:00
2013-01-31 16:03:16 +01:00
# was this project created by clone request ?
u = makeurl ( apiurl , [ ' source ' , project , ' _attribute ' , ' OBS:RequestCloned ' ] )
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
value = root . findtext ( ' attribute/value ' )
2013-11-15 11:39:21 +01:00
if value and not opts . yes :
2013-01-31 16:03:16 +01:00
repl = ' '
2013-04-09 12:51:28 +02:00
print ( ' \n \n There are already following submit request: %s . ' % \
' , ' . join ( [ str ( i ) for i in myreqs ] ) )
2010-08-05 17:00:45 +02:00
repl = raw_input ( ' \n Supersede the old requests? (y/n) ' )
if repl . lower ( ) == ' y ' :
2013-05-27 12:16:44 +02:00
myreqs + = [ value ]
2013-01-31 16:03:16 +01:00
if len ( myreqs ) > 0 :
for req in myreqs :
2013-05-27 12:16:44 +02:00
change_request_state ( apiurl , str ( req ) , ' superseded ' ,
2010-08-05 17:00:45 +02:00
' superseded by %s ' % result , result )
2010-06-26 20:54:02 +02:00
sys . exit ( ' Successfully finished ' )
2009-11-13 09:58:37 +01:00
elif len ( args ) < = 2 :
2009-06-02 16:57:42 +02:00
# try using the working copy at hand
p = findpacs ( os . curdir ) [ 0 ]
src_project = p . prjname
src_package = p . name
2009-12-15 17:38:09 +01:00
apiurl = p . apiurl
2009-06-02 16:57:42 +02:00
if len ( args ) == 0 and p . islink ( ) :
dst_project = p . linkinfo . project
dst_package = p . linkinfo . package
elif len ( args ) > 0 :
dst_project = args [ 0 ]
if len ( args ) == 2 :
dst_package = args [ 1 ]
2009-06-02 15:14:46 +02:00
else :
2012-02-07 11:03:21 +01:00
if p . islink ( ) :
dst_package = p . linkinfo . package
else :
dst_package = src_package
2009-06-02 15:14:46 +02:00
else :
2009-06-02 16:57:42 +02:00
sys . exit ( ' Package \' %s \' is not a source link, so I cannot guess the submit target. \n '
' Please provide it the target via commandline arguments. ' % p . name )
2010-09-21 11:19:27 +02:00
modified = [ i for i in p . filenamelist if not p . status ( i ) in ( ' ' , ' ? ' , ' S ' ) ]
2014-03-12 10:50:46 +01:00
if len ( modified ) > 0 and not opts . yes :
2013-04-09 12:51:28 +02:00
print ( ' Your working copy has local modifications. ' )
2009-06-02 16:57:42 +02:00
repl = raw_input ( ' Proceed without committing the local changes? (y|N) ' )
if repl != ' y ' :
2010-04-20 15:22:03 +02:00
raise oscerr . UserAbort ( )
2009-06-02 16:57:42 +02:00
elif len ( args ) > = 3 :
# get the arguments from the commandline
src_project , src_package , dst_project = args [ 0 : 3 ]
if len ( args ) == 4 :
dst_package = args [ 3 ]
else :
dst_package = src_package
else :
raise oscerr . WrongArgs ( ' Incorrect number of arguments. \n \n ' \
+ self . get_cmd_help ( ' request ' ) )
2017-01-31 23:35:43 +01:00
# check for failed source service
2011-05-02 15:28:44 +02:00
u = makeurl ( apiurl , [ ' source ' , src_project , src_package ] )
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
2017-01-31 23:35:43 +01:00
_check_service ( root )
2011-05-02 15:28:44 +02:00
2009-06-02 16:57:42 +02:00
if not opts . nodevelproject :
devloc = None
try :
2013-10-07 13:12:58 +02:00
devloc , _ = show_devel_project ( apiurl , dst_project , dst_package )
2013-04-09 14:03:17 +02:00
except HTTPError :
2013-04-09 12:51:28 +02:00
print ( """ \
2009-06-02 15:14:46 +02:00
Warning : failed to fetch meta data for ' %s ' package ' %s ' ( new package ? ) """ \
2013-04-09 12:51:28 +02:00
% ( dst_project , dst_package ) , file = sys . stderr )
2009-06-02 15:14:46 +02:00
2009-10-20 16:30:15 +02:00
if devloc and \
dst_project != devloc and \
src_project != devloc :
2013-04-09 12:51:28 +02:00
print ( """ \
2010-02-02 14:38:50 +01:00
A different project , % s , is defined as the place where development
2009-06-02 15:14:46 +02:00
of the package % s primarily takes place .
Please submit there instead , or use - - nodevelproject to force direct submission . """ \
2013-04-09 12:51:28 +02:00
% ( devloc , dst_package ) )
2010-02-02 14:38:50 +01:00
if not opts . diff :
sys . exit ( 1 )
2010-02-02 14:38:35 +01:00
2013-05-27 12:41:50 +02:00
rev = opts . revision
2011-05-19 17:10:08 +02:00
if not rev :
# get _link info from server, that knows about the local state ...
2012-02-24 11:49:18 +01:00
u = makeurl ( apiurl , [ ' source ' , src_project , src_package ] , query = " expand=1 " )
2011-05-19 17:10:08 +02:00
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
linkinfo = root . find ( ' linkinfo ' )
2012-02-24 11:49:18 +01:00
if linkinfo == None :
2013-05-27 12:41:50 +02:00
rev = root . get ( ' rev ' )
2012-02-24 11:49:18 +01:00
else :
2011-05-19 17:10:08 +02:00
if linkinfo . get ( ' project ' ) != dst_project or linkinfo . get ( ' package ' ) != dst_package :
2014-08-12 15:01:16 +02:00
# the submit target is not link target. use merged md5sum references to
2013-05-27 12:16:44 +02:00
# avoid not mergable sources when multiple request from same source get created.
2013-05-27 12:41:50 +02:00
rev = root . get ( ' srcmd5 ' )
2011-05-19 17:10:08 +02:00
2010-02-02 14:38:35 +01:00
rdiff = None
if opts . diff or not opts . message :
try :
2013-05-27 12:41:50 +02:00
rdiff = ' old: %s / %s \n new: %s / %s rev %s \n ' % ( dst_project , dst_package , src_project , src_package , rev )
2010-02-02 14:38:35 +01:00
rdiff + = server_diff ( apiurl ,
2011-05-19 17:10:08 +02:00
dst_project , dst_package , None ,
src_project , src_package , rev , True )
2010-02-02 14:38:35 +01:00
except :
rdiff = ' '
2010-08-05 17:00:45 +02:00
2009-08-28 09:33:16 +02:00
if opts . diff :
2010-09-10 17:28:45 +02:00
run_pager ( rdiff )
2010-08-13 08:55:18 +02:00
return
2013-03-08 19:06:04 +01:00
supersede_existing = False
reqs = [ ]
if not opts . supersede :
( supersede_existing , reqs ) = check_existing_requests ( apiurl ,
src_project ,
src_package ,
dst_project ,
dst_package )
2015-08-07 10:17:40 +02:00
if not supersede_existing :
( supersede_existing , reqs ) = check_existing_maintenance_requests ( apiurl ,
src_project ,
[ src_package ] ,
dst_project , None )
2010-08-05 17:00:45 +02:00
if not opts . message :
difflines = [ ]
doappend = False
changes_re = re . compile ( r ' ^--- .* \ .changes ' )
for line in rdiff . split ( ' \n ' ) :
if line . startswith ( ' --- ' ) :
if changes_re . match ( line ) :
doappend = True
else :
doappend = False
if doappend :
difflines . append ( line )
opts . message = edit_message ( footer = rdiff , template = ' \n ' . join ( parse_diff_for_commit_message ( ' \n ' . join ( difflines ) ) ) )
result = create_submit_request ( apiurl ,
src_project , src_package ,
dst_project , dst_package ,
2015-03-09 08:44:12 +01:00
opts . message , orev = rev ,
src_update = src_update , dst_updatelink = opts . update_link )
2016-02-15 15:32:26 +01:00
print ( ' created request id ' , result )
2013-03-08 19:06:04 +01:00
if supersede_existing :
for req in reqs :
2010-12-30 13:28:11 +01:00
change_request_state ( apiurl , req . reqid , ' superseded ' ,
2010-08-05 17:00:45 +02:00
' superseded by %s ' % result , result )
if opts . supersede :
2011-02-08 16:16:18 +01:00
change_request_state ( apiurl , opts . supersede , ' superseded ' ,
2010-08-05 17:00:45 +02:00
opts . message or ' ' , result )
2010-06-15 17:07:14 +02:00
def _actionparser ( self , opt_str , value , parser ) :
2010-05-24 13:28:44 +02:00
value = [ ]
if not hasattr ( parser . values , ' actiondata ' ) :
setattr ( parser . values , ' actiondata ' , [ ] )
if parser . values . actions == None :
parser . values . actions = [ ]
rargs = parser . rargs
while rargs :
arg = rargs [ 0 ]
if ( ( arg [ : 2 ] == " -- " and len ( arg ) > 2 ) or
( arg [ : 1 ] == " - " and len ( arg ) > 1 and arg [ 1 ] != " - " ) ) :
break
else :
value . append ( arg )
del rargs [ 0 ]
parser . values . actions . append ( value [ 0 ] )
del value [ 0 ]
parser . values . actiondata . append ( value )
def _submit_request ( self , args , opts , options_block ) :
2013-05-27 12:41:50 +02:00
actionxml = " "
2010-05-24 13:28:44 +02:00
apiurl = self . get_api_url ( )
if len ( args ) == 0 and is_project_dir ( os . getcwd ( ) ) :
# submit requests for multiple packages are currently handled via multiple requests
# They could be also one request with multiple actions, but that avoids to accepts parts of it.
project = store_read_project ( os . curdir )
pi = [ ]
pac = [ ]
targetprojects = [ ]
# loop via all packages for checking their state
for p in meta_get_packagelist ( apiurl , project ) :
if p . startswith ( " _patchinfo: " ) :
pi . append ( p )
else :
# get _link info from server, that knows about the local state ...
u = makeurl ( apiurl , [ ' source ' , project , p ] )
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
linkinfo = root . find ( ' linkinfo ' )
if linkinfo == None :
2013-04-09 12:51:28 +02:00
print ( " Package " , p , " is not a source link. " )
2010-05-24 13:28:44 +02:00
sys . exit ( " This is currently not supported. " )
if linkinfo . get ( ' error ' ) :
2013-04-09 12:51:28 +02:00
print ( " Package " , p , " is a broken source link. " )
2010-05-24 13:28:44 +02:00
sys . exit ( " Please fix this first " )
t = linkinfo . get ( ' project ' )
if t :
rdiff = ' '
try :
rdiff = server_diff ( apiurl , t , p , opts . revision , project , p , None , True )
except :
rdiff = ' '
if rdiff != ' ' :
targetprojects . append ( t )
pac . append ( p )
else :
2013-04-09 12:51:28 +02:00
print ( " Skipping package " , p , " since it has no difference with the target package. " )
2010-05-24 13:28:44 +02:00
else :
2013-04-09 12:51:28 +02:00
print ( " Skipping package " , p , " since it is a source link pointing inside the project. " )
2010-05-24 13:28:44 +02:00
# loop via all packages to do the action
for p in pac :
s = """ <action type= " submit " > <source project= " %s " package= " %s " rev= " %s " /> <target project= " %s " package= " %s " /> %s </action> """ % \
( project , p , opts . revision or show_upstream_rev ( apiurl , project , p ) , t , p , options_block )
actionxml + = s
# create submit requests for all found patchinfos
for p in pi :
for t in targetprojects :
s = """ <action type= " submit " > <source project= " %s " package= " %s " /> <target project= " %s " package= " %s " /> %s </action> """ % \
( project , p , t , p , options_block )
actionxml + = s
2014-09-23 13:05:10 +02:00
return actionxml , [ ]
2010-05-24 13:28:44 +02:00
elif len ( args ) < = 2 :
# try using the working copy at hand
p = findpacs ( os . curdir ) [ 0 ]
src_project = p . prjname
src_package = p . name
if len ( args ) == 0 and p . islink ( ) :
dst_project = p . linkinfo . project
dst_package = p . linkinfo . package
elif len ( args ) > 0 :
dst_project = args [ 0 ]
if len ( args ) == 2 :
dst_package = args [ 1 ]
else :
dst_package = src_package
else :
sys . exit ( ' Package \' %s \' is not a source link, so I cannot guess the submit target. \n '
' Please provide it the target via commandline arguments. ' % p . name )
modified = [ i for i in p . filenamelist if p . status ( i ) != ' ' and p . status ( i ) != ' ? ' ]
if len ( modified ) > 0 :
2013-04-09 12:51:28 +02:00
print ( ' Your working copy has local modifications. ' )
2010-05-24 13:28:44 +02:00
repl = raw_input ( ' Proceed without committing the local changes? (y|N) ' )
if repl != ' y ' :
sys . exit ( 1 )
elif len ( args ) > = 3 :
# get the arguments from the commandline
src_project , src_package , dst_project = args [ 0 : 3 ]
if len ( args ) == 4 :
dst_package = args [ 3 ]
else :
dst_package = src_package
else :
raise oscerr . WrongArgs ( ' Incorrect number of arguments. \n \n ' \
+ self . get_cmd_help ( ' request ' ) )
if not opts . nodevelproject :
devloc = None
try :
2013-10-07 13:12:58 +02:00
devloc , _ = show_devel_project ( apiurl , dst_project , dst_package )
2013-04-09 14:03:17 +02:00
except HTTPError :
2013-04-09 12:51:28 +02:00
print ( """ \
2010-05-24 13:28:44 +02:00
Warning : failed to fetch meta data for ' %s ' package ' %s ' ( new package ? ) """ \
2013-04-09 12:51:28 +02:00
% ( dst_project , dst_package ) , file = sys . stderr )
2010-05-24 13:28:44 +02:00
if devloc and \
dst_project != devloc and \
src_project != devloc :
2013-04-09 12:51:28 +02:00
print ( """ \
2010-05-24 13:28:44 +02:00
A different project , % s , is defined as the place where development
of the package % s primarily takes place .
Please submit there instead , or use - - nodevelproject to force direct submission . """ \
2013-04-09 12:51:28 +02:00
% ( devloc , dst_package ) )
2014-09-23 12:45:44 +02:00
sys . exit ( 1 )
2010-05-24 13:28:44 +02:00
2014-09-23 12:45:44 +02:00
reqs = get_request_list ( apiurl , dst_project , dst_package , req_type = ' submit ' , req_state = [ ' new ' , ' review ' ] )
user = conf . get_apiurl_usr ( apiurl )
2014-09-23 13:05:10 +02:00
myreqs = [ i for i in reqs if i . state . who == user and i . reqid != opts . supersede ]
2014-09-23 12:45:44 +02:00
repl = ' y '
if len ( myreqs ) > 0 and not opts . yes :
print ( ' You already created the following submit request: %s . ' % \
' , ' . join ( [ i . reqid for i in myreqs ] ) )
repl = raw_input ( ' Supersede the old requests? (y/n/c) ' )
if repl . lower ( ) == ' c ' :
print ( ' Aborting ' , file = sys . stderr )
sys . exit ( 1 )
2014-09-23 13:05:10 +02:00
elif repl . lower ( ) != ' y ' :
myreqs = [ ]
2010-05-24 13:28:44 +02:00
2014-09-23 12:45:44 +02:00
actionxml = """ <action type= " submit " > <source project= " %s " package= " %s " rev= " %s " /> <target project= " %s " package= " %s " /> %s </action> """ % \
( src_project , src_package , opts . revision or show_upstream_rev ( apiurl , src_project , src_package ) , dst_project , dst_package , options_block )
if opts . supersede :
2014-09-23 13:05:10 +02:00
myreqs . append ( opts . supersede )
2010-05-24 13:28:44 +02:00
2014-09-23 12:45:44 +02:00
#print 'created request id', result
2014-09-23 13:05:10 +02:00
return actionxml , myreqs
2010-05-24 13:28:44 +02:00
def _delete_request ( self , args , opts ) :
if len ( args ) < 1 :
raise oscerr . WrongArgs ( ' Please specify at least a project. ' )
if len ( args ) > 2 :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
package = " "
if len ( args ) > 1 :
package = """ package= " %s " """ % ( args [ 1 ] )
actionxml = """ <action type= " delete " > <target project= " %s " %s /> </action> """ % ( args [ 0 ] , package )
return actionxml
def _changedevel_request ( self , args , opts ) :
if len ( args ) > 4 :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
2011-03-09 16:10:48 +01:00
if len ( args ) == 0 and is_package_dir ( ' . ' ) and find_default_project ( ) :
2010-05-24 13:28:44 +02:00
wd = os . curdir
devel_project = store_read_project ( wd )
devel_package = package = store_read_package ( wd )
2011-03-09 16:10:48 +01:00
project = find_default_project ( self . get_api_url ( ) , package )
2010-05-24 13:28:44 +02:00
else :
if len ( args ) < 3 :
raise oscerr . WrongArgs ( ' Too few arguments. ' )
devel_project = args [ 2 ]
project = args [ 0 ]
package = args [ 1 ]
devel_package = package
if len ( args ) > 3 :
devel_package = args [ 3 ]
actionxml = """ <action type= " change_devel " > <source project= " %s " package= " %s " /> <target project= " %s " package= " %s " /> </action> """ % \
( devel_project , devel_package , project , package )
return actionxml
2011-01-10 13:12:09 +01:00
def _add_me ( self , args , opts ) :
if len ( args ) > 3 :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
if len ( args ) < 2 :
raise oscerr . WrongArgs ( ' Too few arguments. ' )
apiurl = self . get_api_url ( )
user = conf . get_apiurl_usr ( apiurl )
2011-01-12 11:29:46 +01:00
role = args [ 0 ]
project = args [ 1 ]
2011-01-10 13:12:09 +01:00
actionxml = """ <action type= " add_role " > <target project= " %s " /> <person name= " %s " role= " %s " /> </action> """ % \
( project , user , role )
if len ( args ) > 2 :
package = args [ 2 ]
actionxml = """ <action type= " add_role " > <target project= " %s " package= " %s " /> <person name= " %s " role= " %s " /> </action> """ % \
( project , package , user , role )
if get_user_meta ( apiurl , user ) == None :
raise oscerr . WrongArgs ( ' osc: an error occured. ' )
return actionxml
2011-01-11 20:02:48 +01:00
def _add_user ( self , args , opts ) :
2010-05-24 13:28:44 +02:00
if len ( args ) > 4 :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
if len ( args ) < 3 :
raise oscerr . WrongArgs ( ' Too few arguments. ' )
apiurl = self . get_api_url ( )
user = args [ 0 ]
role = args [ 1 ]
project = args [ 2 ]
2010-09-09 22:07:50 +02:00
actionxml = """ <action type= " add_role " > <target project= " %s " /> <person name= " %s " role= " %s " /> </action> """ % \
( project , user , role )
2010-05-24 13:28:44 +02:00
if len ( args ) > 3 :
package = args [ 3 ]
2010-09-09 22:07:50 +02:00
actionxml = """ <action type= " add_role " > <target project= " %s " package= " %s " /> <person name= " %s " role= " %s " /> </action> """ % \
( project , package , user , role )
2010-05-24 13:28:44 +02:00
if get_user_meta ( apiurl , user ) == None :
raise oscerr . WrongArgs ( ' osc: an error occured. ' )
return actionxml
2011-01-11 20:02:48 +01:00
def _add_group ( self , args , opts ) :
if len ( args ) > 4 :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
if len ( args ) < 3 :
raise oscerr . WrongArgs ( ' Too few arguments. ' )
apiurl = self . get_api_url ( )
group = args [ 0 ]
role = args [ 1 ]
project = args [ 2 ]
actionxml = """ <action type= " add_role " > <target project= " %s " /> <group name= " %s " role= " %s " /> </action> """ % \
( project , group , role )
if len ( args ) > 3 :
package = args [ 3 ]
actionxml = """ <action type= " add_role " > <target project= " %s " package= " %s " /> <group name= " %s " role= " %s " /> </action> """ % \
( project , package , group , role )
if get_group ( apiurl , group ) == None :
raise oscerr . WrongArgs ( ' osc: an error occured. ' )
return actionxml
2010-05-24 13:28:44 +02:00
def _set_bugowner ( self , args , opts ) :
if len ( args ) > 3 :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
if len ( args ) < 2 :
raise oscerr . WrongArgs ( ' Too few arguments. ' )
apiurl = self . get_api_url ( )
user = args [ 0 ]
project = args [ 1 ]
2012-11-23 12:52:05 +01:00
package = " "
2010-05-24 13:28:44 +02:00
if len ( args ) > 2 :
2012-11-23 12:52:05 +01:00
package = """ package= " %s " """ % ( args [ 2 ] )
2010-05-24 13:28:44 +02:00
2014-01-24 17:01:35 +01:00
if user . startswith ( ' group: ' ) :
2014-08-13 11:21:55 +02:00
group = user . replace ( ' group: ' , ' ' )
2014-01-24 17:01:35 +01:00
actionxml = """ <action type= " set_bugowner " > <target project= " %s " %s /> <group name= " %s " /> </action> """ % \
( project , package , group )
if get_group ( apiurl , group ) == None :
raise oscerr . WrongArgs ( ' osc: an error occured. ' )
else :
actionxml = """ <action type= " set_bugowner " > <target project= " %s " %s /> <person name= " %s " /> </action> """ % \
( project , package , user )
if get_user_meta ( apiurl , user ) == None :
raise oscerr . WrongArgs ( ' osc: an error occured. ' )
2010-05-24 13:28:44 +02:00
return actionxml
2014-08-13 11:21:55 +02:00
@cmdln.option ( ' -a ' , ' --action ' , action = ' callback ' , callback = _actionparser , dest = ' actions ' ,
2010-05-24 13:28:44 +02:00
help = ' specify action type of a request, can be : submit/delete/change_devel/add_role/set_bugowner ' )
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify message TEXT ' )
@cmdln.option ( ' -r ' , ' --revision ' , metavar = ' REV ' ,
help = ' for " create " , specify a certain source revision ID (the md5 sum) ' )
@cmdln.option ( ' -s ' , ' --supersede ' , metavar = ' SUPERSEDE ' ,
help = ' Superseding another request by this one ' )
@cmdln.option ( ' --nodevelproject ' , action = ' store_true ' ,
help = ' do not follow a defined devel project ' \
' (primary project where a package is developed) ' )
@cmdln.option ( ' --cleanup ' , action = ' store_true ' ,
help = ' remove package if submission gets accepted (default for home:<id>:branch projects) ' )
@cmdln.option ( ' --no-cleanup ' , action = ' store_true ' ,
help = ' never remove source package on accept, but update its content ' )
@cmdln.option ( ' --no-update ' , action = ' store_true ' ,
help = ' never touch source package on accept (will break source links) ' )
@cmdln.option ( ' --yes ' , action = ' store_true ' ,
help = ' proceed without asking. ' )
@cmdln.alias ( " creq " )
def do_createrequest ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : create multiple requests with a single command
usage :
2014-08-12 15:01:16 +02:00
osc creq [ OPTIONS ] [
- a submit SOURCEPRJ SOURCEPKG DESTPRJ [ DESTPKG ]
- a delete PROJECT [ PACKAGE ]
- a change_devel PROJECT PACKAGE DEVEL_PROJECT [ DEVEL_PACKAGE ]
2011-01-10 13:12:09 +01:00
- a add_me ROLE PROJECT [ PACKAGE ]
2011-01-11 20:02:48 +01:00
- a add_group GROUP ROLE PROJECT [ PACKAGE ]
2010-05-24 13:28:44 +02:00
- a add_role USER ROLE PROJECT [ PACKAGE ]
- a set_bugowner USER PROJECT [ PACKAGE ]
]
Option - m works for all types of request , the rest work only for submit .
example :
osc creq - a submit - a delete home : someone : branches : openSUSE : Tools - a change_devel openSUSE : Tools osc home : someone : branches : openSUSE : Tools - m ok
This will submit all modified packages under current directory , delete project home : someone : branches : openSUSE : Tools and change the devel project to home : someone : branches : openSUSE : Tools for package osc in project openSUSE : Tools .
$ { cmd_option_list }
"""
src_update = conf . config [ ' submitrequest_on_accept_action ' ] or None
# we should check here for home:<id>:branch and default to update, but that would require OBS 1.7 server
if opts . cleanup :
src_update = " cleanup "
elif opts . no_cleanup :
src_update = " update "
elif opts . no_update :
src_update = " noupdate "
2013-05-27 12:41:50 +02:00
options_block = " "
2010-05-24 13:28:44 +02:00
if src_update :
2013-05-27 12:41:50 +02:00
options_block = """ <options><sourceupdate> %s </sourceupdate></options> """ % ( src_update )
2010-05-24 13:28:44 +02:00
args = slash_split ( args )
apiurl = self . get_api_url ( )
2016-05-15 17:50:31 +02:00
2010-05-24 13:28:44 +02:00
i = 0
actionsxml = " "
2014-09-23 13:05:10 +02:00
supersede = [ ]
2010-05-24 13:28:44 +02:00
for ai in opts . actions :
if ai == ' submit ' :
args = opts . actiondata [ i ]
i = i + 1
2014-09-23 13:05:10 +02:00
actions , to_supersede = self . _submit_request ( args , opts , options_block )
actionsxml + = actions
supersede . extend ( to_supersede )
2010-05-24 13:28:44 +02:00
elif ai == ' delete ' :
args = opts . actiondata [ i ]
2013-05-27 12:41:50 +02:00
actionsxml + = self . _delete_request ( args , opts )
2010-05-24 13:28:44 +02:00
i = i + 1
elif ai == ' change_devel ' :
args = opts . actiondata [ i ]
2013-05-27 12:41:50 +02:00
actionsxml + = self . _changedevel_request ( args , opts )
2010-05-24 13:28:44 +02:00
i = i + 1
2011-01-10 13:12:09 +01:00
elif ai == ' add_me ' :
args = opts . actiondata [ i ]
2013-05-27 12:41:50 +02:00
actionsxml + = self . _add_me ( args , opts )
2011-01-10 13:12:09 +01:00
i = i + 1
2011-01-11 20:02:48 +01:00
elif ai == ' add_group ' :
args = opts . actiondata [ i ]
2013-05-27 12:41:50 +02:00
actionsxml + = self . _add_group ( args , opts )
2011-01-11 20:02:48 +01:00
i = i + 1
2010-05-24 13:28:44 +02:00
elif ai == ' add_role ' :
args = opts . actiondata [ i ]
2013-05-27 12:41:50 +02:00
actionsxml + = self . _add_user ( args , opts )
2010-05-24 13:28:44 +02:00
i = i + 1
elif ai == ' set_bugowner ' :
args = opts . actiondata [ i ]
2013-05-27 12:41:50 +02:00
actionsxml + = self . _set_bugowner ( args , opts )
2010-05-24 13:28:44 +02:00
i = i + 1
else :
raise oscerr . WrongArgs ( ' Unsupported action %s ' % ai )
if actionsxml == " " :
sys . exit ( ' No actions need to be taken. ' )
if not opts . message :
opts . message = edit_message ( )
import cgi
xml = """ <request> %s <state name= " new " /> <description> %s </description> </request> """ % \
( actionsxml , cgi . escape ( opts . message or " " ) )
u = makeurl ( apiurl , [ ' request ' ] , query = ' cmd=create ' )
f = http_POST ( u , data = xml )
root = ET . parse ( f ) . getroot ( )
2014-09-23 13:05:10 +02:00
rid = root . get ( ' id ' )
for srid in supersede :
change_request_state ( apiurl , srid , ' superseded ' ,
' superseded by %s ' % rid , rid )
return rid
2010-05-24 13:28:44 +02:00
2009-06-02 15:14:46 +02:00
2010-08-18 11:42:50 +02:00
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify message TEXT ' )
2011-06-01 09:50:30 +02:00
@cmdln.option ( ' -r ' , ' --role ' , metavar = ' role ' ,
2010-11-24 16:41:02 +01:00
help = ' specify user role (default: maintainer) ' )
2011-06-01 09:50:30 +02:00
@cmdln.alias ( " reqbugownership " )
@cmdln.alias ( " requestbugownership " )
2010-11-25 22:23:12 +01:00
@cmdln.alias ( " reqmaintainership " )
@cmdln.alias ( " reqms " )
2011-06-01 09:50:30 +02:00
@cmdln.alias ( " reqbs " )
2010-11-25 22:23:12 +01:00
def do_requestmaintainership ( self , subcmd , opts , * args ) :
2011-06-01 09:50:30 +02:00
""" $ {cmd_name} : requests to add user as maintainer or bugowner
2010-08-18 11:42:50 +02:00
usage :
2014-08-19 14:33:06 +02:00
osc requestmaintainership # for current user in checked out package
osc requestmaintainership USER # for specified user in checked out package
osc requestmaintainership PROJECT # for current user if cwd is not a checked out package
osc requestmaintainership PROJECT PACKAGE # for current user
osc requestmaintainership PROJECT PACKAGE USER # request for specified user
osc requestmaintainership PROJECT PACKAGE group : NAME # request for specified group
2016-05-15 17:50:31 +02:00
osc requestbugownership . . . # accepts same parameters but uses bugowner role
2010-08-18 11:42:50 +02:00
$ { cmd_option_list }
"""
2011-01-25 21:06:28 +01:00
import cgi
2010-08-18 11:42:50 +02:00
args = slash_split ( args )
apiurl = self . get_api_url ( )
2011-01-25 21:06:28 +01:00
if len ( args ) == 2 :
2010-08-18 11:42:50 +02:00
project = args [ 0 ]
package = args [ 1 ]
2010-08-18 12:40:43 +02:00
user = conf . get_apiurl_usr ( apiurl )
2010-08-18 11:42:50 +02:00
elif len ( args ) == 3 :
project = args [ 0 ]
package = args [ 1 ]
2010-08-18 12:40:43 +02:00
user = args [ 2 ]
2011-01-25 21:06:28 +01:00
elif len ( args ) < 2 and is_package_dir ( os . curdir ) :
project = store_read_project ( os . curdir )
package = store_read_package ( os . curdir )
if len ( args ) == 0 :
user = conf . get_apiurl_usr ( apiurl )
else :
user = args [ 0 ]
2014-03-12 16:41:46 +01:00
elif len ( args ) == 1 :
user = conf . get_apiurl_usr ( apiurl )
project = args [ 0 ]
package = None
2010-08-18 11:42:50 +02:00
else :
2010-08-18 11:46:57 +02:00
raise oscerr . WrongArgs ( ' Wrong number of arguments. ' )
2010-08-18 11:42:50 +02:00
2011-06-01 09:50:30 +02:00
role = ' maintainer '
if subcmd in ( ' reqbugownership ' , ' requestbugownership ' , ' reqbs ' ) :
role = ' bugowner '
if opts . role :
role = opts . role
if not role in ( ' maintainer ' , ' bugowner ' ) :
2010-11-25 22:23:12 +01:00
raise oscerr . WrongOptions ( ' invalid \' --role \' : either specify \' maintainer \' or \' bugowner \' ' )
2010-08-18 11:42:50 +02:00
if not opts . message :
opts . message = edit_message ( )
2011-01-25 21:06:28 +01:00
r = Request ( )
2014-08-19 14:33:06 +02:00
if user . startswith ( ' group: ' ) :
group = user . replace ( ' group: ' , ' ' )
if role == ' bugowner ' :
r . add_action ( ' set_bugowner ' , tgt_project = project , tgt_package = package ,
group_name = group )
else :
r . add_action ( ' add_role ' , tgt_project = project , tgt_package = package ,
group_name = group , group_role = role )
elif role == ' bugowner ' :
2013-05-27 12:16:44 +02:00
r . add_action ( ' set_bugowner ' , tgt_project = project , tgt_package = package ,
2011-06-01 09:50:30 +02:00
person_name = user )
else :
2013-05-27 12:16:44 +02:00
r . add_action ( ' add_role ' , tgt_project = project , tgt_package = package ,
2011-06-01 09:50:30 +02:00
person_name = user , person_role = role )
2011-01-25 21:06:28 +01:00
r . description = cgi . escape ( opts . message or ' ' )
r . create ( apiurl )
2013-04-09 12:51:28 +02:00
print ( r . reqid )
2010-08-18 11:42:50 +02:00
2009-06-02 16:57:42 +02:00
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify message TEXT ' )
2015-04-26 16:53:25 +02:00
@cmdln.option ( ' -r ' , ' --repository ' , metavar = ' REPOSITORY ' ,
help = ' specify repository ' )
@cmdln.option ( ' --accept-in-hours ' , metavar = ' HOURS ' ,
help = ' specify time when request shall get accepted automatically. Only works with write permissions in target. ' )
2009-06-02 16:57:42 +02:00
@cmdln.alias ( " dr " )
2010-12-14 15:49:27 +01:00
@cmdln.alias ( " dropreq " )
@cmdln.alias ( " droprequest " )
2009-06-02 16:57:42 +02:00
@cmdln.alias ( " deletereq " )
def do_deleterequest ( self , subcmd , opts , * args ) :
2010-12-14 15:49:27 +01:00
""" $ {cmd_name} : Request to delete (or ' drop ' ) a package or project
2009-06-02 15:14:46 +02:00
2009-06-02 16:57:42 +02:00
usage :
2011-01-21 11:04:47 +01:00
osc deletereq [ - m TEXT ] # works in checked out project/package
2009-06-02 16:57:42 +02:00
osc deletereq [ - m TEXT ] PROJECT [ PACKAGE ]
2012-11-13 13:20:09 +01:00
osc deletereq [ - m TEXT ] PROJECT [ - - repository REPOSITORY ]
2009-06-02 16:57:42 +02:00
$ { cmd_option_list }
"""
2011-01-25 20:41:42 +01:00
import cgi
2009-06-02 15:14:46 +02:00
2009-06-02 16:57:42 +02:00
args = slash_split ( args )
2009-06-02 15:14:46 +02:00
2010-07-06 14:16:24 +02:00
project = None
package = None
2012-11-13 13:20:09 +01:00
repository = None
2010-07-06 14:16:24 +02:00
2011-01-25 20:41:42 +01:00
if len ( args ) > 2 :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
2010-07-06 14:16:24 +02:00
elif len ( args ) == 1 :
project = args [ 0 ]
2011-01-25 20:41:42 +01:00
elif len ( args ) == 2 :
2010-07-06 14:16:24 +02:00
project = args [ 0 ]
package = args [ 1 ]
2011-01-25 20:41:42 +01:00
elif is_project_dir ( os . getcwd ( ) ) :
project = store_read_project ( os . curdir )
elif is_package_dir ( os . getcwd ( ) ) :
project = store_read_project ( os . curdir )
package = store_read_package ( os . curdir )
2014-08-12 15:01:16 +02:00
else :
2011-01-25 20:41:42 +01:00
raise oscerr . WrongArgs ( ' Please specify at least a project. ' )
2009-06-23 12:06:31 +02:00
2012-11-13 13:20:09 +01:00
if opts . repository :
repository = opts . repository
2009-08-19 13:28:16 +02:00
if not opts . message :
2010-07-06 14:16:24 +02:00
import textwrap
if package is not None :
2013-05-27 12:41:50 +02:00
footer = textwrap . TextWrapper ( width = 66 ) . fill (
' please explain why you like to delete package %s of project %s '
2014-08-13 11:21:55 +02:00
% ( package , project ) )
2010-07-06 14:16:24 +02:00
else :
2013-05-27 12:41:50 +02:00
footer = textwrap . TextWrapper ( width = 66 ) . fill (
' please explain why you like to delete project %s ' % project )
2010-07-06 14:16:24 +02:00
opts . message = edit_message ( footer )
2009-08-19 13:28:16 +02:00
2011-01-25 20:41:42 +01:00
r = Request ( )
2012-11-13 13:20:09 +01:00
r . add_action ( ' delete ' , tgt_project = project , tgt_package = package , tgt_repository = repository )
2011-01-25 20:41:42 +01:00
r . description = cgi . escape ( opts . message )
2013-12-05 10:23:53 +01:00
if opts . accept_in_hours :
r . accept_at_in_hours ( int ( opts . accept_in_hours ) )
2011-01-25 20:41:42 +01:00
r . create ( self . get_api_url ( ) )
2013-04-09 12:51:28 +02:00
print ( r . reqid )
2009-06-02 15:14:46 +02:00
2009-06-02 16:57:42 +02:00
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify message TEXT ' )
@cmdln.alias ( " cr " )
@cmdln.alias ( " changedevelreq " )
def do_changedevelrequest ( self , subcmd , opts , * args ) :
2009-07-23 10:01:31 +02:00
""" $ {cmd_name} : Create request to change the devel package definition.
2009-06-02 15:14:46 +02:00
2014-08-12 15:01:16 +02:00
[ See http : / / en . opensuse . org / openSUSE : Build_Service_Collaboration
2010-07-26 19:45:42 +02:00
for information on this topic . ]
2009-06-02 16:57:42 +02:00
See the " request " command for showing and modifing existing requests .
osc changedevelrequest PROJECT PACKAGE DEVEL_PROJECT [ DEVEL_PACKAGE ]
"""
2011-01-25 20:41:42 +01:00
import cgi
2010-04-30 17:13:21 +02:00
2011-03-09 16:10:48 +01:00
if len ( args ) == 0 and is_package_dir ( ' . ' ) and find_default_project ( ) :
2010-02-11 11:26:03 +01:00
wd = os . curdir
2010-02-24 11:41:59 +01:00
devel_project = store_read_project ( wd )
devel_package = package = store_read_package ( wd )
2011-03-09 16:10:48 +01:00
project = find_default_project ( self . get_api_url ( ) , package )
2011-01-25 20:41:42 +01:00
elif len ( args ) < 3 :
raise oscerr . WrongArgs ( ' Too few arguments. ' )
elif len ( args ) > 4 :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
2010-02-11 11:26:03 +01:00
else :
devel_project = args [ 2 ]
project = args [ 0 ]
package = args [ 1 ]
devel_package = package
2011-01-25 20:41:42 +01:00
if len ( args ) == 4 :
2010-02-11 11:26:03 +01:00
devel_package = args [ 3 ]
2009-08-19 13:28:16 +02:00
if not opts . message :
2010-02-24 11:41:59 +01:00
import textwrap
2013-05-27 12:41:50 +02:00
footer = textwrap . TextWrapper ( width = 66 ) . fill (
' please explain why you like to change the devel project of %s / %s to %s / %s '
2014-08-13 11:21:55 +02:00
% ( project , package , devel_project , devel_package ) )
2010-02-24 11:41:59 +01:00
opts . message = edit_message ( footer )
2009-08-19 13:28:16 +02:00
2011-01-25 20:41:42 +01:00
r = Request ( )
r . add_action ( ' change_devel ' , src_project = devel_project , src_package = devel_package ,
tgt_project = project , tgt_package = package )
r . description = cgi . escape ( opts . message )
r . create ( self . get_api_url ( ) )
2013-04-09 12:51:28 +02:00
print ( r . reqid )
2009-06-02 15:14:46 +02:00
@cmdln.option ( ' -d ' , ' --diff ' , action = ' store_true ' ,
help = ' generate a diff ' )
@cmdln.option ( ' -u ' , ' --unified ' , action = ' store_true ' ,
help = ' output the diff in the unified diff format ' )
2013-09-25 15:36:54 +02:00
@cmdln.option ( ' --no-devel ' , action = ' store_true ' ,
help = ' Do not attempt to forward to devel project ' )
2009-06-02 15:14:46 +02:00
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify message TEXT ' )
2009-11-20 17:06:05 +01:00
@cmdln.option ( ' -t ' , ' --type ' , metavar = ' TYPE ' ,
2009-06-19 15:10:33 +02:00
help = ' limit to requests which contain a given action type (submit/delete/change_devel) ' )
2009-08-19 15:00:22 +02:00
@cmdln.option ( ' -a ' , ' --all ' , action = ' store_true ' ,
2009-08-20 21:28:05 +02:00
help = ' all states. Same as \' -s all \' ' )
2011-02-08 16:16:18 +01:00
@cmdln.option ( ' -f ' , ' --force ' , action = ' store_true ' ,
help = ' enforce state change, can be used to ignore open reviews ' )
2012-09-10 10:43:28 +02:00
@cmdln.option ( ' -s ' , ' --state ' , default = ' ' , # default is 'all' if no args given, 'declined,new,review' otherwise
2012-09-10 13:49:21 +02:00
help = ' only list requests in one of the comma separated given states (new/review/accepted/revoked/declined) or " all " [default= " declined,new,review " , or " all " , if no args given] ' )
2009-08-21 02:42:51 +02:00
@cmdln.option ( ' -D ' , ' --days ' , metavar = ' DAYS ' ,
2009-09-28 21:50:57 +02:00
help = ' only list requests in state " new " or changed in the last DAYS. [default= %(request_list_days)s ] ' )
2009-08-20 21:28:05 +02:00
@cmdln.option ( ' -U ' , ' --user ' , metavar = ' USER ' ,
2010-07-29 13:45:44 +02:00
help = ' requests or reviews limited for the specified USER ' )
@cmdln.option ( ' -G ' , ' --group ' , metavar = ' GROUP ' ,
help = ' requests or reviews limited for the specified GROUP ' )
2011-01-23 21:21:32 +01:00
@cmdln.option ( ' -P ' , ' --project ' , metavar = ' PROJECT ' ,
help = ' requests or reviews limited for the specified PROJECT ' )
@cmdln.option ( ' -p ' , ' --package ' , metavar = ' PACKAGE ' ,
help = ' requests or reviews limited for the specified PACKAGE, requires also a PROJECT ' )
2009-06-02 15:14:46 +02:00
@cmdln.option ( ' -b ' , ' --brief ' , action = ' store_true ' , default = False ,
help = ' print output in list view as list subcommand ' )
@cmdln.option ( ' -M ' , ' --mine ' , action = ' store_true ' ,
help = ' only show requests created by yourself ' )
2009-09-28 21:50:57 +02:00
@cmdln.option ( ' -B ' , ' --bugowner ' , action = ' store_true ' ,
help = ' also show requests about packages where I am bugowner ' )
2011-01-30 14:24:21 +01:00
@cmdln.option ( ' -e ' , ' --edit ' , action = ' store_true ' ,
help = ' edit a submit action ' )
2010-02-11 01:47:47 +01:00
@cmdln.option ( ' -i ' , ' --interactive ' , action = ' store_true ' ,
help = ' interactive review of request ' )
2013-05-06 18:44:14 +02:00
@cmdln.option ( ' --or-revoke ' , action = ' store_true ' ,
help = ' For automatisation scripts: accepts (if using with accept argument) a request when it is in new or review state. Or revoke it when it got declined. Otherwise just do nothing. ' )
2010-03-23 16:21:09 +01:00
@cmdln.option ( ' --non-interactive ' , action = ' store_true ' ,
help = ' non-interactive review of request ' )
2010-02-25 22:56:21 +01:00
@cmdln.option ( ' --exclude-target-project ' , action = ' append ' ,
help = ' exclude target project from request list ' )
2010-03-13 21:06:18 +01:00
@cmdln.option ( ' --involved-projects ' , action = ' store_true ' ,
2010-03-15 13:34:38 +01:00
help = ' show all requests for project/packages where USER is involved ' )
2010-09-14 16:02:21 +02:00
@cmdln.option ( ' --source-buildstatus ' , action = ' store_true ' ,
2016-02-10 18:19:22 +01:00
help = ' print the buildstatus of the source package (only works with " show " and the interactive review) ' )
2009-06-02 15:14:46 +02:00
@cmdln.alias ( " rq " )
2009-11-17 17:59:17 +01:00
@cmdln.alias ( " review " )
2010-02-26 09:55:58 +01:00
# FIXME: rewrite this mess and split request and review
2009-06-02 15:14:46 +02:00
def do_request ( self , subcmd , opts , * args ) :
2010-02-26 09:55:58 +01:00
""" $ {cmd_name} : Show or modify requests and reviews
2009-06-02 15:14:46 +02:00
2010-07-27 15:20:35 +02:00
[ See http : / / en . opensuse . org / openSUSE : Build_Service_Collaboration
2010-07-26 19:45:42 +02:00
for information on this topic . ]
2009-06-02 15:14:46 +02:00
2010-02-26 09:55:58 +01:00
The ' request ' command has the following sub commands :
2008-03-05 00:41:00 +01:00
2009-08-20 21:28:05 +02:00
" list " lists open requests attached to a project or package or person .
Uses the project / package of the current directory if none of
- M , - U USER , project / package are given .
2008-03-05 00:41:00 +01:00
2008-08-19 16:18:05 +02:00
" log " will show the history of the given ID
2008-03-06 11:25:45 +01:00
" show " will show the request itself , and generate a diff for review , if
2010-01-02 12:25:37 +01:00
used with the - - diff option . The keyword show can be omitted if the ID is numeric .
2008-03-05 00:41:00 +01:00
2010-02-26 09:55:58 +01:00
" decline " will change the request state to " declined "
2008-03-05 00:41:00 +01:00
2010-11-24 14:18:45 +01:00
" reopen " will set the request back to new or review .
2012-01-19 11:43:37 +01:00
" setincident " will direct " maintenance " requests into specific incidents
2011-02-11 16:12:38 +01:00
" supersede " will supersede one request with another existing one .
2008-07-25 11:34:29 +02:00
2010-02-26 09:55:58 +01:00
" revoke " will set the request state to " revoked "
2008-07-09 17:22:18 +02:00
2008-03-13 00:37:35 +01:00
" accept " will change the request state to " accepted " and will trigger
the actual submit process . That would normally be a server - side copy of
the source package to the target package .
2008-03-05 00:41:00 +01:00
2010-02-26 09:55:58 +01:00
" checkout " will checkout the request ' s source package ( " submit " requests only).
2014-09-11 11:25:24 +02:00
" priorize " change the prioritity of a request to either " critical " , " important " , " moderate " or " low "
2010-02-26 09:55:58 +01:00
The ' review ' command has the following sub commands :
" list " lists open requests that need to be reviewed by the
2014-08-12 15:01:16 +02:00
specified user or group
2010-02-26 09:55:58 +01:00
" add " adds a person or group as reviewer to a request
" accept " mark the review positive
" decline " mark the review negative . A negative review will
decline the request .
2008-03-13 00:37:35 +01:00
usage :
2009-09-28 21:50:57 +02:00
osc request list [ - M ] [ - U USER ] [ - s state ] [ - D DAYS ] [ - t type ] [ - B ] [ PRJ [ PKG ] ]
2009-06-02 15:14:46 +02:00
osc request log ID
2009-09-03 19:28:27 +02:00
osc request [ show ] [ - d ] [ - b ] ID
2010-08-10 16:36:29 +02:00
2009-06-02 15:14:46 +02:00
osc request accept [ - m TEXT ] ID
osc request decline [ - m TEXT ] ID
osc request revoke [ - m TEXT ] ID
2010-08-10 16:36:29 +02:00
osc request reopen [ - m TEXT ] ID
2012-01-19 11:43:37 +01:00
osc request setincident [ - m TEXT ] ID INCIDENT
2011-04-26 17:18:49 +02:00
osc request supersede [ - m TEXT ] ID SUPERSEDING_ID
2010-08-10 16:36:29 +02:00
osc request approvenew [ - m TEXT ] PROJECT
2014-09-11 11:25:24 +02:00
osc request priorize [ - m TEXT ] ID PRIORITY
2010-08-10 16:36:29 +02:00
2009-09-16 23:39:45 +02:00
osc request checkout / co ID
2010-08-10 16:36:29 +02:00
osc request clone [ - m TEXT ] ID
2012-03-06 13:25:47 +01:00
osc review show [ - d ] [ - b ] ID
2011-04-26 17:18:49 +02:00
osc review list [ - U USER ] [ - G GROUP ] [ - P PROJECT [ - p PACKAGE ] ] [ - s state ]
osc review add [ - m TEXT ] [ - U USER ] [ - G GROUP ] [ - P PROJECT [ - p PACKAGE ] ] ID
osc review accept [ - m TEXT ] [ - U USER ] [ - G GROUP ] [ - P PROJECT [ - p PACKAGE ] ] ID
osc review decline [ - m TEXT ] [ - U USER ] [ - G GROUP ] [ - P PROJECT [ - p PACKAGE ] ] ID
osc review reopen [ - m TEXT ] [ - U USER ] [ - G GROUP ] [ - P PROJECT [ - p PACKAGE ] ] ID
osc review supersede [ - m TEXT ] [ - U USER ] [ - G GROUP ] [ - P PROJECT [ - p PACKAGE ] ] ID SUPERSEDING_ID
2010-08-10 16:36:29 +02:00
2008-03-05 00:41:00 +01:00
$ { cmd_option_list }
"""
args = slash_split ( args )
2009-08-21 23:31:45 +02:00
if opts . all and opts . state :
2010-03-23 16:21:09 +01:00
raise oscerr . WrongOptions ( ' Sorry, the options \' --all \' and \' --state \' ' \
' are mutually exclusive. ' )
2009-08-21 23:31:45 +02:00
if opts . mine and opts . user :
2010-03-23 16:21:09 +01:00
raise oscerr . WrongOptions ( ' Sorry, the options \' --user \' and \' --mine \' ' \
' are mutually exclusive. ' )
if opts . interactive and opts . non_interactive :
raise oscerr . WrongOptions ( ' Sorry, the options \' --interactive \' and ' \
' \' --non-interactive \' are mutually exclusive ' )
2009-08-21 23:31:45 +02:00
2009-08-20 21:28:05 +02:00
if not args :
args = [ ' list ' ]
opts . mine = 1
if opts . state == ' ' :
opts . state = ' all '
2014-08-25 17:02:56 +02:00
if opts . state == ' ' and subcmd != ' review ' :
2012-09-10 10:43:28 +02:00
opts . state = ' declined,new,review '
2009-08-20 21:28:05 +02:00
2010-08-13 09:42:47 +02:00
if args [ 0 ] == ' help ' :
2010-08-10 16:36:29 +02:00
return self . do_help ( [ ' help ' , ' request ' ] )
2014-09-11 11:25:24 +02:00
cmds = [ ' list ' , ' ls ' , ' log ' , ' show ' , ' decline ' , ' reopen ' , ' clone ' , ' accept ' , ' approvenew ' , ' wipe ' , ' setincident ' , ' supersede ' , ' revoke ' , ' checkout ' , ' co ' , ' priorize ' ]
2010-08-13 09:51:20 +02:00
if subcmd != ' review ' and args [ 0 ] not in cmds :
2009-09-03 19:28:27 +02:00
raise oscerr . WrongArgs ( ' Unknown request action %s . Choose one of %s . ' \
2014-08-13 11:21:55 +02:00
% ( args [ 0 ] , ' , ' . join ( cmds ) ) )
2012-03-06 13:22:25 +01:00
cmds = [ ' show ' , ' list ' , ' add ' , ' decline ' , ' accept ' , ' reopen ' , ' supersede ' ]
2010-08-13 09:51:20 +02:00
if subcmd == ' review ' and args [ 0 ] not in cmds :
2010-08-10 16:36:29 +02:00
raise oscerr . WrongArgs ( ' Unknown review action %s . Choose one of %s . ' \
2014-08-13 11:21:55 +02:00
% ( args [ 0 ] , ' , ' . join ( cmds ) ) )
2008-03-05 00:41:00 +01:00
cmd = args [ 0 ]
del args [ 0 ]
2014-09-11 11:25:24 +02:00
if cmd == ' ls ' :
cmd = " list "
2008-03-05 00:41:00 +01:00
2010-10-12 10:59:53 +02:00
apiurl = self . get_api_url ( )
2010-05-19 12:29:56 +02:00
if cmd in [ ' list ' ] :
2008-06-24 11:37:49 +02:00
min_args , max_args = 0 , 2
2014-09-11 11:25:24 +02:00
elif cmd in [ ' supersede ' , ' setincident ' , ' priorize ' ] :
2011-02-11 16:12:38 +01:00
min_args , max_args = 2 , 2
2008-03-05 00:41:00 +01:00
else :
min_args , max_args = 1 , 1
if len ( args ) < min_args :
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
raise oscerr . WrongArgs ( ' Too few arguments. ' )
2008-03-05 00:41:00 +01:00
if len ( args ) > max_args :
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
raise oscerr . WrongArgs ( ' Too many arguments. ' )
2011-04-26 17:18:49 +02:00
if cmd in [ ' add ' ] and not opts . user and not opts . group and not opts . project :
raise oscerr . WrongArgs ( ' No reviewer specified. ' )
2008-06-06 14:04:34 +02:00
2016-02-10 18:27:35 +01:00
source_buildstatus = conf . config [ ' request_show_source_buildstatus ' ] or opts . source_buildstatus
2011-02-11 16:12:38 +01:00
reqid = None
supersedid = None
2010-05-19 12:50:52 +02:00
if cmd == ' list ' or cmd == ' approvenew ' :
2008-06-24 11:37:49 +02:00
package = None
project = None
if len ( args ) > 0 :
project = args [ 0 ]
2009-08-21 03:26:37 +02:00
elif not opts . mine and not opts . user :
2009-05-15 17:32:15 +02:00
try :
2009-07-24 21:15:51 +02:00
project = store_read_project ( os . curdir )
2009-05-15 17:32:15 +02:00
package = store_read_package ( os . curdir )
except oscerr . NoWorkingCopy :
pass
2011-07-07 10:12:57 +02:00
elif opts . project :
project = opts . project
if opts . package :
package = opts . package
2008-06-24 11:37:49 +02:00
2008-03-05 00:41:00 +01:00
if len ( args ) > 1 :
package = args [ 1 ]
2011-02-11 16:12:38 +01:00
elif cmd == ' supersede ' :
reqid = args [ 0 ]
supersedid = args [ 1 ]
2012-01-19 11:43:37 +01:00
elif cmd == ' setincident ' :
reqid = args [ 0 ]
incident = args [ 1 ]
2014-09-11 11:25:24 +02:00
elif cmd == ' priorize ' :
reqid = args [ 0 ]
priority = args [ 1 ]
2010-08-05 15:54:48 +02:00
elif cmd in [ ' log ' , ' add ' , ' show ' , ' decline ' , ' reopen ' , ' clone ' , ' accept ' , ' wipe ' , ' revoke ' , ' checkout ' , ' co ' ] :
2008-03-05 00:41:00 +01:00
reqid = args [ 0 ]
2010-08-05 15:54:48 +02:00
# clone all packages from a given request
if cmd in [ ' clone ' ] :
2010-10-26 15:34:32 +02:00
# should we force a message?
2013-04-09 12:51:28 +02:00
print ( ' Cloned packages are available in project: %s ' % clone_request ( apiurl , reqid , opts . message ) )
2010-08-05 15:54:48 +02:00
2012-01-19 11:43:37 +01:00
# change incidents
elif cmd == ' setincident ' :
query = { ' cmd ' : ' setincident ' , ' incident ' : incident }
url = makeurl ( apiurl , [ ' request ' , reqid ] , query )
r = http_POST ( url , data = opts . message )
2013-04-09 12:51:28 +02:00
print ( ET . parse ( r ) . getroot ( ) . get ( ' code ' ) )
2012-01-19 11:43:37 +01:00
2014-09-11 11:25:24 +02:00
# change priority
elif cmd == ' priorize ' :
query = { ' cmd ' : ' setpriority ' , ' priority ' : priority }
url = makeurl ( apiurl , [ ' request ' , reqid ] , query )
r = http_POST ( url , data = opts . message )
print ( ET . parse ( r ) . getroot ( ) . get ( ' code ' ) )
2010-07-30 11:36:17 +02:00
# add new reviewer to existing request
2010-08-05 15:54:48 +02:00
elif cmd in [ ' add ' ] and subcmd == ' review ' :
2010-07-30 11:36:17 +02:00
query = { ' cmd ' : ' addreview ' }
if opts . user :
query [ ' by_user ' ] = opts . user
if opts . group :
query [ ' by_group ' ] = opts . group
2011-01-23 21:21:32 +01:00
if opts . project :
query [ ' by_project ' ] = opts . project
if opts . package :
query [ ' by_package ' ] = opts . package
2010-07-30 11:36:17 +02:00
url = makeurl ( apiurl , [ ' request ' , reqid ] , query )
2010-10-12 11:09:19 +02:00
if not opts . message :
opts . message = edit_message ( )
2010-08-05 10:24:00 +02:00
r = http_POST ( url , data = opts . message )
2013-04-09 12:51:28 +02:00
print ( ET . parse ( r ) . getroot ( ) . get ( ' code ' ) )
2010-07-30 11:36:17 +02:00
2010-05-19 12:50:52 +02:00
# list and approvenew
2010-07-30 11:36:17 +02:00
elif cmd == ' list ' or cmd == ' approvenew ' :
2010-09-07 17:31:07 +02:00
states = ( ' new ' , ' accepted ' , ' revoked ' , ' declined ' , ' review ' , ' superseded ' )
2009-05-17 15:07:55 +02:00
who = ' '
2010-05-19 12:50:52 +02:00
if cmd == ' approvenew ' :
2013-05-27 12:16:44 +02:00
states = ( ' new ' )
results = get_request_list ( apiurl , project , package , ' ' , [ ' new ' ] )
2010-03-13 21:06:18 +01:00
else :
2013-05-27 12:16:44 +02:00
state_list = opts . state . split ( ' , ' )
2014-08-25 17:02:56 +02:00
if state_list == [ ' ' ] :
state_list = ( )
2013-05-27 12:16:44 +02:00
if opts . all :
state_list = [ ' all ' ]
else :
for s in state_list :
if not s in states and not s == ' all ' :
raise oscerr . WrongArgs ( ' Unknown state \' %s \' , try one of %s ' % ( s , ' , ' . join ( states ) ) )
if opts . mine :
who = conf . get_apiurl_usr ( apiurl )
if opts . user :
who = opts . user
## FIXME -B not implemented!
if opts . bugowner :
if ( self . options . debug ) :
print ( ' list: option --bugowner ignored: not impl. ' )
if subcmd == ' review ' :
# FIXME: do the review list for the user and for all groups he belong to
results = get_review_list ( apiurl , project , package , who , opts . group , opts . project , opts . package , state_list )
else :
if opts . involved_projects :
who = who or conf . get_apiurl_usr ( apiurl )
results = get_user_projpkgs_request_list ( apiurl , who , req_state = state_list ,
req_type = opts . type , exclude_projects = opts . exclude_target_project or [ ] )
else :
results = get_request_list ( apiurl , project , package , who ,
state_list , opts . type , opts . exclude_target_project or [ ] )
2010-05-19 12:29:56 +02:00
2011-07-08 15:11:17 +02:00
# Check if project actually exists if result list is empty
if not results :
2013-06-17 16:26:00 +02:00
if project :
2015-08-04 12:51:45 +02:00
msg = ' No results for %(kind)s %(entity)s '
emsg = ' %(kind)s %(entity)s does not exist '
d = { ' entity ' : [ project ] , ' kind ' : ' project ' }
meth = show_project_meta
if package :
d [ ' kind ' ] = ' package '
d [ ' entity ' ] . append ( package )
meth = show_package_meta
2013-06-17 16:26:00 +02:00
try :
2015-08-04 12:51:45 +02:00
entity = d [ ' entity ' ]
d [ ' entity ' ] = ' / ' . join ( entity )
meth ( apiurl , * entity )
print ( msg % d )
2013-06-17 17:37:40 +02:00
except HTTPError :
2015-08-04 12:51:45 +02:00
print ( emsg % d )
2013-06-17 16:26:00 +02:00
else :
print ( ' No results ' )
2011-07-08 15:11:17 +02:00
return
2014-11-11 08:26:08 +01:00
# we must not sort the results here, since the api is doing it already "the right way"
2009-08-21 02:42:51 +02:00
days = opts . days or conf . config [ ' request_list_days ' ]
since = ' '
2009-10-20 16:30:15 +02:00
try :
2014-01-14 11:04:04 +01:00
days = float ( days )
2009-08-21 02:42:51 +02:00
except ValueError :
days = 0
if days > 0 :
2013-05-27 12:41:50 +02:00
since = time . strftime ( ' % Y- % m- %d T % H: % M: % S ' , time . localtime ( time . time ( ) - days * 24 * 3600 ) )
2008-06-27 18:36:36 +02:00
2009-08-20 21:28:05 +02:00
skipped = 0
## bs has received 2009-09-20 a new xquery compare() function
## which allows us to limit the list inside of get_request_list
## That would be much faster for coolo. But counting the remainder
2009-09-28 21:50:57 +02:00
## would not be possible with current xquery implementation.
## Workaround: fetch all, and filter on client side.
2009-09-03 13:25:12 +02:00
## FIXME: date filtering should become implemented on server side
2008-03-05 00:41:00 +01:00
for result in results :
2009-09-28 21:50:57 +02:00
if days == 0 or result . state . when > since or result . state . name == ' new ' :
2010-09-17 21:03:52 +02:00
if ( opts . interactive or conf . config [ ' request_show_interactive ' ] ) and not opts . non_interactive :
2012-10-26 15:19:00 +02:00
ignore_reviews = subcmd != ' review '
2016-02-10 18:19:22 +01:00
request_interactive_review ( apiurl , result , group = opts . group ,
ignore_reviews = ignore_reviews ,
2016-02-10 18:27:35 +01:00
source_buildstatus = source_buildstatus )
2010-09-17 21:03:52 +02:00
else :
2013-04-09 12:51:28 +02:00
print ( result . list_view ( ) , ' \n ' )
2009-08-20 21:28:05 +02:00
else :
skipped + = 1
if skipped :
2013-04-09 12:51:28 +02:00
print ( " There are %d requests older than %s days. \n " % ( skipped , days ) )
2008-03-05 00:41:00 +01:00
2010-05-19 12:50:52 +02:00
if cmd == ' approvenew ' :
2013-04-09 12:51:28 +02:00
print ( " \n *** Approve them all ? [y/n] *** " )
2010-05-19 12:29:56 +02:00
if sys . stdin . read ( 1 ) == " y " :
2016-05-15 17:50:31 +02:00
2010-05-19 12:29:56 +02:00
if not opts . message :
opts . message = edit_message ( )
for result in results :
2013-04-09 12:51:28 +02:00
print ( result . reqid , " : " , end = ' ' )
2010-07-29 17:29:07 +02:00
r = change_request_state ( apiurl ,
2011-02-08 16:16:18 +01:00
result . reqid , ' accepted ' , opts . message or ' ' , force = opts . force )
2013-04-09 12:51:28 +02:00
print ( ' Result of change request state: %s ' % r )
2010-05-19 12:29:56 +02:00
else :
2013-04-09 12:51:28 +02:00
print ( ' Aborted... ' , file = sys . stderr )
2010-05-19 12:29:56 +02:00
raise oscerr . UserAbort ( )
2008-08-19 16:18:05 +02:00
elif cmd == ' log ' :
2010-07-29 17:29:07 +02:00
for l in get_request_log ( apiurl , reqid ) :
2013-04-09 12:51:28 +02:00
print ( l )
2008-08-19 16:18:05 +02:00
2008-03-05 00:41:00 +01:00
# show
elif cmd == ' show ' :
2010-08-03 09:34:33 +02:00
r = get_request ( apiurl , reqid )
2009-04-22 13:02:32 +02:00
if opts . brief :
2013-04-09 12:51:28 +02:00
print ( r . list_view ( ) )
2011-01-30 14:24:21 +01:00
elif opts . edit :
if not r . get_actions ( ' submit ' ) :
raise oscerr . WrongOptions ( ' \' --edit \' not possible ' \
' (request has no \' submit \' action) ' )
return request_interactive_review ( apiurl , r , ' e ' )
2010-03-23 16:21:09 +01:00
elif ( opts . interactive or conf . config [ ' request_show_interactive ' ] ) and not opts . non_interactive :
2012-10-26 15:19:00 +02:00
ignore_reviews = subcmd != ' review '
2016-02-10 18:19:22 +01:00
return request_interactive_review ( apiurl , r , group = opts . group ,
ignore_reviews = ignore_reviews ,
2016-02-10 18:27:35 +01:00
source_buildstatus = source_buildstatus )
2009-04-22 13:02:32 +02:00
else :
2013-04-09 12:51:28 +02:00
print ( r )
2015-10-19 13:14:53 +02:00
print_comments ( apiurl , ' request ' , reqid )
2016-02-10 18:27:35 +01:00
if source_buildstatus :
2011-01-29 18:47:26 +01:00
sr_actions = r . get_actions ( ' submit ' )
if not sr_actions :
raise oscerr . WrongOptions ( ' \' --source-buildstatus \' not possible ' \
' (request has no \' submit \' actions) ' )
for action in sr_actions :
2013-04-09 12:51:28 +02:00
print ( ' Buildstatus for \' %s / %s \' : ' % ( action . src_project , action . src_package ) )
print ( ' \n ' . join ( get_results ( apiurl , action . src_project , action . src_package ) ) )
2011-01-29 17:24:45 +01:00
if opts . diff :
diff = ' '
2008-03-20 21:11:30 +01:00
try :
2010-09-02 10:29:28 +02:00
# works since OBS 2.1
2011-01-29 17:24:45 +01:00
diff = request_diff ( apiurl , reqid )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2010-09-02 10:29:28 +02:00
# for OBS 2.0 and before
2011-01-29 17:47:28 +01:00
sr_actions = r . get_actions ( ' submit ' )
2015-06-11 11:05:08 +02:00
if not r . get_actions ( ' submit ' ) and not r . get_actions ( ' maintenance_incident ' ) and not r . get_actions ( ' maintenance_release ' ) :
raise oscerr . WrongOptions ( ' \' --diff \' not possible (request has no supported actions) ' )
2011-01-29 17:24:45 +01:00
for action in sr_actions :
diff + = ' old: %s / %s \n new: %s / %s \n ' % ( action . src_project , action . src_package ,
action . tgt_project , action . tgt_package )
diff + = submit_action_diff ( apiurl , action )
diff + = ' \n \n '
2011-04-24 00:27:47 +02:00
run_pager ( diff , tmp_suffix = ' ' )
2008-03-05 00:41:00 +01:00
2009-09-16 23:39:45 +02:00
# checkout
elif cmd == ' checkout ' or cmd == ' co ' :
2010-07-29 17:29:07 +02:00
r = get_request ( apiurl , reqid )
2012-05-04 17:18:46 +02:00
sr_actions = r . get_actions ( ' submit ' , ' maintenance_release ' )
2011-01-29 18:47:26 +01:00
if not sr_actions :
raise oscerr . WrongArgs ( ' \' checkout \' not possible (request has no \' submit \' actions) ' )
for action in sr_actions :
checkout_package ( apiurl , action . src_project , action . src_package , \
action . src_rev , expand_link = True , prj_dir = action . src_project )
2008-03-05 00:41:00 +01:00
2009-08-19 13:28:16 +02:00
else :
2011-02-11 16:12:38 +01:00
state_map = { ' reopen ' : ' new ' , ' accept ' : ' accepted ' , ' decline ' : ' declined ' , ' wipe ' : ' deleted ' , ' revoke ' : ' revoked ' , ' supersede ' : ' superseded ' }
2009-11-17 17:59:17 +01:00
# Change review state only
if subcmd == ' review ' :
2010-08-18 17:58:42 +02:00
if not opts . message :
2013-05-27 12:16:44 +02:00
opts . message = edit_message ( )
2011-02-11 16:12:38 +01:00
if cmd in [ ' accept ' , ' decline ' , ' reopen ' , ' supersede ' ] :
2011-04-26 17:18:49 +02:00
if opts . user or opts . group or opts . project or opts . package :
2011-08-18 11:40:21 +02:00
r = change_review_state ( apiurl , reqid , state_map [ cmd ] , opts . user , opts . group , opts . project ,
opts . package , opts . message or ' ' , supersed = supersedid )
2013-04-09 12:51:28 +02:00
print ( r )
2011-04-26 17:18:49 +02:00
else :
rq = get_request ( apiurl , reqid )
2011-08-18 11:40:21 +02:00
if rq . state . name in [ ' new ' , ' review ' ] :
for review in rq . reviews : # try all, but do not fail on error
try :
r = change_review_state ( apiurl , reqid , state_map [ cmd ] , review . by_user , review . by_group ,
review . by_project , review . by_package , opts . message or ' ' , supersed = supersedid )
2013-04-09 12:51:28 +02:00
print ( r )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2014-01-30 11:52:24 +01:00
body = e . read ( )
if e . code in [ 403 ] :
if review . by_user :
2015-07-01 09:47:53 +02:00
print ( ' No permission on review by user %s : ' % review . by_user )
2014-01-30 11:52:24 +01:00
if review . by_group :
print ( ' No permission on review by group %s ' % review . by_group )
if review . by_package :
print ( ' No permission on review by package %s / %s ' % ( review . by_project , review . by_package ) )
elif review . by_project :
print ( ' No permission on review by project %s ' % review . by_project )
2015-07-01 09:47:53 +02:00
print ( e , file = sys . stderr )
2011-08-18 11:40:21 +02:00
else :
2013-04-09 12:51:28 +02:00
print ( ' Request is closed, please reopen the request first before changing any reviews. ' )
2009-11-17 17:59:17 +01:00
# Change state of entire request
2011-02-11 16:12:38 +01:00
elif cmd in [ ' reopen ' , ' accept ' , ' decline ' , ' wipe ' , ' revoke ' , ' supersede ' ] :
2010-08-18 17:58:42 +02:00
rq = get_request ( apiurl , reqid )
2013-05-06 18:44:14 +02:00
if opts . or_revoke :
if rq . state . name == " declined " :
2013-05-27 12:41:50 +02:00
cmd = " revoke "
2013-05-06 18:44:14 +02:00
elif rq . state . name != " new " and rq . state . name != " review " :
2013-02-28 10:28:56 +01:00
return 0
2010-08-18 17:58:42 +02:00
if rq . state . name == state_map [ cmd ] :
2013-05-27 13:03:46 +02:00
repl = raw_input ( " \n *** The state of the request (# %s ) is already ' %s ' . Change state anyway? [y/n] *** " % \
( reqid , rq . state . name ) )
2010-08-18 17:58:42 +02:00
if repl . lower ( ) != ' y ' :
2013-04-09 12:51:28 +02:00
print ( ' Aborted... ' , file = sys . stderr )
2010-08-18 17:58:42 +02:00
raise oscerr . UserAbort ( )
2016-05-15 17:50:31 +02:00
2010-08-18 17:58:42 +02:00
if not opts . message :
2010-11-14 18:32:02 +01:00
tmpl = change_request_state_template ( rq , state_map [ cmd ] )
opts . message = edit_message ( template = tmpl )
2013-05-06 18:44:14 +02:00
try :
r = change_request_state ( apiurl ,
reqid , state_map [ cmd ] , opts . message or ' ' , supersed = supersedid , force = opts . force )
print ( ' Result of change request state: %s ' % r )
except HTTPError as e :
2014-01-30 11:52:24 +01:00
print ( e , file = sys . stderr )
2014-06-08 21:33:06 +02:00
details = e . hdrs . get ( ' X-Opensuse-Errorcode ' )
2014-02-04 14:35:30 +01:00
if details :
print ( details , file = sys . stderr )
2014-05-15 18:09:27 +02:00
root = ET . fromstring ( e . read ( ) )
summary = root . find ( ' summary ' )
if not summary is None :
print ( summary . text )
2013-05-06 18:44:14 +02:00
if opts . or_revoke :
if e . code in [ 400 , 403 , 404 , 500 ] :
print ( ' Revoking it ... ' )
r = change_request_state ( apiurl ,
reqid , ' revoked ' , opts . message or ' ' , supersed = supersedid , force = opts . force )
2014-05-21 15:45:07 +02:00
sys . exit ( 1 )
2008-03-05 00:41:00 +01:00
2012-06-26 17:13:33 +02:00
# check for devel instances after accepted requests
if cmd in [ ' accept ' ] :
import cgi
sr_actions = rq . get_actions ( ' submit ' )
for action in sr_actions :
u = makeurl ( apiurl , [ ' /search/package ' ] , {
' match ' : " ([devel/[@project= ' %s ' and @package= ' %s ' ]]) " % ( action . tgt_project , action . tgt_package )
} )
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
2013-09-25 15:36:54 +02:00
if root . findall ( ' package ' ) and not opts . no_devel :
2013-05-27 12:16:44 +02:00
for node in root . findall ( ' package ' ) :
project = node . get ( ' project ' )
package = node . get ( ' name ' )
# skip it when this is anyway a link to me
link_url = makeurl ( apiurl , [ ' source ' , project , package ] )
links_to_project = links_to_package = None
try :
file = http_GET ( link_url )
root = ET . parse ( file ) . getroot ( )
link_node = root . find ( ' linkinfo ' )
if link_node != None :
links_to_project = link_node . get ( ' project ' ) or project
links_to_package = link_node . get ( ' package ' ) or package
except HTTPError as e :
if e . code != 404 :
print ( ' Cannot get list of files for %s / %s : %s ' % ( project , package , e ) , file = sys . stderr )
except SyntaxError as e :
print ( ' Cannot parse list of files for %s / %s : %s ' % ( project , package , e ) , file = sys . stderr )
2013-05-27 12:41:50 +02:00
if links_to_project == action . tgt_project and links_to_package == action . tgt_package :
2013-05-27 12:16:44 +02:00
# links to my request target anyway, no need to forward submit
continue
print ( project , end = ' ' )
if package != action . tgt_package :
print ( " / " , package , end = ' ' )
repl = raw_input ( ' \n Forward this submit to it? ([y]/n) ' )
if repl . lower ( ) == ' y ' or repl == ' ' :
( supersede , reqs ) = check_existing_requests ( apiurl , action . tgt_project , action . tgt_package ,
project , package )
msg = " %s (forwarded request %s from %s ) " % ( rq . description , reqid , rq . get_creator ( ) )
rid = create_submit_request ( apiurl , action . tgt_project , action . tgt_package ,
project , package , cgi . escape ( msg ) )
print ( msg )
print ( " New request # " , rid )
for req in reqs :
change_request_state ( apiurl , req . reqid , ' superseded ' ,
' superseded by %s ' % rid , rid )
2012-06-26 17:13:33 +02:00
2007-07-16 18:20:09 +02:00
# editmeta and its aliases are all depracated
@cmdln.alias ( " editprj " )
@cmdln.alias ( " createprj " )
@cmdln.alias ( " editpac " )
@cmdln.alias ( " createpac " )
@cmdln.alias ( " edituser " )
@cmdln.alias ( " usermeta " )
2009-06-02 15:14:46 +02:00
@cmdln.hide ( 1 )
2007-07-16 18:20:09 +02:00
def do_editmeta ( self , subcmd , opts , * args ) :
2009-05-18 16:50:43 +02:00
""" $ {cmd_name} :
2007-07-16 18:20:09 +02:00
Obsolete command to edit metadata . Use ' meta ' now .
See the help output of ' meta ' .
"""
2007-07-13 18:01:02 +02:00
2016-05-15 17:50:31 +02:00
print ( " This command is obsolete. Use ' osc meta <metatype> ... ' . " , file = sys . stderr )
print ( " See ' osc help meta ' . " , file = sys . stderr )
2007-07-16 18:20:09 +02:00
return 2
2007-07-13 18:01:02 +02:00
2009-04-09 10:21:12 +02:00
@cmdln.option ( ' -r ' , ' --revision ' , metavar = ' rev ' ,
help = ' use the specified revision. ' )
2010-09-07 12:14:13 +02:00
@cmdln.option ( ' -R ' , ' --use-plain-revision ' , action = ' store_true ' ,
2014-03-03 22:44:30 +01:00
help = ' Do not expand revision the specified or latest rev ' )
2009-06-18 11:18:17 +02:00
@cmdln.option ( ' -u ' , ' --unset ' , action = ' store_true ' ,
help = ' remove revision in link, it will point always to latest revision ' )
2009-04-09 10:21:12 +02:00
def do_setlinkrev ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Updates a revision number in a source link.
2009-05-18 16:50:43 +02:00
2009-04-09 10:21:12 +02:00
This command adds or updates a specified revision number in a source link .
The current revision of the source is used , if no revision number is specified .
2009-05-18 16:50:43 +02:00
usage :
2009-04-09 10:21:12 +02:00
osc setlinkrev
2009-06-18 11:18:17 +02:00
osc setlinkrev PROJECT [ PACKAGE ]
2009-04-09 10:21:12 +02:00
$ { cmd_option_list }
"""
args = slash_split ( args )
2010-07-29 17:29:07 +02:00
apiurl = self . get_api_url ( )
2009-06-18 11:18:17 +02:00
package = None
2011-02-22 17:43:05 +01:00
rev = parseRevisionOption ( opts . revision ) [ 0 ] or ' '
if opts . unset :
rev = None
2010-02-09 00:08:21 +01:00
if len ( args ) == 0 :
2009-04-09 10:21:12 +02:00
p = findpacs ( os . curdir ) [ 0 ]
project = p . prjname
package = p . name
2009-04-09 13:44:32 +02:00
apiurl = p . apiurl
if not p . islink ( ) :
2009-04-16 10:13:55 +02:00
sys . exit ( ' Local directory is no checked out source link package, aborting ' )
2009-04-09 10:21:12 +02:00
elif len ( args ) == 2 :
project = args [ 0 ]
package = args [ 1 ]
2009-06-18 11:18:17 +02:00
elif len ( args ) == 1 :
project = args [ 0 ]
2009-04-09 10:21:12 +02:00
else :
raise oscerr . WrongArgs ( ' Incorrect number of arguments. \n \n ' \
+ self . get_cmd_help ( ' setlinkrev ' ) )
2009-06-18 11:18:17 +02:00
if package :
2011-02-22 17:43:05 +01:00
packages = [ package ]
2009-06-18 11:18:17 +02:00
else :
packages = meta_get_packagelist ( apiurl , project )
for p in packages :
2014-03-03 22:44:30 +01:00
rev = set_link_rev ( apiurl , project , p , revision = rev ,
expand = not opts . use_plain_revision )
2011-11-17 21:33:57 +01:00
if rev is None :
2013-04-09 12:51:28 +02:00
print ( ' removed revision from link ' )
2011-11-17 21:33:57 +01:00
else :
2013-04-09 12:51:28 +02:00
print ( ' set revision to %s for package %s ' % ( rev , p ) )
2009-04-09 10:21:12 +02:00
2010-01-11 16:36:33 +01:00
def do_linktobranch ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Convert a package containing a classic link with patch to a branch
This command tells the server to convert a _link with or without a project . diff
to a branch . This is a full copy with a _link file pointing to the branched place .
usage :
2010-01-14 12:24:48 +01:00
osc linktobranch # can be used in checked out package
osc linktobranch PROJECT PACKAGE
2010-01-11 16:36:33 +01:00
$ { cmd_option_list }
"""
args = slash_split ( args )
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2010-01-14 12:24:48 +01:00
if len ( args ) == 0 :
wd = os . curdir
project = store_read_project ( wd )
package = store_read_package ( wd )
2010-01-14 20:25:14 +01:00
update_local_dir = True
2010-01-14 12:24:48 +01:00
elif len ( args ) < 2 :
raise oscerr . WrongArgs ( ' Too few arguments (required none or two) ' )
elif len ( args ) > 2 :
raise oscerr . WrongArgs ( ' Too many arguments (required none or two) ' )
else :
project = args [ 0 ]
package = args [ 1 ]
2010-01-14 20:25:14 +01:00
update_local_dir = False
2010-01-11 16:36:33 +01:00
2010-01-14 12:24:48 +01:00
# execute
link_to_branch ( apiurl , project , package )
2010-01-14 20:25:14 +01:00
if update_local_dir :
2010-02-18 14:14:31 +01:00
pac = Package ( wd )
pac . update ( rev = pac . latest_rev ( ) )
2010-01-11 16:36:33 +01:00
2011-02-11 17:38:59 +01:00
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify message TEXT ' )
2011-02-11 17:11:44 +01:00
def do_detachbranch ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : replace a link with its expanded sources
If a package is a link it is replaced with its expanded sources . The link
does not exist anymore .
usage :
osc detachbranch # can be used in package working copy
osc detachbranch PROJECT PACKAGE
$ { cmd_option_list }
"""
args = slash_split ( args )
apiurl = self . get_api_url ( )
if len ( args ) == 0 :
project = store_read_project ( os . curdir )
package = store_read_package ( os . curdir )
elif len ( args ) == 2 :
project , package = args
elif len ( args ) > 2 :
raise oscerr . WrongArgs ( ' Too many arguments (required none or two) ' )
else :
raise oscerr . WrongArgs ( ' Too few arguments (required none or two) ' )
try :
2011-02-11 17:38:59 +01:00
copy_pac ( apiurl , project , package , apiurl , project , package , expand = True , comment = opts . message )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2011-02-11 17:11:44 +01:00
root = ET . fromstring ( show_files_meta ( apiurl , project , package , ' latest ' , expand = False ) )
li = Linkinfo ( )
li . read ( root . find ( ' linkinfo ' ) )
if li . islink ( ) and li . haserror ( ) :
raise oscerr . LinkExpandError ( project , package , li . error )
2011-02-11 17:38:59 +01:00
elif not li . islink ( ) :
2013-04-09 12:51:28 +02:00
print ( ' package \' %s / %s \' is no link ' % ( project , package ) , file = sys . stderr )
2011-02-11 17:38:59 +01:00
else :
raise e
2011-02-11 17:11:44 +01:00
2009-05-13 09:59:01 +02:00
@cmdln.option ( ' -C ' , ' --cicount ' , choices = [ ' add ' , ' copy ' , ' local ' ] ,
help = ' cicount attribute in the link, known values are add, copy, and local, default in buildservice is currently add. ' )
2009-06-18 11:18:17 +02:00
@cmdln.option ( ' -c ' , ' --current ' , action = ' store_true ' ,
help = ' link fixed against current revision. ' )
2008-06-26 12:47:58 +02:00
@cmdln.option ( ' -r ' , ' --revision ' , metavar = ' rev ' ,
help = ' link the specified revision. ' )
2009-06-15 17:19:16 +02:00
@cmdln.option ( ' -f ' , ' --force ' , action = ' store_true ' ,
help = ' overwrite an existing link file if it is there. ' )
2009-12-21 14:24:33 +01:00
@cmdln.option ( ' -d ' , ' --disable-publish ' , action = ' store_true ' ,
help = ' disable publishing of the linked package ' )
2011-12-15 15:12:13 +01:00
@cmdln.option ( ' -N ' , ' --new-package ' , action = ' store_true ' ,
help = ' create a link to a not yet existing package ' )
2007-04-25 01:00:12 +02:00
def do_linkpac ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : " Link " a package to another package
2009-05-18 16:50:43 +02:00
2007-04-25 01:00:12 +02:00
A linked package is a clone of another package , but plus local
modifications . It can be cross - project .
2006-08-07 12:08:54 +02:00
2007-04-25 01:00:12 +02:00
The DESTPAC name is optional ; the source packages ' name will be used if
DESTPAC is omitted .
2006-08-07 12:08:54 +02:00
2007-04-25 01:00:12 +02:00
Afterwards , you will want to ' checkout DESTPRJ DESTPAC ' .
2006-08-07 12:08:54 +02:00
2007-04-25 01:00:12 +02:00
To add a patch , add the patch as file and add it to the _link file .
You can also specify text which will be inserted at the top of the spec file .
2006-08-07 12:08:54 +02:00
2007-04-25 01:00:12 +02:00
See the examples in the _link file .
2006-08-07 12:08:54 +02:00
2011-12-12 12:57:13 +01:00
NOTE : In case you want to fix or update another package , you should use the ' branch '
command . A branch has correct repositories ( and a link ) setup up by default and
will be cleaned up automatically after it was submitted back .
2010-07-21 09:46:54 +02:00
2009-05-18 16:50:43 +02:00
usage :
2007-04-25 01:00:12 +02:00
osc linkpac SOURCEPRJ SOURCEPAC DESTPRJ [ DESTPAC ]
$ { cmd_option_list }
"""
2006-08-07 12:08:54 +02:00
2007-06-26 15:17:38 +02:00
args = slash_split ( args )
2010-07-29 17:29:07 +02:00
apiurl = self . get_api_url ( )
2007-06-26 15:17:38 +02:00
2007-04-25 01:00:12 +02:00
if not args or len ( args ) < 3 :
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
raise oscerr . WrongArgs ( ' Incorrect number of arguments. \n \n ' \
+ self . get_cmd_help ( ' linkpac ' ) )
2006-08-07 12:08:54 +02:00
2008-06-26 12:47:58 +02:00
rev , dummy = parseRevisionOption ( opts . revision )
2012-03-02 15:44:15 +01:00
vrev = None
2008-06-26 12:47:58 +02:00
2007-04-25 01:00:12 +02:00
src_project = args [ 0 ]
src_package = args [ 1 ]
dst_project = args [ 2 ]
if len ( args ) > 3 :
dst_package = args [ 3 ]
else :
dst_package = src_package
2006-09-21 16:33:24 +02:00
2007-04-25 01:00:12 +02:00
if src_project == dst_project and src_package == dst_package :
2010-01-09 14:25:41 +01:00
raise oscerr . WrongArgs ( ' Error: source and destination are the same. ' )
2008-06-26 12:47:58 +02:00
2009-11-02 22:02:58 +01:00
if src_project == dst_project and not opts . cicount :
# in this case, the user usually wants to build different spec
# files from the same source
opts . cicount = " copy "
2011-12-15 15:12:13 +01:00
if opts . current and not opts . new_package :
2014-03-03 22:44:30 +01:00
rev , vrev = show_upstream_rev_vrev ( apiurl , src_project , src_package , expand = True )
2012-03-02 15:44:15 +01:00
if rev == None or len ( rev ) < 32 :
# vrev is only needed for srcmd5 and OBS instances < 2.1.17 do not support it
vrev = None
2009-04-08 13:48:34 +02:00
2008-06-26 12:47:58 +02:00
if rev and not checkRevision ( src_project , src_package , rev ) :
2013-04-09 12:51:28 +02:00
print ( ' Revision \' %s \' does not exist ' % rev , file = sys . stderr )
2008-06-26 12:47:58 +02:00
sys . exit ( 1 )
2012-03-02 15:44:15 +01:00
link_pac ( src_project , src_package , dst_project , dst_package , opts . force , rev , opts . cicount , opts . disable_publish , opts . new_package , vrev )
2006-09-21 16:33:24 +02:00
2010-07-20 14:48:27 +02:00
@cmdln.option ( ' --nosources ' , action = ' store_true ' ,
help = ' ignore source packages when copying build results to destination project ' )
2009-07-31 16:31:20 +02:00
@cmdln.option ( ' -m ' , ' --map-repo ' , metavar = ' SRC=TARGET[,SRC=TARGET] ' ,
help = ' Allows repository mapping(s) to be given as SRC=TARGET[,SRC=TARGET] ' )
2009-12-21 14:24:33 +01:00
@cmdln.option ( ' -d ' , ' --disable-publish ' , action = ' store_true ' ,
help = ' disable publishing of the aggregated package ' )
2007-10-30 14:45:54 +01:00
def do_aggregatepac ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : " Aggregate " a package to another package
2009-05-18 16:50:43 +02:00
2008-07-17 19:46:21 +02:00
Aggregation of a package means that the build results ( binaries ) of a
package are basically copied into another project .
This can be used to make packages available from building that are
needed in a project but available only in a different project . Note
2009-05-18 16:50:43 +02:00
that this is done at the expense of disk space . See
2010-12-03 12:39:18 +01:00
http : / / en . opensuse . org / openSUSE : Build_Service_Tips_and_Tricks #link_and_aggregate
2008-07-17 19:46:21 +02:00
for more information .
2007-10-30 14:45:54 +01:00
The DESTPAC name is optional ; the source packages ' name will be used if
DESTPAC is omitted .
2009-05-18 16:50:43 +02:00
usage :
2007-10-30 14:45:54 +01:00
osc aggregatepac SOURCEPRJ SOURCEPAC DESTPRJ [ DESTPAC ]
$ { cmd_option_list }
"""
args = slash_split ( args )
if not args or len ( args ) < 3 :
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
raise oscerr . WrongArgs ( ' Incorrect number of arguments. \n \n ' \
+ self . get_cmd_help ( ' aggregatepac ' ) )
2007-10-30 14:45:54 +01:00
src_project = args [ 0 ]
src_package = args [ 1 ]
dst_project = args [ 2 ]
if len ( args ) > 3 :
dst_package = args [ 3 ]
else :
dst_package = src_package
if src_project == dst_project and src_package == dst_package :
2010-01-09 14:25:41 +01:00
raise oscerr . WrongArgs ( ' Error: source and destination are the same. ' )
2009-07-31 16:31:20 +02:00
repo_map = { }
if opts . map_repo :
for pair in opts . map_repo . split ( ' , ' ) :
src_tgt = pair . split ( ' = ' )
if len ( src_tgt ) != 2 :
2010-01-09 14:25:41 +01:00
raise oscerr . WrongOptions ( ' map " %s " must be SRC=TARGET[,SRC=TARGET] ' % opts . map_repo )
2009-07-31 16:31:20 +02:00
repo_map [ src_tgt [ 0 ] ] = src_tgt [ 1 ]
2010-07-20 14:48:27 +02:00
aggregate_pac ( src_project , src_package , dst_project , dst_package , repo_map , opts . disable_publish , opts . nosources )
2006-09-21 16:33:24 +02:00
2008-05-21 17:49:00 +02:00
2008-04-02 16:36:23 +02:00
@cmdln.option ( ' -c ' , ' --client-side-copy ' , action = ' store_true ' ,
help = ' do a (slower) client-side copy ' )
2008-04-30 14:28:25 +02:00
@cmdln.option ( ' -k ' , ' --keep-maintainers ' , action = ' store_true ' ,
help = ' keep original maintainers. Default is remove all and replace with the one calling the script. ' )
2011-11-21 12:33:32 +01:00
@cmdln.option ( ' -K ' , ' --keep-link ' , action = ' store_true ' ,
help = ' keep the source link in target, this also expands the source ' )
2009-03-11 16:23:23 +01:00
@cmdln.option ( ' -d ' , ' --keep-develproject ' , action = ' store_true ' ,
help = ' keep develproject tag in the package metadata ' )
2009-05-14 13:50:53 +02:00
@cmdln.option ( ' -r ' , ' --revision ' , metavar = ' rev ' ,
2013-06-21 15:11:20 +02:00
help = ' copy the specified revision. ' )
2007-05-04 23:51:54 +02:00
@cmdln.option ( ' -t ' , ' --to-apiurl ' , metavar = ' URL ' ,
help = ' URL of destination api server. Default is the source api server. ' )
2009-05-14 13:50:53 +02:00
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify message TEXT ' )
2009-03-31 00:17:18 +02:00
@cmdln.option ( ' -e ' , ' --expand ' , action = ' store_true ' ,
help = ' if the source package is a link then copy the expanded version of the link ' )
2007-04-25 01:00:12 +02:00
def do_copypac ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Copy a package
2006-09-21 16:33:24 +02:00
2009-05-18 16:50:43 +02:00
A way to copy package to somewhere else .
2008-04-02 16:36:23 +02:00
It can be done across buildservice instances , if the - t option is used .
2010-08-11 22:42:16 +02:00
In that case , a client - side copy and link expansion are implied .
2008-04-02 16:36:23 +02:00
Using - - client - side - copy always involves downloading all files , and
uploading them to the target .
2006-09-21 16:33:24 +02:00
2007-04-25 01:00:12 +02:00
The DESTPAC name is optional ; the source packages ' name will be used if
DESTPAC is omitted .
2006-09-21 16:33:24 +02:00
2009-05-18 16:50:43 +02:00
usage :
2007-04-25 01:00:12 +02:00
osc copypac SOURCEPRJ SOURCEPAC DESTPRJ [ DESTPAC ]
$ { cmd_option_list }
"""
2006-09-21 16:33:24 +02:00
2007-06-26 15:17:38 +02:00
args = slash_split ( args )
2007-04-25 01:00:12 +02:00
if not args or len ( args ) < 3 :
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
raise oscerr . WrongArgs ( ' Incorrect number of arguments. \n \n ' \
+ self . get_cmd_help ( ' copypac ' ) )
2006-09-21 16:33:24 +02:00
2007-04-25 01:00:12 +02:00
src_project = args [ 0 ]
src_package = args [ 1 ]
dst_project = args [ 2 ]
if len ( args ) > 3 :
dst_package = args [ 3 ]
else :
dst_package = src_package
2006-09-21 16:33:24 +02:00
2007-05-04 23:51:54 +02:00
src_apiurl = conf . config [ ' apiurl ' ]
if opts . to_apiurl :
2009-12-15 17:24:25 +01:00
dst_apiurl = conf . config [ ' apiurl_aliases ' ] . get ( opts . to_apiurl , opts . to_apiurl )
2007-05-04 23:51:54 +02:00
else :
dst_apiurl = src_apiurl
2008-04-02 16:36:23 +02:00
if src_apiurl != dst_apiurl :
opts . client_side_copy = True
2010-08-11 22:42:16 +02:00
opts . expand = True
2008-03-17 22:46:42 +01:00
2009-05-14 13:50:53 +02:00
rev , dummy = parseRevisionOption ( opts . revision )
if opts . message :
2009-07-15 20:53:47 +02:00
comment = opts . message
else :
2009-08-20 21:28:05 +02:00
if not rev :
2009-10-20 16:30:15 +02:00
rev = show_upstream_rev ( src_apiurl , src_project , src_package )
2009-07-15 20:53:47 +02:00
comment = ' osc copypac from project: %s package: %s revision: %s ' % ( src_project , src_package , rev )
2011-11-25 13:05:41 +01:00
if opts . keep_link :
2013-05-27 12:16:44 +02:00
comment + = " , using keep-link "
2011-11-25 13:05:41 +01:00
if opts . expand :
2013-05-27 12:16:44 +02:00
comment + = " , using expand "
2011-11-25 13:05:41 +01:00
if opts . client_side_copy :
2013-05-27 12:16:44 +02:00
comment + = " , using client side copy "
2009-05-14 13:50:53 +02:00
2010-05-08 08:03:56 +02:00
if src_project == dst_project and \
src_package == dst_package and \
not rev and \
src_apiurl == dst_apiurl :
raise oscerr . WrongArgs ( ' Source and destination are the same. ' )
2009-05-18 16:50:43 +02:00
r = copy_pac ( src_apiurl , src_project , src_package ,
2008-03-17 22:46:42 +01:00
dst_apiurl , dst_project , dst_package ,
2008-04-30 14:28:25 +02:00
client_side_copy = opts . client_side_copy ,
2009-03-11 16:23:23 +01:00
keep_maintainers = opts . keep_maintainers ,
2009-03-31 00:17:18 +02:00
keep_develproject = opts . keep_develproject ,
2009-05-14 13:50:53 +02:00
expand = opts . expand ,
revision = rev ,
2011-11-21 12:33:32 +01:00
comment = comment ,
keep_link = opts . keep_link )
2013-09-17 16:39:23 +02:00
print ( r )
2013-07-08 15:58:41 +02:00
@cmdln.option ( ' -r ' , ' --repo ' , metavar = ' REPO ' ,
help = ' Release only binaries from the specified repository ' )
@cmdln.option ( ' --target-project ' , metavar = ' TARGETPROJECT ' ,
help = ' Release only to specified project ' )
@cmdln.option ( ' --target-repository ' , metavar = ' TARGETREPOSITORY ' ,
help = ' Release only to specified repository ' )
2014-03-05 16:03:23 +01:00
@cmdln.option ( ' --set-release ' , metavar = ' RELEASETAG ' ,
help = ' rename binaries during release using this release tag ' )
2013-07-08 15:58:41 +02:00
def do_release ( self , subcmd , opts , * args ) :
2014-08-12 15:01:16 +02:00
""" $ {cmd_name} : Release sources and binaries
2013-07-08 15:58:41 +02:00
This command is used to transfer sources and binaries without rebuilding them .
It requires defined release targets set to trigger = " manual " . Please refer the
release management chapter in the OBS book for details .
usage :
osc release [ SOURCEPROJECT [ SOURCEPACKAGE ] ]
$ { cmd_option_list }
"""
2016-05-15 17:50:31 +02:00
2013-07-08 15:58:41 +02:00
args = slash_split ( args )
apiurl = self . get_api_url ( )
source_project = source_package = None
if len ( args ) > 2 :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
if len ( args ) == 0 :
2016-08-02 14:09:18 +02:00
if is_package_dir ( os . curdir ) :
source_project = store_read_project ( os . curdir )
source_package = store_read_package ( os . curdir )
elif is_project_dir ( os . curdir ) :
2013-07-08 15:58:41 +02:00
source_project = store_read_project ( os . curdir )
else :
raise oscerr . WrongArgs ( ' Too few arguments. ' )
if len ( args ) > 0 :
source_project = args [ 0 ]
if len ( args ) > 1 :
source_package = args [ 1 ]
query = { ' cmd ' : ' release ' }
if opts . target_project :
2015-09-07 12:37:33 +02:00
query [ " target_project " ] = opts . target_project
2013-07-08 15:58:41 +02:00
if opts . target_repository :
2015-09-07 12:37:33 +02:00
query [ " target_repository " ] = opts . target_repository
if opts . repo :
query [ " repository " ] = opts . repo
2014-03-05 16:03:23 +01:00
if opts . set_release :
query [ " setrelease " ] = opts . set_release
2013-07-08 15:58:41 +02:00
baseurl = [ ' source ' , source_project ]
if source_package :
baseurl . append ( source_package )
url = makeurl ( apiurl , baseurl , query = query )
f = http_POST ( url )
while True :
buf = f . read ( 16384 )
if not buf :
break
sys . stdout . write ( buf )
2006-08-11 12:37:29 +02:00
2011-03-07 19:45:44 +01:00
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify message TEXT ' )
def do_releaserequest ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Create a request for releasing a maintenance update.
2012-03-26 15:43:33 +02:00
[ See http : / / doc . opensuse . org / products / draft / OBS / obs - reference - guide_draft / cha . obs . maintenance_setup . html
2011-05-19 17:10:08 +02:00
for information on this topic . ]
2011-03-07 19:45:44 +01:00
This command is used by the maintence team to start the release process of a maintenance update .
This includes usually testing based on the defined reviewers of the update project .
usage :
osc releaserequest [ SOURCEPROJECT ]
2011-05-19 17:10:08 +02:00
2011-03-07 19:45:44 +01:00
$ { cmd_option_list }
"""
2016-05-15 17:50:31 +02:00
2011-03-07 19:45:44 +01:00
# FIXME: additional parameters can be a certain repo list to create a partitial release
args = slash_split ( args )
apiurl = self . get_api_url ( )
source_project = None
if len ( args ) > 1 :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
if len ( args ) == 0 and is_project_dir ( os . curdir ) :
source_project = store_read_project ( os . curdir )
elif len ( args ) == 0 :
raise oscerr . WrongArgs ( ' Too few arguments. ' )
if len ( args ) > 0 :
source_project = args [ 0 ]
if not opts . message :
opts . message = edit_message ( )
r = create_release_request ( apiurl , source_project , opts . message )
2013-04-09 12:51:28 +02:00
print ( r . reqid )
2011-03-07 19:45:44 +01:00
2011-05-02 13:21:28 +02:00
@cmdln.option ( ' -a ' , ' --attribute ' , metavar = ' ATTRIBUTE ' ,
help = ' Use this attribute to find default maintenance project (default is OBS:MaintenanceProject) ' )
2011-05-04 12:11:24 +02:00
@cmdln.option ( ' --noaccess ' , action = ' store_true ' ,
help = ' Create a hidden project ' )
2011-05-02 13:21:28 +02:00
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify message TEXT ' )
def do_createincident ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Create a maintenance incident
2012-03-26 15:43:33 +02:00
[ See http : / / doc . opensuse . org / products / draft / OBS / obs - reference - guide_draft / cha . obs . maintenance_setup . html
2011-05-02 13:21:28 +02:00
for information on this topic . ]
This command is asking to open an empty maintence incident . This can usually only be done by a responsible
maintenance team .
Please see the " mbranch " command on how to full such a project content and
2011-06-08 12:10:47 +02:00
the " patchinfo " command how add the required maintenance update information .
2011-05-02 13:21:28 +02:00
usage :
osc createincident [ MAINTENANCEPROJECT ]
$ { cmd_option_list }
"""
args = slash_split ( args )
apiurl = self . get_api_url ( )
maintenance_attribute = conf . config [ ' maintenance_attribute ' ]
if opts . attribute :
maintenance_attribute = opts . attribute
source_project = target_project = None
if len ( args ) > 1 :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
if len ( args ) == 1 :
2011-06-27 14:37:08 +02:00
target_project = args [ 0 ]
2011-05-02 13:21:28 +02:00
else :
xpath = ' attribute/@name = \' %s \' ' % maintenance_attribute
res = search ( apiurl , project_id = xpath )
root = res [ ' project_id ' ]
project = root . find ( ' project ' )
if project is None :
sys . exit ( ' Unable to find defined OBS:MaintenanceProject project on server. ' )
target_project = project . get ( ' name ' )
2013-04-09 12:51:28 +02:00
print ( ' Using target project \' %s \' ' % target_project )
2011-05-02 13:21:28 +02:00
query = { ' cmd ' : ' createmaintenanceincident ' }
2011-05-04 12:11:24 +02:00
if opts . noaccess :
2013-05-27 12:16:44 +02:00
query [ " noaccess " ] = 1
2011-05-02 13:21:28 +02:00
url = makeurl ( apiurl , [ ' source ' , target_project ] , query = query )
r = http_POST ( url , data = opts . message )
2011-07-19 18:05:07 +02:00
project = None
for i in ET . fromstring ( r . read ( ) ) . findall ( ' data ' ) :
if i . get ( ' name ' ) == ' targetproject ' :
project = i . text . strip ( )
if project :
2013-05-27 12:16:44 +02:00
print ( " Incident project created: " , project )
2011-07-19 18:05:07 +02:00
else :
2013-05-27 12:16:44 +02:00
print ( ET . parse ( r ) . getroot ( ) . get ( ' code ' ) )
print ( ET . parse ( r ) . getroot ( ) . get ( ' error ' ) )
2011-05-02 13:21:28 +02:00
2011-03-07 11:46:51 +01:00
@cmdln.option ( ' -a ' , ' --attribute ' , metavar = ' ATTRIBUTE ' ,
2011-03-11 11:07:35 +01:00
help = ' Use this attribute to find default maintenance project (default is OBS:MaintenanceProject) ' )
2011-03-07 11:46:51 +01:00
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify message TEXT ' )
2014-12-12 13:44:24 +01:00
@cmdln.option ( ' --release-project ' , metavar = ' RELEASEPROJECT ' ,
help = ' Specify the release project ' )
2011-10-31 11:30:26 +01:00
@cmdln.option ( ' --no-cleanup ' , action = ' store_true ' ,
help = ' do not remove source project on accept ' )
2012-10-10 15:54:21 +02:00
@cmdln.option ( ' --cleanup ' , action = ' store_true ' ,
help = ' do remove source project on accept ' )
2012-01-19 11:36:57 +01:00
@cmdln.option ( ' --incident ' , metavar = ' INCIDENT ' ,
help = ' specify incident number to merge in ' )
@cmdln.option ( ' --incident-project ' , metavar = ' INCIDENT_PROJECT ' ,
help = ' specify incident project to merge in ' )
2015-08-07 10:17:40 +02:00
@cmdln.option ( ' -s ' , ' --supersede ' , metavar = ' SUPERSEDE ' ,
help = ' Superseding another request by this one ' )
2012-02-21 18:01:54 +01:00
@cmdln.alias ( " mr " )
2011-03-07 11:46:51 +01:00
def do_maintenancerequest ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Create a request for starting a maintenance incident.
2012-03-26 15:43:33 +02:00
[ See http : / / doc . opensuse . org / products / draft / OBS / obs - reference - guide_draft / cha . obs . maintenance_setup . html
2011-03-07 11:46:51 +01:00
for information on this topic . ]
2011-04-28 11:14:38 +02:00
This command is asking the maintence team to start a maintence incident based on a
2011-03-07 11:46:51 +01:00
created maintenance update . Please see the " mbranch " command on how to create such a project and
2011-04-28 11:14:38 +02:00
the " patchinfo " command how add the required maintenance update information .
2011-03-07 11:46:51 +01:00
usage :
2012-02-21 18:01:54 +01:00
osc maintenancerequest [ SOURCEPROJECT [ SOURCEPACKAGES RELEASEPROJECT ] ]
2015-08-25 12:34:13 +02:00
osc maintenancerequest .
2016-05-15 17:50:31 +02:00
The 2 nd line when issued within a package directory provides a short cut to submit a single
2015-08-25 12:34:13 +02:00
package ( the one in the current directory ) from the project of this package to be submitted
to the release project this package links to . This syntax is only valid when specified from
a package subdirectory .
2011-03-07 11:46:51 +01:00
$ { cmd_option_list }
"""
2014-12-12 13:44:24 +01:00
#FIXME: the follow syntax would make more sense and would obsolete the --release-project parameter
# but is incompatible with the current one
# osc maintenancerequest [ SOURCEPROJECT [ RELEASEPROJECT [ SOURCEPACKAGES ] ]
2011-03-07 11:46:51 +01:00
args = slash_split ( args )
apiurl = self . get_api_url ( )
2011-05-02 13:21:28 +02:00
maintenance_attribute = conf . config [ ' maintenance_attribute ' ]
2011-03-07 11:46:51 +01:00
if opts . attribute :
2011-05-02 13:21:28 +02:00
maintenance_attribute = opts . attribute
2011-03-07 11:46:51 +01:00
2015-09-24 18:25:22 +02:00
source_project = target_project = release_project = opt_sourceupdate = None
source_packages = [ ]
2011-03-07 11:46:51 +01:00
2012-05-03 13:50:44 +02:00
if len ( args ) == 0 and ( is_project_dir ( os . curdir ) or is_package_dir ( os . curdir ) ) :
2011-03-07 13:08:34 +01:00
source_project = store_read_project ( os . curdir )
elif len ( args ) == 0 :
raise oscerr . WrongArgs ( ' Too few arguments. ' )
2011-03-07 11:46:51 +01:00
if len ( args ) > 0 :
2015-08-25 12:34:13 +02:00
if len ( args ) == 1 and args [ 0 ] == ' . ' :
if is_package_dir ( os . curdir ) :
source_project = store_read_project ( os . curdir )
source_packages = [ store_read_package ( os . curdir ) ]
p = Package ( os . curdir )
release_project = p . linkinfo . project
else :
raise oscerr . WrongArgs ( ' No package directory ' )
else :
source_project = args [ 0 ]
2011-03-07 11:46:51 +01:00
if len ( args ) > 1 :
2012-02-21 18:01:54 +01:00
if len ( args ) == 2 :
sys . exit ( ' Source package defined, but no release project. ' )
2012-01-19 11:36:57 +01:00
source_packages = args [ 1 : ]
2012-02-21 18:01:54 +01:00
release_project = args [ - 1 ]
source_packages . remove ( release_project )
2012-10-10 15:54:21 +02:00
if opts . cleanup :
opt_sourceupdate = ' cleanup '
2012-02-15 13:13:44 +01:00
if not opts . no_cleanup :
default_branch = ' home: %s :branches: ' % ( conf . get_apiurl_usr ( apiurl ) )
2012-10-10 15:54:21 +02:00
if source_project . startswith ( default_branch ) :
2012-02-15 13:13:44 +01:00
opt_sourceupdate = ' cleanup '
2012-01-19 11:36:57 +01:00
2014-12-12 13:44:24 +01:00
if opts . release_project :
release_project = opts . release_project
2012-01-19 11:36:57 +01:00
if opts . incident_project :
target_project = opts . incident_project
2011-03-07 11:46:51 +01:00
else :
2011-05-02 13:21:28 +02:00
xpath = ' attribute/@name = \' %s \' ' % maintenance_attribute
2011-03-07 13:08:34 +01:00
res = search ( apiurl , project_id = xpath )
root = res [ ' project_id ' ]
project = root . find ( ' project ' )
if project is None :
2011-03-11 11:07:35 +01:00
sys . exit ( ' Unable to find defined OBS:MaintenanceProject project on server. ' )
2011-03-07 13:08:34 +01:00
target_project = project . get ( ' name ' )
2012-01-19 11:36:57 +01:00
if opts . incident :
target_project + = " : " + opts . incident
2013-04-09 12:51:28 +02:00
print ( ' Using target project \' %s \' ' % target_project )
2011-03-07 11:46:51 +01:00
if not opts . message :
opts . message = edit_message ( )
2015-08-07 10:17:40 +02:00
supersede_existing = False
reqs = [ ]
if not opts . supersede :
( supersede_existing , reqs ) = check_existing_maintenance_requests ( apiurl ,
source_project ,
source_packages ,
target_project ,
None ) # unspecified release project
2012-02-21 18:01:54 +01:00
r = create_maintenance_request ( apiurl , source_project , source_packages , target_project , release_project , opt_sourceupdate , opts . message )
2013-04-09 12:51:28 +02:00
print ( r . reqid )
2011-03-07 11:46:51 +01:00
2015-08-07 10:17:40 +02:00
if supersede_existing :
for req in reqs :
change_request_state ( apiurl , req . reqid , ' superseded ' ,
' superseded by %s ' % r . reqid , r . reqid )
if opts . supersede :
change_request_state ( apiurl , opts . supersede , ' superseded ' ,
opts . message or ' ' , r . reqid )
2011-03-07 11:46:51 +01:00
2009-11-02 09:32:15 +01:00
@cmdln.option ( ' -c ' , ' --checkout ' , action = ' store_true ' ,
help = ' Checkout branched package afterwards ' \
' ( \' osc bco \' is a shorthand for this option) ' )
@cmdln.option ( ' -a ' , ' --attribute ' , metavar = ' ATTRIBUTE ' ,
help = ' Use this attribute to find affected packages (default is OBS:Maintained) ' )
@cmdln.option ( ' -u ' , ' --update-project-attribute ' , metavar = ' UPDATE_ATTRIBUTE ' ,
help = ' Use this attribute to find update projects (default is OBS:UpdateProject) ' )
2012-01-05 16:15:29 +01:00
@cmdln.option ( ' --dryrun ' , action = ' store_true ' ,
help = ' Just simulate the action and report back the result. ' )
@cmdln.option ( ' --noaccess ' , action = ' store_true ' ,
help = ' Create a hidden project ' )
@cmdln.option ( ' --nodevelproject ' , action = ' store_true ' ,
help = ' do not follow a defined devel project ' \
' (primary project where a package is developed) ' )
@cmdln.alias ( ' sm ' )
@cmdln.alias ( ' maintained ' )
2009-11-02 09:32:15 +01:00
def do_mbranch ( self , subcmd , opts , * args ) :
2016-03-19 22:01:52 +01:00
""" $ {cmd_name} : Search or branch multiple instances of a package
2012-01-05 16:15:29 +01:00
This command is used for searching all relevant instances of packages
and creating links of them in one project .
This is esp . used for maintenance updates . It can also be used to branch
all packages marked before with a given attribute .
2009-11-02 09:32:15 +01:00
2010-07-27 15:20:35 +02:00
[ See http : / / en . opensuse . org / openSUSE : Build_Service_Concept_Maintenance
2010-07-26 19:45:42 +02:00
for information on this topic . ]
2009-11-02 09:32:15 +01:00
The branched package will live in
home : USERNAME : branches : ATTRIBUTE : PACKAGE
if nothing else specified .
usage :
2012-01-05 16:15:29 +01:00
osc sm [ SOURCEPACKAGE ] [ - a ATTRIBUTE ]
2009-11-02 09:32:15 +01:00
osc mbranch [ SOURCEPACKAGE [ TARGETPROJECT ] ]
$ { cmd_option_list }
"""
args = slash_split ( args )
2010-07-29 17:29:07 +02:00
apiurl = self . get_api_url ( )
2009-11-02 09:32:15 +01:00
tproject = None
maintained_attribute = conf . config [ ' maintained_attribute ' ]
2012-01-05 11:27:22 +01:00
if opts . attribute :
maintained_attribute = opts . attribute
2009-11-02 09:32:15 +01:00
maintained_update_project_attribute = conf . config [ ' maintained_update_project_attribute ' ]
2012-01-05 14:37:09 +01:00
if opts . update_project_attribute :
maintained_update_project_attribute = opts . update_project_attribute
2009-11-02 09:32:15 +01:00
2010-02-09 00:08:21 +01:00
if not len ( args ) or len ( args ) > 2 :
2009-11-02 09:32:15 +01:00
raise oscerr . WrongArgs ( ' Wrong number of arguments. ' )
if len ( args ) > = 1 :
package = args [ 0 ]
if len ( args ) > = 2 :
tproject = args [ 1 ]
2012-01-05 16:15:29 +01:00
if subcmd == ' sm ' or subcmd == ' maintained ' :
opts . dryrun = 1
2009-11-02 09:32:15 +01:00
2012-01-05 16:15:29 +01:00
result = attribute_branch_pkg ( apiurl , maintained_attribute , maintained_update_project_attribute , \
package , tproject , noaccess = opts . noaccess , nodevelproject = opts . nodevelproject , dryrun = opts . dryrun )
if result is None :
2013-04-09 12:51:28 +02:00
print ( ' ERROR: Attribute branch call came not back with a project. ' , file = sys . stderr )
2009-11-02 09:32:15 +01:00
sys . exit ( 1 )
2012-01-05 16:15:29 +01:00
if opts . dryrun :
for r in result . findall ( ' package ' ) :
2015-05-05 14:01:10 +02:00
line = " %s / %s " % ( r . get ( ' project ' ) , r . get ( ' package ' ) )
for d in r . findall ( ' devel ' ) :
line + = " using sources from %s / %s " % ( d . get ( ' project ' ) , d . get ( ' package ' ) )
print ( line )
2012-01-05 16:15:29 +01:00
return
2016-05-15 17:50:31 +02:00
2013-11-05 15:07:38 +01:00
apiopt = ' '
if conf . get_configParser ( ) . get ( ' general ' , ' apiurl ' ) != apiurl :
apiopt = ' -A %s ' % apiurl
print ( ' A working copy of the maintenance branch can be checked out with: \n \n ' \
' osc %s co %s ' \
% ( apiopt , result ) )
2009-11-02 09:32:15 +01:00
if opts . checkout :
2012-01-05 16:15:29 +01:00
Project . init_project ( apiurl , result , result , conf . config [ ' do_package_tracking ' ] )
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' A ' , result ) )
2009-11-02 09:32:15 +01:00
# all packages
2012-01-05 16:15:29 +01:00
for package in meta_get_packagelist ( apiurl , result ) :
2009-11-02 09:32:15 +01:00
try :
2012-01-05 16:15:29 +01:00
checkout_package ( apiurl , result , package , expand_link = True , prj_dir = result )
2009-11-02 09:32:15 +01:00
except :
2013-04-09 12:51:28 +02:00
print ( ' Error while checkout package: \n ' , package , file = sys . stderr )
2009-11-02 09:32:15 +01:00
if conf . config [ ' verbose ' ] :
2013-04-09 12:51:28 +02:00
print ( ' Note: You can use " osc delete " or " osc submitpac " when done. \n ' )
2009-11-02 09:32:15 +01:00
2009-08-20 21:28:05 +02:00
@cmdln.alias ( ' branchco ' )
@cmdln.alias ( ' bco ' )
@cmdln.alias ( ' getpac ' )
2008-06-03 15:16:55 +02:00
@cmdln.option ( ' --nodevelproject ' , action = ' store_true ' ,
help = ' do not follow a defined devel project ' \
' (primary project where a package is developed) ' )
2009-04-17 14:02:02 +02:00
@cmdln.option ( ' -c ' , ' --checkout ' , action = ' store_true ' ,
2011-02-02 17:11:14 +01:00
help = ' Checkout branched package afterwards using " co -e -S " ' \
2009-08-20 21:28:05 +02:00
' ( \' osc bco \' is a shorthand for this option) ' )
2010-05-17 20:14:49 +02:00
@cmdln.option ( ' -f ' , ' --force ' , default = False , action = " store_true " ,
2010-05-19 10:47:01 +02:00
help = ' force branch, overwrite target ' )
2011-11-25 10:12:16 +01:00
@cmdln.option ( ' --add-repositories ' , default = False , action = " store_true " ,
help = ' Add repositories to target project (happens by default when project is new) ' )
2011-12-01 15:54:50 +01:00
@cmdln.option ( ' --extend-package-names ' , default = False , action = " store_true " ,
help = ' Extend packages names with project name as suffix ' )
2011-05-04 12:11:24 +02:00
@cmdln.option ( ' --noaccess ' , action = ' store_true ' ,
help = ' Create a hidden project ' )
2010-03-02 01:34:17 +01:00
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify message TEXT ' )
2012-02-09 10:04:44 +01:00
@cmdln.option ( ' -M ' , ' --maintenance ' , default = False , action = " store_true " ,
help = ' Create project and package in maintenance mode ' )
2011-12-15 15:12:13 +01:00
@cmdln.option ( ' -N ' , ' --new-package ' , action = ' store_true ' ,
help = ' create a branch pointing to a not yet existing package ' )
2010-05-17 20:14:49 +02:00
@cmdln.option ( ' -r ' , ' --revision ' , metavar = ' rev ' ,
help = ' branch against a specific revision ' )
2015-10-23 11:08:30 +02:00
@cmdln.option ( ' --linkrev ' , metavar = ' linkrev ' ,
help = ' specify the used revision in the link target. ' )
2016-03-02 17:12:28 +01:00
@cmdln.option ( ' --add-repositories-block ' , metavar = ' add_repositories_block ' ,
help = ' specify the used block strategy for new repositories ' )
@cmdln.option ( ' --add-repositories-rebuild ' , metavar = ' add_repositories_rebuild ' ,
help = ' specify the used rebuild strategy for new repositories ' )
2008-10-16 14:34:41 +02:00
def do_branch ( self , subcmd , opts , * args ) :
2008-05-21 17:49:00 +02:00
""" $ {cmd_name} : Branch a package
2010-07-27 15:20:35 +02:00
[ See http : / / en . opensuse . org / openSUSE : Build_Service_Collaboration
2010-07-26 19:45:42 +02:00
for information on this topic . ]
2008-06-06 14:04:34 +02:00
2008-05-21 17:49:00 +02:00
Create a source link from a package of an existing project to a new
subproject of the requesters home project ( home : branches : )
The branched package will live in
home : USERNAME : branches : PROJECT / PACKAGE
2009-04-17 14:02:02 +02:00
if nothing else specified .
2009-05-18 16:50:43 +02:00
2011-03-09 16:10:48 +01:00
With getpac or bco , the branched package will come from one of
2009-09-03 23:32:36 +02:00
% ( getpac_default_project ) s
2011-03-17 18:48:20 +01:00
( list of projects from oscrc : getpac_default_project )
if nothing else is specfied on the command line .
2009-09-03 20:08:43 +02:00
2015-10-23 11:08:30 +02:00
In case of branch errors , where the source has currently merge
conflicts use - - linkrev = base option .
2009-05-18 16:50:43 +02:00
usage :
2010-04-27 12:23:03 +02:00
osc branch
2009-04-17 14:02:02 +02:00
osc branch SOURCEPROJECT SOURCEPACKAGE
osc branch SOURCEPROJECT SOURCEPACKAGE TARGETPROJECT
osc branch SOURCEPROJECT SOURCEPACKAGE TARGETPROJECT TARGETPACKAGE
2010-08-20 13:23:23 +02:00
osc getpac SOURCEPACKAGE
2009-08-20 21:28:05 +02:00
osc bco . . .
2008-05-21 17:49:00 +02:00
$ { cmd_option_list }
"""
2014-08-12 15:01:16 +02:00
if subcmd == ' getpac ' or subcmd == ' branchco ' or subcmd == ' bco ' :
2013-05-27 13:38:49 +02:00
opts . checkout = True
2008-10-16 14:34:41 +02:00
args = slash_split ( args )
2009-04-17 14:02:02 +02:00
tproject = tpackage = None
2009-08-20 21:28:05 +02:00
2009-09-03 23:32:36 +02:00
if ( subcmd == ' getpac ' or subcmd == ' bco ' ) and len ( args ) == 1 :
2011-03-09 16:10:48 +01:00
def_p = find_default_project ( self . get_api_url ( ) , args [ 0 ] )
2013-04-09 12:51:28 +02:00
print ( ' defaulting to %s / %s ' % ( def_p , args [ 0 ] ) , file = sys . stderr )
2009-09-03 20:08:43 +02:00
# python has no args.unshift ???
2011-03-09 16:10:48 +01:00
args = [ def_p , args [ 0 ] ]
2016-05-15 17:50:31 +02:00
2010-04-27 12:23:03 +02:00
if len ( args ) == 0 and is_package_dir ( ' . ' ) :
args = ( store_read_project ( ' . ' ) , store_read_package ( ' . ' ) )
2009-09-03 20:08:43 +02:00
2010-02-08 23:31:27 +01:00
if len ( args ) < 2 or len ( args ) > 4 :
2008-10-16 14:34:41 +02:00
raise oscerr . WrongArgs ( ' Wrong number of arguments. ' )
2010-04-27 12:23:03 +02:00
2010-07-29 17:29:07 +02:00
apiurl = self . get_api_url ( )
2010-08-20 13:25:32 +02:00
expected = ' home: %s :branches: %s ' % ( conf . get_apiurl_usr ( apiurl ) , args [ 0 ] )
2009-04-17 14:02:02 +02:00
if len ( args ) > = 3 :
2010-01-15 10:29:07 +01:00
expected = tproject = args [ 2 ]
2009-04-17 14:02:02 +02:00
if len ( args ) > = 4 :
tpackage = args [ 3 ]
2008-10-16 14:34:41 +02:00
2015-07-21 13:02:48 +02:00
try :
exists , targetprj , targetpkg , srcprj , srcpkg = \
2010-07-29 17:29:07 +02:00
branch_pkg ( apiurl , args [ 0 ] , args [ 1 ] ,
2009-10-20 16:30:15 +02:00
nodevelproject = opts . nodevelproject , rev = opts . revision ,
2015-10-23 11:08:30 +02:00
linkrev = opts . linkrev ,
2009-10-20 16:30:15 +02:00
target_project = tproject , target_package = tpackage ,
2010-05-17 20:14:49 +02:00
return_existing = opts . checkout , msg = opts . message or ' ' ,
2011-12-01 15:54:50 +01:00
force = opts . force , noaccess = opts . noaccess ,
add_repositories = opts . add_repositories ,
2016-03-02 17:12:28 +01:00
add_repositories_block = opts . add_repositories_block ,
add_repositories_rebuild = opts . add_repositories_rebuild ,
2012-02-09 10:04:44 +01:00
extend_package_names = opts . extend_package_names ,
missingok = opts . new_package ,
maintenance = opts . maintenance )
2015-07-21 13:02:48 +02:00
except oscerr . NotMissing as e :
print ( ' NOTE: Package target exists already via project links, link will point to given project. ' )
print ( ' A submission will initialize a new instance. ' )
exists , targetprj , targetpkg , srcprj , srcpkg = \
branch_pkg ( apiurl , args [ 0 ] , args [ 1 ] ,
nodevelproject = opts . nodevelproject , rev = opts . revision ,
2015-10-23 11:08:30 +02:00
linkrev = opts . linkrev ,
2015-07-21 13:02:48 +02:00
target_project = tproject , target_package = tpackage ,
return_existing = opts . checkout , msg = opts . message or ' ' ,
force = opts . force , noaccess = opts . noaccess ,
add_repositories = opts . add_repositories ,
2016-03-02 17:12:28 +01:00
add_repositories_block = opts . add_repositories_block ,
add_repositories_rebuild = opts . add_repositories_rebuild ,
2015-07-21 13:02:48 +02:00
extend_package_names = opts . extend_package_names ,
missingok = False ,
maintenance = opts . maintenance ,
newinstance = opts . new_package )
2016-05-15 17:50:31 +02:00
2010-02-08 19:58:14 +01:00
if exists :
2013-04-09 12:51:28 +02:00
print ( ' Using existing branch project: %s ' % targetprj , file = sys . stderr )
2009-08-20 21:28:05 +02:00
2009-09-23 01:31:10 +02:00
devloc = None
2011-02-08 16:56:16 +01:00
if not exists and ( srcprj != args [ 0 ] or srcpkg != args [ 1 ] ) :
try :
root = ET . fromstring ( ' ' . join ( show_attribute_meta ( apiurl , args [ 0 ] , None , None ,
conf . config [ ' maintained_update_project_attribute ' ] , False , False ) ) )
# this might raise an AttributeError
uproject = root . find ( ' attribute ' ) . find ( ' value ' ) . text
2013-04-09 12:51:28 +02:00
print ( ' \n Note: The branch has been created from the configured update project: %s ' \
% uproject )
2013-04-09 14:03:17 +02:00
except ( AttributeError , HTTPError ) as e :
2011-02-08 16:56:16 +01:00
devloc = srcprj
2013-04-09 12:51:28 +02:00
print ( ' \n Note: The branch has been created of a different project, \n ' \
2011-02-08 16:56:16 +01:00
' %s , \n ' \
' which is the primary location of where development for \n ' \
' that package takes place. \n ' \
' That \' s also where you would normally make changes against. \n ' \
' A direct branch of the specified package can be forced \n ' \
2013-04-09 12:51:28 +02:00
' with the --nodevelproject option. \n ' % devloc )
2009-04-17 14:02:02 +02:00
2012-01-05 17:15:39 +01:00
package = targetpkg or args [ 1 ]
2009-04-17 14:02:02 +02:00
if opts . checkout :
2015-10-03 22:24:58 +02:00
checkout_package ( apiurl , targetprj , package , server_service_files = False ,
2010-02-08 19:58:14 +01:00
expand_link = True , prj_dir = targetprj )
2009-08-20 21:28:05 +02:00
if conf . config [ ' verbose ' ] :
2013-04-09 12:51:28 +02:00
print ( ' Note: You can use " osc delete " or " osc submitpac " when done. \n ' )
2009-04-17 14:02:02 +02:00
else :
apiopt = ' '
2010-07-29 17:29:07 +02:00
if conf . get_configParser ( ) . get ( ' general ' , ' apiurl ' ) != apiurl :
apiopt = ' -A %s ' % apiurl
2013-04-09 12:51:28 +02:00
print ( ' A working copy of the branched package can be checked out with: \n \n ' \
2009-04-17 14:02:02 +02:00
' osc %s co %s / %s ' \
2013-04-09 12:51:28 +02:00
% ( apiopt , targetprj , package ) )
2010-07-29 17:29:07 +02:00
print_request_list ( apiurl , args [ 0 ] , args [ 1 ] )
2009-09-23 01:31:10 +02:00
if devloc :
2011-02-08 16:56:16 +01:00
print_request_list ( apiurl , devloc , srcpkg )
2008-05-21 17:49:00 +02:00
2009-05-18 16:50:43 +02:00
2011-05-26 10:21:14 +02:00
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify log message TEXT ' )
2010-05-21 19:02:42 +02:00
def do_undelete ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Restores a deleted project or package on the server.
The server restores a package including the sources and meta configuration .
Binaries remain to be lost and will be rebuild .
usage :
osc undelete PROJECT
osc undelete PROJECT PACKAGE [ PACKAGE . . . ]
$ { cmd_option_list }
"""
args = slash_split ( args )
if len ( args ) < 1 :
raise oscerr . WrongArgs ( ' Missing argument. ' )
2010-07-29 17:29:07 +02:00
2011-05-26 10:21:14 +02:00
msg = ' '
if opts . message :
msg = opts . message
else :
msg = edit_message ( )
2010-07-29 17:29:07 +02:00
apiurl = self . get_api_url ( )
2010-05-21 19:02:42 +02:00
prj = args [ 0 ]
pkgs = args [ 1 : ]
if pkgs :
for pkg in pkgs :
2011-05-26 10:21:14 +02:00
undelete_package ( apiurl , prj , pkg , msg )
2010-05-21 19:02:42 +02:00
else :
2011-05-26 10:21:14 +02:00
undelete_project ( apiurl , prj , msg )
2010-05-21 19:02:42 +02:00
2006-08-11 12:37:29 +02:00
2011-05-23 20:42:35 +02:00
@cmdln.option ( ' -r ' , ' --recursive ' , action = ' store_true ' ,
help = ' deletes a project with packages inside ' )
2007-10-14 01:15:49 +02:00
@cmdln.option ( ' -f ' , ' --force ' , action = ' store_true ' ,
2011-05-23 20:42:35 +02:00
help = ' deletes a project where other depends on ' )
2011-05-26 10:21:14 +02:00
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify log message TEXT ' )
2009-05-04 21:07:05 +02:00
def do_rdelete ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Delete a project or packages on the server.
2006-09-25 17:11:03 +02:00
2007-10-14 01:15:49 +02:00
As a safety measure , project must be empty ( i . e . , you need to delete all
2011-03-05 20:08:47 +01:00
packages first ) . Also , packages must have no requests pending ( i . e . , you need
to accept / revoke such requests first ) .
If you are sure that you want to remove this project and all
2011-05-23 20:42:35 +02:00
its packages use \' --recursive \' switch.
It may still not work because other depends on it . If you want to ignore this as
well use \' --force \' switch.
2006-09-25 17:11:03 +02:00
2009-05-04 21:07:05 +02:00
usage :
2011-05-23 20:42:35 +02:00
osc rdelete [ - r ] [ - f ] PROJECT [ PACKAGE ]
2007-05-08 10:59:10 +02:00
2007-04-25 01:00:12 +02:00
$ { cmd_option_list }
"""
2006-09-25 17:11:03 +02:00
2009-05-04 21:07:05 +02:00
args = slash_split ( args )
2010-11-24 14:17:14 +01:00
if len ( args ) < 1 or len ( args ) > 2 :
raise oscerr . WrongArgs ( ' Wrong number of arguments ' )
2010-07-29 17:29:07 +02:00
apiurl = self . get_api_url ( )
2009-05-04 21:07:05 +02:00
prj = args [ 0 ]
2011-05-26 10:21:14 +02:00
msg = ' '
if opts . message :
msg = opts . message
else :
msg = edit_message ( )
2010-11-24 14:17:14 +01:00
# empty arguments result in recursive project delete ...
if not len ( prj ) :
raise oscerr . WrongArgs ( ' Project argument is empty ' )
if len ( args ) > 1 :
pkg = args [ 1 ]
if not len ( pkg ) :
raise oscerr . WrongArgs ( ' Package argument is empty ' )
2011-03-05 20:08:47 +01:00
## FIXME: core.py:commitDelPackage() should have something similar
rlist = get_request_list ( apiurl , prj , pkg )
2014-08-12 15:01:16 +02:00
for rq in rlist :
2013-05-27 13:38:49 +02:00
print ( rq )
2011-03-05 20:08:47 +01:00
if len ( rlist ) > = 1 and not opts . force :
2013-05-27 12:16:44 +02:00
print ( ' Package has pending requests. Deleting the package will break them. ' \
' They should be accepted/declined/revoked before deleting the package. ' \
' Or just use \' --force \' . ' , file = sys . stderr )
sys . exit ( 1 )
2011-03-05 20:08:47 +01:00
2011-05-26 10:21:14 +02:00
delete_package ( apiurl , prj , pkg , opts . force , msg )
2010-11-24 14:17:14 +01:00
2011-05-23 20:42:35 +02:00
elif ( not opts . recursive ) and len ( meta_get_packagelist ( apiurl , prj ) ) > = 1 :
2013-04-09 12:51:28 +02:00
print ( ' Project contains packages. It must be empty before deleting it. ' \
2007-10-14 01:15:49 +02:00
' If you are sure that you want to remove this project and all its ' \
2013-04-09 12:51:28 +02:00
' packages use the \' --recursive \' switch. ' , file = sys . stderr )
2007-10-14 01:15:49 +02:00
sys . exit ( 1 )
else :
2011-05-26 10:21:14 +02:00
delete_project ( apiurl , prj , opts . force , msg )
2009-05-04 21:07:05 +02:00
2012-03-15 09:54:56 +01:00
2016-11-03 08:39:50 +01:00
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify log message TEXT ' )
2015-05-30 16:27:54 +02:00
def do_lock ( self , subcmd , opts , project , package = None ) :
""" $ {cmd_name} : Locks a project or package.
usage :
osc lock PROJECT [ PACKAGE ]
$ { cmd_option_list }
"""
apiurl = self . get_api_url ( )
kind = ' prj '
path_args = ( project , )
if package is not None :
kind = ' pkg '
path_args = ( project , package )
meta = meta_exists ( kind , path_args , create_new = False , apiurl = apiurl )
root = ET . fromstring ( ' ' . join ( meta ) )
if root . find ( ' lock ' ) is not None :
print ( ' Already locked ' , file = sys . stderr )
sys . exit ( 1 )
# alternatively, we could also use the set_flag api call
# instead of manually manipulating the xml
lock = ET . SubElement ( root , ' lock ' )
ET . SubElement ( lock , ' enable ' )
meta = ET . tostring ( root )
2016-11-03 08:39:50 +01:00
edit_meta ( kind , path_args = path_args , data = meta , msg = opts . message )
2015-05-30 16:27:54 +02:00
2012-03-15 09:54:56 +01:00
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify log message TEXT ' )
def do_unlock ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Unlocks a project or package
Unlocks a locked project or package . A comment is required .
usage :
osc unlock PROJECT [ PACKAGE ]
$ { cmd_option_list }
"""
args = slash_split ( args )
if len ( args ) < 1 or len ( args ) > 2 :
raise oscerr . WrongArgs ( ' Wrong number of arguments ' )
apiurl = self . get_api_url ( )
prj = args [ 0 ]
msg = ' '
if opts . message :
msg = opts . message
else :
msg = edit_message ( )
# empty arguments result in recursive project delete ...
if not len ( prj ) :
raise oscerr . WrongArgs ( ' Project argument is empty ' )
if len ( args ) > 1 :
pkg = args [ 1 ]
if not len ( pkg ) :
raise oscerr . WrongArgs ( ' Package argument is empty ' )
unlock_package ( apiurl , prj , pkg , msg )
else :
unlock_project ( apiurl , prj , msg )
2009-05-04 21:07:05 +02:00
@cmdln.hide ( 1 )
def do_deletepac ( self , subcmd , opts , * args ) :
2016-05-15 17:50:31 +02:00
""" $ {cmd_name} :
Obsolete command to delete package . Use ' delete ' or ' rdelete ' now .
See the help output of ' delete ' and ' rdelete ' .
"""
print ( """ Command deletepac is obsolete !
2009-05-11 15:21:33 +02:00
Please use either
2009-05-04 21:07:05 +02:00
osc delete for checked out packages or projects
or
2016-05-15 17:50:31 +02:00
osc rdelete for server side operations . """ , file=sys.stderr)
2009-05-04 21:07:05 +02:00
2016-05-15 17:50:31 +02:00
return 2
2009-05-04 21:07:05 +02:00
@cmdln.hide ( 1 )
@cmdln.option ( ' -f ' , ' --force ' , action = ' store_true ' ,
help = ' deletes a project and its packages ' )
def do_deleteprj ( self , subcmd , opts , project ) :
2016-05-15 17:50:31 +02:00
""" $ {cmd_name} :
2006-09-25 17:11:03 +02:00
2016-05-15 17:50:31 +02:00
Obsolete command to delete project . Use ' rdelete ' now .
2006-09-25 17:11:03 +02:00
2016-05-15 17:50:31 +02:00
See the help output of ' rdelete ' .
2009-05-04 21:07:05 +02:00
"""
2016-05-15 17:50:31 +02:00
print ( " This command is obsolete. Use ' osc rdelete <project> ' . " , file = sys . stderr )
print ( " See ' osc help rdelete ' . " , file = sys . stderr )
return 2
2006-09-25 17:11:03 +02:00
2008-08-08 17:23:03 +02:00
@cmdln.alias ( ' metafromspec ' )
2014-05-22 13:01:44 +02:00
@cmdln.alias ( ' updatepkgmetafromspec ' )
2007-06-30 17:39:47 +02:00
@cmdln.option ( ' ' , ' --specfile ' , metavar = ' FILE ' ,
help = ' Path to specfile. (if you pass more than working copy this option is ignored) ' )
2007-04-25 01:00:12 +02:00
def do_updatepacmetafromspec ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Update package meta information from a specfile
2006-09-25 17:11:03 +02:00
2007-04-25 01:00:12 +02:00
ARG , if specified , is a package working copy .
2006-09-25 17:11:03 +02:00
2007-04-25 01:00:12 +02:00
$ { cmd_usage }
$ { cmd_option_list }
"""
2006-05-31 14:13:26 +02:00
2007-04-25 01:00:12 +02:00
args = parseargs ( args )
2010-02-09 00:08:21 +01:00
if opts . specfile and len ( args ) == 1 :
2007-06-30 17:39:47 +02:00
specfile = opts . specfile
else :
specfile = None
2007-04-25 01:00:12 +02:00
pacs = findpacs ( args )
for p in pacs :
2007-06-30 17:39:47 +02:00
p . read_meta_from_spec ( specfile )
2007-07-16 15:40:58 +02:00
p . update_package_meta ( )
2006-05-31 14:13:26 +02:00
2010-12-24 22:44:19 +01:00
@cmdln.alias ( ' linkdiff ' )
@cmdln.alias ( ' ldiff ' )
2007-04-25 01:00:12 +02:00
@cmdln.alias ( ' di ' )
2009-05-18 16:50:43 +02:00
@cmdln.option ( ' -c ' , ' --change ' , metavar = ' rev ' ,
help = ' the change made by revision rev (like -r rev-1:rev). '
' If rev is negative this is like -r rev:rev-1. ' )
2007-07-04 14:55:26 +02:00
@cmdln.option ( ' -r ' , ' --revision ' , metavar = ' rev1[:rev2] ' ,
help = ' If rev1 is specified it will compare your working copy against '
' the revision (rev1) on the server. '
2009-01-09 18:09:29 +01:00
' If rev1 and rev2 are specified it will compare rev1 against rev2 '
2009-01-16 15:45:27 +01:00
' (NOTE: changes in your working copy are ignored in this case) ' )
2009-09-07 20:49:01 +02:00
@cmdln.option ( ' -p ' , ' --plain ' , action = ' store_true ' ,
help = ' output the diff in plain (not unified) diff format ' )
2010-12-24 22:44:19 +01:00
@cmdln.option ( ' -l ' , ' --link ' , action = ' store_true ' ,
help = ' (osc linkdiff): compare against the base revision of the link ' )
2010-04-10 15:44:15 +02:00
@cmdln.option ( ' --missingok ' , action = ' store_true ' ,
help = ' do not fail if the source or target project/package does not exist on the server ' )
2007-04-25 01:00:12 +02:00
def do_diff ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Generates a diff
2006-05-31 14:13:26 +02:00
2007-04-25 01:00:12 +02:00
Generates a diff , comparing local changes against the repository
server .
2009-05-18 16:50:43 +02:00
2007-04-25 01:00:12 +02:00
$ { cmd_usage }
2010-12-24 22:44:19 +01:00
ARG , if specified , is a filename to include in the diff .
Default : all files .
osc diff - - link
2014-08-12 15:01:16 +02:00
osc linkdiff
2010-12-24 22:44:19 +01:00
Compare current checkout directory against the link base .
2014-08-12 15:01:16 +02:00
osc diff - - link PROJ PACK
osc linkdiff PROJ PACK
2010-12-24 22:44:19 +01:00
Compare a package against the link base ( ignoring working copy changes ) .
2007-04-25 01:00:12 +02:00
$ { cmd_option_list }
"""
2010-12-24 22:44:19 +01:00
if ( subcmd == ' ldiff ' or subcmd == ' linkdiff ' ) :
opts . link = True
2007-04-25 01:00:12 +02:00
args = parseargs ( args )
2016-05-15 17:50:31 +02:00
2010-12-24 22:44:19 +01:00
pacs = None
if not opts . link or not len ( args ) == 2 :
pacs = findpacs ( args )
if opts . link :
query = { ' rev ' : ' latest ' }
if pacs :
u = makeurl ( pacs [ 0 ] . apiurl , [ ' source ' , pacs [ 0 ] . prjname , pacs [ 0 ] . name ] , query = query )
else :
u = makeurl ( self . get_api_url ( ) , [ ' source ' , args [ 0 ] , args [ 1 ] ] , query = query )
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
linkinfo = root . find ( ' linkinfo ' )
if linkinfo == None :
raise oscerr . APIError ( ' package is not a source link ' )
baserev = linkinfo . get ( ' baserev ' )
opts . revision = baserev
if pacs :
2013-04-09 12:51:28 +02:00
print ( " diff working copy against last commited version \n " )
2010-12-24 22:44:19 +01:00
else :
2013-04-09 12:51:28 +02:00
print ( " diff commited package against linked revision %s \n " % baserev )
2012-01-04 13:27:31 +01:00
run_pager ( server_diff ( self . get_api_url ( ) , linkinfo . get ( ' project ' ) , linkinfo . get ( ' package ' ) , baserev ,
2010-12-24 22:44:19 +01:00
args [ 0 ] , args [ 1 ] , linkinfo . get ( ' lsrcmd5 ' ) , not opts . plain , opts . missingok ) )
return
2009-05-18 16:50:43 +02:00
if opts . change :
try :
rev = int ( opts . change )
if rev > 0 :
rev1 = rev - 1
rev2 = rev
elif rev < 0 :
rev1 = - rev
rev2 = - rev - 1
else :
return
except :
2013-04-09 12:51:28 +02:00
print ( ' Revision \' %s \' not an integer ' % opts . change , file = sys . stderr )
2009-05-18 16:50:43 +02:00
return
else :
rev1 , rev2 = parseRevisionOption ( opts . revision )
2007-11-26 19:13:51 +01:00
diff = ' '
for pac in pacs :
2009-01-09 18:09:29 +01:00
if not rev2 :
2010-08-27 16:24:12 +02:00
for i in pac . get_diff ( rev1 ) :
2011-08-05 18:51:02 +02:00
diff + = ' ' . join ( i )
2009-01-09 18:09:29 +01:00
else :
2010-12-23 10:33:31 +01:00
diff + = server_diff_noex ( pac . apiurl , pac . prjname , pac . name , rev1 ,
pac . prjname , pac . name , rev2 , not opts . plain , opts . missingok )
2010-09-10 17:28:45 +02:00
run_pager ( diff )
2007-07-04 14:55:26 +02:00
2007-04-25 01:00:12 +02:00
2007-11-29 18:22:57 +01:00
@cmdln.option ( ' --oldprj ' , metavar = ' OLDPRJ ' ,
2010-01-10 12:12:26 +01:00
help = ' project to compare against '
' (deprecated, use 3 argument form) ' )
2007-11-29 18:22:57 +01:00
@cmdln.option ( ' --oldpkg ' , metavar = ' OLDPKG ' ,
2010-01-10 12:12:26 +01:00
help = ' package to compare against '
' (deprecated, use 3 argument form) ' )
2011-03-03 10:07:32 +01:00
@cmdln.option ( ' -M ' , ' --meta ' , action = ' store_true ' ,
help = ' diff meta data ' )
2007-11-29 18:22:57 +01:00
@cmdln.option ( ' -r ' , ' --revision ' , metavar = ' N[:M] ' ,
help = ' revision id, where N = old revision and M = new revision ' )
2009-09-07 20:49:01 +02:00
@cmdln.option ( ' -p ' , ' --plain ' , action = ' store_true ' ,
help = ' output the diff in plain (not unified) diff format ' )
@cmdln.option ( ' -c ' , ' --change ' , metavar = ' rev ' ,
2010-01-10 12:12:26 +01:00
help = ' the change made by revision rev (like -r rev-1:rev). '
2009-09-07 20:49:01 +02:00
' If rev is negative this is like -r rev:rev-1. ' )
2010-04-10 15:44:15 +02:00
@cmdln.option ( ' --missingok ' , action = ' store_true ' ,
help = ' do not fail if the source or target project/package does not exist on the server ' )
2010-10-19 15:25:25 +02:00
@cmdln.option ( ' -u ' , ' --unexpand ' , action = ' store_true ' ,
help = ' diff unexpanded version if sources are linked ' )
2010-01-10 12:12:26 +01:00
def do_rdiff ( self , subcmd , opts , * args ) :
2007-12-10 15:23:58 +01:00
""" $ {cmd_name} : Server-side " pretty " diff of two packages
2007-11-29 18:22:57 +01:00
2010-01-10 12:12:26 +01:00
Compares two packages ( three or four arguments ) or shows the
changes of a specified revision of a package ( two arguments )
If no revision is specified the latest revision is used .
2007-11-29 18:32:52 +01:00
2009-07-27 22:03:01 +02:00
Note that this command doesn ' t return a normal diff (which could be
applied as patch ) , but a " pretty " diff , which also compares the content
of tarballs .
2007-11-29 18:32:52 +01:00
2007-11-29 18:22:57 +01:00
2010-01-10 12:12:26 +01:00
usage :
osc $ { cmd_name } OLDPRJ OLDPAC NEWPRJ [ NEWPAC ]
osc $ { cmd_name } PROJECT PACKAGE
2007-11-29 18:22:57 +01:00
$ { cmd_option_list }
"""
2010-01-10 12:12:26 +01:00
args = slash_split ( args )
2010-07-29 17:29:07 +02:00
apiurl = self . get_api_url ( )
2010-01-10 12:12:26 +01:00
2009-09-07 20:49:01 +02:00
rev1 = None
rev2 = None
2010-01-10 12:12:26 +01:00
old_project = None
old_package = None
new_project = None
new_package = None
if len ( args ) == 2 :
new_project = args [ 0 ]
new_package = args [ 1 ]
if opts . oldprj :
old_project = opts . oldprj
if opts . oldpkg :
old_package = opts . oldpkg
elif len ( args ) == 3 or len ( args ) == 4 :
if opts . oldprj or opts . oldpkg :
raise oscerr . WrongArgs ( ' --oldpkg and --oldprj are only valid with two arguments ' )
old_project = args [ 0 ]
2010-01-18 10:25:00 +01:00
new_package = old_package = args [ 1 ]
2010-01-10 12:12:26 +01:00
new_project = args [ 2 ]
if len ( args ) == 4 :
new_package = args [ 3 ]
2011-03-03 10:07:32 +01:00
elif len ( args ) == 1 and opts . meta :
new_project = args [ 0 ]
new_package = ' _project '
2010-01-10 12:12:26 +01:00
else :
raise oscerr . WrongArgs ( ' Wrong number of arguments ' )
2011-03-03 10:07:32 +01:00
if opts . meta :
opts . unexpand = True
2010-01-10 12:12:26 +01:00
2009-09-07 20:49:01 +02:00
if opts . change :
try :
rev = int ( opts . change )
if rev > 0 :
rev1 = rev - 1
rev2 = rev
elif rev < 0 :
rev1 = - rev
rev2 = - rev - 1
else :
return
except :
2013-04-09 12:51:28 +02:00
print ( ' Revision \' %s \' not an integer ' % opts . change , file = sys . stderr )
2009-09-07 20:49:01 +02:00
return
else :
if opts . revision :
rev1 , rev2 = parseRevisionOption ( opts . revision )
2007-11-29 18:22:57 +01:00
2010-12-23 10:33:31 +01:00
rdiff = server_diff_noex ( apiurl ,
old_project , old_package , rev1 ,
new_project , new_package , rev2 , not opts . plain , opts . missingok ,
2011-03-03 10:07:32 +01:00
meta = opts . meta ,
2010-12-23 10:33:31 +01:00
expand = not opts . unexpand )
2010-10-19 15:25:25 +02:00
2010-09-10 17:28:45 +02:00
run_pager ( rdiff )
2011-04-28 13:49:48 +02:00
def _pdiff_raise_non_existing_package ( self , project , package , msg = None ) :
raise oscerr . PackageMissing ( project , package , msg or ' %s / %s does not exist. ' % ( project , package ) )
def _pdiff_package_exists ( self , apiurl , project , package ) :
try :
show_package_meta ( apiurl , project , package )
return True
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2011-04-28 13:49:48 +02:00
if e . code != 404 :
2013-04-09 12:51:28 +02:00
print ( ' Cannot check that %s / %s exists: %s ' % ( project , package , e ) , file = sys . stderr )
2011-04-28 13:49:48 +02:00
return False
def _pdiff_guess_parent ( self , apiurl , project , package , check_exists_first = False ) :
# Make sure the parent exists
if check_exists_first and not self . _pdiff_package_exists ( apiurl , project , package ) :
self . _pdiff_raise_non_existing_package ( project , package )
if project . startswith ( ' home: ' ) :
guess = project [ len ( ' home: ' ) : ]
# remove user name
pos = guess . find ( ' : ' )
if pos > 0 :
guess = guess [ guess . find ( ' : ' ) + 1 : ]
if guess . startswith ( ' branches: ' ) :
guess = guess [ len ( ' branches: ' ) : ]
return ( guess , package )
return ( None , None )
def _pdiff_get_parent_from_link ( self , apiurl , project , package ) :
link_url = makeurl ( apiurl , [ ' source ' , project , package , ' _link ' ] )
try :
file = http_GET ( link_url )
root = ET . parse ( file ) . getroot ( )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2011-04-28 13:49:48 +02:00
return ( None , None )
2013-04-09 11:27:02 +02:00
except SyntaxError as e :
2013-04-09 12:51:28 +02:00
print ( ' Cannot parse %s / %s /_link: %s ' % ( project , package , e ) , file = sys . stderr )
2011-04-28 13:49:48 +02:00
return ( None , None )
parent_project = root . get ( ' project ' )
parent_package = root . get ( ' package ' ) or package
if parent_project is None :
return ( None , None )
return ( parent_project , parent_package )
def _pdiff_get_exists_and_parent ( self , apiurl , project , package ) :
link_url = makeurl ( apiurl , [ ' public ' , ' source ' , project , package ] )
try :
file = http_GET ( link_url )
root = ET . parse ( file ) . getroot ( )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2011-04-28 13:49:48 +02:00
if e . code != 404 :
2013-04-09 12:51:28 +02:00
print ( ' Cannot get list of files for %s / %s : %s ' % ( project , package , e ) , file = sys . stderr )
2011-04-28 13:49:48 +02:00
return ( None , None , None )
2013-04-09 11:27:02 +02:00
except SyntaxError as e :
2013-04-09 12:51:28 +02:00
print ( ' Cannot parse list of files for %s / %s : %s ' % ( project , package , e ) , file = sys . stderr )
2011-04-28 13:49:48 +02:00
return ( None , None , None )
link_node = root . find ( ' linkinfo ' )
if link_node is None :
return ( True , None , None )
parent_project = link_node . get ( ' project ' )
parent_package = link_node . get ( ' package ' ) or package
if parent_project is None :
raise oscerr . APIError ( ' %s / %s is a link with no parent? ' % ( project , package ) )
return ( True , parent_project , parent_package )
@cmdln.option ( ' -p ' , ' --plain ' , action = ' store_true ' ,
dest = ' plain ' ,
help = ' output the diff in plain (not unified) diff format ' )
@cmdln.option ( ' -n ' , ' --nomissingok ' , action = ' store_true ' ,
dest = ' nomissingok ' ,
help = ' fail if the parent package does not exist on the server ' )
def do_pdiff ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Quick alias to diff the content of a package with its parent.
Usage :
osc pdiff [ - - plain | - p ] [ - - nomissing - ok | - n ]
osc pdiff [ - - plain | - p ] [ - - nomissing - ok | - n ] PKG
osc pdiff [ - - plain | - p ] [ - - nomissing - ok | - n ] PRJ PKG
$ { cmd_option_list }
"""
apiurl = self . get_api_url ( )
args = slash_split ( args )
unified = not opts . plain
noparentok = not opts . nomissingok
if len ( args ) > 2 :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
if len ( args ) == 0 :
if not is_package_dir ( os . getcwd ( ) ) :
raise oscerr . WrongArgs ( ' Current directory is not a checked out package. Please specify a project and a package. ' )
project = store_read_project ( os . curdir )
package = store_read_package ( os . curdir )
elif len ( args ) == 1 :
if not is_project_dir ( os . getcwd ( ) ) :
raise oscerr . WrongArgs ( ' Current directory is not a checked out project. Please specify a project and a package. ' )
project = store_read_project ( os . curdir )
package = args [ 0 ]
elif len ( args ) == 2 :
project = args [ 0 ]
package = args [ 1 ]
else :
raise RuntimeError ( ' Internal error: bad check for arguments. ' )
## Find parent package
# Old way, that does one more request to api
#(parent_project, parent_package) = self._pdiff_get_parent_from_link(apiurl, project, package)
#if not parent_project:
# (parent_project, parent_package) = self._pdiff_guess_parent(apiurl, project, package, check_exists_first = True)
# if parent_project and parent_package:
# print 'Guessed that %s/%s is the parent package.' % (parent_project, parent_package)
# New way
( exists , parent_project , parent_package ) = self . _pdiff_get_exists_and_parent ( apiurl , project , package )
if not exists :
self . _pdiff_raise_non_existing_package ( project , package )
if not parent_project :
( parent_project , parent_package ) = self . _pdiff_guess_parent ( apiurl , project , package , check_exists_first = False )
if parent_project and parent_package :
2013-04-09 12:51:28 +02:00
print ( ' Guessed that %s / %s is the parent package. ' % ( parent_project , parent_package ) )
2011-04-28 13:49:48 +02:00
if not parent_project or not parent_package :
2013-04-09 12:51:28 +02:00
print ( ' Cannot find a parent for %s / %s to diff against. ' % ( project , package ) , file = sys . stderr )
2011-04-28 13:49:48 +02:00
return 1
if not noparentok and not self . _pdiff_package_exists ( apiurl , parent_project , parent_package ) :
2014-08-12 15:01:16 +02:00
self . _pdiff_raise_non_existing_package ( parent_project , parent_package ,
2013-05-27 13:03:46 +02:00
msg = ' Parent for %s / %s ( %s / %s ) does not exist. ' % \
( project , package , parent_project , parent_package ) )
2011-04-28 13:49:48 +02:00
2013-05-27 13:03:46 +02:00
rdiff = server_diff ( apiurl , parent_project , parent_package , None , project ,
package , None , unified = unified , missingok = noparentok )
2011-04-28 13:49:48 +02:00
run_pager ( rdiff )
2007-11-29 18:22:57 +01:00
2013-01-18 22:58:53 +01:00
def _get_branch_parent ( self , prj ) :
m = re . match ( ' ^home:[^:]+:branches:(.+) ' , prj )
# OBS_Maintained is a special case
if m and prj . find ( ' :branches:OBS_Maintained: ' ) == - 1 :
return m . group ( 1 )
return None
def _prdiff_skip_package ( self , opts , pkg ) :
if opts . exclude and re . search ( opts . exclude , pkg ) :
return True
if opts . include and not re . search ( opts . include , pkg ) :
return True
return False
def _prdiff_output_diff ( self , opts , rdiff ) :
if opts . diffstat :
2013-04-09 12:51:28 +02:00
print ( )
2013-01-18 22:58:53 +01:00
p = subprocess . Popen ( " diffstat " ,
stdin = subprocess . PIPE ,
stdout = subprocess . PIPE ,
close_fds = True )
2013-04-10 11:34:59 +02:00
p . stdin . write ( rdiff . encode ( ) )
2013-01-18 22:58:53 +01:00
p . stdin . close ( )
2013-04-10 11:34:59 +02:00
print ( " " . join ( x . decode ( ) for x in p . stdout . readlines ( ) ) )
2013-01-18 22:58:53 +01:00
elif opts . unified :
2013-04-09 12:51:28 +02:00
print ( )
print ( rdiff )
2013-01-18 22:58:53 +01:00
#run_pager(rdiff)
def _prdiff_output_matching_requests ( self , opts , requests ,
srcprj , pkg ) :
"""
Search through the given list of requests and output any
submitrequests which target pkg and originate from srcprj .
"""
for req in requests :
for action in req . get_actions ( ' submit ' ) :
if action . src_project != srcprj :
continue
if action . tgt_package != pkg :
continue
2013-04-09 12:51:28 +02:00
print ( )
print ( req . list_view ( ) )
2013-01-18 22:58:53 +01:00
break
@cmdln.alias ( ' projectdiff ' )
@cmdln.alias ( ' projdiff ' )
@cmdln.option ( ' -r ' , ' --requests ' , action = ' store_true ' ,
help = ' show open requests for any packages with differences ' )
@cmdln.option ( ' -e ' , ' --exclude ' , metavar = ' REGEXP ' , dest = ' exclude ' ,
help = ' skip packages matching REGEXP ' )
@cmdln.option ( ' -i ' , ' --include ' , metavar = ' REGEXP ' , dest = ' include ' ,
help = ' only consider packages matching REGEXP ' )
@cmdln.option ( ' -n ' , ' --show-not-in-old ' , action = ' store_true ' ,
help = ' show packages only in the new project ' )
@cmdln.option ( ' -o ' , ' --show-not-in-new ' , action = ' store_true ' ,
help = ' show packages only in the old project ' )
@cmdln.option ( ' -u ' , ' --unified ' , action = ' store_true ' ,
help = ' show full unified diffs of differences ' )
@cmdln.option ( ' -d ' , ' --diffstat ' , action = ' store_true ' ,
help = ' show diffstat of differences ' )
def do_prdiff ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Server-side diff of two projects
Compares two projects and either summarises or outputs the
differences in full . In the second form , a project is compared
with one of its branches inside a home : $ USER project ( the branch
is treated as NEWPRJ ) . The home branch is optional if the current
working directory is a checked out copy of it .
Usage :
osc prdiff [ OPTIONS ] OLDPRJ NEWPRJ
osc prdiff [ OPTIONS ] [ home : $ USER : branch : $ PRJ ]
$ { cmd_option_list }
"""
if len ( args ) > 2 :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
if len ( args ) == 0 :
if is_project_dir ( os . curdir ) :
newprj = Project ( ' . ' , getPackageList = False ) . name
oldprj = self . _get_branch_parent ( newprj )
if oldprj is None :
raise oscerr . WrongArgs ( ' Current directory is not a valid home branch. ' )
else :
raise oscerr . WrongArgs ( ' Current directory is not a project. ' )
elif len ( args ) == 1 :
newprj = args [ 0 ]
oldprj = self . _get_branch_parent ( newprj )
if oldprj is None :
raise oscerr . WrongArgs ( ' Single-argument form must be for a home branch. ' )
elif len ( args ) == 2 :
oldprj , newprj = args
else :
raise RuntimeError ( ' BUG in argument parsing, please report. \n '
' args: ' + repr ( args ) )
if opts . diffstat and opts . unified :
2013-04-09 12:51:28 +02:00
print ( ' error - cannot specify both --diffstat and --unified ' , file = sys . stderr )
2013-01-18 22:58:53 +01:00
sys . exit ( 1 )
apiurl = self . get_api_url ( )
old_packages = meta_get_packagelist ( apiurl , oldprj )
new_packages = meta_get_packagelist ( apiurl , newprj )
if opts . requests :
requests = get_request_list ( apiurl , project = oldprj ,
req_state = ( ' new ' , ' review ' ) )
for pkg in old_packages :
if self . _prdiff_skip_package ( opts , pkg ) :
continue
if pkg not in new_packages :
if opts . show_not_in_new :
2013-04-09 12:51:28 +02:00
print ( " old only: %s " % pkg )
2013-01-18 22:58:53 +01:00
continue
rdiff = server_diff_noex (
apiurl ,
oldprj , pkg , None ,
newprj , pkg , None ,
unified = True , missingok = False , meta = False , expand = True
)
if rdiff :
2013-04-09 12:51:28 +02:00
print ( " differs: %s " % pkg )
2013-01-18 22:58:53 +01:00
self . _prdiff_output_diff ( opts , rdiff )
if opts . requests :
self . _prdiff_output_matching_requests ( opts , requests ,
newprj , pkg )
else :
2013-04-09 12:51:28 +02:00
print ( " identical: %s " % pkg )
2013-01-18 22:58:53 +01:00
for pkg in new_packages :
if self . _prdiff_skip_package ( opts , pkg ) :
continue
if pkg not in old_packages :
if opts . show_not_in_old :
2013-04-09 12:51:28 +02:00
print ( " new only: %s " % pkg )
2013-01-18 22:58:53 +01:00
2007-11-29 18:22:57 +01:00
2007-04-25 01:00:12 +02:00
def do_repourls ( self , subcmd , opts , * args ) :
2009-05-18 16:50:43 +02:00
""" $ {cmd_name} : Shows URLs of .repo files
2007-04-25 01:00:12 +02:00
Shows URLs on which to access the project . repos files ( yum - style
2007-07-16 11:45:17 +02:00
metadata ) on download . opensuse . org .
2006-05-23 15:48:58 +02:00
2009-11-30 10:31:28 +01:00
usage :
osc repourls [ PROJECT ]
2006-05-23 15:48:58 +02:00
2007-04-25 01:00:12 +02:00
$ { cmd_option_list }
"""
2006-05-23 15:48:58 +02:00
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2007-03-12 16:46:15 +01:00
2009-11-30 10:31:28 +01:00
if len ( args ) == 1 :
project = args [ 0 ]
elif len ( args ) == 0 :
project = store_read_project ( ' . ' )
else :
raise oscerr . WrongArgs ( ' Wrong number of arguments ' )
2006-05-23 15:48:58 +02:00
2015-06-29 23:59:59 +02:00
root = ET . fromstring ( ' ' . join ( show_configuration ( apiurl ) ) )
elm = root . find ( ' download_url ' )
if elm is None or not elm . text :
raise oscerr . APIError ( ' download_url configuration element expected ' )
url_tmpl = elm . text + ' / %s / %s / %s .repo '
2009-11-30 10:31:28 +01:00
repos = get_repositories_of_project ( apiurl , project )
for repo in repos :
2013-04-09 12:51:28 +02:00
print ( url_tmpl % ( project . replace ( ' : ' , ' :/ ' ) , repo , project ) )
2006-05-23 15:48:58 +02:00
2007-07-04 14:55:26 +02:00
@cmdln.option ( ' -r ' , ' --revision ' , metavar = ' rev ' ,
2007-07-04 15:48:24 +02:00
help = ' checkout the specified revision. '
' NOTE: if you checkout the complete project '
' this option is ignored! ' )
2008-03-24 21:24:49 +01:00
@cmdln.option ( ' -e ' , ' --expand-link ' , action = ' store_true ' ,
2009-05-18 16:50:43 +02:00
help = ' if a package is a link, check out the expanded '
2008-06-06 14:04:34 +02:00
' sources (no-op, since this became the default) ' )
@cmdln.option ( ' -u ' , ' --unexpand-link ' , action = ' store_true ' ,
help = ' if a package is a link, check out the _link file ' \
' instead of the expanded sources ' )
2010-05-25 14:00:50 +02:00
@cmdln.option ( ' -M ' , ' --meta ' , action = ' store_true ' ,
2010-05-22 08:22:12 +02:00
help = ' checkout out meta data instead of sources ' )
2009-04-16 19:41:47 +02:00
@cmdln.option ( ' -c ' , ' --current-dir ' , action = ' store_true ' ,
help = ' place PACKAGE folder in the current directory ' \
' instead of a PROJECT/PACKAGE directory ' )
2011-11-02 21:02:26 +01:00
@cmdln.option ( ' -o ' , ' --output-dir ' , metavar = ' outdir ' ,
help = ' place package in the specified directory ' \
' instead of a PROJECT/PACKAGE directory ' )
2009-08-07 14:18:15 +02:00
@cmdln.option ( ' -s ' , ' --source-service-files ' , action = ' store_true ' ,
2011-02-02 17:11:14 +01:00
help = ' Run source services. ' )
2010-06-08 11:24:10 +02:00
@cmdln.option ( ' -S ' , ' --server-side-source-service-files ' , action = ' store_true ' ,
help = ' Use server side generated sources instead of local generation. ' )
2010-04-22 15:27:54 +02:00
@cmdln.option ( ' -l ' , ' --limit-size ' , metavar = ' limit_size ' ,
help = ' Skip all files with a given size ' )
2007-04-25 01:00:12 +02:00
@cmdln.alias ( ' co ' )
def do_checkout ( self , subcmd , opts , * args ) :
2007-12-10 15:23:58 +01:00
""" $ {cmd_name} : Check out content from the repository
2009-05-18 16:50:43 +02:00
2007-04-25 01:00:12 +02:00
Check out content from the repository server , creating a local working
copy .
2008-03-24 21:24:49 +01:00
When checking out a single package , the option - - revision can be used
2009-05-27 14:09:50 +02:00
to specify a revision of the package to be checked out .
2008-03-24 21:24:49 +01:00
2009-05-18 16:50:43 +02:00
When a package is a source link , then it will be checked out in
expanded form . If - - unexpand - link option is used , the checkout will
2008-06-06 14:04:34 +02:00
instead produce the raw _link file plus patches .
2007-04-25 01:00:12 +02:00
2009-05-18 16:50:43 +02:00
usage :
2007-04-25 01:00:12 +02:00
osc co PROJECT [ PACKAGE ] [ FILE ]
2009-04-17 10:39:04 +02:00
osc co PROJECT # entire project
osc co PROJECT PACKAGE # a package
osc co PROJECT PACKAGE FILE # single file -> to current dir
2009-04-24 01:59:40 +02:00
while inside a project directory :
osc co PACKAGE # check out PACKAGE from project
2016-05-15 17:50:31 +02:00
2011-07-20 17:17:56 +02:00
with the result of rpm - q - - qf ' %% {DISTURL} \\ n ' PACKAGE
2014-08-12 15:01:16 +02:00
osc co obs : / / API / PROJECT / PLATFORM / REVISION - PACKAGE
2009-04-17 10:39:04 +02:00
2007-04-25 01:00:12 +02:00
$ { cmd_option_list }
"""
2008-06-06 14:04:34 +02:00
2009-09-16 23:39:45 +02:00
if opts . unexpand_link :
expand_link = False
else :
expand_link = True
2011-02-01 18:37:17 +01:00
osc co: print help instead of crashing if no arguments are given
This fixes:
~> osc checkout
Traceback (most recent call last):
File "/usr/bin/osc", line 21, in <module>
r = babysitter.run(osccli)
File "/usr/lib/python2.7/site-packages/osc/babysitter.py", line 52, in run
return prg.main()
File "/usr/lib/python2.7/site-packages/osc/cmdln.py", line 310, in main
return self.cmd(args)
File "/usr/lib/python2.7/site-packages/osc/cmdln.py", line 333, in cmd
retval = self.onecmd(argv)
File "/usr/lib/python2.7/site-packages/osc/cmdln.py", line 449, in onecmd
return self._dispatch_cmd(handler, argv)
File "/usr/lib/python2.7/site-packages/osc/cmdln.py", line 1179, in _dispatch_cmd
return handler(argv[0], opts, *args)
File "/usr/lib/python2.7/site-packages/osc/commandline.py", line 3386, in do_checkout
m = re.match(r"obs://([^/]+)/(\S+)/([^/]+)/([A-Fa-f\d]+)\-(\S+)", args[0])
IndexError: tuple index out of range
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2011-06-08 13:35:47 +02:00
if not args :
raise oscerr . WrongArgs ( ' Incorrect number of arguments. \n \n ' \
+ self . get_cmd_help ( ' checkout ' ) )
2011-02-01 18:37:17 +01:00
# XXX: this too openSUSE-setup specific...
2014-08-12 15:01:16 +02:00
# FIXME: this should go into ~jw/patches/osc/osc.proj_pack_20101201.diff
2011-01-31 17:49:04 +01:00
# to be available to all subcommands via @cmdline.prep(proj_pack)
# obs://build.opensuse.org/openSUSE:11.3/standard/fc6c25e795a89503e99d59da5dc94a79-screen
m = re . match ( r " obs://([^/]+)/( \ S+)/([^/]+)/([A-Fa-f \ d]+) \ -( \ S+) " , args [ 0 ] )
if m and len ( args ) == 1 :
2011-02-01 18:37:17 +01:00
apiurl = " https:// " + m . group ( 1 )
project = project_dir = m . group ( 2 )
# platform = m.group(3)
opts . revision = m . group ( 4 )
package = m . group ( 5 )
apiurl = apiurl . replace ( ' /build. ' , ' /api. ' )
filename = None
2011-01-31 17:49:04 +01:00
else :
2011-02-01 18:37:17 +01:00
args = slash_split ( args )
project = package = filename = None
apiurl = self . get_api_url ( )
try :
project = project_dir = args [ 0 ]
package = args [ 1 ]
filename = args [ 2 ]
except :
pass
2007-04-25 01:00:12 +02:00
2011-02-01 18:37:17 +01:00
if len ( args ) == 1 and is_project_dir ( os . curdir ) :
project = store_read_project ( os . curdir )
project_dir = os . curdir
2009-04-17 10:39:04 +02:00
package = args [ 0 ]
2008-06-06 14:04:34 +02:00
2007-07-04 14:55:26 +02:00
rev , dummy = parseRevisionOption ( opts . revision )
2013-05-27 12:41:50 +02:00
if rev == None :
rev = " latest "
2007-07-04 14:55:26 +02:00
2009-10-16 10:26:01 +02:00
if rev and rev != " latest " and not checkRevision ( project , package , rev ) :
2013-04-09 12:51:28 +02:00
print ( ' Revision \' %s \' does not exist ' % rev , file = sys . stderr )
2007-07-06 13:54:34 +02:00
sys . exit ( 1 )
2007-04-25 01:00:12 +02:00
if filename :
2011-03-08 18:48:00 +01:00
# Note: same logic as with 'osc cat' (not 'osc ls', which never merges!)
2010-12-30 02:31:28 +01:00
if expand_link :
2011-03-08 18:48:00 +01:00
rev = show_upstream_srcmd5 ( apiurl , project , package , expand = True , revision = rev )
2010-02-09 20:57:10 +01:00
get_source_file ( apiurl , project , package , filename , revision = rev , progress_obj = self . download_progress )
2007-04-25 01:00:12 +02:00
elif package :
2009-09-16 23:39:45 +02:00
if opts . current_dir :
project_dir = None
2011-11-02 19:41:47 +01:00
checkout_package ( apiurl , project , package , rev , expand_link = expand_link , \
2013-05-27 13:03:46 +02:00
prj_dir = project_dir , service_files = opts . source_service_files , \
server_service_files = opts . server_side_source_service_files , \
progress_obj = self . download_progress , size_limit = opts . limit_size , \
meta = opts . meta , outdir = opts . output_dir )
2009-09-18 03:10:41 +02:00
print_request_list ( apiurl , project , package )
2007-04-25 01:00:12 +02:00
elif project :
2016-06-15 15:28:10 +02:00
prj_dir = opts . output_dir if opts . output_dir else project
2009-09-08 13:16:21 +02:00
if sys . platform [ : 3 ] == ' win ' :
2009-05-15 13:40:50 +02:00
prj_dir = prj_dir . replace ( ' : ' , ' ; ' )
if os . path . exists ( prj_dir ) :
2016-06-15 15:28:10 +02:00
sys . exit ( ' osc: project directory \' %s \' already exists ' % prj_dir )
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
# check if the project does exist (show_project_meta will throw an exception)
2009-04-17 10:39:04 +02:00
show_project_meta ( apiurl , project )
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
2016-06-15 15:28:10 +02:00
Project . init_project ( apiurl , prj_dir , project , conf . config [ ' do_package_tracking ' ] )
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' A ' , prj_dir ) )
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
2007-04-25 01:00:12 +02:00
# all packages
2009-04-17 10:39:04 +02:00
for package in meta_get_packagelist ( apiurl , project ) :
2015-09-25 17:02:35 +02:00
if opts . output_dir is not None :
outputdir = os . path . join ( opts . output_dir , package )
if not os . path . exists ( opts . output_dir ) :
os . mkdir ( os . path . join ( opts . output_dir ) )
else :
outputdir = None
2011-07-20 17:27:05 +02:00
# don't check out local links by default
try :
m = show_files_meta ( apiurl , project , package )
li = Linkinfo ( )
li . read ( ET . fromstring ( ' ' . join ( m ) ) . find ( ' linkinfo ' ) )
if not li . haserror ( ) :
2013-05-27 12:16:44 +02:00
if li . project == project :
print ( statfrmt ( ' S ' , package + " link to package " + li . package ) )
continue
2011-07-20 17:27:05 +02:00
except :
pass
2008-10-02 17:46:52 +02:00
try :
2010-02-09 20:57:10 +01:00
checkout_package ( apiurl , project , package , expand_link = expand_link , \
2013-05-27 13:03:46 +02:00
prj_dir = prj_dir , service_files = opts . source_service_files , \
server_service_files = opts . server_side_source_service_files , \
progress_obj = self . download_progress , size_limit = opts . limit_size , \
2016-06-15 15:28:10 +02:00
meta = opts . meta )
2013-04-09 11:27:02 +02:00
except oscerr . LinkExpandError as e :
2013-04-09 12:51:28 +02:00
print ( ' Link cannot be expanded: \n ' , e , file = sys . stderr )
print ( ' Use " osc repairlink " for fixing merge conflicts: \n ' , file = sys . stderr )
2008-10-02 17:46:52 +02:00
# check out in unexpanded form at least
2010-02-09 20:57:10 +01:00
checkout_package ( apiurl , project , package , expand_link = False , \
2013-05-27 13:03:46 +02:00
prj_dir = prj_dir , service_files = opts . source_service_files , \
server_service_files = opts . server_side_source_service_files , \
progress_obj = self . download_progress , size_limit = opts . limit_size , \
meta = opts . meta )
2009-09-18 03:10:41 +02:00
print_request_list ( apiurl , project )
2008-10-02 17:46:52 +02:00
2007-04-25 01:00:12 +02:00
else :
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
raise oscerr . WrongArgs ( ' Missing argument. \n \n ' \
+ self . get_cmd_help ( ' checkout ' ) )
2007-04-25 01:00:12 +02:00
2008-05-21 15:44:49 +02:00
@cmdln.option ( ' -q ' , ' --quiet ' , action = ' store_true ' ,
help = ' print as little as possible ' )
2007-04-25 01:00:12 +02:00
@cmdln.option ( ' -v ' , ' --verbose ' , action = ' store_true ' ,
help = ' print extra information ' )
2010-08-11 18:05:12 +02:00
@cmdln.option ( ' -e ' , ' --show-excluded ' , action = ' store_true ' ,
help = ' also show files which are excluded by the ' \
' " exclude_glob " config option ' )
2007-04-25 01:00:12 +02:00
@cmdln.alias ( ' st ' )
def do_status ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Show status of files in working copy
Show the status of files in a local working copy , indicating whether
files have been changed locally , deleted , added , . . .
The first column in the output specifies the status and is one of the
following characters :
' ' no modifications
' A ' Added
' C ' Conflicted
' D ' Deleted
' M ' Modified
' ? ' item is not under version control
2009-07-15 23:16:34 +02:00
' ! ' item is missing ( removed by non - osc command ) or incomplete
2015-01-21 03:01:29 +01:00
' S ' item is skipped ( item exceeds a file size limit or is _service : * file )
2014-11-21 16:12:26 +01:00
' F ' Frozen ( use " osc pull " to merge conflicts ) ( package - only state )
2007-04-25 01:00:12 +02:00
examples :
osc st
osc st < directory >
osc st file1 file2 . . .
2009-05-18 16:50:43 +02:00
usage :
2007-04-25 01:00:12 +02:00
osc status [ OPTS ] [ PATH . . . ]
$ { cmd_option_list }
"""
2010-12-22 23:17:11 +01:00
if opts . quiet and opts . verbose :
raise oscerr . WrongOptions ( ' \' --quiet \' and \' --verbose \' are mutually exclusive ' )
2007-04-25 01:00:12 +02:00
2010-12-22 23:17:11 +01:00
args = parseargs ( args )
lines = [ ]
excl_states = ( ' ' , )
if opts . quiet :
excl_states + = ( ' ? ' , )
elif opts . verbose :
excl_states = ( )
2007-04-25 01:00:12 +02:00
for arg in args :
if is_project_dir ( arg ) :
2008-03-10 19:04:23 +01:00
prj = Project ( arg , False )
2010-12-22 23:17:11 +01:00
# don't exclude packages with state ' ' because the packages
# might have modified etc. files
prj_excl = [ st for st in excl_states if st != ' ' ]
for st , pac in sorted ( prj . get_status ( * prj_excl ) , lambda x , y : cmp ( x [ 1 ] , y [ 1 ] ) ) :
p = prj . get_pacobj ( pac )
if p is None :
# state is != ' '
lines . append ( statfrmt ( st , os . path . normpath ( os . path . join ( prj . dir , pac ) ) ) )
continue
2014-11-21 16:12:26 +01:00
if p . isfrozen ( ) :
lines . append ( statfrmt ( ' F ' , os . path . normpath ( os . path . join ( prj . dir , pac ) ) ) )
elif st == ' ' and opts . verbose or st != ' ' :
2010-12-22 23:17:11 +01:00
lines . append ( statfrmt ( st , os . path . normpath ( os . path . join ( prj . dir , pac ) ) ) )
states = p . get_status ( opts . show_excluded , * excl_states )
for st , filename in sorted ( states , lambda x , y : cmp ( x [ 1 ] , y [ 1 ] ) ) :
lines . append ( statfrmt ( st , os . path . normpath ( os . path . join ( p . dir , filename ) ) ) )
2007-04-25 01:00:12 +02:00
else :
2010-12-22 23:17:11 +01:00
p = findpacs ( [ arg ] ) [ 0 ]
for st , filename in sorted ( p . get_status ( opts . show_excluded , * excl_states ) , lambda x , y : cmp ( x [ 1 ] , y [ 1 ] ) ) :
lines . append ( statfrmt ( st , os . path . normpath ( os . path . join ( p . dir , filename ) ) ) )
2010-12-25 20:57:26 +01:00
if lines :
2013-04-09 12:51:28 +02:00
print ( ' \n ' . join ( lines ) )
2006-06-02 16:00:58 +02:00
2006-05-23 15:48:58 +02:00
2007-04-25 01:00:12 +02:00
def do_add ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Mark files to be added upon the next commit
2006-05-23 15:48:58 +02:00
2010-05-14 16:59:45 +02:00
In case a URL is given the file will get downloaded and registered to be downloaded
by the server as well via the download_url source service .
This is recommended for release tar balls to track their source and to help
others to review your changes esp . on version upgrades .
2009-05-18 16:50:43 +02:00
usage :
2010-05-14 16:59:45 +02:00
osc add URL [ URL . . . ]
2007-04-25 01:00:12 +02:00
osc add FILE [ FILE . . . ]
$ { cmd_option_list }
"""
if not args :
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
raise oscerr . WrongArgs ( ' Missing argument. \n \n ' \
+ self . get_cmd_help ( ' add ' ) )
2006-05-23 15:48:58 +02:00
2010-05-14 16:59:45 +02:00
# Do some magic here, when adding a url. We want that the server to download the tar ball and to verify it
2010-05-14 16:44:42 +02:00
for arg in parseargs ( args ) :
2011-01-26 17:29:43 +01:00
if arg . startswith ( ' http:// ' ) or arg . startswith ( ' https:// ' ) or arg . startswith ( ' ftp:// ' ) or arg . startswith ( ' git:// ' ) :
2010-09-20 11:09:43 +02:00
if arg . endswith ( ' .git ' ) :
addGitSource ( arg )
else :
addDownloadUrlService ( arg )
2016-08-26 17:12:09 +02:00
else :
addFiles ( [ arg ] )
2006-05-23 15:48:58 +02:00
2009-05-18 16:50:43 +02:00
2008-03-10 19:04:23 +01:00
def do_mkpac ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Create a new package under version control
2006-09-29 15:15:41 +02:00
2008-03-10 19:04:23 +01:00
usage :
osc mkpac new_package
$ { cmd_option_list }
"""
2008-03-18 00:43:32 +01:00
if not conf . config [ ' do_package_tracking ' ] :
2013-04-09 12:51:28 +02:00
print ( " to use this feature you have to enable \' do_package_tracking \' " \
" in the [general] section in the configuration file " , file = sys . stderr )
2008-03-18 00:43:32 +01:00
sys . exit ( 1 )
2008-03-10 19:04:23 +01:00
if len ( args ) != 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
raise oscerr . WrongArgs ( ' Wrong number of arguments. ' )
2008-03-15 23:51:37 +01:00
createPackageDir ( args [ 0 ] )
2006-05-23 15:48:58 +02:00
2008-08-20 21:24:55 +02:00
@cmdln.option ( ' -r ' , ' --recursive ' , action = ' store_true ' ,
help = ' If CWD is a project dir then scan all package dirs as well ' )
2009-05-11 15:21:33 +02:00
@cmdln.alias ( ' ar ' )
2007-04-25 01:00:12 +02:00
def do_addremove ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Adds new files, removes disappeared files
2006-04-20 16:26:50 +02:00
2007-04-25 01:00:12 +02:00
Adds all files new in the local copy , and removes all disappeared files .
2006-04-20 16:26:50 +02:00
2007-04-25 01:00:12 +02:00
ARG , if specified , is a package working copy .
2006-04-20 16:26:50 +02:00
2007-04-25 01:00:12 +02:00
$ { cmd_usage }
$ { cmd_option_list }
"""
2006-05-11 09:27:50 +02:00
2007-04-25 01:00:12 +02:00
args = parseargs ( args )
2008-08-20 21:24:55 +02:00
arg_list = args [ : ]
for arg in arg_list :
2009-03-16 22:29:42 +01:00
if is_project_dir ( arg ) and conf . config [ ' do_package_tracking ' ] :
2008-08-20 21:24:55 +02:00
prj = Project ( arg , False )
for pac in prj . pacs_unvers :
pac_dir = getTransActPath ( os . path . join ( prj . dir , pac ) )
if os . path . isdir ( pac_dir ) :
addFiles ( [ pac_dir ] , prj )
for pac in prj . pacs_broken :
if prj . get_state ( pac ) != ' D ' :
prj . set_state ( pac , ' D ' )
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' D ' , getTransActPath ( os . path . join ( prj . dir , pac ) ) ) )
2008-08-20 21:24:55 +02:00
if opts . recursive :
for pac in prj . pacs_have :
state = prj . get_state ( pac )
if state != None and state != ' D ' :
pac_dir = getTransActPath ( os . path . join ( prj . dir , pac ) )
args . append ( pac_dir )
args . remove ( arg )
prj . write_packages ( )
2009-03-16 22:29:42 +01:00
elif is_project_dir ( arg ) :
2013-04-09 12:51:28 +02:00
print ( ' osc: addremove is not supported in a project dir unless ' \
' \' do_package_tracking \' is enabled in the configuration file ' , file = sys . stderr )
2009-03-16 22:29:42 +01:00
sys . exit ( 1 )
2008-08-20 21:24:55 +02:00
2007-04-25 01:00:12 +02:00
pacs = findpacs ( args )
for p in pacs :
2014-10-21 22:15:54 +02:00
todo = list ( set ( p . filenamelist + p . filenamelist_unvers + p . to_be_added ) )
for filename in todo :
2014-10-21 22:23:28 +02:00
abs_filename = os . path . join ( p . absdir , filename )
if os . path . isdir ( abs_filename ) :
2007-04-25 01:00:12 +02:00
continue
2007-07-06 13:20:30 +02:00
# ignore foo.rXX, foo.mine for files which are in 'C' state
if os . path . splitext ( filename ) [ 0 ] in p . in_conflict :
2009-10-20 16:30:15 +02:00
continue
2007-04-25 01:00:12 +02:00
state = p . status ( filename )
if state == ' ? ' :
2009-08-20 21:28:05 +02:00
# TODO: should ignore typical backup files suffix ~ or .orig
2007-04-25 01:00:12 +02:00
p . addfile ( filename )
2014-10-21 22:31:30 +02:00
elif state == ' D ' and os . path . isfile ( abs_filename ) :
# if the "deleted" file exists in the wc, track it again
p . addfile ( filename )
2007-04-25 01:00:12 +02:00
elif state == ' ! ' :
2010-09-06 15:28:23 +02:00
p . delete_file ( filename )
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' D ' , getTransActPath ( os . path . join ( p . dir , filename ) ) ) )
2007-04-25 01:00:12 +02:00
@cmdln.alias ( ' ci ' )
@cmdln.alias ( ' checkin ' )
2007-07-12 01:24:26 +02:00
@cmdln.option ( ' -m ' , ' --message ' , metavar = ' TEXT ' ,
help = ' specify log message TEXT ' )
2014-02-12 14:50:18 +01:00
@cmdln.option ( ' -n ' , ' --no-message ' , default = False , action = ' store_true ' ,
help = ' do not specify a log message ' )
2007-07-13 12:02:35 +02:00
@cmdln.option ( ' -F ' , ' --file ' , metavar = ' FILE ' ,
2011-03-30 23:33:30 +02:00
help = ' read log message from FILE, \' - \' denotes standard input. ' )
2009-08-03 15:03:24 +02:00
@cmdln.option ( ' -f ' , ' --force ' , default = False , action = " store_true " ,
2015-04-29 13:43:23 +02:00
help = ' force commit, even if there were no changes ' )
2011-09-10 22:56:26 +02:00
@cmdln.option ( ' --skip-validation ' , default = False , action = " store_true " ,
help = ' deprecated, don \' t use it ' )
2011-05-25 13:34:32 +02:00
@cmdln.option ( ' -v ' , ' --verbose ' , default = False , action = " store_true " ,
2011-09-07 13:55:05 +02:00
help = ' Run the source services with verbose information ' )
2012-02-23 14:27:04 +01:00
@cmdln.option ( ' --skip-local-service-run ' , ' --noservice ' , default = False , action = " store_true " ,
2011-11-22 14:47:11 +01:00
help = ' Skip service run of configured source services for local run ' )
2007-04-25 01:00:12 +02:00
def do_commit ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Upload content to the repository server
Upload content which is changed in your working copy , to the repository
server .
2009-05-18 16:50:43 +02:00
examples :
2007-04-25 01:00:12 +02:00
osc ci # current dir
osc ci < dir >
osc ci file1 file2 . . .
$ { cmd_usage }
$ { cmd_option_list }
"""
2016-09-09 13:20:15 +02:00
try :
self . _commit ( subcmd , opts , args )
except oscerr . ExtRuntimeError as e :
print ( " ERROR: service run failed " , e , file = sys . stderr )
return 1
except oscerr . PackageNotInstalled as e :
2016-09-09 13:23:55 +02:00
print ( " ERROR: please install %s " % e . args , end = ' ' )
2016-09-09 13:20:15 +02:00
print ( " or use the --noservice option " )
return 1
2008-05-21 15:44:49 +02:00
2016-09-09 13:20:15 +02:00
def _commit ( self , subcmd , opts , args ) :
args = parseargs ( args )
2011-09-10 22:56:26 +02:00
if opts . skip_validation :
2013-04-09 12:51:28 +02:00
print ( " WARNING: deprecated option --skip-validation ignored. " , file = sys . stderr )
2011-09-10 22:56:26 +02:00
2010-05-22 08:51:04 +02:00
msg = ' '
2008-03-10 19:04:23 +01:00
if opts . message :
msg = opts . message
elif opts . file :
2011-03-30 23:33:30 +02:00
if opts . file == ' - ' :
msg = sys . stdin . read ( )
else :
try :
msg = open ( opts . file ) . read ( )
except :
sys . exit ( ' could not open file \' %s \' . ' % opts . file )
2011-09-07 15:19:54 +02:00
skip_local_service_run = False
if not conf . config [ ' local_service_run ' ] or opts . skip_local_service_run :
skip_local_service_run = True
2008-08-20 21:24:55 +02:00
arg_list = args [ : ]
for arg in arg_list :
2008-03-10 19:04:23 +01:00
if conf . config [ ' do_package_tracking ' ] and is_project_dir ( arg ) :
2016-09-09 13:20:15 +02:00
prj = Project ( arg )
if not msg and not opts . no_message :
msg = edit_message ( )
# check any of the packages is a link, if so, as for branching
pacs = ( Package ( os . path . join ( prj . dir , pac ) )
for pac in prj . pacs_have if prj . get_state ( pac ) == ' ' )
can_branch = False
if any ( pac . is_link_to_different_project ( ) for pac in pacs ) :
repl = raw_input ( ' Some of the packages are links to a different project! \n ' \
' Create a local branch before commit? (y|N) ' )
if repl in ( ' y ' , ' Y ' ) :
can_branch = True
prj . commit ( msg = msg , skip_local_service_run = skip_local_service_run , verbose = opts . verbose , can_branch = can_branch )
2008-03-10 19:04:23 +01:00
args . remove ( arg )
2007-04-25 01:00:12 +02:00
2008-03-10 19:04:23 +01:00
pacs = findpacs ( args )
2008-05-21 15:44:49 +02:00
2008-03-10 19:04:23 +01:00
if conf . config [ ' do_package_tracking ' ] and len ( pacs ) > 0 :
prj_paths = { }
single_paths = [ ]
files = { }
2010-09-09 12:30:49 +02:00
# XXX: this is really ugly
pac_objs = { }
2008-03-10 19:04:23 +01:00
# it is possible to commit packages from different projects at the same
# time: iterate over all pacs and put each pac to the right project in the dict
for pac in pacs :
path = os . path . normpath ( os . path . join ( pac . dir , os . pardir ) )
if is_project_dir ( path ) :
pac_path = os . path . basename ( os . path . normpath ( pac . absdir ) )
prj_paths . setdefault ( path , [ ] ) . append ( pac_path )
2010-09-09 12:30:49 +02:00
pac_objs . setdefault ( path , [ ] ) . append ( pac )
2008-03-10 19:04:23 +01:00
files [ pac_path ] = pac . todo
else :
single_paths . append ( pac . dir )
2011-05-26 16:39:12 +02:00
if not pac . todo :
pac . todo = pac . filenamelist + pac . filenamelist_unvers
pac . todo . sort ( )
2013-04-09 11:25:19 +02:00
for prj_path , packages in prj_paths . items ( ) :
2010-09-09 12:30:49 +02:00
prj = Project ( prj_path )
2014-02-12 14:50:18 +01:00
if not msg and not opts . no_message :
2010-12-26 13:33:14 +01:00
msg = get_commit_msg ( prj . absdir , pac_objs [ prj_path ] )
2014-02-25 16:51:39 +01:00
# check any of the packages is a link, if so, as for branching
can_branch = False
if any ( pac . is_link_to_different_project ( ) for pac in pacs ) :
repl = raw_input ( ' Some of the packages are links to a different project! \n ' \
' Create a local branch before commit? (y|N) ' )
if repl in ( ' y ' , ' Y ' ) :
can_branch = True
2015-04-29 13:43:23 +02:00
prj . commit ( packages , msg = msg , files = files , skip_local_service_run = skip_local_service_run , verbose = opts . verbose , can_branch = can_branch , force = opts . force )
2010-12-26 13:33:14 +01:00
store_unlink_file ( prj . absdir , ' _commit_msg ' )
2008-03-10 19:04:23 +01:00
for pac in single_paths :
2010-09-09 12:30:49 +02:00
p = Package ( pac )
2014-02-12 14:50:18 +01:00
if not msg and not opts . no_message :
2010-12-26 13:33:14 +01:00
msg = get_commit_msg ( p . absdir , [ p ] )
2015-04-29 13:43:23 +02:00
p . commit ( msg , skip_local_service_run = skip_local_service_run , verbose = opts . verbose , force = opts . force )
2010-12-26 13:33:14 +01:00
store_unlink_file ( p . absdir , ' _commit_msg ' )
2008-03-10 19:04:23 +01:00
else :
for p in pacs :
2011-05-26 16:39:12 +02:00
if not p . todo :
p . todo = p . filenamelist + p . filenamelist_unvers
p . todo . sort ( )
2014-02-12 14:50:18 +01:00
if not msg and not opts . no_message :
2010-12-26 13:33:14 +01:00
msg = get_commit_msg ( p . absdir , [ p ] )
2015-04-29 13:43:23 +02:00
p . commit ( msg , skip_local_service_run = skip_local_service_run , verbose = opts . verbose , force = opts . force )
2010-12-26 13:33:14 +01:00
store_unlink_file ( p . absdir , ' _commit_msg ' )
2006-04-20 16:26:50 +02:00
2008-03-24 21:24:49 +01:00
@cmdln.option ( ' -r ' , ' --revision ' , metavar = ' REV ' ,
2007-07-04 14:55:26 +02:00
help = ' update to specified revision (this option will be ignored '
' if you are going to update the complete project or more than '
' one package) ' )
2008-03-24 21:24:49 +01:00
@cmdln.option ( ' -u ' , ' --unexpand-link ' , action = ' store_true ' ,
help = ' if a package is an expanded link, update to the raw _link file ' )
@cmdln.option ( ' -e ' , ' --expand-link ' , action = ' store_true ' ,
help = ' if a package is a link, update to the expanded sources ' )
2009-09-03 16:56:48 +02:00
@cmdln.option ( ' -s ' , ' --source-service-files ' , action = ' store_true ' ,
2010-11-24 15:34:40 +01:00
help = ' Run local source services after update. ' )
2010-06-08 11:24:10 +02:00
@cmdln.option ( ' -S ' , ' --server-side-source-service-files ' , action = ' store_true ' ,
help = ' Use server side generated sources instead of local generation. ' )
2010-04-22 15:27:54 +02:00
@cmdln.option ( ' -l ' , ' --limit-size ' , metavar = ' limit_size ' ,
help = ' Skip all files with a given size ' )
2007-04-25 01:00:12 +02:00
@cmdln.alias ( ' up ' )
def do_update ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Update a working copy
2006-04-20 16:26:50 +02:00
2009-05-18 16:50:43 +02:00
examples :
2006-04-20 16:26:50 +02:00
2007-04-25 01:00:12 +02:00
1. osc up
If the current working directory is a package , update it .
If the directory is a project directory , update all contained
packages , AND check out newly added packages .
2006-05-23 15:48:58 +02:00
2007-04-25 01:00:12 +02:00
To update only checked out packages , without checking out new
ones , you might want to use " osc up * " from within the project
dir .
2006-05-23 15:48:58 +02:00
2007-04-25 01:00:12 +02:00
2. osc up PAC
Update the packages specified by the path argument ( s )
2006-04-20 16:26:50 +02:00
2008-03-24 21:24:49 +01:00
When - - expand - link is used with source link packages , the expanded
sources will be checked out . Without this option , the _link file and
patches will be checked out . The option - - unexpand - link can be used to
switch back to the " raw " source with a _link file plus patch ( es ) .
2007-04-25 01:00:12 +02:00
$ { cmd_usage }
$ { cmd_option_list }
"""
2006-04-20 16:26:50 +02:00
2009-08-12 01:01:03 +02:00
if ( opts . expand_link and opts . unexpand_link ) \
or ( opts . expand_link and opts . revision ) \
or ( opts . unexpand_link and opts . revision ) :
raise oscerr . WrongOptions ( ' Sorry, the options --expand-link, --unexpand-link and '
' --revision are mutually exclusive. ' )
2007-04-25 01:00:12 +02:00
args = parseargs ( args )
2008-08-20 21:24:55 +02:00
arg_list = args [ : ]
2006-04-24 14:04:20 +02:00
2008-08-20 21:24:55 +02:00
for arg in arg_list :
2007-04-25 01:00:12 +02:00
if is_project_dir ( arg ) :
2010-02-09 20:57:10 +01:00
prj = Project ( arg , progress_obj = self . download_progress )
2006-04-20 16:26:50 +02:00
2008-03-10 19:04:23 +01:00
if conf . config [ ' do_package_tracking ' ] :
2009-05-18 16:50:43 +02:00
prj . update ( expand_link = opts . expand_link ,
2008-03-24 21:24:49 +01:00
unexpand_link = opts . unexpand_link )
2008-03-10 19:04:23 +01:00
args . remove ( arg )
2009-05-18 16:50:43 +02:00
else :
# if not tracking package, and 'update' is run inside a project dir,
2008-03-10 19:04:23 +01:00
# it should do the following:
# (a) update all packages
args + = prj . pacs_have
# (b) fetch new packages
2016-10-06 11:15:30 +02:00
prj . checkout_missing_pacs ( opts . expand_link , opts . unexpand_link )
2008-03-10 19:04:23 +01:00
args . remove ( arg )
2009-09-18 03:10:41 +02:00
print_request_list ( prj . apiurl , prj . name )
2006-06-06 12:50:40 +02:00
2009-06-09 11:34:25 +02:00
args . sort ( )
2010-02-09 20:57:10 +01:00
pacs = findpacs ( args , progress_obj = self . download_progress )
2006-04-20 16:26:50 +02:00
2010-02-09 00:08:21 +01:00
if opts . revision and len ( args ) == 1 :
2007-07-04 14:55:26 +02:00
rev , dummy = parseRevisionOption ( opts . revision )
2008-02-18 14:44:20 +01:00
if not checkRevision ( pacs [ 0 ] . prjname , pacs [ 0 ] . name , rev , pacs [ 0 ] . apiurl ) :
2013-04-09 12:51:28 +02:00
print ( ' Revision \' %s \' does not exist ' % rev , file = sys . stderr )
2007-07-06 13:54:34 +02:00
sys . exit ( 1 )
2007-07-04 14:55:26 +02:00
else :
rev = None
2007-04-25 01:00:12 +02:00
for p in pacs :
if len ( pacs ) > 1 :
2013-04-09 12:51:28 +02:00
print ( ' Updating %s ' % p . name )
2008-03-24 21:24:49 +01:00
2010-08-25 11:55:56 +02:00
# this shouldn't be needed anymore with the new update mechanism
# an expand/unexpand update is treated like a normal update (there's nothing special)
2010-01-20 17:55:44 +01:00
# FIXME: ugly workaround for #399247
2010-08-25 11:55:56 +02:00
# if opts.expand_link or opts.unexpand_link:
# if [ i for i in p.filenamelist+p.filenamelist_unvers if p.status(i) != ' ' and p.status(i) != '?']:
# print >>sys.stderr, 'osc: cannot expand/unexpand because your working ' \
# 'copy has local modifications.\nPlease revert/commit them ' \
# 'and try again.'
# sys.exit(1)
2009-04-06 22:08:14 +02:00
2008-11-19 13:13:18 +01:00
if not rev :
2016-02-08 17:24:35 +01:00
if opts . expand_link :
2012-03-28 23:14:28 +02:00
rev = p . latest_rev ( expand = True )
2016-02-08 17:24:35 +01:00
if p . islink ( ) and not p . isexpanded ( ) :
print ( ' Expanding to rev ' , rev )
2008-11-19 13:13:18 +01:00
elif opts . unexpand_link and p . islink ( ) and p . isexpanded ( ) :
2012-03-28 23:14:28 +02:00
rev = show_upstream_rev ( p . apiurl , p . prjname , p . name , meta = p . meta )
2013-04-09 12:51:28 +02:00
print ( ' Unexpanding to rev ' , rev )
2011-06-09 17:20:51 +02:00
elif ( p . islink ( ) and p . isexpanded ( ) ) or opts . server_side_source_service_files :
2011-05-23 15:26:13 +02:00
rev = p . latest_rev ( include_service_files = opts . server_side_source_service_files )
2008-03-24 21:24:49 +01:00
2010-06-08 11:24:10 +02:00
p . update ( rev , opts . server_side_source_service_files , opts . limit_size )
if opts . source_service_files :
2013-04-09 12:51:28 +02:00
print ( ' Running local source services ' )
2010-06-08 11:24:10 +02:00
p . run_source_services ( )
2010-01-20 17:55:44 +01:00
if opts . unexpand_link :
p . unmark_frozen ( )
2008-06-11 10:29:27 +02:00
rev = None
2009-09-18 03:10:41 +02:00
print_request_list ( p . apiurl , p . prjname , p . name )
2009-05-18 16:50:43 +02:00
2006-05-22 12:50:37 +02:00
2008-03-10 19:04:23 +01:00
@cmdln.option ( ' -f ' , ' --force ' , action = ' store_true ' ,
2009-05-04 21:07:05 +02:00
help = ' forces removal of entire package and its files ' )
2007-04-25 01:00:12 +02:00
@cmdln.alias ( ' rm ' )
@cmdln.alias ( ' del ' )
@cmdln.alias ( ' remove ' )
def do_delete ( self , subcmd , opts , * args ) :
2009-10-08 16:21:43 +02:00
""" $ {cmd_name} : Mark files or package directories to be deleted upon the next ' checkin '
2006-05-22 12:50:37 +02:00
2009-05-18 16:50:43 +02:00
usage :
2009-10-08 16:21:43 +02:00
cd . . . / PROJECT / PACKAGE
osc delete FILE [ . . . ]
cd . . . / PROJECT
osc delete PACKAGE [ . . . ]
2009-05-04 21:07:05 +02:00
This command works on check out copies . Use " rdelete " for working on server
side only . This is needed for removing the entire project .
2009-10-08 16:21:43 +02:00
As a safety measure , projects must be empty ( i . e . , you need to delete all
2009-10-20 16:30:15 +02:00
packages first ) .
2009-10-08 16:21:43 +02:00
If you are sure that you want to remove a package and all
its files use \' --force \' switch. Sometimes this also works without --force.
2009-05-04 21:07:05 +02:00
2007-04-25 01:00:12 +02:00
$ { cmd_option_list }
"""
2006-05-22 12:50:37 +02:00
2007-04-25 01:00:12 +02:00
if not args :
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
raise oscerr . WrongArgs ( ' Missing argument. \n \n ' \
+ self . get_cmd_help ( ' delete ' ) )
2006-06-26 17:11:22 +02:00
2007-04-25 01:00:12 +02:00
args = parseargs ( args )
2008-03-10 19:04:23 +01:00
# check if args contains a package which was removed by
# a non-osc command and mark it with the 'D'-state
2008-08-20 21:24:55 +02:00
arg_list = args [ : ]
for i in arg_list :
2008-03-10 19:04:23 +01:00
if not os . path . exists ( i ) :
prj_dir , pac_dir = getPrjPacPaths ( i )
if is_project_dir ( prj_dir ) :
prj = Project ( prj_dir , False )
if i in prj . pacs_broken :
if prj . get_state ( i ) != ' A ' :
prj . set_state ( pac_dir , ' D ' )
else :
prj . del_package_node ( i )
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' D ' , getTransActPath ( i ) ) )
2008-03-10 19:04:23 +01:00
args . remove ( i )
prj . write_packages ( )
2007-04-25 01:00:12 +02:00
pacs = findpacs ( args )
2006-04-20 16:26:50 +02:00
2007-04-25 01:00:12 +02:00
for p in pacs :
2008-03-10 19:04:23 +01:00
if not p . todo :
prj_dir , pac_dir = getPrjPacPaths ( p . absdir )
2009-05-04 21:07:05 +02:00
if is_project_dir ( prj_dir ) :
2009-10-20 16:30:15 +02:00
if conf . config [ ' do_package_tracking ' ] :
prj = Project ( prj_dir , False )
prj . delPackage ( p , opts . force )
else :
2013-04-09 12:51:28 +02:00
print ( " WARNING: package tracking is disabled, operation skipped ! " , file = sys . stderr )
2008-03-10 19:04:23 +01:00
else :
pathn = getTransActPath ( p . dir )
for filename in p . todo :
2010-07-28 12:13:46 +02:00
p . clear_from_conflictlist ( filename )
2009-07-15 23:10:38 +02:00
ret , state = p . delete_file ( filename , opts . force )
if ret :
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' D ' , os . path . join ( pathn , filename ) ) )
2009-07-15 23:10:38 +02:00
continue
if state == ' ? ' :
2008-03-10 19:04:23 +01:00
sys . exit ( ' \' %s \' is not under version control ' % filename )
2009-07-15 23:10:38 +02:00
elif state in [ ' A ' , ' M ' ] and not opts . force :
sys . exit ( ' \' %s \' has local modifications (use --force to remove this file) ' % filename )
2011-01-18 19:38:33 +01:00
elif state == ' S ' :
sys . exit ( ' \' %s \' is marked as skipped and no local file with this name exists ' % filename )
2006-05-23 15:48:58 +02:00
2007-04-25 01:00:12 +02:00
def do_resolved ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Remove ' conflicted ' state on working copy files
2009-05-18 16:50:43 +02:00
2007-04-25 01:00:12 +02:00
If an upstream change can ' t be merged automatically, a file is put into
in ' conflicted ' ( ' C ' ) state . Within the file , conflicts are marked with
special << << << < as well as == == == == and >> >> >> > lines .
2009-05-18 16:50:43 +02:00
2007-04-25 01:00:12 +02:00
After manually resolving all conflicting parts , use this command to
remove the ' conflicted ' state .
Note : this subcommand does not semantically resolve conflicts or
remove conflict markers ; it merely removes the conflict - related
artifact files and allows PATH to be committed again .
2006-05-23 15:48:58 +02:00
2009-05-18 16:50:43 +02:00
usage :
2007-04-25 01:00:12 +02:00
osc resolved FILE [ FILE . . . ]
$ { cmd_option_list }
"""
2006-05-23 15:48:58 +02:00
2007-04-25 01:00:12 +02:00
if not args :
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
raise oscerr . WrongArgs ( ' Missing argument. \n \n ' \
+ self . get_cmd_help ( ' resolved ' ) )
2006-04-20 16:26:50 +02:00
2007-04-25 01:00:12 +02:00
args = parseargs ( args )
pacs = findpacs ( args )
2006-04-28 17:37:25 +02:00
2007-04-25 01:00:12 +02:00
for p in pacs :
for filename in p . todo :
2013-04-09 12:51:28 +02:00
print ( ' Resolved conflicted state of " %s " ' % filename )
2007-04-25 01:00:12 +02:00
p . clear_from_conflictlist ( filename )
2006-04-20 16:26:50 +02:00
2010-07-28 16:04:27 +02:00
@cmdln.alias ( ' dists ' )
2010-07-29 07:37:54 +02:00
# FIXME: using just ^DISCONTINUED as match is not a general approach and only valid for one instance
# we need to discuss an api call for that, if we need this
# @cmdln.option('-d', '--discontinued', action='store_true',
# help='show discontinued distributions')
2010-07-28 16:04:27 +02:00
def do_distributions ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Shows all available distributions
2010-08-13 00:30:05 +02:00
This command shows the available distributions . For active distributions
2014-08-12 15:01:16 +02:00
it shows the name , project and name of the repository and a suggested default repository name .
2010-07-28 16:04:27 +02:00
usage :
2014-08-12 15:01:16 +02:00
osc distributions
2010-07-28 16:04:27 +02:00
$ { cmd_option_list }
"""
apiurl = self . get_api_url ( )
2013-04-09 12:51:28 +02:00
print ( ' \n ' . join ( get_distibutions ( apiurl ) ) ) #FIXME:, opts.discontinued))
2010-07-28 16:04:27 +02:00
2009-05-15 11:24:53 +02:00
@cmdln.hide ( 1 )
2007-05-04 23:51:54 +02:00
def do_results_meta ( self , subcmd , opts , * args ) :
2016-05-15 17:50:31 +02:00
""" $ {cmd_name} :
Obsolete command to show build results . Use ' results --xml ' now .
See the help output of ' results ' .
"""
print ( " This command is obsolete. Use ' osc results --xml ' . " ,
file = sys . stderr )
print ( " See ' osc help results ' . " , file = sys . stderr )
return 2
2006-05-22 16:12:06 +02:00
2009-05-25 13:33:04 +02:00
@cmdln.hide ( 1 )
2009-08-20 21:28:05 +02:00
@cmdln.option ( ' -l ' , ' --last-build ' , action = ' store_true ' ,
help = ' show last build results (succeeded/failed/unknown) ' )
@cmdln.option ( ' -r ' , ' --repo ' , action = ' append ' , default = [ ] ,
help = ' Show results only for specified repo(s) ' )
@cmdln.option ( ' -a ' , ' --arch ' , action = ' append ' , default = [ ] ,
help = ' Show results only for specified architecture(s) ' )
@cmdln.option ( ' ' , ' --xml ' , action = ' store_true ' ,
help = ' generate output in XML (former results_meta) ' )
2009-05-25 13:33:04 +02:00
def do_rresults ( self , subcmd , opts , * args ) :
2016-05-15 17:50:31 +02:00
""" $ {cmd_name} :
2009-05-18 16:50:43 +02:00
2016-05-15 17:50:31 +02:00
Obsolete command to show build results . Use ' results ' now .
See the help output of ' results ' .
"""
2009-05-18 16:50:43 +02:00
2016-05-15 17:50:31 +02:00
print ( " Command rresults is obsolete. Running ' osc results ' instead " ,
file = sys . stderr )
print ( " See ' osc help results ' . " , file = sys . stderr )
return self . do_results ( ' results ' , opts , * args )
2009-07-07 16:30:15 +02:00
@cmdln.option ( ' -f ' , ' --force ' , action = ' store_true ' , default = False ,
help = " Don ' t ask and delete files " )
def do_rremove ( self , subcmd , opts , project , package , * files ) :
""" $ {cmd_name} : Remove source files from selected package
$ { cmd_usage }
$ { cmd_option_list }
"""
2010-08-13 00:30:05 +02:00
apiurl = self . get_api_url ( )
2009-07-07 16:30:15 +02:00
if len ( files ) == 0 :
if not ' / ' in project :
raise oscerr . WrongArgs ( " Missing operand, type osc help rremove for help " )
else :
files = ( package , )
project , package = project . split ( ' / ' )
2010-08-20 14:34:41 +02:00
for filename in files :
2009-07-07 16:30:15 +02:00
if not opts . force :
2010-08-20 14:34:41 +02:00
resp = raw_input ( " rm: remove source file ` %s ' from ` %s / %s ' ? (yY|nN) " % ( filename , project , package ) )
2009-07-07 16:30:15 +02:00
if resp not in ( ' y ' , ' Y ' ) :
continue
try :
2010-08-20 14:34:41 +02:00
delete_files ( apiurl , project , package , ( filename , ) )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2009-07-07 16:30:15 +02:00
if opts . force :
2013-04-09 12:51:28 +02:00
print ( e , file = sys . stderr )
2009-07-07 16:30:15 +02:00
body = e . read ( )
if e . code in [ 400 , 403 , 404 , 500 ] :
if ' <summary> ' in body :
msg = body . split ( ' <summary> ' ) [ 1 ]
msg = msg . split ( ' </summary> ' ) [ 0 ]
2013-04-09 12:51:28 +02:00
print ( msg , file = sys . stderr )
2009-07-07 16:30:15 +02:00
else :
raise e
2008-06-17 08:12:48 +02:00
@cmdln.alias ( ' r ' )
2009-02-23 13:25:56 +01:00
@cmdln.option ( ' -l ' , ' --last-build ' , action = ' store_true ' ,
help = ' show last build results (succeeded/failed/unknown) ' )
2009-05-15 10:48:32 +02:00
@cmdln.option ( ' -r ' , ' --repo ' , action = ' append ' , default = [ ] ,
2009-05-15 09:16:26 +02:00
help = ' Show results only for specified repo(s) ' )
2009-05-15 10:48:32 +02:00
@cmdln.option ( ' -a ' , ' --arch ' , action = ' append ' , default = [ ] ,
2009-05-15 09:16:26 +02:00
help = ' Show results only for specified architecture(s) ' )
2010-05-06 14:23:27 +02:00
@cmdln.option ( ' -v ' , ' --verbose ' , action = ' store_true ' , default = False ,
help = ' more verbose output ' )
2017-01-17 16:45:06 +01:00
@cmdln.option ( ' --no-multibuild ' , action = ' store_true ' , default = False ,
help = ' Disable results for all direct affect packages inside of the project ' )
2016-11-23 15:35:09 +01:00
@cmdln.option ( ' -M ' , ' --multibuild-package ' , action = ' append ' , default = [ ] ,
help = ' Only show results for the specified multibuild package ' )
2012-01-23 17:26:53 +01:00
@cmdln.option ( ' -w ' , ' --watch ' , action = ' store_true ' , default = False ,
2012-01-24 09:59:23 +01:00
help = ' watch the results until all finished building ' )
2010-04-20 15:38:52 +02:00
@cmdln.option ( ' ' , ' --xml ' , action = ' store_true ' , default = False ,
2009-05-15 11:24:53 +02:00
help = ' generate output in XML (former results_meta) ' )
2010-04-20 15:38:52 +02:00
@cmdln.option ( ' ' , ' --csv ' , action = ' store_true ' , default = False ,
help = ' generate output in CSV format ' )
@cmdln.option ( ' ' , ' --format ' , default = ' %(repository)s | %(arch)s | %(state)s | %(dirty)s | %(code)s | %(details)s ' ,
help = ' format string for csv output ' )
2007-04-25 01:00:12 +02:00
def do_results ( self , subcmd , opts , * args ) :
2010-12-02 23:36:40 +01:00
""" $ {cmd_name} : Shows the build results of a package or project
2006-04-20 16:26:50 +02:00
2009-05-25 12:41:16 +02:00
Usage :
2010-12-02 23:36:40 +01:00
osc results # (inside working copy of PRJ or PKG)
osc results PROJECT [ PACKAGE ]
2008-05-16 14:25:50 +02:00
$ { cmd_option_list }
"""
2009-05-25 13:33:04 +02:00
2009-05-10 22:29:34 +02:00
args = slash_split ( args )
2009-08-20 21:28:05 +02:00
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2012-04-04 10:28:27 +02:00
if len ( args ) > 2 :
2010-12-02 23:36:40 +01:00
raise oscerr . WrongArgs ( ' Too many arguments (required none, one, or two) ' )
2012-04-04 10:28:27 +02:00
project = package = None
wd = os . curdir
if is_project_dir ( wd ) :
project = store_read_project ( wd )
elif is_package_dir ( wd ) :
project = store_read_project ( wd )
package = store_read_package ( wd )
if len ( args ) > 0 :
2009-05-25 13:33:04 +02:00
project = args [ 0 ]
2012-04-04 10:28:27 +02:00
if len ( args ) > 1 :
2009-05-25 13:33:04 +02:00
package = args [ 1 ]
2009-05-18 16:50:43 +02:00
2012-04-04 10:28:27 +02:00
if project == None :
raise oscerr . WrongOptions ( " No project given " )
if package == None :
if opts . arch == [ ] :
opts . arch = None
if opts . repo == [ ] :
opts . repo = None
opts . hide_legend = None
opts . name_filter = None
opts . status_filter = None
opts . vertical = None
opts . show_non_building = None
opts . show_excluded = None
self . do_prjresults ( ' prjresults ' , opts , * args )
2014-02-27 08:39:54 +01:00
return
2012-04-04 10:28:27 +02:00
2010-04-20 15:38:52 +02:00
if opts . xml and opts . csv :
raise oscerr . WrongOptions ( " --xml and --csv are mutual exclusive " )
2016-02-07 00:55:23 +01:00
kwargs = { ' apiurl ' : apiurl , ' project ' : project , ' package ' : package ,
' lastbuild ' : opts . last_build , ' repository ' : opts . repo ,
' arch ' : opts . arch , ' wait ' : opts . watch }
2016-11-23 15:35:09 +01:00
if opts . multibuild_package :
2017-01-17 16:45:06 +01:00
opts . no_multibuild = False
2016-11-23 15:35:09 +01:00
kwargs [ ' multibuild_packages ' ] = opts . multibuild_package
2017-01-17 16:45:06 +01:00
if not opts . no_multibuild :
kwargs [ ' multibuild ' ] = kwargs [ ' locallink ' ] = True
2016-02-07 00:55:23 +01:00
if opts . xml or opts . csv :
for xml in get_package_results ( * * kwargs ) :
if opts . xml :
print ( xml , end = ' ' )
else :
# csv formatting
2017-01-12 15:33:26 +01:00
results = [ r for r , _ in result_xml_to_dicts ( xml ) ]
2016-02-07 00:55:23 +01:00
print ( ' \n ' . join ( format_results ( results , opts . format ) ) )
2010-04-20 15:38:52 +02:00
else :
2016-02-07 00:55:23 +01:00
kwargs [ ' verbose ' ] = opts . verbose
kwargs [ ' wait ' ] = opts . watch
kwargs [ ' printJoin ' ] = ' \n '
get_results ( * * kwargs )
2009-05-18 16:50:43 +02:00
2010-01-14 15:20:00 +01:00
# WARNING: this function is also called by do_results. You need to set a default there
# as well when adding a new option!
2008-05-15 20:09:24 +02:00
@cmdln.option ( ' -q ' , ' --hide-legend ' , action = ' store_true ' ,
help = ' hide the legend ' )
2008-03-13 12:13:22 +01:00
@cmdln.option ( ' -c ' , ' --csv ' , action = ' store_true ' ,
2008-02-12 13:45:06 +01:00
help = ' csv output ' )
2013-01-18 16:56:13 +01:00
@cmdln.option ( ' ' , ' --xml ' , action = ' store_true ' , default = False ,
help = ' generate output in XML ' )
2008-05-15 20:09:24 +02:00
@cmdln.option ( ' -s ' , ' --status-filter ' , metavar = ' STATUS ' ,
help = ' show only packages with buildstatus STATUS (see legend) ' )
@cmdln.option ( ' -n ' , ' --name-filter ' , metavar = ' EXPR ' ,
2008-08-19 21:37:08 +02:00
help = ' show only packages whose names match EXPR ' )
2009-10-15 16:24:12 +02:00
@cmdln.option ( ' -a ' , ' --arch ' , metavar = ' ARCH ' ,
help = ' show results only for specified architecture(s) ' )
@cmdln.option ( ' -r ' , ' --repo ' , metavar = ' REPO ' ,
help = ' show results only for specified repo(s) ' )
2010-01-11 16:36:21 +01:00
@cmdln.option ( ' -V ' , ' --vertical ' , action = ' store_true ' ,
help = ' list packages vertically instead horizontally ' )
2010-08-04 17:16:59 +02:00
@cmdln.option ( ' --show-excluded ' , action = ' store_true ' ,
help = ' show packages that are excluded in all repos, also hide repos that have only excluded packages ' )
2008-06-17 08:12:48 +02:00
@cmdln.alias ( ' pr ' )
2007-04-25 01:00:12 +02:00
def do_prjresults ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Shows project-wide build results
2009-05-18 16:50:43 +02:00
2009-05-25 13:33:04 +02:00
Usage :
osc prjresults ( inside working copy )
2010-01-11 16:36:21 +01:00
osc prjresults PROJECT
2008-08-19 21:37:08 +02:00
2007-04-25 01:00:12 +02:00
$ { cmd_option_list }
"""
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2006-04-29 22:44:09 +02:00
2009-05-25 13:33:04 +02:00
if args :
if len ( args ) == 1 :
project = args [ 0 ]
2008-08-19 21:37:08 +02:00
else :
2010-01-11 16:36:21 +01:00
raise oscerr . WrongArgs ( ' Wrong number of arguments. ' )
2009-05-25 13:33:04 +02:00
else :
wd = os . curdir
2008-08-19 21:37:08 +02:00
project = store_read_project ( wd )
2006-05-23 15:48:58 +02:00
2013-01-18 16:56:13 +01:00
if opts . xml :
2013-04-09 12:51:28 +02:00
print ( ' ' . join ( show_prj_results_meta ( apiurl , project ) ) )
2013-01-18 16:56:13 +01:00
return
2013-05-27 13:03:46 +02:00
print ( ' \n ' . join ( get_prj_results ( apiurl , project , hide_legend = opts . hide_legend , \
csv = opts . csv , status_filter = opts . status_filter , \
name_filter = opts . name_filter , repo = opts . repo , \
arch = opts . arch , vertical = opts . vertical , \
show_excluded = opts . show_excluded ) ) )
2008-05-16 14:25:50 +02:00
@cmdln.option ( ' -q ' , ' --hide-legend ' , action = ' store_true ' ,
help = ' hide the legend ' )
@cmdln.option ( ' -c ' , ' --csv ' , action = ' store_true ' ,
help = ' csv output ' )
@cmdln.option ( ' -s ' , ' --status-filter ' , metavar = ' STATUS ' ,
help = ' show only packages with buildstatus STATUS (see legend) ' )
@cmdln.option ( ' -n ' , ' --name-filter ' , metavar = ' EXPR ' ,
2008-08-19 21:37:08 +02:00
help = ' show only packages whose names match EXPR ' )
2008-05-16 14:25:50 +02:00
2009-05-25 13:33:04 +02:00
@cmdln.hide ( 1 )
def do_rprjresults ( self , subcmd , opts , * args ) :
2016-05-15 17:50:31 +02:00
""" $ {cmd_name} :
Obsolete command to show project - wide build results . Use ' prjresults ' now .
See the help output of ' prjresults ' .
"""
print ( " Command rprjresults is obsolete. Please use ' osc prjresults ' " ,
file = sys . stderr )
print ( " See ' osc help prjresults ' . " , file = sys . stderr )
return 2
2009-05-18 16:50:43 +02:00
2007-07-12 01:24:26 +02:00
@cmdln.alias ( ' bl ' )
2011-01-07 23:05:44 +01:00
@cmdln.alias ( ' blt ' )
@cmdln.alias ( ' buildlogtail ' )
2013-08-13 10:38:43 +02:00
@cmdln.option ( ' -l ' , ' --last ' , action = ' store_true ' ,
help = ' Show the last finished log file ' )
2011-01-07 23:05:44 +01:00
@cmdln.option ( ' -o ' , ' --offset ' , metavar = ' OFFSET ' ,
help = ' get log start or end from the offset ' )
2012-12-15 01:50:24 +01:00
@cmdln.option ( ' -s ' , ' --strip-time ' , action = ' store_true ' ,
help = ' strip leading build time from the log ' )
2009-11-23 11:13:19 +01:00
def do_buildlog ( self , subcmd , opts , * args ) :
2007-04-25 01:00:12 +02:00
""" $ {cmd_name} : Shows the build log of a package
Shows the log file of the build of a package . Can be used to follow the
log while it is being written .
Needs to be called from within a package directory .
2006-05-23 15:48:58 +02:00
2011-01-07 23:05:44 +01:00
When called as buildlogtail ( or blt ) it just shows the end of the logfile .
2011-04-28 11:14:38 +02:00
This is useful to see just a build failure reasons .
2011-01-07 23:05:44 +01:00
2009-09-08 10:14:27 +02:00
The arguments REPOSITORY and ARCH are the first two columns in the ' osc
2010-02-16 13:49:14 +01:00
results ' output. If the buildlog url is used buildlog command has the
same behavior as remotebuildlog .
2007-04-25 01:00:12 +02:00
2010-02-16 13:49:14 +01:00
$ { cmd_usage } [ REPOSITORY ARCH | BUILDLOGURL ]
2007-04-25 01:00:12 +02:00
$ { cmd_option_list }
"""
2016-02-05 16:10:43 +01:00
import osc . build
2007-04-25 01:00:12 +02:00
2016-02-05 16:10:43 +01:00
project = package = repository = arch = None
2010-02-16 13:49:14 +01:00
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2010-02-16 13:49:14 +01:00
if len ( args ) == 1 and args [ 0 ] . startswith ( ' http ' ) :
apiurl , project , package , repository , arch = parse_buildlogurl ( args [ 0 ] )
else :
2016-02-05 16:10:43 +01:00
project = store_read_project ( os . curdir )
package = store_read_package ( os . curdir )
if len ( args ) == 1 :
repository , arch = self . _find_last_repo_arch ( args [ 0 ] , fatal = False )
if repository is None :
# no local build with this repo was done
print ( ' failed to guess arch, using hostarch ' )
repository = args [ 0 ]
arch = osc . build . hostarch
elif len ( args ) < 2 :
self . print_repos ( )
elif len ( args ) > 2 :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
else :
repository = args [ 0 ]
arch = args [ 1 ]
2007-03-13 00:21:34 +01:00
2013-05-27 12:41:50 +02:00
offset = 0
2011-01-07 23:05:44 +01:00
if subcmd == " blt " or subcmd == " buildlogtail " :
query = { ' view ' : ' entry ' }
2013-08-13 10:38:43 +02:00
if opts . last :
query [ ' last ' ] = 1
2011-01-07 23:05:44 +01:00
u = makeurl ( self . get_api_url ( ) , [ ' build ' , project , repository , arch , package , ' _log ' ] , query = query )
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
offset = int ( root . find ( ' entry ' ) . get ( ' size ' ) )
if opts . offset :
offset = offset - int ( opts . offset )
else :
2011-02-27 14:20:41 +01:00
offset = offset - ( 8 * 1024 )
2011-01-07 23:05:44 +01:00
if offset < 0 :
2013-05-27 12:41:50 +02:00
offset = 0
2011-01-07 23:05:44 +01:00
elif opts . offset :
offset = int ( opts . offset )
2012-12-15 01:50:24 +01:00
strip_time = opts . strip_time or conf . config [ ' buildlog_strip_time ' ]
2013-08-13 10:38:43 +02:00
print_buildlog ( apiurl , project , package , repository , arch , offset , strip_time , opts . last )
2008-01-03 23:10:16 +01:00
2011-03-02 14:38:24 +01:00
def print_repos ( self , repos_only = False , exc_class = oscerr . WrongArgs , exc_msg = ' Missing arguments ' ) :
2010-02-27 20:11:15 +01:00
wd = os . curdir
doprint = False
if is_package_dir ( wd ) :
2010-08-20 14:34:41 +02:00
msg = " package "
2010-02-27 20:11:15 +01:00
doprint = True
elif is_project_dir ( wd ) :
2010-08-20 14:34:41 +02:00
msg = " project "
2010-02-27 20:11:15 +01:00
doprint = True
if doprint :
2013-04-09 12:51:28 +02:00
print ( ' Valid arguments for this %s are: ' % msg )
print ( )
2010-07-30 16:17:41 +02:00
if repos_only :
self . do_repositories ( " repos_only " , None )
else :
self . do_repositories ( None , None )
2011-03-02 14:38:24 +01:00
raise exc_class ( exc_msg )
2009-11-23 11:13:19 +01:00
2008-01-03 23:10:16 +01:00
@cmdln.alias ( ' rbl ' )
2009-05-21 14:05:39 +02:00
@cmdln.alias ( ' rbuildlog ' )
2011-01-07 23:05:44 +01:00
@cmdln.alias ( ' rblt ' )
@cmdln.alias ( ' rbuildlogtail ' )
@cmdln.alias ( ' remotebuildlogtail ' )
2013-08-13 10:38:43 +02:00
@cmdln.option ( ' -l ' , ' --last ' , action = ' store_true ' ,
help = ' Show the last finished log file ' )
2011-01-07 23:05:44 +01:00
@cmdln.option ( ' -o ' , ' --offset ' , metavar = ' OFFSET ' ,
help = ' get log starting or ending from the offset ' )
2012-12-15 01:50:24 +01:00
@cmdln.option ( ' -s ' , ' --strip-time ' , action = ' store_true ' ,
help = ' strip leading build time from the log ' )
2008-01-03 23:10:16 +01:00
def do_remotebuildlog ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Shows the build log of a package
Shows the log file of the build of a package . Can be used to follow the
log while it is being written .
2011-01-07 23:05:44 +01:00
remotebuildlogtail shows just the tail of the log file .
2008-01-03 23:10:16 +01:00
usage :
2009-09-08 10:14:27 +02:00
osc remotebuildlog project package repository arch
2008-01-03 23:10:16 +01:00
or
2009-09-08 10:14:27 +02:00
osc remotebuildlog project / package / repository / arch
2010-02-16 12:23:25 +01:00
or
osc remotebuildlog buildlogurl
2008-01-03 23:10:16 +01:00
$ { cmd_option_list }
"""
2010-01-28 20:00:34 +01:00
if len ( args ) == 1 and args [ 0 ] . startswith ( ' http ' ) :
2010-01-28 13:20:11 +01:00
apiurl , project , package , repository , arch = parse_buildlogurl ( args [ 0 ] )
else :
args = slash_split ( args )
2010-07-29 17:29:07 +02:00
apiurl = self . get_api_url ( )
2010-01-28 13:20:11 +01:00
if len ( args ) < 4 :
raise oscerr . WrongArgs ( ' Too few arguments. ' )
elif len ( args ) > 4 :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
else :
project , package , repository , arch = args
2010-02-28 02:30:13 +01:00
2013-05-27 12:41:50 +02:00
offset = 0
2011-01-07 23:05:44 +01:00
if subcmd == " rblt " or subcmd == " rbuildlogtail " or subcmd == " remotebuildlogtail " :
query = { ' view ' : ' entry ' }
2013-08-13 10:38:43 +02:00
if opts . last :
query [ ' last ' ] = 1
2011-01-07 23:05:44 +01:00
u = makeurl ( self . get_api_url ( ) , [ ' build ' , project , repository , arch , package , ' _log ' ] , query = query )
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
offset = int ( root . find ( ' entry ' ) . get ( ' size ' ) )
if opts . offset :
offset = offset - int ( opts . offset )
else :
2011-02-27 14:20:41 +01:00
offset = offset - ( 8 * 1024 )
2011-01-07 23:05:44 +01:00
if offset < 0 :
2013-05-27 12:41:50 +02:00
offset = 0
2011-01-07 23:05:44 +01:00
elif opts . offset :
offset = int ( opts . offset )
2012-12-15 01:50:24 +01:00
strip_time = opts . strip_time or conf . config [ ' buildlog_strip_time ' ]
2013-08-13 10:38:43 +02:00
print_buildlog ( apiurl , project , package , repository , arch , offset , strip_time , opts . last )
2006-05-23 15:48:58 +02:00
2016-02-05 16:10:43 +01:00
def _find_last_repo_arch ( self , repo = None , fatal = True ) :
import glob
files = glob . glob ( os . path . join ( os . getcwd ( ) , store , " _buildinfo-* " ) )
if repo is not None :
files = [ f for f in files
if os . path . basename ( f ) . replace ( ' _buildinfo- ' , ' ' ) . startswith ( repo + ' - ' ) ]
if not files :
if not fatal :
return None , None
self . print_repos ( )
cfg = files [ 0 ]
# find newest file
for f in files [ 1 : ] :
2016-02-05 16:11:11 +01:00
if os . stat ( f ) . st_atime > os . stat ( cfg ) . st_atime :
2016-02-05 16:10:43 +01:00
cfg = f
root = ET . parse ( cfg ) . getroot ( )
repo = root . get ( " repository " )
arch = root . find ( " arch " ) . text
return repo , arch
2010-02-12 15:54:33 +01:00
@cmdln.alias ( ' lbl ' )
2011-01-07 23:05:44 +01:00
@cmdln.option ( ' -o ' , ' --offset ' , metavar = ' OFFSET ' ,
2010-02-12 15:54:33 +01:00
help = ' get log starting from offset ' )
2012-12-15 01:50:24 +01:00
@cmdln.option ( ' -s ' , ' --strip-time ' , action = ' store_true ' ,
help = ' strip leading build time from the log ' )
2010-02-23 13:41:10 +01:00
def do_localbuildlog ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Shows the build log of a local buildchroot
2010-02-18 14:20:40 +01:00
2010-02-23 13:41:10 +01:00
usage :
2013-03-25 20:28:27 +01:00
osc lbl [ REPOSITORY [ ARCH ] ]
2010-02-23 13:41:10 +01:00
osc lbl # show log of newest last local build
2010-02-18 14:20:40 +01:00
$ { cmd_option_list }
"""
2010-02-12 15:54:33 +01:00
if conf . config [ ' build-type ' ] :
2010-02-23 13:41:10 +01:00
# FIXME: raise Exception instead
2013-04-09 12:51:28 +02:00
print ( ' Not implemented for VMs ' , file = sys . stderr )
2010-02-12 15:54:33 +01:00
sys . exit ( 1 )
2010-02-23 13:41:10 +01:00
2013-03-25 20:28:27 +01:00
if len ( args ) == 0 or len ( args ) == 1 :
2016-02-05 16:10:43 +01:00
project = store_read_project ( ' . ' )
2010-02-23 13:41:10 +01:00
package = store_read_package ( ' . ' )
2016-02-05 16:10:43 +01:00
repo = None
2013-03-25 20:28:27 +01:00
if args :
2016-02-05 16:10:43 +01:00
repo = args [ 0 ]
repo , arch = self . _find_last_repo_arch ( repo )
2010-02-23 13:41:10 +01:00
elif len ( args ) == 2 :
project = store_read_project ( ' . ' )
package = store_read_package ( ' . ' )
repo = args [ 0 ]
arch = args [ 1 ]
else :
if is_package_dir ( os . curdir ) :
self . print_repos ( )
raise oscerr . WrongArgs ( ' Wrong number of arguments. ' )
2014-08-04 11:14:48 +02:00
# TODO: refactor/unify buildroot calculation and move it to core.py
2010-02-12 15:54:33 +01:00
buildroot = os . environ . get ( ' OSC_BUILD_ROOT ' , conf . config [ ' build-root ' ] )
2014-08-04 11:14:48 +02:00
apihost = urlsplit ( self . get_api_url ( ) ) [ 1 ]
2010-02-23 13:41:10 +01:00
buildroot = buildroot % { ' project ' : project , ' package ' : package ,
2014-08-04 11:14:48 +02:00
' repo ' : repo , ' arch ' : arch , ' apihost ' : apihost }
2010-02-12 15:54:33 +01:00
offset = 0
2011-01-28 15:52:10 +01:00
if opts . offset :
offset = int ( opts . offset )
2010-02-12 15:54:33 +01:00
logfile = os . path . join ( buildroot , ' .build.log ' )
if not os . path . isfile ( logfile ) :
raise oscerr . OscIOError ( None , ' logfile \' %s \' does not exist ' % logfile )
f = open ( logfile , ' r ' )
f . seek ( offset )
data = f . read ( BUFSIZE )
while len ( data ) :
2012-12-15 01:50:24 +01:00
if opts . strip_time or conf . config [ ' buildlog_strip_time ' ] :
data = buildlog_strip_time ( data )
2010-02-12 15:54:33 +01:00
sys . stdout . write ( data )
data = f . read ( BUFSIZE )
f . close ( )
2006-09-25 17:11:03 +02:00
2009-12-09 07:53:33 +01:00
@cmdln.alias ( ' tr ' )
def do_triggerreason ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Show reason why a package got triggered to build
The server decides when a package needs to get rebuild , this command
shows the detailed reason for a package . A brief reason is also stored
in the jobhistory , which can be accessed via " osc jobhistory " .
Trigger reasons might be :
- new build ( never build yet or rebuild manually forced )
- source change ( eg . on updating sources )
- meta change ( packages which are used for building have changed )
- rebuild count sync ( In case that it is configured to sync release numbers )
usage in package or project directory :
osc reason REPOSITORY ARCH
osc reason PROJECT PACKAGE REPOSITORY ARCH
$ { cmd_option_list }
"""
wd = os . curdir
args = slash_split ( args )
project = package = repository = arch = None
2010-02-28 02:30:13 +01:00
2010-02-09 00:08:21 +01:00
if len ( args ) < 2 :
2009-12-09 07:53:33 +01:00
self . print_repos ( )
2016-05-15 17:50:31 +02:00
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2009-12-09 07:53:33 +01:00
if len ( args ) == 2 : # 2
if is_package_dir ( ' . ' ) :
2010-02-27 20:11:15 +01:00
package = store_read_package ( wd )
2009-12-09 07:53:33 +01:00
else :
2010-02-27 20:11:15 +01:00
raise oscerr . WrongArgs ( ' package is not specified. ' )
2009-12-09 07:53:33 +01:00
project = store_read_project ( wd )
repository = args [ 0 ]
arch = args [ 1 ]
elif len ( args ) == 4 :
project = args [ 0 ]
package = args [ 1 ]
repository = args [ 2 ]
arch = args [ 3 ]
else :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
2013-04-09 12:51:28 +02:00
print ( apiurl , project , package , repository , arch )
2009-12-09 07:53:33 +01:00
xml = show_package_trigger_reason ( apiurl , project , package , repository , arch )
2009-12-26 14:22:34 +01:00
root = ET . fromstring ( xml )
reason = root . find ( ' explain ' ) . text
2013-04-09 12:51:28 +02:00
print ( reason )
2009-12-09 07:53:33 +01:00
if reason == " meta change " :
2013-04-09 12:51:28 +02:00
print ( " changed keys: " )
2010-02-27 20:11:15 +01:00
for package in root . findall ( ' packagechange ' ) :
2013-04-09 12:51:28 +02:00
print ( " " , package . get ( ' change ' ) , package . get ( ' key ' ) )
2009-12-09 07:53:33 +01:00
2009-12-04 16:20:17 +01:00
# FIXME: the new osc syntax should allow to specify multiple packages
# FIXME: the command should optionally use buildinfo data to show all dependencies
@cmdln.alias ( ' whatdependson ' )
def do_dependson ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Show the build dependencies
The command dependson and whatdependson can be used to find out what
will be triggered when a certain package changes .
This is no guarantee , since the new build might have changed dependencies .
2010-02-28 02:30:13 +01:00
dependson shows the build dependencies inside of a project , valid for a
2009-12-04 16:20:17 +01:00
given repository and architecture .
2010-02-28 02:30:13 +01:00
NOTE : to see all binary packages , which can trigger a build you need to
2009-12-04 16:20:17 +01:00
refer the buildinfo , since this command shows only the dependencies
inside of a project .
The arguments REPOSITORY and ARCH can be taken from the first two columns
of the ' osc repos ' output .
usage in package or project directory :
osc dependson REPOSITORY ARCH
osc whatdependson REPOSITORY ARCH
usage :
osc dependson PROJECT [ PACKAGE ] REPOSITORY ARCH
osc whatdependson PROJECT [ PACKAGE ] REPOSITORY ARCH
$ { cmd_option_list }
"""
wd = os . curdir
args = slash_split ( args )
project = packages = repository = arch = reverse = None
2010-02-28 02:30:13 +01:00
2010-02-09 00:08:21 +01:00
if len ( args ) < 2 and ( is_package_dir ( ' . ' ) or is_project_dir ( ' . ' ) ) :
2009-12-04 16:20:17 +01:00
self . print_repos ( )
2012-04-04 14:34:47 +02:00
if len ( args ) > 4 :
2009-12-04 16:20:17 +01:00
raise oscerr . WrongArgs ( ' Too many arguments. ' )
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2009-12-04 16:20:17 +01:00
if len ( args ) < 3 : # 2
if is_package_dir ( ' . ' ) :
2010-02-27 20:11:15 +01:00
packages = [ store_read_package ( wd ) ]
2009-12-04 16:20:17 +01:00
elif not is_project_dir ( ' . ' ) :
2010-02-27 20:11:15 +01:00
raise oscerr . WrongArgs ( ' Project and package is not specified. ' )
2009-12-04 16:20:17 +01:00
project = store_read_project ( wd )
repository = args [ 0 ]
arch = args [ 1 ]
if len ( args ) == 3 :
project = args [ 0 ]
repository = args [ 1 ]
arch = args [ 2 ]
if len ( args ) == 4 :
project = args [ 0 ]
packages = [ args [ 1 ] ]
repository = args [ 2 ]
arch = args [ 3 ]
if subcmd == ' whatdependson ' :
reverse = 1
xml = get_dependson ( apiurl , project , repository , arch , packages , reverse )
2009-12-26 14:22:34 +01:00
root = ET . fromstring ( xml )
for package in root . findall ( ' package ' ) :
2013-04-09 12:51:28 +02:00
print ( package . get ( ' name ' ) , " : " )
2009-12-04 16:20:17 +01:00
for dep in package . findall ( ' pkgdep ' ) :
2013-04-09 12:51:28 +02:00
print ( " " , dep . text )
2009-12-04 16:20:17 +01:00
2012-12-04 16:44:14 +01:00
@cmdln.option ( ' -d ' , ' --debug ' , action = ' store_true ' ,
2013-05-27 12:41:50 +02:00
help = ' verbose output of build dependencies ' )
2007-05-09 11:36:55 +02:00
@cmdln.option ( ' -x ' , ' --extra-pkgs ' , metavar = ' PAC ' , action = ' append ' ,
help = ' Add this package when computing the buildinfo ' )
2010-07-26 15:41:02 +02:00
@cmdln.option ( ' -p ' , ' --prefer-pkgs ' , metavar = ' DIR ' , action = ' append ' ,
help = ' Prefer packages from this directory when installing the build-root ' )
2007-04-25 01:00:12 +02:00
def do_buildinfo ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Shows the build info
Shows the build " info " which is used in building a package .
This command is mostly used internally by the ' build ' subcommand .
It needs to be called from within a package directory .
The BUILD_DESCR argument is optional . BUILD_DESCR is a local RPM specfile
or Debian " dsc " file . If specified , it is sent to the server , and the
buildinfo will be based on it . If the argument is not supplied , the
buildinfo is derived from the specfile which is currently on the source
repository server .
The returned data is XML and contains a list of the packages used in
building , their source , and the expanded BuildRequires .
2010-09-10 15:17:45 +02:00
The arguments REPOSITORY and ARCH are optional . They can be taken from
the first two columns of the ' osc repos ' output . If not specified ,
REPOSITORY defaults to the ' build_repositoy ' config entry in your ' .oscrc '
and ARCH defaults to your host architecture .
2007-04-25 01:00:12 +02:00
2009-05-18 16:50:43 +02:00
usage :
2010-10-04 15:57:52 +02:00
in a package working copy :
osc buildinfo [ OPTS ] REPOSITORY ARCH BUILD_DESCR
osc buildinfo [ OPTS ] REPOSITORY ( ARCH = hostarch , BUILD_DESCR is detected automatically )
osc buildinfo [ OPTS ] ARCH ( REPOSITORY = build_repository ( config option ) , BUILD_DESCR is detected automatically )
osc buildinfo [ OPTS ] BUILD_DESCR ( REPOSITORY = build_repository ( config option ) , ARCH = hostarch )
osc buildinfo [ OPTS ] ( REPOSITORY = build_repository ( config option ) , ARCH = hostarch , BUILD_DESCR is detected automatically )
Note : if BUILD_DESCR does not exist locally the remote BUILD_DESCR is used
osc buildinfo [ OPTS ] PROJECT PACKAGE REPOSITORY ARCH [ BUILD_DESCR ]
2009-11-06 20:52:28 +01:00
2007-04-25 01:00:12 +02:00
$ { cmd_option_list }
"""
2006-09-25 17:11:03 +02:00
wd = os . curdir
2009-11-06 20:52:28 +01:00
args = slash_split ( args )
2010-02-28 02:30:13 +01:00
2010-10-04 15:57:52 +02:00
project = package = repository = arch = build_descr = None
if len ( args ) < = 3 :
if not is_package_dir ( ' . ' ) :
raise oscerr . WrongArgs ( ' Incorrect number of arguments (Note: \' . \' is no package wc) ' )
project = store_read_project ( ' . ' )
package = store_read_package ( ' . ' )
repository , arch , build_descr = self . parse_repoarchdescr ( args , ignore_descr = True )
2010-09-10 15:17:45 +02:00
elif len ( args ) == 4 or len ( args ) == 5 :
2009-11-06 20:52:28 +01:00
project = args [ 0 ]
package = args [ 1 ]
repository = args [ 2 ]
arch = args [ 3 ]
2010-10-04 15:57:52 +02:00
if len ( args ) == 5 :
build_descr = args [ 4 ]
2010-09-10 15:17:45 +02:00
else :
raise oscerr . WrongArgs ( ' Too many arguments. ' )
apiurl = self . get_api_url ( )
2007-04-25 01:00:12 +02:00
2010-07-26 15:41:02 +02:00
build_descr_data = None
2010-10-04 15:57:52 +02:00
if not build_descr is None :
build_descr_data = open ( build_descr , ' r ' ) . read ( )
2010-07-26 15:41:02 +02:00
if opts . prefer_pkgs and build_descr_data is None :
raise oscerr . WrongArgs ( ' error: a build description is needed if \' --prefer-pkgs \' is used ' )
elif opts . prefer_pkgs :
2013-04-09 11:35:53 +02:00
from . build import get_prefer_pkgs
2016-04-14 16:25:48 +02:00
from . util import cpio
2013-04-09 12:51:28 +02:00
print ( ' Scanning the following dirs for local packages: %s ' % ' , ' . join ( opts . prefer_pkgs ) )
2016-04-14 16:25:48 +02:00
cpiodata = cpio . CpioWrite ( )
prefer_pkgs , cpio = get_prefer_pkgs ( opts . prefer_pkgs , arch ,
os . path . splitext ( build_descr ) [ 1 ] ,
cpiodata )
cpiodata . add ( os . path . basename ( build_descr ) , build_descr_data )
build_descr_data = cpiodata . get ( )
2007-04-25 01:00:12 +02:00
2013-04-09 12:51:28 +02:00
print ( ' ' . join ( get_buildinfo ( apiurl ,
2009-09-08 10:14:27 +02:00
project , package , repository , arch ,
2010-07-26 15:41:02 +02:00
specfile = build_descr_data ,
2012-12-04 16:44:14 +01:00
debug = opts . debug ,
2013-04-09 12:51:28 +02:00
addlist = opts . extra_pkgs ) ) )
2007-04-25 01:00:12 +02:00
2006-09-25 17:11:03 +02:00
2009-11-06 20:52:28 +01:00
def do_buildconfig ( self , subcmd , opts , * args ) :
2007-04-25 01:00:12 +02:00
""" $ {cmd_name} : Shows the build config
Shows the build configuration which is used in building a package .
This command is mostly used internally by the ' build ' command .
The returned data is the project - wide build configuration in a format
which is directly readable by the build script . It contains RPM macros
and BuildRequires expansions , for example .
2014-08-12 15:01:16 +02:00
The argument REPOSITORY an be taken from the first column of the
2010-07-27 13:58:52 +02:00
' osc repos ' output .
2007-04-25 01:00:12 +02:00
2009-11-06 20:52:28 +01:00
usage :
2010-07-27 13:58:52 +02:00
osc buildconfig REPOSITORY ( in pkg or prj dir )
osc buildconfig PROJECT REPOSITORY
2007-04-25 01:00:12 +02:00
$ { cmd_option_list }
"""
wd = os . curdir
2009-11-06 20:52:28 +01:00
args = slash_split ( args )
2010-02-28 02:30:13 +01:00
2010-07-27 13:58:52 +02:00
if len ( args ) < 1 and ( is_package_dir ( ' . ' ) or is_project_dir ( ' . ' ) ) :
2010-07-30 16:17:41 +02:00
self . print_repos ( True )
2009-11-06 20:52:28 +01:00
2010-07-27 13:58:52 +02:00
if len ( args ) > 2 :
2009-11-06 20:52:28 +01:00
raise oscerr . WrongArgs ( ' Too many arguments. ' )
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2010-07-27 13:58:52 +02:00
if len ( args ) == 1 :
2010-07-30 16:17:41 +02:00
#FIXME: check if args[0] is really a repo and not a project, need a is_project() function for this
2009-11-06 20:52:28 +01:00
project = store_read_project ( wd )
repository = args [ 0 ]
2010-07-27 13:58:52 +02:00
elif len ( args ) == 2 :
2009-11-06 20:52:28 +01:00
project = args [ 0 ]
2010-07-27 13:58:52 +02:00
repository = args [ 1 ]
2009-11-06 20:52:28 +01:00
else :
raise oscerr . WrongArgs ( ' Wrong number of arguments. ' )
2006-09-25 17:11:03 +02:00
2013-04-09 12:51:28 +02:00
print ( ' ' . join ( get_buildconfig ( apiurl , project , repository ) ) )
2006-09-25 17:11:03 +02:00
2006-05-23 15:48:58 +02:00
2016-12-29 12:46:07 +01:00
def do_workerinfo ( self , subcmd , opts , worker ) :
""" $ {cmd_name} : gets the information to a worker from the server
Examples :
osc workerinfo < workername >
$ { cmd_usage }
$ { cmd_option_list }
"""
apiurl = self . get_api_url ( )
print ( ' ' . join ( get_worker_info ( apiurl , worker ) ) )
@cmdln.option ( ' ' , ' --ignore-file ' , action = ' store_true ' ,
help = ' ignore _constraints file and only check project constraints ' )
def do_checkconstraints ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : check the constraints and view compliant workers
Checks the constraints for compliant workers .
usage :
in a package working copy :
osc checkconstraints [ OPTS ] REPOSITORY ARCH CONSTRAINTSFILE
osc checkconstraints [ OPTS ] CONSTRAINTSFILE
osc checkconstraints [ OPTS ]
$ { cmd_option_list }
"""
repository = arch = constraintsfile = None
project = store_read_project ( ' . ' )
package = store_read_package ( ' . ' )
if len ( args ) == 1 :
constraintsfile = args [ 0 ]
elif len ( args ) == 2 or len ( args ) == 3 :
repository = args [ 0 ]
arch = args [ 1 ]
if len ( args ) == 3 :
constraintsfile = args [ 2 ]
constraintsfile_data = None
if constraintsfile is not None :
constraintsfile_data = open ( constraintsfile , ' r ' ) . read ( )
elif not opts . ignore_file :
if os . path . isfile ( " _constraints " ) :
constraintsfile_data = open ( " _constraints " , ' r ' ) . read ( )
else :
print ( " No local _constraints file. Using just the project constraints " )
apiurl = self . get_api_url ( )
r = [ ]
if not arch and not repository :
result_line_templ = ' %(name)-25s %(arch)-25s %(comp_workers)s '
for repo in get_repos_of_project ( apiurl , project ) :
rmap = { }
rmap [ ' name ' ] = repo . name
rmap [ ' arch ' ] = repo . arch
workers = check_constraints ( apiurl , project , repo . name , repo . arch , package , constraintsfile_data )
rmap [ ' comp_workers ' ] = len ( workers )
r . append ( result_line_templ % rmap )
r . insert ( 0 , ' Repository Arch Worker ' )
r . insert ( 1 , ' ---------- ---- ------ ' )
else :
r = check_constraints ( apiurl , project , repository , arch , package , constraintsfile_data )
r . insert ( 0 , ' Worker ' )
r . insert ( 1 , ' ------ ' )
print ( ' \n ' . join ( r ) )
2010-07-29 16:59:54 +02:00
@cmdln.alias ( ' repos ' )
@cmdln.alias ( ' platforms ' )
def do_repositories ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : shows repositories configured for a project.
It skips repositories by default which are disabled for a given package .
2006-06-22 13:26:01 +02:00
2009-11-30 10:57:39 +01:00
usage :
osc repos
2010-07-12 14:56:08 +02:00
osc repos [ PROJECT ] [ PACKAGE ]
2006-09-25 17:11:03 +02:00
2007-04-25 01:00:12 +02:00
$ { cmd_option_list }
"""
2006-09-15 13:47:34 +02:00
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2010-07-29 16:59:54 +02:00
project = None
2010-07-12 14:56:08 +02:00
package = None
disabled = None
2006-09-15 13:47:34 +02:00
2009-11-30 10:57:39 +01:00
if len ( args ) == 1 :
project = args [ 0 ]
2010-07-29 16:59:54 +02:00
elif len ( args ) == 2 :
2010-07-12 14:56:08 +02:00
project = args [ 0 ]
package = args [ 1 ]
2009-11-30 10:57:39 +01:00
elif len ( args ) == 0 :
2010-07-12 14:56:08 +02:00
if is_package_dir ( ' . ' ) :
package = store_read_package ( ' . ' )
project = store_read_project ( ' . ' )
elif is_project_dir ( ' . ' ) :
project = store_read_project ( ' . ' )
2009-11-30 10:57:39 +01:00
else :
raise oscerr . WrongArgs ( ' Wrong number of arguments ' )
2006-07-05 12:25:31 +02:00
2010-07-29 16:59:54 +02:00
if project is None :
raise oscerr . WrongArgs ( ' No project specified ' )
2010-07-12 14:56:08 +02:00
if package is not None :
disabled = show_package_disabled_repos ( apiurl , project , package )
2010-07-30 16:17:41 +02:00
if subcmd == ' repos_only ' :
2014-08-12 15:01:16 +02:00
for repo in get_repositories_of_project ( apiurl , project ) :
2010-07-30 16:17:41 +02:00
if ( disabled is None ) or ( ( disabled is not None ) and ( repo not in disabled ) ) :
2013-04-09 12:51:28 +02:00
print ( repo )
2010-07-30 16:17:41 +02:00
else :
data = [ ]
for repo in get_repos_of_project ( apiurl , project ) :
if ( disabled is None ) or ( ( disabled is not None ) and ( repo . name not in disabled ) ) :
data + = [ repo . name , repo . arch ]
2016-05-15 17:50:31 +02:00
2010-07-30 16:17:41 +02:00
for row in build_table ( 2 , data , width = 2 ) :
2013-04-09 12:51:28 +02:00
print ( row )
2006-07-05 12:25:31 +02:00
2010-01-30 16:18:30 +01:00
2013-02-03 19:07:17 +01:00
def parse_repoarchdescr ( self , args , noinit = False , alternative_project = None , ignore_descr = False , vm_type = None ) :
2010-01-30 16:18:30 +01:00
""" helper to parse the repo, arch and build description from args """
import osc . build
2010-04-27 18:18:34 +02:00
import glob
2017-01-23 15:32:58 +01:00
import tempfile
2010-01-30 16:18:30 +01:00
arg_arch = arg_repository = arg_descr = None
if len ( args ) < 3 :
2013-04-16 15:42:37 +02:00
# some magic, works only sometimes, but people seem to like it :/
all_archs = [ ]
for mainarch in osc . build . can_also_build :
2013-05-27 12:16:44 +02:00
all_archs . append ( mainarch )
for subarch in osc . build . can_also_build . get ( mainarch ) :
all_archs . append ( subarch )
2010-01-30 16:18:30 +01:00
for arg in args :
2015-09-10 11:27:13 +02:00
if arg . endswith ( ' .spec ' ) or arg . endswith ( ' .dsc ' ) or arg . endswith ( ' .kiwi ' ) or arg . endswith ( ' .livebuild ' ) or arg == ' PKGBUILD ' or arg == ' build.collax ' :
2010-01-30 16:18:30 +01:00
arg_descr = arg
else :
2013-04-16 15:42:37 +02:00
if ( arg == osc . build . hostarch or arg in all_archs ) and arg_arch is None :
# it seems to be an architecture in general
2010-01-30 16:18:30 +01:00
arg_arch = arg
2013-04-16 15:42:37 +02:00
if not ( arg in osc . build . can_also_build . get ( osc . build . hostarch ) or arg == osc . build . hostarch ) :
2013-05-27 12:16:44 +02:00
print ( " WARNING: native compile is not possible, an emulator must be configured! " )
2010-01-30 16:18:30 +01:00
elif not arg_repository :
arg_repository = arg
else :
2014-07-02 23:56:34 +02:00
# raise oscerr.WrongArgs('\'%s\' is neither a build description nor a supported arch' % arg)
# take it as arch (even though this is no supported arch) - hopefully, this invalid
# arch will be detected below
arg_arch = arg
2010-01-30 16:18:30 +01:00
else :
arg_repository , arg_arch , arg_descr = args
arg_arch = arg_arch or osc . build . hostarch
2010-04-29 14:25:38 +02:00
repositories = [ ]
# store list of repos for potential offline use
2011-01-06 14:10:59 +01:00
repolistfile = os . path . join ( os . getcwd ( ) , osc . core . store , " _build_repositories " )
2010-04-29 14:25:38 +02:00
if noinit :
2014-07-02 22:07:01 +02:00
repositories = Repo . fromfile ( repolistfile )
2010-04-29 14:25:38 +02:00
else :
2010-01-30 16:18:30 +01:00
project = alternative_project or store_read_project ( ' . ' )
2010-06-30 13:37:26 +02:00
apiurl = self . get_api_url ( )
2014-07-02 22:07:01 +02:00
repositories = list ( get_repos_of_project ( apiurl , project ) )
2010-01-30 16:18:30 +01:00
if not len ( repositories ) :
raise oscerr . WrongArgs ( ' no repositories defined for project \' %s \' ' % project )
2014-07-02 22:07:01 +02:00
if alternative_project is None :
# only persist our own repos
Repo . tofile ( repolistfile , repositories )
2010-04-29 14:25:38 +02:00
2017-01-23 15:32:58 +01:00
no_repo = False
2014-07-21 14:32:54 +02:00
repo_names = sorted ( set ( [ r . name for r in repositories ] ) )
2014-07-02 22:07:01 +02:00
if not arg_repository and repositories :
2014-11-17 10:12:35 +01:00
# XXX: we should avoid hardcoding repository names
2010-04-29 14:25:38 +02:00
# Use a default value from config, but just even if it's available
2014-11-17 10:12:35 +01:00
# unless try standard, or openSUSE_Factory, or openSUSE_Tumbleweed
2017-01-23 15:32:58 +01:00
no_repo = True
2014-07-02 22:07:01 +02:00
arg_repository = repositories [ - 1 ] . name
2014-11-17 10:12:35 +01:00
for repository in ( conf . config [ ' build_repository ' ] , ' standard ' , ' openSUSE_Factory ' , ' openSUSE_Tumbleweed ' ) :
2014-07-02 22:07:01 +02:00
if repository in repo_names :
2010-04-29 14:25:38 +02:00
arg_repository = repository
2017-01-23 15:32:58 +01:00
no_repo = False
2010-04-29 14:25:38 +02:00
break
if not arg_repository :
2010-01-30 16:18:30 +01:00
raise oscerr . WrongArgs ( ' please specify a repository ' )
2014-07-02 22:07:01 +02:00
if not noinit :
if not arg_repository in repo_names :
raise oscerr . WrongArgs ( ' %s is not a valid repository, use one of: %s ' % ( arg_repository , ' , ' . join ( repo_names ) ) )
arches = [ r . arch for r in repositories if r . name == arg_repository and r . arch ]
if arches and not arg_arch in arches :
raise oscerr . WrongArgs ( ' %s is not a valid arch for the repository %s , use one of: %s ' % ( arg_arch , arg_repository , ' , ' . join ( arches ) ) )
2010-01-30 16:18:30 +01:00
2010-04-27 18:18:34 +02:00
# can be implemented using
2010-04-30 15:19:35 +02:00
# reduce(lambda x, y: x + y, (glob.glob(x) for x in ('*.spec', '*.dsc', '*.kiwi')))
2010-04-27 18:18:34 +02:00
# but be a bit more readable :)
2015-09-10 11:27:13 +02:00
descr = glob . glob ( ' *.spec ' ) + glob . glob ( ' *.dsc ' ) + glob . glob ( ' *.kiwi ' ) + glob . glob ( ' *.livebuild ' ) + glob . glob ( ' PKGBUILD ' ) + glob . glob ( ' build.collax ' )
2016-05-15 17:50:31 +02:00
2010-01-30 16:18:30 +01:00
# FIXME:
# * request repos from server and select by build type.
if not arg_descr and len ( descr ) == 1 :
arg_descr = descr [ 0 ]
2010-04-30 15:25:24 +02:00
elif not arg_descr :
2010-05-12 11:41:43 +02:00
msg = None
2010-04-27 18:23:03 +02:00
if len ( descr ) > 1 :
2017-01-23 15:32:58 +01:00
if no_repo :
raise oscerr . WrongArgs ( " Repository is missing. Cannot guess build description without repository " )
apiurl = self . get_api_url ( )
project = store_read_project ( ' . ' )
bc = get_buildconfig ( apiurl , project , arg_repository )
with tempfile . NamedTemporaryFile ( ) as f :
f . write ( bc )
f . flush ( )
recipe = return_external ( ' /usr/lib/build/queryconfig ' , ' --dist ' , f . name , ' type ' )
recipe = recipe . strip ( )
if recipe == ' arch ' :
recipe = ' PKGBUILD '
2011-01-30 16:38:11 +01:00
pac = os . path . basename ( os . getcwd ( ) )
if is_package_dir ( os . getcwd ( ) ) :
pac = store_read_package ( os . getcwd ( ) )
2017-01-23 15:32:58 +01:00
if recipe == ' PKGBUILD ' :
cands = [ d for d in descr if d . startswith ( recipe ) ]
else :
cands = [ d for d in descr if d . endswith ( ' . ' + recipe ) ]
if len ( cands ) > 1 :
repo_cands = [ d for d in cands if d == ' %s - %s . %s ' % ( pac , arg_repository , recipe ) ]
if repo_cands :
cands = repo_cands
else :
pac_cands = [ d for d in cands if d == ' %s . %s ' % ( pac , recipe ) ]
if pac_cands :
cands = pac_cands
2011-01-30 16:38:11 +01:00
if len ( cands ) == 1 :
arg_descr = cands [ 0 ]
2010-08-08 23:15:25 +02:00
if not arg_descr :
2017-01-23 15:32:58 +01:00
msg = ' Multiple build description files found: %s ' % ' , ' . join ( cands )
2010-10-04 15:57:52 +02:00
elif not ignore_descr :
2014-07-08 21:18:01 +02:00
msg = ' Missing argument: build description (spec, dsc, kiwi or livebuild file) '
2010-04-27 18:23:03 +02:00
try :
p = Package ( ' . ' )
if p . islink ( ) and not p . isexpanded ( ) :
msg + = ' (this package is not expanded - you might want to try osc up --expand) '
except :
pass
2010-05-12 11:41:43 +02:00
if msg :
raise oscerr . WrongArgs ( msg )
2010-04-27 18:23:03 +02:00
2010-01-30 16:18:30 +01:00
return arg_repository , arg_arch , arg_descr
2007-04-25 01:00:12 +02:00
@cmdln.option ( ' --clean ' , action = ' store_true ' ,
help = ' Delete old build root before initializing it ' )
2010-04-17 10:53:53 +02:00
@cmdln.option ( ' -o ' , ' --offline ' , action = ' store_true ' ,
help = ' Start with cached prjconf and packages without contacting the api server ' )
@cmdln.option ( ' -l ' , ' --preload ' , action = ' store_true ' ,
2012-02-02 11:49:17 +01:00
help = ' Preload all files into the cache for offline operation ' )
2007-09-03 12:25:18 +02:00
@cmdln.option ( ' --no-changelog ' , action = ' store_true ' ,
help = ' don \' t update the package changelog from a changes file ' )
2009-10-20 16:30:15 +02:00
@cmdln.option ( ' --rsync-src ' , metavar = ' RSYNCSRCPATH ' , dest = ' rsyncsrc ' ,
2009-08-18 23:28:33 +02:00
help = ' Copy folder to buildroot after installing all RPMs. Use together with --rsync-dest. This is the path on the HOST filesystem e.g. /tmp/linux-kernel-tree. It defines RSYNCDONE 1 . ' )
2009-10-20 16:30:15 +02:00
@cmdln.option ( ' --rsync-dest ' , metavar = ' RSYNCDESTPATH ' , dest = ' rsyncdest ' ,
2009-08-18 23:28:33 +02:00
help = ' Copy folder to buildroot after installing all RPMs. Use together with --rsync-src. This is the path on the TARGET filesystem e.g. /usr/src/packages/BUILD/linux-2.6 . ' )
@cmdln.option ( ' --overlay ' , metavar = ' OVERLAY ' ,
help = ' Copy overlay filesystem to buildroot after installing all RPMs . ' )
2007-04-25 01:00:12 +02:00
@cmdln.option ( ' --noinit ' , ' --no-init ' , action = ' store_true ' ,
help = ' Skip initialization of build root and start with build immediately. ' )
2008-07-23 22:05:09 +02:00
@cmdln.option ( ' --nochecks ' , ' --no-checks ' , action = ' store_true ' ,
2014-03-03 11:59:45 +01:00
help = ' Do not run build checks on the resulting packages. ' )
2014-02-12 12:26:59 +01:00
@cmdln.option ( ' --no-verify ' , ' --noverify ' , action = ' store_true ' ,
2016-07-05 17:11:48 +02:00
help = ' Skip signature verification (via pgp keys) of packages used for build. (Global config in .oscrc: no_verify) ' )
2010-02-05 10:32:27 +01:00
@cmdln.option ( ' --noservice ' , ' --no-service ' , action = ' store_true ' ,
help = ' Skip run of local source services as specified in _service file. ' )
2007-05-03 17:54:40 +02:00
@cmdln.option ( ' -p ' , ' --prefer-pkgs ' , metavar = ' DIR ' , action = ' append ' ,
2007-05-02 15:49:57 +02:00
help = ' Prefer packages from this directory when installing the build-root ' )
2009-05-18 16:50:43 +02:00
@cmdln.option ( ' -k ' , ' --keep-pkgs ' , metavar = ' DIR ' ,
2007-05-03 17:54:40 +02:00
help = ' Save built packages into this directory ' )
2007-05-09 11:36:55 +02:00
@cmdln.option ( ' -x ' , ' --extra-pkgs ' , metavar = ' PAC ' , action = ' append ' ,
help = ' Add this package when installing the build-root ' )
2009-11-23 14:53:59 +01:00
@cmdln.option ( ' --root ' , metavar = ' ROOT ' ,
help = ' Build in specified directory ' )
2008-04-24 11:00:23 +02:00
@cmdln.option ( ' -j ' , ' --jobs ' , metavar = ' N ' ,
help = ' Compile with N jobs ' )
2015-03-10 11:58:08 +01:00
@cmdln.option ( ' -t ' , ' --threads ' , metavar = ' N ' ,
help = ' Compile with N threads ' )
2008-12-11 12:36:07 +01:00
@cmdln.option ( ' --icecream ' , metavar = ' N ' ,
help = ' use N parallel build jobs with icecream ' )
@cmdln.option ( ' --ccache ' , action = ' store_true ' ,
help = ' use ccache to speed up rebuilds ' )
2009-11-24 10:49:26 +01:00
@cmdln.option ( ' --with ' , metavar = ' X ' , dest = ' _with ' , action = ' append ' ,
2008-12-11 12:36:07 +01:00
help = ' enable feature X for build ' )
2009-11-24 10:49:26 +01:00
@cmdln.option ( ' --without ' , metavar = ' X ' , action = ' append ' ,
2008-12-11 12:36:07 +01:00
help = ' disable feature X for build ' )
2010-12-07 16:07:20 +01:00
@cmdln.option ( ' --define ' , metavar = ' \' X Y \' ' , action = ' append ' ,
help = ' define macro X with value Y ' )
2007-05-14 10:29:50 +02:00
@cmdln.option ( ' --userootforbuild ' , action = ' store_true ' ,
help = ' Run build as root. The default is to build as '
' unprivileged user. Note that a line " # norootforbuild " '
' in the spec file will invalidate this option. ' )
2010-02-12 22:54:39 +01:00
@cmdln.option ( ' --build-uid ' , metavar = ' uid:gid| " caller " ' ,
help = ' specify the numeric uid:gid pair to assign to the '
' unprivileged " abuild " user or use " caller " to use the current user uid:gid ' )
2009-03-31 13:45:30 +02:00
@cmdln.option ( ' --local-package ' , action = ' store_true ' ,
2008-01-07 15:54:31 +01:00
help = ' build a package which does not exist on the server ' )
2009-12-09 06:53:27 +01:00
@cmdln.option ( ' --linksources ' , action = ' store_true ' ,
help = ' use hard links instead of a deep copied source ' )
2016-11-29 09:07:10 +01:00
@cmdln.option ( ' --vm-memory ' , metavar = ' TYPE ' ,
help = ' use given MB for VM ' )
2010-04-29 14:27:29 +02:00
@cmdln.option ( ' --vm-type ' , metavar = ' TYPE ' ,
help = ' use VM type TYPE (e.g. kvm) ' )
2015-11-25 14:20:55 +01:00
@cmdln.option ( ' --vm-telnet ' , metavar = ' TELNET ' ,
help = ' Launch a telnet server inside of VM build ' )
2013-02-06 17:12:52 +01:00
@cmdln.option ( ' --target ' , metavar = ' TARGET ' ,
2013-05-07 09:29:59 +02:00
help = ' define target platform ' )
2009-03-31 13:45:30 +02:00
@cmdln.option ( ' --alternative-project ' , metavar = ' PROJECT ' ,
2008-01-07 15:54:31 +01:00
help = ' specify the build target project ' )
2008-03-11 16:18:02 +01:00
@cmdln.option ( ' -d ' , ' --debuginfo ' , action = ' store_true ' ,
help = ' also build debuginfo sub-packages ' )
2009-03-31 13:45:30 +02:00
@cmdln.option ( ' --disable-debuginfo ' , action = ' store_true ' ,
help = ' disable build of debuginfo packages ' )
2008-05-08 14:21:57 +02:00
@cmdln.option ( ' -b ' , ' --baselibs ' , action = ' store_true ' ,
help = ' Create -32bit/-64bit/-x86 rpms for other architectures ' )
2009-12-01 14:36:11 +01:00
@cmdln.option ( ' --release ' , metavar = ' N ' ,
help = ' set release number of the package to N ' )
2010-09-07 16:08:05 +02:00
@cmdln.option ( ' --disable-cpio-bulk-download ' , action = ' store_true ' ,
2010-09-15 15:28:47 +02:00
help = ' disable downloading packages as cpio archive from api ' )
@cmdln.option ( ' --cpio-bulk-download ' , action = ' store_false ' ,
dest = ' disable_cpio_bulk_download ' , help = SUPPRESS_HELP )
2010-01-20 09:15:17 +01:00
@cmdln.option ( ' --download-api-only ' , action = ' store_true ' ,
2014-05-15 17:46:10 +02:00
help = ' only fetch packages from the api ' )
2010-06-24 10:51:38 +02:00
@cmdln.option ( ' --oldpackages ' , metavar = ' DIR ' ,
help = ' take previous build from DIR (special values: _self, _link) ' )
2010-06-24 10:51:55 +02:00
@cmdln.option ( ' --shell ' , action = ' store_true ' ,
help = SUPPRESS_HELP )
2013-02-11 14:27:18 +01:00
@cmdln.option ( ' --host ' , metavar = ' HOST ' ,
help = ' perform the build on a remote server - user@server:~/remote/directory ' )
2015-05-05 23:39:58 +02:00
@cmdln.option ( ' --trust-all-projects ' , action = ' store_true ' ,
help = ' trust packages from all projects ' )
2016-06-09 16:24:30 +02:00
@cmdln.option ( ' --nopreinstallimage ' , ' --no-preinstallimage ' , action = ' store_true ' ,
help = ' Do not use preinstall images for creating the build root. ' )
2007-04-25 01:00:12 +02:00
def do_build ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Build a package on your local machine
2006-09-15 13:47:34 +02:00
2007-04-25 01:00:12 +02:00
You need to call the command inside a package directory , which should be a
buildsystem checkout . ( Local modifications are fine . )
2006-07-05 12:25:31 +02:00
2009-09-08 10:14:27 +02:00
The arguments REPOSITORY and ARCH can be taken from the first two columns
2007-04-25 01:00:12 +02:00
of the ' osc repos ' output . BUILD_DESCR is either a RPM spec file , or a
Debian dsc file .
2006-07-05 12:25:31 +02:00
2010-02-12 22:54:39 +01:00
The command honours packagecachedir , build - root and build - uid
settings in . oscrc , if present . You may want to set su - wrapper = ' sudo '
in . oscrc , and configure sudo with option NOPASSWD for / usr / bin / build .
2006-07-05 12:25:31 +02:00
2007-05-02 15:49:57 +02:00
If neither - - clean nor - - noinit is given , build will reuse an existing
build - root again , removing unneeded packages and add missing ones . This
is usually the fastest option .
2006-07-05 12:25:31 +02:00
2008-01-07 15:54:31 +01:00
If the package doesn ' t exist on the server please use the --local-package
option .
If the project of the package doesn ' t exist on the server please use the
- - alternative - project < alternative - project > option :
Example :
osc build [ OPTS ] - - alternative - project openSUSE : 10.3 standard i586 BUILD_DESCR
2009-05-18 16:50:43 +02:00
usage :
2009-09-08 10:14:27 +02:00
osc build [ OPTS ] REPOSITORY ARCH BUILD_DESCR
2011-09-30 14:26:58 +02:00
osc build [ OPTS ] REPOSITORY ARCH
2009-09-08 10:14:27 +02:00
osc build [ OPTS ] REPOSITORY ( ARCH = hostarch , BUILD_DESCR is detected automatically )
osc build [ OPTS ] ARCH ( REPOSITORY = build_repository ( config option ) , BUILD_DESCR is detected automatically )
osc build [ OPTS ] BUILD_DESCR ( REPOSITORY = build_repository ( config option ) , ARCH = hostarch )
osc build [ OPTS ] ( REPOSITORY = build_repository ( config option ) , ARCH = hostarch , BUILD_DESCR is detected automatically )
2008-04-09 20:45:59 +02:00
2009-05-18 16:50:43 +02:00
# Note:
# Configuration can be overridden by envvars, e.g.
# OSC_SU_WRAPPER overrides the setting of su-wrapper.
2008-04-09 20:45:59 +02:00
# OSC_BUILD_ROOT overrides the setting of build-root.
# OSC_PACKAGECACHEDIR overrides the setting of packagecachedir.
$ { cmd_option_list }
"""
2006-07-14 19:39:46 +02:00
2007-04-25 01:00:12 +02:00
import osc . build
2006-07-14 19:45:44 +02:00
2014-10-01 14:45:48 +02:00
if which ( conf . config [ ' build-cmd ' ] ) is None :
print ( ' Error: build ( \' %s \' ) command not found ' % conf . config [ ' build-cmd ' ] , file = sys . stderr )
print ( ' Install the build package from http://download.opensuse.org/repositories/openSUSE:/Tools/ ' , file = sys . stderr )
2007-04-25 01:00:12 +02:00
return 1
2006-07-17 15:15:42 +02:00
2009-03-31 13:45:30 +02:00
if opts . debuginfo and opts . disable_debuginfo :
raise oscerr . WrongOptions ( ' osc: --debuginfo and --disable-debuginfo are mutual exclusive ' )
2008-07-30 18:45:00 +02:00
if len ( args ) > 3 :
raise oscerr . WrongArgs ( ' Too many arguments ' )
2009-05-18 16:50:43 +02:00
2013-02-03 19:07:17 +01:00
args = self . parse_repoarchdescr ( args , opts . noinit or opts . offline , opts . alternative_project , False , opts . vm_type )
2009-11-26 10:52:26 +01:00
2009-09-03 16:56:48 +02:00
# check for source services
2011-09-12 16:15:19 +02:00
r = None
try :
2012-02-23 13:21:22 +01:00
if not opts . offline and not opts . noservice :
2013-05-27 12:16:44 +02:00
p = Package ( ' . ' )
r = p . run_source_services ( verbose = True )
2011-09-12 16:15:19 +02:00
except :
2013-04-09 12:51:28 +02:00
print ( " WARNING: package is not existing on server yet " )
2011-09-12 16:15:19 +02:00
opts . local_package = True
2016-05-15 17:50:31 +02:00
2011-09-12 16:15:19 +02:00
if opts . offline or opts . local_package or r == None :
2013-04-09 12:51:28 +02:00
print ( " WARNING: source service from package or project will not be executed. This may not be the same build as on server! " )
2011-09-07 16:53:11 +02:00
elif ( conf . config [ ' local_service_run ' ] and not opts . noservice ) and not opts . noinit :
2011-05-24 10:49:08 +02:00
if r != 0 :
2013-04-09 12:51:28 +02:00
print ( ' Source service run failed! ' , file = sys . stderr )
2011-05-24 10:49:08 +02:00
sys . exit ( 1 )
# that is currently unreadable on cli, we should not have a backtrace on standard errors:
#raise oscerr.ServiceRuntimeError('Service run failed: \'%s\'', r)
2009-09-03 16:56:48 +02:00
2010-08-12 23:13:51 +02:00
if conf . config [ ' no_verify ' ] :
2010-08-12 21:34:08 +02:00
opts . no_verify = True
2010-08-26 18:50:20 +02:00
if opts . keep_pkgs and not os . path . isdir ( opts . keep_pkgs ) :
if os . path . exists ( opts . keep_pkgs ) :
raise oscerr . WrongOptions ( ' Preferred save location \' %s \' is not a directory ' % opts . keep_pkgs )
else :
os . makedirs ( opts . keep_pkgs )
2007-05-03 17:54:40 +02:00
if opts . prefer_pkgs :
for d in opts . prefer_pkgs :
2007-05-02 15:49:57 +02:00
if not os . path . isdir ( d ) :
2010-01-09 14:25:41 +01:00
raise oscerr . WrongOptions ( ' Preferred package location \' %s \' is not a directory ' % d )
2007-05-02 15:49:57 +02:00
2010-04-17 10:53:53 +02:00
if opts . offline and opts . preload :
raise oscerr . WrongOptions ( ' --offline and --preload are mutually exclusive ' )
2016-06-09 16:24:30 +02:00
if opts . preload :
opts . nopreinstallimage = True
2013-04-09 12:51:28 +02:00
print ( ' Building %s for %s / %s ' % ( args [ 2 ] , args [ 0 ] , args [ 1 ] ) )
2013-02-11 14:27:18 +01:00
if not opts . host :
return osc . build . main ( self . get_api_url ( ) , opts , args )
else :
return self . _do_rbuild ( subcmd , opts , * args )
def _do_rbuild ( self , subcmd , opts , * args ) :
# drop the --argument, value tuple from the list
def drop_arg2 ( lst , name ) :
2014-08-12 15:01:16 +02:00
if not name :
2013-05-27 13:38:49 +02:00
return lst
2013-02-11 14:27:18 +01:00
while name in lst :
i = lst . index ( name )
lst . pop ( i + 1 )
lst . pop ( i )
return lst
# change the local directory to more suitable remote one in hostargs
# and perform the rsync to such location as well
def rsync_dirs_2host ( hostargs , short_name , long_name , dirs ) :
drop_arg2 ( hostargs , short_name )
drop_arg2 ( hostargs , long_name )
for pdir in dirs :
# drop the last '/' from pdir name - this is because
# rsync foo remote:/bar create /bar/foo on remote machine
# rsync foo/ remote:/bar copy the content of foo in the /bar
if pdir [ - 1 : ] == os . path . sep :
pdir = pdir [ : - 1 ]
hostprefer = os . path . join (
hostpath ,
basename ,
2014-08-13 11:21:55 +02:00
" %s __ " % ( long_name . replace ( ' - ' , ' _ ' ) ) ,
2013-02-11 14:27:18 +01:00
os . path . basename ( os . path . abspath ( pdir ) ) )
hostargs . append ( long_name )
hostargs . append ( hostprefer )
2014-01-08 15:18:02 +01:00
rsync_prefer_cmd = [ ' rsync ' , ' -az ' , ' --delete ' , ' -e ' , ' ssh ' ,
2013-02-11 14:27:18 +01:00
pdir ,
" %s : %s " % ( hostname , os . path . dirname ( hostprefer ) ) ]
2013-04-09 12:51:28 +02:00
print ( ' Run: %s ' % " " . join ( rsync_prefer_cmd ) )
2013-03-08 00:56:57 +01:00
ret = run_external ( rsync_prefer_cmd [ 0 ] , * rsync_prefer_cmd [ 1 : ] )
2013-02-11 14:27:18 +01:00
if ret != 0 :
return ret
return 0
2016-05-15 17:50:31 +02:00
2013-02-11 14:27:18 +01:00
2013-04-09 11:32:34 +02:00
cwd = os . getcwd ( )
2013-02-11 14:27:18 +01:00
basename = os . path . basename ( cwd )
if not ' : ' in opts . host :
hostname = opts . host
hostpath = " ~/ "
else :
hostname , hostpath = opts . host . split ( ' : ' , 1 )
# arguments for build: use all arguments behind build and drop --host 'HOST'
hostargs = sys . argv [ sys . argv . index ( subcmd ) + 1 : ]
drop_arg2 ( hostargs , ' --host ' )
# global arguments: use first '-' up to subcmd
gi = 0
for i , a in enumerate ( sys . argv ) :
if a == subcmd :
break
if a [ 0 ] == ' - ' :
gi = i
break
if gi :
hostglobalargs = sys . argv [ gi : sys . argv . index ( subcmd ) + 1 ]
else :
hostglobalargs = ( subcmd , )
# keep-pkgs
hostkeep = None
if opts . keep_pkgs :
drop_arg2 ( hostargs , ' -k ' )
drop_arg2 ( hostargs , ' --keep-pkgs ' )
hostkeep = os . path . join (
hostpath ,
basename ,
" __keep_pkgs__ " ,
" " ) # <--- this adds last '/', thus triggers correct rsync behavior
hostargs . append ( ' --keep-pkgs ' )
hostargs . append ( hostkeep )
### run all commands ###
# 1.) rsync sources
2014-01-08 15:18:02 +01:00
rsync_source_cmd = [ ' rsync ' , ' -az ' , ' --delete ' , ' -e ' , ' ssh ' , cwd , " %s : %s " % ( hostname , hostpath ) ]
2013-04-09 12:51:28 +02:00
print ( ' Run: %s ' % " " . join ( rsync_source_cmd ) )
2013-03-08 00:56:57 +01:00
ret = run_external ( rsync_source_cmd [ 0 ] , * rsync_source_cmd [ 1 : ] )
2013-02-11 14:27:18 +01:00
if ret != 0 :
return ret
# 2.) rsync prefer-pkgs dirs, overlay and rsyns-src
if opts . prefer_pkgs :
ret = rsync_dirs_2host ( hostargs , ' -p ' , ' --prefer-pkgs ' , opts . prefer_pkgs )
if ret != 0 :
return ret
for arg , long_name in ( ( opts . rsyncsrc , ' --rsync-src ' ) , ( opts . overlay , ' --overlay ' ) ) :
2014-08-12 15:01:16 +02:00
if not arg :
2013-05-27 13:38:49 +02:00
continue
2013-02-11 14:27:18 +01:00
ret = rsync_dirs_2host ( hostargs , None , long_name , ( arg , ) )
if ret != 0 :
return ret
# 3.) call osc build
osc_cmd = " osc "
for var in ( ' OSC_SU_WRAPPER ' , ' OSC_BUILD_ROOT ' , ' OSC_PACKAGECACHEDIR ' ) :
if os . getenv ( var ) :
osc_cmd = " %s = %s %s " % ( var , os . getenv ( var ) , osc_cmd )
ssh_cmd = \
[ ' ssh ' , ' -t ' , hostname ,
" cd %(remote_dir)s ; %(osc_cmd)s %(global_args)s %(local_args)s " % dict (
remote_dir = os . path . join ( hostpath , basename ) ,
osc_cmd = osc_cmd ,
global_args = " " . join ( hostglobalargs ) ,
local_args = " " . join ( hostargs ) )
]
2013-04-09 12:51:28 +02:00
print ( ' Run: %s ' % " " . join ( ssh_cmd ) )
2013-03-08 00:56:57 +01:00
build_ret = run_external ( ssh_cmd [ 0 ] , * ssh_cmd [ 1 : ] )
2013-02-11 14:27:18 +01:00
if build_ret != 0 :
return build_ret
# 4.) get keep-pkgs back
if opts . keep_pkgs :
ret = rsync_keep_cmd = [ ' rsync ' , ' -az ' , ' -e ' , ' ssh ' , " %s : %s " % ( hostname , hostkeep ) , opts . keep_pkgs ]
2013-04-09 12:51:28 +02:00
print ( ' Run: %s ' % " " . join ( rsync_keep_cmd ) )
2013-03-08 00:56:57 +01:00
ret = run_external ( rsync_keep_cmd [ 0 ] , * rsync_keep_cmd [ 1 : ] )
2013-02-11 14:27:18 +01:00
if ret != 0 :
return ret
return build_ret
2006-07-14 19:39:46 +02:00
2009-05-18 16:50:43 +02:00
2010-01-30 16:18:30 +01:00
@cmdln.option ( ' --local-package ' , action = ' store_true ' ,
help = ' package doesn \' t exist on the server ' )
@cmdln.option ( ' --alternative-project ' , metavar = ' PROJECT ' ,
help = ' specify the used build target project ' )
@cmdln.option ( ' --noinit ' , ' --no-init ' , action = ' store_true ' ,
help = ' do not guess/verify specified repository ' )
2014-11-14 15:54:55 +01:00
@cmdln.option ( ' -r ' , ' --login-as-root ' , action = ' store_true ' ,
2010-01-30 16:18:30 +01:00
help = ' login as root instead of abuild ' )
2014-11-14 15:54:55 +01:00
@cmdln.option ( ' --root ' , metavar = ' ROOT ' ,
help = ' Path to the buildroot ' )
2010-04-17 10:53:53 +02:00
@cmdln.option ( ' -o ' , ' --offline ' , action = ' store_true ' ,
help = ' Use cached data without contacting the api server ' )
2016-09-21 09:21:46 +02:00
@cmdln.option ( ' --wipe ' , action = ' store_true ' ,
help = ' Delete the build root instead of chrooting into it ' )
@cmdln.option ( ' -f ' , ' --force ' , action = ' store_true ' ,
help = ' Do not ask confirmation for wipe ' )
2010-01-30 16:18:30 +01:00
def do_chroot ( self , subcmd , opts , * args ) :
2015-06-09 17:26:33 +02:00
""" $ {cmd_name} : opens a shell inside of the build root
2010-01-30 16:18:30 +01:00
2015-06-09 17:26:33 +02:00
chroot into the build root for the given repository , arch and build description
( NOTE : this command does not work if a VM is used )
2010-01-30 16:18:30 +01:00
usage :
osc chroot [ OPTS ] REPOSITORY ARCH BUILD_DESCR
osc chroot [ OPTS ] REPOSITORY ( ARCH = hostarch , BUILD_DESCR is detected automatically )
osc chroot [ OPTS ] ARCH ( REPOSITORY = build_repository ( config option ) , BUILD_DESCR is detected automatically )
osc chroot [ OPTS ] BUILD_DESCR ( REPOSITORY = build_repository ( config option ) , ARCH = hostarch )
osc chroot [ OPTS ] ( REPOSITORY = build_repository ( config option ) , ARCH = hostarch , BUILD_DESCR is detected automatically )
$ { cmd_option_list }
"""
if len ( args ) > 3 :
raise oscerr . WrongArgs ( ' Too many arguments ' )
2015-06-09 17:26:33 +02:00
if conf . config [ ' build-type ' ] and conf . config [ ' build-type ' ] != " lxc " :
2013-04-09 12:51:28 +02:00
print ( ' Not implemented for VMs ' , file = sys . stderr )
2010-01-30 16:18:30 +01:00
sys . exit ( 1 )
user = ' abuild '
2014-11-14 15:54:55 +01:00
if opts . login_as_root :
2010-04-08 23:15:55 +02:00
user = ' root '
2014-11-14 15:54:55 +01:00
buildroot = opts . root
if buildroot is None :
repository , arch , descr = self . parse_repoarchdescr ( args , opts . noinit or opts . offline , opts . alternative_project )
project = opts . alternative_project or store_read_project ( ' . ' )
if opts . local_package :
2016-11-14 12:16:16 +01:00
package = os . path . splitext ( os . path . basename ( descr ) ) [ 0 ]
2014-11-14 15:54:55 +01:00
else :
package = store_read_package ( ' . ' )
apihost = urlsplit ( self . get_api_url ( ) ) [ 1 ]
if buildroot is None :
buildroot = os . environ . get ( ' OSC_BUILD_ROOT ' , conf . config [ ' build-root ' ] ) \
% { ' repo ' : repository , ' arch ' : arch , ' project ' : project , ' package ' : package , ' apihost ' : apihost }
2010-01-30 16:18:30 +01:00
if not os . path . isdir ( buildroot ) :
raise oscerr . OscIOError ( None , ' \' %s \' is not a directory ' % buildroot )
2010-01-30 21:41:49 +01:00
suwrapper = os . environ . get ( ' OSC_SU_WRAPPER ' , conf . config [ ' su-wrapper ' ] )
2016-09-21 09:21:46 +02:00
# Wipe build root if --wipe was given
if opts . wipe :
sucmd = suwrapper . split ( )
cmd = [ conf . config [ ' build-cmd ' ] , ' --root= ' + buildroot , ' --wipe ' ]
if sucmd [ 0 ] == ' su ' :
if sucmd [ - 1 ] == ' -c ' :
sucmd . pop ( )
cmd = sucmd + [ ' -s ' , cmd [ 0 ] , ' root ' , ' -- ' ] + cmd [ 1 : ]
else :
cmd = sucmd + cmd
if opts . force :
sys . exit ( run_external ( cmd [ 0 ] , * cmd [ 1 : ] ) )
else :
# Confirm delete
2016-10-31 19:32:08 +01:00
print ( " Really wipe ' %s ' ? [y/N]: " % buildroot )
2016-09-21 09:21:46 +02:00
choice = raw_input ( ) . lower ( )
if choice == ' y ' :
sys . exit ( run_external ( cmd [ 0 ] , * cmd [ 1 : ] ) )
else :
2016-10-31 19:32:08 +01:00
print ( ' Aborting ' )
2016-09-21 09:21:46 +02:00
sys . exit ( 0 )
# Normal chroot
2010-01-30 21:41:49 +01:00
sucmd = suwrapper . split ( ) [ 0 ]
suargs = ' ' . join ( suwrapper . split ( ) [ 1 : ] )
if suwrapper . startswith ( ' su ' ) :
cmd = [ sucmd , ' %s chroot " %s " su - %s ' % ( suargs , buildroot , user ) ]
else :
cmd = [ sucmd , ' chroot ' , buildroot , ' su ' , ' - ' , user ]
if suargs :
2013-02-07 15:13:21 +01:00
cmd [ 1 : 1 ] = suargs . split ( )
2013-04-09 12:51:28 +02:00
print ( ' running: %s ' % ' ' . join ( cmd ) )
2010-01-30 21:41:49 +01:00
os . execvp ( sucmd , cmd )
2010-01-30 16:18:30 +01:00
2006-07-14 19:39:46 +02:00
2009-05-13 11:04:27 +02:00
@cmdln.option ( ' ' , ' --csv ' , action = ' store_true ' ,
help = ' generate output in CSV (separated by |) ' )
2015-12-07 10:05:08 +01:00
@cmdln.option ( ' -l ' , ' --limit ' , metavar = ' limit ' ,
help = ' for setting the number of results ' )
2007-04-25 01:00:12 +02:00
@cmdln.alias ( ' buildhist ' )
2009-09-08 10:14:27 +02:00
def do_buildhistory ( self , subcmd , opts , * args ) :
2007-04-25 01:00:12 +02:00
""" $ {cmd_name} : Shows the build history of a package
2006-05-19 22:13:29 +02:00
2009-09-08 10:14:27 +02:00
The arguments REPOSITORY and ARCH can be taken from the first two columns
2007-04-25 01:00:12 +02:00
of the ' osc repos ' output .
2009-09-08 10:14:27 +02:00
usage :
osc buildhist REPOSITORY ARCHITECTURE
osc buildhist PROJECT PACKAGE REPOSITORY ARCHITECTURE
2007-04-25 01:00:12 +02:00
$ { cmd_option_list }
"""
2006-05-23 15:48:58 +02:00
2015-04-11 08:34:59 +02:00
args = slash_split ( args )
2010-02-09 00:08:21 +01:00
if len ( args ) < 2 and is_package_dir ( ' . ' ) :
2009-11-23 11:13:19 +01:00
self . print_repos ( )
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2009-09-08 10:14:27 +02:00
if len ( args ) == 4 :
2009-10-20 16:30:15 +02:00
project = args [ 0 ]
package = args [ 1 ]
repository = args [ 2 ]
arch = args [ 3 ]
2009-09-08 10:14:27 +02:00
elif len ( args ) == 2 :
2009-10-20 16:30:15 +02:00
wd = os . curdir
package = store_read_package ( wd )
project = store_read_project ( wd )
repository = args [ 0 ]
arch = args [ 1 ]
2009-09-08 10:14:27 +02:00
else :
2009-10-20 16:30:15 +02:00
raise oscerr . WrongArgs ( ' Wrong number of arguments ' )
2006-09-29 12:37:53 +02:00
2009-05-13 11:04:27 +02:00
format = ' text '
if opts . csv :
format = ' csv '
2015-12-07 10:05:08 +01:00
print ( ' \n ' . join ( get_buildhistory ( apiurl , project , package , repository , arch , format , opts . limit ) ) )
2006-06-08 12:30:29 +02:00
2009-05-13 11:04:27 +02:00
@cmdln.option ( ' ' , ' --csv ' , action = ' store_true ' ,
help = ' generate output in CSV (separated by |) ' )
2009-11-13 14:31:10 +01:00
@cmdln.option ( ' -l ' , ' --limit ' , metavar = ' limit ' ,
help = ' for setting the number of results ' )
2009-02-20 12:04:45 +01:00
@cmdln.alias ( ' jobhist ' )
2009-11-06 19:47:54 +01:00
def do_jobhistory ( self , subcmd , opts , * args ) :
2009-02-20 12:04:45 +01:00
""" $ {cmd_name} : Shows the job history of a project
2009-09-08 10:14:27 +02:00
The arguments REPOSITORY and ARCH can be taken from the first two columns
2009-02-20 12:04:45 +01:00
of the ' osc repos ' output .
2009-11-06 19:47:54 +01:00
usage :
osc jobhist REPOSITORY ARCHITECTURE ( in project dir )
osc jobhist PROJECT [ PACKAGE ] REPOSITORY ARCHITECTURE
2009-02-20 12:04:45 +01:00
$ { cmd_option_list }
"""
wd = os . curdir
2009-11-06 19:47:54 +01:00
args = slash_split ( args )
2010-02-09 02:27:29 +01:00
if len ( args ) < 2 and ( is_project_dir ( ' . ' ) or is_package_dir ( ' . ' ) ) :
2009-11-23 11:13:19 +01:00
self . print_repos ( )
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2009-11-06 19:47:54 +01:00
if len ( args ) == 4 :
project = args [ 0 ]
package = args [ 1 ]
repository = args [ 2 ]
arch = args [ 3 ]
elif len ( args ) == 3 :
project = args [ 0 ]
package = None # skipped = prj
repository = args [ 1 ]
arch = args [ 2 ]
elif len ( args ) == 2 :
package = None
try :
package = store_read_package ( wd )
except :
pass
project = store_read_project ( wd )
repository = args [ 0 ]
arch = args [ 1 ]
else :
raise oscerr . WrongArgs ( ' Wrong number of arguments ' )
2009-02-20 12:04:45 +01:00
2009-05-13 11:04:27 +02:00
format = ' text '
if opts . csv :
format = ' csv '
2009-11-23 11:13:12 +01:00
print_jobhistory ( apiurl , project , package , repository , arch , format , opts . limit )
2009-02-20 12:04:45 +01:00
2009-05-25 13:33:04 +02:00
@cmdln.hide ( 1 )
def do_rlog ( self , subcmd , opts , * args ) :
2016-05-15 17:50:31 +02:00
""" $ {cmd_name} :
Obsolete command to show commit logs . Use ' log ' now .
See the help output of ' log ' .
"""
print ( " This command is obsolete. Use ' osc log ' . " , file = sys . stderr )
print ( " See ' osc help log ' . " , file = sys . stderr )
return 2
2006-10-10 16:04:34 +02:00
2010-01-14 11:58:34 +01:00
2007-07-12 02:48:52 +02:00
@cmdln.option ( ' -r ' , ' --revision ' , metavar = ' rev ' ,
help = ' show log of the specified revision ' )
2009-05-13 10:53:32 +02:00
@cmdln.option ( ' ' , ' --csv ' , action = ' store_true ' ,
help = ' generate output in CSV (separated by |) ' )
@cmdln.option ( ' ' , ' --xml ' , action = ' store_true ' ,
help = ' generate output in XML ' )
2011-01-19 20:26:38 +01:00
@cmdln.option ( ' -D ' , ' --deleted ' , action = ' store_true ' ,
help = ' work on deleted package ' )
2010-05-25 14:00:50 +02:00
@cmdln.option ( ' -M ' , ' --meta ' , action = ' store_true ' ,
2010-05-25 13:59:46 +02:00
help = ' checkout out meta data instead of sources ' )
2009-05-25 13:33:04 +02:00
def do_log ( self , subcmd , opts , * args ) :
2007-07-12 01:24:26 +02:00
""" $ {cmd_name} : Shows the commit log of a package
2009-05-25 12:41:16 +02:00
Usage :
2009-05-25 13:33:04 +02:00
osc log ( inside working copy )
2010-05-27 07:17:27 +02:00
osc log remote_project [ remote_package ]
2009-05-25 12:41:16 +02:00
2008-09-23 15:39:54 +02:00
$ { cmd_option_list }
"""
2009-05-25 12:41:16 +02:00
args = slash_split ( args )
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2009-05-25 12:41:16 +02:00
if len ( args ) == 0 :
2009-05-25 13:33:04 +02:00
wd = os . curdir
2010-06-07 09:01:32 +02:00
if is_project_dir ( wd ) or is_package_dir ( wd ) :
project = store_read_project ( wd )
if is_project_dir ( wd ) :
package = " _project "
else :
package = store_read_package ( wd )
2010-05-27 07:21:33 +02:00
else :
2010-06-07 09:01:32 +02:00
raise oscerr . NoWorkingCopy ( " Error: \" %s \" is not an osc working copy. " % os . path . abspath ( wd ) )
2010-05-27 07:17:27 +02:00
elif len ( args ) < 1 :
2009-05-25 13:33:04 +02:00
raise oscerr . WrongArgs ( ' Too few arguments (required none or two) ' )
2009-05-25 12:41:16 +02:00
elif len ( args ) > 2 :
2009-05-25 13:33:04 +02:00
raise oscerr . WrongArgs ( ' Too many arguments (required none or two) ' )
2010-05-27 07:17:27 +02:00
elif len ( args ) == 1 :
project = args [ 0 ]
package = " _project "
2009-05-25 13:33:04 +02:00
else :
project = args [ 0 ]
package = args [ 1 ]
2009-05-25 12:41:16 +02:00
2011-11-22 20:12:28 +01:00
rev , rev_upper = parseRevisionOption ( opts . revision )
2010-05-27 02:18:00 +02:00
if rev and not checkRevision ( project , package , rev , apiurl , opts . meta ) :
2013-04-09 12:51:28 +02:00
print ( ' Revision \' %s \' does not exist ' % rev , file = sys . stderr )
2008-09-23 15:39:54 +02:00
sys . exit ( 1 )
2009-05-13 10:53:32 +02:00
format = ' text '
if opts . csv :
format = ' csv '
if opts . xml :
format = ' xml '
2011-11-22 20:12:28 +01:00
log = ' \n ' . join ( get_commitlog ( apiurl , project , package , rev , format , opts . meta , opts . deleted , rev_upper ) )
2010-05-03 10:05:36 +02:00
run_pager ( log )
2008-09-23 15:39:54 +02:00
2010-09-01 12:44:47 +02:00
def do_service ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Handle source services
Source services can be used to modify sources like downloading files ,
verify files , generating files or modify existing files .
usage :
osc service COMMAND ( inside working copy )
2011-02-15 09:41:03 +01:00
osc service run [ SOURCE_SERVICE ]
2015-11-12 09:23:39 +01:00
osc service localrun
2011-02-15 09:41:03 +01:00
osc service disabledrun
osc service remoterun [ PROJECT PACKAGE ]
2016-03-03 11:05:48 +01:00
osc service merge [ PROJECT PACKAGE ]
osc service wait [ PROJECT PACKAGE ]
2010-09-01 12:44:47 +02:00
COMMAND can be :
2014-08-12 15:01:16 +02:00
run r run defined services locally , it takes an optional parameter to run only a
2013-03-02 15:26:03 +01:00
specified source service . In case parameters exist for this one in _service file
2011-02-15 09:41:03 +01:00
they are used .
2016-06-01 17:01:34 +02:00
runall ra run all services independend of the used mode
2011-01-26 16:30:57 +01:00
remoterun rr trigger a re - run on the server side
2016-03-03 11:05:48 +01:00
merge commits all server side generated files and drops the _service definition
wait waits until the service finishes and returns with an error if it failed
2010-09-01 12:44:47 +02:00
$ { cmd_option_list }
"""
2016-06-01 17:01:34 +02:00
# disabledrun and localrun exists as well, but are considered to be obsolete
2010-09-01 12:44:47 +02:00
args = slash_split ( args )
2011-02-17 14:22:16 +01:00
project = package = singleservice = mode = None
2010-09-01 12:44:47 +02:00
apiurl = self . get_api_url ( )
2011-03-22 10:21:25 +01:00
if len ( args ) < 1 :
raise oscerr . WrongArgs ( ' No command given. ' )
elif len ( args ) < 3 :
2010-09-01 12:44:47 +02:00
if is_package_dir ( os . curdir ) :
project = store_read_project ( os . curdir )
package = store_read_package ( os . curdir )
else :
raise oscerr . WrongArgs ( ' Too few arguments. ' )
2011-02-15 09:41:03 +01:00
if len ( args ) == 2 :
singleservice = args [ 1 ]
2016-03-03 11:05:48 +01:00
elif len ( args ) == 3 and args [ 0 ] in ( ' remoterun ' , ' rr ' , ' merge ' , ' wait ' ) :
2010-09-01 12:44:47 +02:00
project = args [ 1 ]
package = args [ 2 ]
else :
2011-02-17 01:57:53 +01:00
raise oscerr . WrongArgs ( ' Too many arguments. ' )
2010-09-01 12:44:47 +02:00
command = args [ 0 ]
2016-06-01 17:01:34 +02:00
if not ( command in ( ' runall ' , ' ra ' , ' run ' , ' localrun ' , ' disabledrun ' , ' remoterun ' , ' lr ' , ' dr ' , ' r ' , ' rr ' , ' merge ' , ' wait ' ) ) :
2011-03-22 10:21:25 +01:00
raise oscerr . WrongArgs ( ' Wrong command given. ' )
2011-01-26 17:22:03 +01:00
if command == " remoterun " or command == " rr " :
2013-04-09 12:51:28 +02:00
print ( runservice ( apiurl , project , package ) )
2011-02-15 09:41:03 +01:00
return
2010-09-01 12:44:47 +02:00
2016-03-03 11:05:48 +01:00
if command == " wait " :
print ( waitservice ( apiurl , project , package ) )
return
if command == " merge " :
print ( mergeservice ( apiurl , project , package ) )
return
2016-06-01 17:01:34 +02:00
if command in ( ' runall ' , ' ra ' , ' run ' , ' localrun ' , ' disabledrun ' , ' lr ' , ' dr ' , ' r ' ) :
2010-09-01 12:44:47 +02:00
if not is_package_dir ( os . curdir ) :
raise oscerr . WrongArgs ( ' Local directory is no package ' )
p = Package ( " . " )
2011-01-26 16:30:57 +01:00
if command == " localrun " or command == " lr " :
2011-02-15 09:41:03 +01:00
mode = " local "
2011-01-26 16:30:57 +01:00
elif command == " disabledrun " or command == " dr " :
2011-02-15 09:41:03 +01:00
mode = " disabled "
2016-06-01 17:01:34 +02:00
elif command == " runall " or command == " ra " :
mode = " all "
2011-02-15 09:41:03 +01:00
2014-09-30 13:51:13 +02:00
return p . run_source_services ( mode , singleservice )
2010-09-01 12:44:47 +02:00
2010-11-08 16:20:01 +01:00
@cmdln.option ( ' -a ' , ' --arch ' , metavar = ' ARCH ' ,
help = ' trigger rebuilds for a specific architecture ' )
@cmdln.option ( ' -r ' , ' --repo ' , metavar = ' REPO ' ,
help = ' trigger rebuilds for a specific repository ' )
2007-04-25 01:00:12 +02:00
@cmdln.option ( ' -f ' , ' --failed ' , action = ' store_true ' ,
help = ' rebuild all failed packages ' )
2011-02-22 22:44:04 +01:00
@cmdln.option ( ' --all ' , action = ' store_true ' ,
help = ' Rebuild all packages of entire project ' )
2009-06-15 17:38:39 +02:00
@cmdln.alias ( ' rebuildpac ' )
def do_rebuild ( self , subcmd , opts , * args ) :
2010-04-23 12:01:24 +02:00
""" $ {cmd_name} : Trigger package rebuilds
2006-06-08 12:30:29 +02:00
2007-04-25 01:00:12 +02:00
Note that it is normally NOT needed to kick off rebuilds like this , because
they principally happen in a fully automatic way , triggered by source
check - ins . In particular , the order in which packages are built is handled
by the build service .
2006-09-25 17:11:03 +02:00
2009-09-08 10:14:27 +02:00
The arguments REPOSITORY and ARCH can be taken from the first two columns
2009-06-23 12:06:31 +02:00
of the ' osc repos ' output .
2006-06-08 12:30:29 +02:00
2009-05-18 16:50:43 +02:00
usage :
2011-04-20 14:05:00 +02:00
osc rebuild [ PROJECT [ PACKAGE [ REPOSITORY [ ARCH ] ] ] ]
2007-04-25 01:00:12 +02:00
$ { cmd_option_list }
"""
2006-06-08 12:30:29 +02:00
2007-06-26 15:17:38 +02:00
args = slash_split ( args )
2010-04-23 12:01:24 +02:00
package = repo = arch = code = None
2010-07-29 17:29:07 +02:00
apiurl = self . get_api_url ( )
2010-04-23 12:01:24 +02:00
2010-11-08 16:20:01 +01:00
if opts . repo :
repo = opts . repo
if opts . arch :
arch = opts . arch
2007-04-25 01:00:12 +02:00
if len ( args ) < 1 :
2010-05-25 17:50:36 +02:00
if is_package_dir ( os . curdir ) :
2010-04-23 12:01:24 +02:00
project = store_read_project ( os . curdir )
package = store_read_package ( os . curdir )
2010-05-25 17:50:36 +02:00
apiurl = store_read_apiurl ( os . curdir )
2010-10-08 12:25:32 +02:00
elif is_project_dir ( os . curdir ) :
project = store_read_project ( os . curdir )
apiurl = store_read_apiurl ( os . curdir )
2010-05-05 09:03:51 +02:00
else :
2010-04-23 12:01:24 +02:00
raise oscerr . WrongArgs ( ' Too few arguments. ' )
2010-05-05 09:03:51 +02:00
else :
project = args [ 0 ]
if len ( args ) > 1 :
package = args [ 1 ]
2006-05-23 15:48:58 +02:00
2007-04-25 01:00:12 +02:00
if len ( args ) > 2 :
repo = args [ 2 ]
if len ( args ) > 3 :
arch = args [ 3 ]
2006-05-23 15:48:58 +02:00
2007-04-25 01:00:12 +02:00
if opts . failed :
code = ' failed '
2011-02-22 22:44:04 +01:00
if not ( opts . all or package or repo or arch or code ) :
raise oscerr . WrongOptions ( ' No option has been provided. If you want to rebuild all packages of the entire project, use --all option. ' )
2013-04-09 12:51:28 +02:00
print ( rebuild ( apiurl , project , package , repo , arch , code ) )
2006-05-23 15:48:58 +02:00
2006-04-20 16:26:50 +02:00
2007-05-04 23:51:54 +02:00
def do_info ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Print information about a working copy
Print information about each ARG ( default : ' . ' )
ARG is a working - copy path .
$ { cmd_usage }
$ { cmd_option_list }
"""
args = parseargs ( args )
pacs = findpacs ( args )
for p in pacs :
2013-04-09 12:51:28 +02:00
print ( p . info ( ) )
2007-05-04 23:51:54 +02:00
2006-05-19 22:13:29 +02:00
2007-06-14 16:30:36 +02:00
@cmdln.option ( ' -a ' , ' --arch ' , metavar = ' ARCH ' ,
2013-10-28 18:29:56 +01:00
help = ' Restart builds for a specific architecture ' )
2007-06-14 16:30:36 +02:00
@cmdln.option ( ' -r ' , ' --repo ' , metavar = ' REPO ' ,
2013-10-28 18:29:56 +01:00
help = ' Restart builds for a specific repository ' )
2011-02-22 22:44:04 +01:00
@cmdln.option ( ' --all ' , action = ' store_true ' ,
2013-10-28 18:29:56 +01:00
help = ' Restart all running builds of entire project ' )
@cmdln.alias ( ' abortbuild ' )
def do_restartbuild ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Restart the build of a certain project or package
2009-05-18 16:50:43 +02:00
usage :
2013-10-28 18:29:56 +01:00
osc restartbuild [ PROJECT [ PACKAGE [ REPOSITORY [ ARCH ] ] ] ]
2007-06-14 16:30:36 +02:00
$ { cmd_option_list }
"""
2011-04-20 14:05:00 +02:00
args = slash_split ( args )
package = repo = arch = code = None
2010-07-29 17:29:07 +02:00
apiurl = self . get_api_url ( )
2007-06-14 16:30:36 +02:00
2011-04-20 14:05:00 +02:00
if opts . repo :
repo = opts . repo
2007-06-14 16:30:36 +02:00
2011-04-20 14:05:00 +02:00
if opts . arch :
arch = opts . arch
if len ( args ) < 1 :
if is_package_dir ( os . curdir ) :
project = store_read_project ( os . curdir )
package = store_read_package ( os . curdir )
apiurl = store_read_apiurl ( os . curdir )
elif is_project_dir ( os . curdir ) :
project = store_read_project ( os . curdir )
apiurl = store_read_apiurl ( os . curdir )
else :
raise oscerr . WrongArgs ( ' Too few arguments. ' )
2007-06-14 16:30:36 +02:00
else :
2011-04-20 14:05:00 +02:00
project = args [ 0 ]
if len ( args ) > 1 :
package = args [ 1 ]
if len ( args ) > 2 :
repo = args [ 2 ]
if len ( args ) > 3 :
arch = args [ 3 ]
2007-06-14 16:30:36 +02:00
2011-02-22 22:44:04 +01:00
if not ( opts . all or package or repo or arch ) :
2013-10-28 18:29:56 +01:00
raise oscerr . WrongOptions ( ' No option has been provided. If you want to restart all packages of the entire project, use --all option. ' )
2011-02-22 22:44:04 +01:00
2016-12-17 01:06:18 +01:00
print ( cmdbuild ( apiurl , subcmd , project , package , arch , repo ) )
2007-06-14 16:30:36 +02:00
@cmdln.option ( ' -a ' , ' --arch ' , metavar = ' ARCH ' ,
2007-07-04 16:57:19 +02:00
help = ' Delete all binary packages for a specific architecture ' )
2007-06-14 16:30:36 +02:00
@cmdln.option ( ' -r ' , ' --repo ' , metavar = ' REPO ' ,
help = ' Delete all binary packages for a specific repository ' )
2007-07-04 16:57:19 +02:00
@cmdln.option ( ' --build-disabled ' , action = ' store_true ' ,
help = ' Delete all binaries of packages for which the build is disabled ' )
2007-10-27 21:13:24 +02:00
@cmdln.option ( ' --build-failed ' , action = ' store_true ' ,
help = ' Delete all binaries of packages for which the build failed ' )
@cmdln.option ( ' --broken ' , action = ' store_true ' ,
help = ' Delete all binaries of packages for which the package source is bad ' )
2010-04-23 14:38:00 +02:00
@cmdln.option ( ' --unresolvable ' , action = ' store_true ' ,
help = ' Delete all binaries of packages which have dependency errors ' )
2009-05-31 13:00:03 +02:00
@cmdln.option ( ' --all ' , action = ' store_true ' ,
help = ' Delete all binaries regardless of the package status (previously default) ' )
2017-01-16 11:58:02 +01:00
@cmdln.alias ( " unpublish " )
2007-06-14 16:30:36 +02:00
def do_wipebinaries ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Delete all binary packages of a certain project/package
2007-07-15 15:49:13 +02:00
With the optional argument < package > you can specify a certain package
2007-06-14 16:30:36 +02:00
otherwise all binary packages in the project will be deleted .
2009-05-18 16:50:43 +02:00
usage :
2011-01-21 11:04:47 +01:00
osc wipebinaries OPTS # works in checked out project dir
2009-05-31 13:00:03 +02:00
osc wipebinaries OPTS PROJECT [ PACKAGE ]
2017-01-16 11:58:02 +01:00
osc unpublish OPTS # works in checked out project dir
osc unpublish OPTS PROJECT [ PACKAGE ]
2007-06-14 16:30:36 +02:00
$ { cmd_option_list }
"""
2009-05-18 16:50:43 +02:00
2007-06-26 15:17:38 +02:00
args = slash_split ( args )
2010-06-29 15:32:53 +02:00
package = project = None
apiurl = self . get_api_url ( )
2010-06-27 19:07:46 +02:00
# try to get project and package from checked out dirs
2007-06-14 16:30:36 +02:00
if len ( args ) < 1 :
2010-06-27 19:07:46 +02:00
if is_project_dir ( os . getcwd ( ) ) :
project = store_read_project ( os . curdir )
if is_package_dir ( os . getcwd ( ) ) :
project = store_read_project ( os . curdir )
package = store_read_package ( os . curdir )
if project is None :
raise oscerr . WrongArgs ( ' Missing <project> argument. ' )
2008-06-11 10:01:10 +02:00
if len ( args ) > 2 :
raise oscerr . WrongArgs ( ' Wrong number of arguments. ' )
2010-06-27 19:07:46 +02:00
# respect given project and package
if len ( args ) > = 1 :
2013-05-27 12:16:44 +02:00
project = args [ 0 ]
2010-06-27 19:07:46 +02:00
2007-06-14 16:30:36 +02:00
if len ( args ) == 2 :
2013-05-27 12:16:44 +02:00
package = args [ 1 ]
2007-10-27 21:13:24 +02:00
codes = [ ]
if opts . build_disabled :
codes . append ( ' disabled ' )
if opts . build_failed :
codes . append ( ' failed ' )
if opts . broken :
codes . append ( ' broken ' )
2010-04-23 14:38:00 +02:00
if opts . unresolvable :
codes . append ( ' unresolvable ' )
2009-07-07 16:31:59 +02:00
if opts . all or opts . repo or opts . arch :
2009-05-31 13:00:03 +02:00
codes . append ( None )
2007-10-27 21:13:24 +02:00
if len ( codes ) == 0 :
2010-01-09 14:25:41 +01:00
raise oscerr . WrongOptions ( ' No option has been provided. If you want to delete all binaries, use --all option. ' )
2007-10-27 21:13:24 +02:00
# make a new request for each code= parameter
for code in codes :
2017-01-16 11:58:02 +01:00
if subcmd == ' unpublish ' :
print ( unpublish ( apiurl , project , package , opts . arch , opts . repo , code ) )
else :
print ( wipebinaries ( apiurl , project , package , opts . arch , opts . repo , code ) )
2007-06-14 16:30:36 +02:00
2008-09-30 16:54:08 +02:00
@cmdln.option ( ' -q ' , ' --quiet ' , action = ' store_true ' ,
help = ' do not show downloading progress ' )
2011-01-21 10:35:47 +01:00
@cmdln.option ( ' -d ' , ' --destdir ' , default = ' ./binaries ' , metavar = ' DIR ' ,
2008-09-30 16:54:08 +02:00
help = ' destination directory ' )
2009-01-16 11:31:38 +01:00
@cmdln.option ( ' --sources ' , action = " store_true " ,
help = ' also fetch source packages ' )
2010-09-27 17:43:44 +02:00
@cmdln.option ( ' --debug ' , action = " store_true " ,
help = ' also fetch debug packages ' )
2009-04-21 11:46:32 +02:00
def do_getbinaries ( self , subcmd , opts , * args ) :
2008-09-30 16:54:08 +02:00
""" $ {cmd_name} : Download binaries to a local directory
2009-05-18 16:50:43 +02:00
This command downloads packages directly from the api server .
2009-02-20 16:01:16 +01:00
Thus , it directly accesses the packages that are used for building
others even when they are not " published " yet .
2008-09-30 16:54:08 +02:00
2009-04-21 11:46:32 +02:00
usage :
2010-07-01 15:32:21 +02:00
osc getbinaries REPOSITORY # works in checked out project/package (check out all archs in subdirs)
osc getbinaries REPOSITORY ARCHITECTURE # works in checked out project/package
2016-10-07 14:13:46 +02:00
osc getbinaries PROJECT REPOSITORY ARCHITECTRUE
2009-04-21 11:46:32 +02:00
osc getbinaries PROJECT PACKAGE REPOSITORY ARCHITECTURE
2012-11-19 10:21:24 +01:00
osc getbinaries PROJECT PACKAGE REPOSITORY ARCHITECTURE FILE
2008-09-30 16:54:08 +02:00
$ { cmd_option_list }
"""
2009-04-21 11:46:32 +02:00
args = slash_split ( args )
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2010-07-12 14:56:08 +02:00
project = None
2012-11-19 10:21:24 +01:00
package = None
binary = None
2009-04-21 11:46:32 +02:00
2010-04-21 15:20:40 +02:00
if len ( args ) < 1 and is_package_dir ( ' . ' ) :
2009-11-23 11:13:19 +01:00
self . print_repos ( )
2010-05-22 18:27:11 +02:00
architecture = None
2012-11-19 10:21:24 +01:00
if len ( args ) == 4 or len ( args ) == 5 :
2009-04-21 11:46:32 +02:00
project = args [ 0 ]
package = args [ 1 ]
repository = args [ 2 ]
architecture = args [ 3 ]
2012-11-19 10:21:24 +01:00
if len ( args ) == 5 :
binary = args [ 4 ]
2016-10-07 14:13:46 +02:00
elif len ( args ) == 3 :
project , repository , architecture = args
2011-11-18 21:51:03 +01:00
elif len ( args ) > = 1 and len ( args ) < = 2 :
2010-07-01 15:32:21 +02:00
if is_package_dir ( os . getcwd ( ) ) :
project = store_read_project ( os . curdir )
package = store_read_package ( os . curdir )
elif is_project_dir ( os . getcwd ( ) ) :
project = store_read_project ( os . curdir )
else :
2010-05-22 18:27:11 +02:00
raise oscerr . WrongArgs ( ' Missing arguments: either specify <project> and ' \
2010-07-01 15:32:21 +02:00
' <package> or move to a project or package working copy ' )
2010-05-22 18:27:11 +02:00
repository = args [ 0 ]
if len ( args ) == 2 :
2009-10-20 16:30:15 +02:00
architecture = args [ 1 ]
2009-04-21 11:46:32 +02:00
else :
2016-11-15 14:06:33 +01:00
raise oscerr . WrongArgs ( ' Need either 1, 2, 3 or 4 arguments ' )
2009-04-21 11:46:32 +02:00
2011-03-02 14:25:22 +01:00
repos = list ( get_repos_of_project ( apiurl , project ) )
if not [ i for i in repos if repository == i . name ] :
2011-03-02 14:38:24 +01:00
self . print_repos ( exc_msg = ' Invalid repository \' %s \' ' % repository )
2011-03-02 14:25:22 +01:00
2010-05-22 18:27:11 +02:00
arches = [ architecture ]
if architecture is None :
2011-03-02 14:25:22 +01:00
arches = [ i . arch for i in repos if repository == i . name ]
2010-07-01 15:32:21 +02:00
2010-08-13 00:30:05 +02:00
if package is None :
package = meta_get_packagelist ( apiurl , project )
2014-08-12 15:01:16 +02:00
else :
2010-08-13 00:30:05 +02:00
package = [ package ]
2010-07-01 15:32:21 +02:00
2011-01-21 10:35:47 +01:00
# Set binary target directory and create if not existing
target_dir = os . path . normpath ( opts . destdir )
if not os . path . isdir ( target_dir ) :
2013-04-09 12:51:28 +02:00
print ( ' Creating %s ' % target_dir )
2013-04-09 12:45:16 +02:00
os . makedirs ( target_dir , 0o755 )
2011-01-21 10:35:47 +01:00
2010-05-22 18:27:11 +02:00
for arch in arches :
2010-07-01 15:32:21 +02:00
for pac in package :
2010-08-13 00:30:05 +02:00
binaries = get_binarylist ( apiurl , project , repository , arch ,
package = pac , verbose = True )
if not binaries :
2013-04-09 12:51:28 +02:00
print ( ' no binaries found: Either the package %s ' \
' does not exist or no binaries have been built. ' % pac , file = sys . stderr )
2010-08-13 00:30:05 +02:00
continue
for i in binaries :
2012-11-19 10:21:24 +01:00
if binary != None and binary != i . name :
continue
2010-08-13 00:30:05 +02:00
# skip source rpms
2016-03-02 18:47:22 +01:00
if not opts . sources and ( i . name . endswith ( ' src.rpm ' ) or i . name . endswith ( ' sdeb ' ) ) :
2011-11-18 21:52:30 +01:00
continue
2010-09-27 17:43:44 +02:00
if not opts . debug :
if i . name . find ( ' -debuginfo- ' ) > = 0 :
2010-09-28 16:20:55 +02:00
continue
2010-12-23 10:32:50 +01:00
if i . name . find ( ' -debugsource- ' ) > = 0 :
continue
2010-08-13 00:30:05 +02:00
fname = ' %s / %s ' % ( target_dir , i . name )
if os . path . exists ( fname ) :
st = os . stat ( fname )
if st . st_mtime == i . mtime and st . st_size == i . size :
continue
get_binary_file ( apiurl ,
project ,
repository , arch ,
i . name ,
package = pac ,
target_filename = fname ,
target_mtime = i . mtime ,
progress_meter = not opts . quiet )
2008-09-30 16:54:08 +02:00
2010-01-12 15:10:32 +01:00
@cmdln.option ( ' -b ' , ' --bugowner ' , action = ' store_true ' ,
help = ' restrict listing to items where the user is bugowner ' )
@cmdln.option ( ' -m ' , ' --maintainer ' , action = ' store_true ' ,
help = ' restrict listing to items where the user is maintainer ' )
2009-08-21 03:26:37 +02:00
@cmdln.option ( ' -a ' , ' --all ' , action = ' store_true ' ,
2010-01-12 15:10:32 +01:00
help = ' all involvements ' )
@cmdln.option ( ' -U ' , ' --user ' , metavar = ' USER ' ,
help = ' search for USER instead of yourself ' )
2010-03-13 14:06:48 +01:00
@cmdln.option ( ' --exclude-project ' , action = ' append ' ,
2010-01-12 15:10:32 +01:00
help = ' exclude requests for specified project ' )
@cmdln.option ( ' -v ' , ' --verbose ' , action = ' store_true ' ,
help = ' verbose listing ' )
2010-07-07 16:25:09 +02:00
@cmdln.option ( ' --maintained ' , action = ' store_true ' ,
help = ' limit search results to packages with maintained attribute set. ' )
2012-01-26 12:04:55 +01:00
def do_my ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : show waiting work, packages, projects or requests involving yourself
2010-01-12 15:10:32 +01:00
Examples :
2013-02-20 11:41:17 +01:00
# list all open tasks for me
2012-01-26 12:04:55 +01:00
osc $ { cmd_name } [ work ]
2010-01-12 15:10:32 +01:00
# list packages where I am bugowner
osc $ { cmd_name } pkg - b
# list projects where I am maintainer
osc $ { cmd_name } prj - m
# list request for all my projects and packages
osc $ { cmd_name } rq
# list requests, excluding project 'foo' and 'bar'
osc $ { cmd_name } rq - - exclude - project foo , bar
2015-07-29 11:05:05 +02:00
# list requests I made
2010-01-12 15:10:32 +01:00
osc $ { cmd_name } sr
$ { cmd_usage }
where TYPE is one of requests , submitrequests ,
projects or packages ( rq , sr , prj or pkg )
$ { cmd_option_list }
2009-09-03 20:08:43 +02:00
"""
2009-08-21 03:26:37 +02:00
2011-03-03 16:31:33 +01:00
# TODO: please clarify the difference between sr and rq.
2014-08-12 15:01:16 +02:00
# My first implementeation was to make no difference between requests FROM one
2011-03-03 16:31:33 +01:00
# of my projects and TO one of my projects. The current implementation appears to make this difference.
# The usage above indicates, that sr would be a subset of rq, which is no the case with my tests.
# jw.
2012-01-26 12:04:55 +01:00
args_rq = ( ' requests ' , ' request ' , ' req ' , ' rq ' , ' work ' )
2010-01-12 15:10:32 +01:00
args_sr = ( ' submitrequests ' , ' submitrequest ' , ' submitreq ' , ' submit ' , ' sr ' )
args_prj = ( ' projects ' , ' project ' , ' projs ' , ' proj ' , ' prj ' )
args_pkg = ( ' packages ' , ' package ' , ' pack ' , ' pkgs ' , ' pkg ' )
2012-01-26 12:04:55 +01:00
args_patchinfos = ( ' patchinfos ' , ' work ' )
2010-01-12 15:10:32 +01:00
2010-03-13 14:06:48 +01:00
if opts . bugowner and opts . maintainer :
raise oscerr . WrongOptions ( ' Sorry, \' --bugowner \' and \' maintainer \' are mutually exclusive ' )
elif opts . all and ( opts . bugowner or opts . maintainer ) :
raise oscerr . WrongOptions ( ' Sorry, \' --all \' and \' --bugowner \' or \' --maintainer \' are mutually exclusive ' )
2009-08-21 03:26:37 +02:00
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2010-04-21 15:58:57 +02:00
2010-03-13 14:06:48 +01:00
exclude_projects = [ ]
for i in opts . exclude_project or [ ] :
prj = i . split ( ' , ' )
if len ( prj ) == 1 :
exclude_projects . append ( i )
else :
exclude_projects . extend ( prj )
2010-01-12 15:10:32 +01:00
if not opts . user :
2010-04-21 15:58:57 +02:00
user = conf . get_apiurl_usr ( apiurl )
2010-01-12 15:10:32 +01:00
else :
user = opts . user
2010-03-13 14:06:48 +01:00
what = { ' project ' : ' ' , ' package ' : ' ' }
2013-05-27 12:41:50 +02:00
type = " work "
2012-01-26 12:04:55 +01:00
if len ( args ) > 0 :
2013-05-27 12:41:50 +02:00
type = args [ 0 ]
2012-01-26 12:04:55 +01:00
list_patchinfos = list_requests = False
if type in args_patchinfos :
list_patchinfos = True
2010-01-12 15:10:32 +01:00
if type in args_rq :
list_requests = True
elif type in args_prj :
2010-03-13 14:06:48 +01:00
what = { ' project ' : ' ' }
elif type in args_sr :
2015-07-29 11:05:05 +02:00
requests = get_request_collection ( apiurl , ' creator ' , req_who = user )
2011-02-09 15:51:26 +01:00
for r in sorted ( requests ) :
2013-04-09 12:51:28 +02:00
print ( r . list_view ( ) , ' \n ' )
2010-03-13 14:06:48 +01:00
return
elif not type in args_pkg :
2010-01-12 15:10:32 +01:00
raise oscerr . WrongArgs ( " invalid type %s " % type )
2010-03-13 14:06:48 +01:00
role_filter = ' '
if opts . maintainer :
2010-01-12 15:10:32 +01:00
role_filter = ' maintainer '
elif opts . bugowner :
role_filter = ' bugowner '
2010-03-13 14:06:48 +01:00
elif list_requests :
role_filter = ' maintainer '
if opts . all :
role_filter = ' '
2012-01-26 12:04:55 +01:00
if list_patchinfos :
2013-05-27 12:16:44 +02:00
u = makeurl ( apiurl , [ ' /search/package ' ] , {
' match ' : " ([kind= ' patchinfo ' and issue/[@state= ' OPEN ' and owner/@login= ' %s ' ]]) " % user
} )
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
if root . findall ( ' package ' ) :
print ( " Patchinfos with open bugs assigned to you: \n " )
for node in root . findall ( ' package ' ) :
project = node . get ( ' project ' )
package = node . get ( ' name ' )
print ( project , " / " , package , ' \n ' )
p = makeurl ( apiurl , [ ' source ' , project , package ] , { ' view ' : ' issues ' } )
fp = http_GET ( p )
issues = ET . parse ( fp ) . findall ( ' issue ' )
for issue in issues :
if issue . find ( ' state ' ) == None or issue . find ( ' state ' ) . text != " OPEN " :
continue
if issue . find ( ' owner ' ) == None or issue . find ( ' owner ' ) . find ( ' login ' ) . text != user :
continue
print ( " # " , issue . find ( ' label ' ) . text , ' : ' , end = ' ' )
desc = issue . find ( ' summary ' )
if desc != None :
print ( desc . text )
else :
print ( " \n " )
print ( " " )
2012-01-26 12:04:55 +01:00
2011-01-23 21:21:32 +01:00
if list_requests :
# try api side search as supported since OBS 2.2
try :
2011-04-20 16:53:42 +02:00
requests = [ ]
2011-12-16 09:44:57 +01:00
# open reviews
2011-12-15 15:35:11 +01:00
u = makeurl ( apiurl , [ ' request ' ] , {
2014-08-13 11:21:55 +02:00
' view ' : ' collection ' ,
2011-12-16 09:44:57 +01:00
' states ' : ' review ' ,
' reviewstates ' : ' new ' ,
' roles ' : ' reviewer ' ,
2014-08-13 11:21:55 +02:00
' user ' : user ,
2011-12-15 15:35:11 +01:00
} )
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
if root . findall ( ' request ' ) :
2013-05-27 12:16:44 +02:00
print ( " Requests which request a review by you: \n " )
for node in root . findall ( ' request ' ) :
r = Request ( )
r . read ( node )
print ( r . list_view ( ) , ' \n ' )
print ( " " )
2011-12-16 09:44:57 +01:00
# open requests
2011-02-04 10:29:13 +01:00
u = makeurl ( apiurl , [ ' request ' ] , {
2014-08-13 11:21:55 +02:00
' view ' : ' collection ' ,
2011-12-16 09:44:57 +01:00
' states ' : ' new ' ,
' roles ' : ' maintainer ' ,
2014-08-13 11:21:55 +02:00
' user ' : user ,
2011-04-20 16:53:42 +02:00
} )
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
2011-12-15 15:35:11 +01:00
if root . findall ( ' request ' ) :
2013-05-27 12:16:44 +02:00
print ( " Requests for your packages: \n " )
for node in root . findall ( ' request ' ) :
r = Request ( )
r . read ( node )
print ( r . list_view ( ) , ' \n ' )
print ( " " )
2011-12-16 09:44:57 +01:00
# declined requests submitted by me
2011-04-20 16:53:42 +02:00
u = makeurl ( apiurl , [ ' request ' ] , {
2014-08-13 11:21:55 +02:00
' view ' : ' collection ' ,
2011-12-16 09:44:57 +01:00
' states ' : ' declined ' ,
' roles ' : ' creator ' ,
2014-08-13 11:21:55 +02:00
' user ' : user ,
2011-02-04 10:29:13 +01:00
} )
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
2011-12-15 15:35:11 +01:00
if root . findall ( ' request ' ) :
2013-05-27 12:16:44 +02:00
print ( " Declined requests created by you (revoke, reopen or supersede): \n " )
for node in root . findall ( ' request ' ) :
r = Request ( )
r . read ( node )
print ( r . list_view ( ) , ' \n ' )
print ( " " )
2011-02-04 10:14:04 +01:00
return
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2016-09-13 12:34:48 +02:00
if e . code != 400 :
raise e
# skip it ... try again with old style below
2011-01-23 21:21:32 +01:00
2010-09-29 19:57:00 +02:00
res = get_user_projpkgs ( apiurl , user , role_filter , exclude_projects ,
2013-04-09 11:33:25 +02:00
' project ' in what , ' package ' in what ,
2010-09-29 19:57:00 +02:00
opts . maintained , opts . verbose )
2010-12-22 08:45:36 +01:00
# map of project =>[list of packages]
# if list of packages is empty user is maintainer of the whole project
2010-03-13 14:06:48 +01:00
request_todo = { }
2010-12-22 08:45:36 +01:00
2016-09-13 12:39:24 +02:00
dummy_elm = ET . Element ( ' dummy ' )
2010-03-13 14:06:48 +01:00
roles = { }
if len ( what . keys ( ) ) == 2 :
2016-09-13 12:39:24 +02:00
for i in res . get ( ' project_id ' , res . get ( ' project ' , dummy_elm ) ) . findall ( ' project ' ) :
2010-03-13 14:06:48 +01:00
request_todo [ i . get ( ' name ' ) ] = [ ]
roles [ i . get ( ' name ' ) ] = [ p . get ( ' role ' ) for p in i . findall ( ' person ' ) if p . get ( ' userid ' ) == user ]
2016-09-13 12:39:24 +02:00
for i in res . get ( ' package_id ' , res . get ( ' package ' , dummy_elm ) ) . findall ( ' package ' ) :
2010-12-22 08:45:36 +01:00
prj = i . get ( ' project ' )
roles [ ' / ' . join ( [ prj , i . get ( ' name ' ) ] ) ] = [ p . get ( ' role ' ) for p in i . findall ( ' person ' ) if p . get ( ' userid ' ) == user ]
if not prj in request_todo or request_todo [ prj ] != [ ] :
request_todo . setdefault ( prj , [ ] ) . append ( i . get ( ' name ' ) )
2010-03-13 14:06:48 +01:00
else :
2016-09-13 12:39:24 +02:00
for i in res . get ( ' project_id ' , res . get ( ' project ' , dummy_elm ) ) . findall ( ' project ' ) :
2010-03-13 14:06:48 +01:00
roles [ i . get ( ' name ' ) ] = [ p . get ( ' role ' ) for p in i . findall ( ' person ' ) if p . get ( ' userid ' ) == user ]
2010-01-12 15:10:32 +01:00
if list_requests :
2011-01-23 21:21:32 +01:00
# old style, only for OBS 2.1 and before. Should not be used, since it is slow and incomplete
2010-04-21 15:58:57 +02:00
requests = get_user_projpkgs_request_list ( apiurl , user , projpkgs = request_todo )
2011-02-09 15:53:36 +01:00
for r in sorted ( requests ) :
2013-04-09 12:51:28 +02:00
print ( r . list_view ( ) , ' \n ' )
2011-03-03 16:31:33 +01:00
if not len ( requests ) :
2013-04-09 12:51:28 +02:00
print ( " -> try also ' osc my sr ' to see more. " )
2010-01-12 15:10:32 +01:00
else :
2010-03-13 14:06:48 +01:00
for i in sorted ( roles . keys ( ) ) :
out = ' %s ' % i
prjpac = i . split ( ' / ' )
if type in args_pkg and len ( prjpac ) == 1 and not opts . verbose :
continue
2010-01-12 15:10:32 +01:00
if opts . verbose :
2010-03-13 14:06:48 +01:00
out = ' %s ( %s ) ' % ( i , ' , ' . join ( sorted ( roles [ i ] ) ) )
if len ( prjpac ) == 2 :
out = ' %s ( %s ) ' % ( prjpac [ 1 ] , ' , ' . join ( sorted ( roles [ i ] ) ) )
2013-04-09 12:51:28 +02:00
print ( out )
2009-08-21 03:26:37 +02:00
2008-09-30 16:54:08 +02:00
2007-08-09 13:35:08 +02:00
@cmdln.option ( ' --repos-baseurl ' , action = ' store_true ' ,
help = ' show base URLs of download repositories ' )
2009-04-07 20:45:42 +02:00
@cmdln.option ( ' -e ' , ' --exact ' , action = ' store_true ' ,
2009-11-23 17:13:57 +01:00
help = ' show only exact matches, this is default now ' )
@cmdln.option ( ' -s ' , ' --substring ' , action = ' store_true ' ,
help = ' Show also results where the search term is a sub string, slower search ' )
2007-07-15 15:49:13 +02:00
@cmdln.option ( ' --package ' , action = ' store_true ' ,
help = ' search for a package ' )
@cmdln.option ( ' --project ' , action = ' store_true ' ,
help = ' search for a project ' )
@cmdln.option ( ' --title ' , action = ' store_true ' ,
help = ' search for matches in the \' title \' element ' )
@cmdln.option ( ' --description ' , action = ' store_true ' ,
help = ' search for matches in the \' description \' element ' )
2009-10-22 12:10:15 +02:00
@cmdln.option ( ' -a ' , ' --limit-to-attribute ' , metavar = ' ATTRIBUTE ' ,
help = ' match only when given attribute exists in meta data ' )
2007-07-15 15:49:13 +02:00
@cmdln.option ( ' -v ' , ' --verbose ' , action = ' store_true ' ,
help = ' show more information ' )
2014-08-12 15:01:16 +02:00
@cmdln.option ( ' -V ' , ' --version ' , action = ' store_true ' ,
2010-12-26 21:14:40 +01:00
help = ' show package version, revision, and srcmd5. CAUTION: This is slow and unreliable ' )
2008-06-24 17:07:44 +02:00
@cmdln.option ( ' -i ' , ' --involved ' , action = ' store_true ' ,
2015-04-22 12:22:44 +02:00
help = ' show projects/packages where given person (or myself) is involved as bugowner or maintainer [[ { group|person}/]<name>] default: person ' )
2009-08-21 03:26:37 +02:00
@cmdln.option ( ' -b ' , ' --bugowner ' , action = ' store_true ' ,
help = ' as -i, but only bugowner ' )
@cmdln.option ( ' -m ' , ' --maintainer ' , action = ' store_true ' ,
help = ' as -i, but only maintainer ' )
2009-11-06 17:08:20 +01:00
@cmdln.option ( ' --maintained ' , action = ' store_true ' ,
2013-02-14 11:31:05 +01:00
help = ' OBSOLETE: please use maintained command instead. ' )
2009-08-21 03:26:37 +02:00
@cmdln.option ( ' -M ' , ' --mine ' , action = ' store_true ' ,
help = ' shorthand for --bugowner --package ' )
2009-05-15 10:33:25 +02:00
@cmdln.option ( ' --csv ' , action = ' store_true ' ,
help = ' generate output in CSV (separated by |) ' )
2010-03-15 16:08:00 +01:00
@cmdln.option ( ' --binary ' , action = ' store_true ' ,
help = ' search binary packages ' )
@cmdln.option ( ' -B ' , ' --baseproject ' , metavar = ' PROJECT ' ,
help = ' search packages built for PROJECT (implies --binary) ' )
2012-01-13 15:18:33 +01:00
@cmdln.option ( ' --binaryversion ' , metavar = ' VERSION ' ,
help = ' search for binary with specified version (implies --binary) ' )
2009-08-21 03:26:37 +02:00
@cmdln.alias ( ' se ' )
2010-03-20 12:27:27 +01:00
@cmdln.alias ( ' bse ' )
2011-01-17 19:28:50 +01:00
def do_search ( self , subcmd , opts , * args ) :
2007-12-10 15:23:58 +01:00
""" $ {cmd_name} : Search for a project and/or package.
2007-07-15 15:49:13 +02:00
If no option is specified osc will search for projects and
packages which contains the \' search term \' in their name,
title or description .
usage :
osc search \' search term \' <options>
2010-03-20 12:27:27 +01:00
osc bse . . . ( ' osc search --binary ' )
2010-11-12 23:55:11 +01:00
osc se ' perl(Foo::Bar) ' ( ' osc --package perl-Foo-Bar ' )
2007-07-15 15:49:13 +02:00
$ { cmd_option_list }
"""
2010-03-10 23:36:09 +01:00
def build_xpath ( attr , what , substr = False ) :
if substr :
return ' contains( %s , \' %s \' ) ' % ( attr , what )
else :
return ' %s = \' %s \' ' % ( attr , what )
2009-09-03 20:08:43 +02:00
2011-01-17 19:33:02 +01:00
search_term = ' '
2011-01-17 19:28:50 +01:00
if len ( args ) > 1 :
raise oscerr . WrongArgs ( ' Too many arguments ' )
elif len ( args ) == 0 :
if opts . involved or opts . bugowner or opts . maintainer or opts . mine :
search_term = conf . get_apiurl_usr ( conf . config [ ' apiurl ' ] )
else :
raise oscerr . WrongArgs ( ' Too few arguments ' )
2011-01-17 19:33:02 +01:00
else :
search_term = args [ 0 ]
2011-01-17 19:28:50 +01:00
2013-02-14 11:31:05 +01:00
if opts . maintained :
raise oscerr . WrongOptions ( ' The --maintained option is not anymore supported. Please use the maintained command instead. ' )
2011-01-30 21:37:45 +01:00
# XXX: is it a good idea to make this the default?
# support perl symbols:
2010-11-12 23:55:11 +01:00
if re . match ( ' ^perl \ ( \ w+(:: \ w+)* \ )$ ' , search_term ) :
2013-05-27 12:41:50 +02:00
search_term = re . sub ( ' \ ) ' , ' ' , re . sub ( ' (::| \ () ' , ' - ' , search_term ) )
2010-11-12 23:55:11 +01:00
opts . package = True
2009-09-03 20:08:43 +02:00
if opts . mine :
opts . bugowner = True
opts . package = True
2009-10-20 16:30:15 +02:00
2010-03-10 23:36:09 +01:00
if ( opts . title or opts . description ) and ( opts . involved or opts . bugowner or opts . maintainer ) :
raise oscerr . WrongOptions ( ' Sorry, the options \' --title \' and/or \' --description \' ' \
' are mutually exclusive with \' -i \' / \' -b \' / \' -m \' / \' -M \' ' )
if opts . substring and opts . exact :
raise oscerr . WrongOptions ( ' Sorry, the options \' --substring \' and \' --exact \' are mutually exclusive ' )
2007-07-15 15:49:13 +02:00
2009-11-23 17:13:57 +01:00
if not opts . substring :
opts . exact = True
2012-01-13 17:43:32 +01:00
if subcmd == ' bse ' or opts . baseproject or opts . binaryversion :
2010-03-15 16:08:00 +01:00
opts . binary = True
if opts . binary and ( opts . title or opts . description or opts . involved or opts . bugowner or opts . maintainer
or opts . project or opts . package ) :
raise oscerr . WrongOptions ( ' Sorry, \' --binary \' and \' --title \' or \' --description \' or \' --involved ' \
' or \' --bugowner \' or \' --maintainer \' or \' --limit-to-attribute <attr> \ ' \
' or \' --project \' or \' --package \' are mutually exclusive ' )
2010-02-28 02:30:13 +01:00
2010-07-29 17:29:07 +02:00
apiurl = self . get_api_url ( )
2010-03-10 23:36:09 +01:00
xpath = ' '
if opts . title :
xpath = xpath_join ( xpath , build_xpath ( ' title ' , search_term , opts . substring ) , inner = True )
if opts . description :
xpath = xpath_join ( xpath , build_xpath ( ' description ' , search_term , opts . substring ) , inner = True )
2010-03-15 16:08:00 +01:00
if opts . project or opts . package or opts . binary :
2010-03-10 23:36:09 +01:00
xpath = xpath_join ( xpath , build_xpath ( ' @name ' , search_term , opts . substring ) , inner = True )
# role filter
role_filter = ' '
if opts . bugowner or opts . maintainer or opts . involved :
2015-04-24 09:47:12 +02:00
tmp = search_term . split ( ' : ' )
2015-04-22 12:22:44 +02:00
if len ( tmp ) > 1 :
search_type , search_term = [ tmp [ 0 ] , tmp [ 1 ] ]
else :
search_type = ' person '
search_dict = { ' person ' : ' userid ' ,
' group ' : ' groupid ' }
try :
search_id = search_dict [ search_type ]
except KeyError :
search_type , search_id = [ ' person ' , ' userid ' ]
xpath = xpath_join ( xpath , ' %s /@ %s = \' %s \' ' % ( search_type , search_id , search_term ) , inner = True )
role_filter = ' %s ( %s ) ' % ( search_term , search_type )
2010-03-12 15:22:11 +01:00
role_filter_xpath = xpath
2010-03-10 23:36:09 +01:00
if opts . bugowner and not opts . maintainer :
2015-04-22 14:59:36 +02:00
xpath = xpath_join ( xpath , ' %s /@role= \' bugowner \' ' % search_type , op = ' and ' )
2010-03-12 15:22:11 +01:00
role_filter = ' bugowner '
2010-03-10 23:36:09 +01:00
elif not opts . bugowner and opts . maintainer :
2015-04-22 14:59:36 +02:00
xpath = xpath_join ( xpath , ' %s /@role= \' maintainer \' ' % search_type , op = ' and ' )
2010-03-12 15:22:11 +01:00
role_filter = ' maintainer '
2010-03-10 23:36:09 +01:00
if opts . limit_to_attribute :
xpath = xpath_join ( xpath , ' attribute/@name= \' %s \' ' % opts . limit_to_attribute , op = ' and ' )
2010-03-15 16:08:00 +01:00
if opts . baseproject :
xpath = xpath_join ( xpath , ' path/@project= \' %s \' ' % opts . baseproject , op = ' and ' )
2012-01-13 15:18:33 +01:00
if opts . binaryversion :
m = re . match ( r ' (.+)-(.*?)$ ' , opts . binaryversion )
if m :
if m . group ( 2 ) != ' ' :
xpath = xpath_join ( xpath , ' @versrel= \' %s \' ' % opts . binaryversion , op = ' and ' )
else :
xpath = xpath_join ( xpath , ' @version= \' %s \' ' % m . group ( 1 ) , op = ' and ' )
else :
xpath = xpath_join ( xpath , ' @version= \' %s \' ' % opts . binaryversion , op = ' and ' )
2009-08-21 03:26:37 +02:00
2010-03-10 23:36:09 +01:00
if not xpath :
xpath = xpath_join ( xpath , build_xpath ( ' @name ' , search_term , opts . substring ) , inner = True )
xpath = xpath_join ( xpath , build_xpath ( ' title ' , search_term , opts . substring ) , inner = True )
xpath = xpath_join ( xpath , build_xpath ( ' description ' , search_term , opts . substring ) , inner = True )
what = { ' project ' : xpath , ' package ' : xpath }
2012-01-05 16:15:29 +01:00
if opts . project and not opts . package :
2010-03-10 23:36:09 +01:00
what = { ' project ' : xpath }
elif not opts . project and opts . package :
what = { ' package ' : xpath }
2010-03-18 17:57:25 +01:00
elif opts . binary :
2010-03-15 16:08:00 +01:00
what = { ' published/binary/id ' : xpath }
2010-03-12 15:22:11 +01:00
try :
2010-07-29 17:29:07 +02:00
res = search ( apiurl , * * what )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2010-03-12 15:22:11 +01:00
if e . code != 400 or not role_filter :
raise e
# backward compatibility: local role filtering
if opts . limit_to_attribute :
role_filter_xpath = xpath_join ( role_filter_xpath , ' attribute/@name= \' %s \' ' % opts . limit_to_attribute , op = ' and ' )
what = dict ( [ [ kind , role_filter_xpath ] for kind in what . keys ( ) ] )
2010-07-29 17:29:07 +02:00
res = search ( apiurl , * * what )
2010-03-13 14:06:48 +01:00
filter_role ( res , search_term , role_filter )
2010-03-12 15:22:11 +01:00
if role_filter :
role_filter = ' %s ( %s ) ' % ( search_term , role_filter )
2010-03-15 16:08:00 +01:00
kind_map = { ' published/binary/id ' : ' binary ' }
2013-04-09 11:25:19 +02:00
for kind , root in res . items ( ) :
2010-03-10 23:36:09 +01:00
results = [ ]
2010-03-15 16:08:00 +01:00
for node in root . findall ( kind_map . get ( kind , kind ) ) :
2010-03-10 23:36:09 +01:00
result = [ ]
project = node . get ( ' project ' )
package = None
if project is None :
project = node . get ( ' name ' )
else :
2012-07-03 14:16:15 +02:00
if kind == ' published/binary/id ' :
package = node . get ( ' package ' )
else :
package = node . get ( ' name ' )
2010-03-10 23:36:09 +01:00
result . append ( project )
if not package is None :
result . append ( package )
2010-12-26 21:14:40 +01:00
2011-02-11 15:11:50 +01:00
if opts . version and package != None :
2013-05-27 12:41:50 +02:00
sr = get_source_rev ( apiurl , project , package )
2011-02-21 13:41:02 +01:00
v = sr . get ( ' version ' )
r = sr . get ( ' rev ' )
s = sr . get ( ' srcmd5 ' )
2013-05-27 13:38:49 +02:00
if not v or v == ' unknown ' :
v = ' - '
if not r :
r = ' - '
if not s :
s = ' - '
2010-12-26 21:14:40 +01:00
result . append ( v )
result . append ( r )
result . append ( s )
2010-03-10 23:36:09 +01:00
if opts . verbose :
title = node . findtext ( ' title ' ) . strip ( )
if len ( title ) > 60 :
title = title [ : 61 ] + ' ... '
result . append ( title )
2010-12-26 21:14:40 +01:00
2010-03-10 23:36:09 +01:00
if opts . repos_baseurl :
# FIXME: no hardcoded URL of instance
result . append ( ' http://download.opensuse.org/repositories/ %s / ' % project . replace ( ' : ' , ' :/ ' ) )
2010-03-15 16:08:00 +01:00
if kind == ' published/binary/id ' :
result . append ( node . get ( ' filepath ' ) )
2010-03-10 23:36:09 +01:00
results . append ( result )
if not len ( results ) :
2013-04-09 12:51:28 +02:00
print ( ' No matches found for \' %s \' in %s s ' % ( role_filter or search_term , kind ) )
2009-06-09 19:07:02 +02:00
continue
2010-03-10 23:36:09 +01:00
# construct a sorted, flat list
2010-08-12 20:21:04 +02:00
# Sort by first column, follwed by second column if we have two columns, else sort by first.
2014-08-12 15:01:16 +02:00
results . sort ( lambda x , y : ( cmp ( x [ 0 ] , y [ 0 ] ) or
2010-08-13 00:07:59 +02:00
( len ( x ) > 1 and len ( y ) > 1 and cmp ( x [ 1 ] , y [ 1 ] ) ) ) )
2010-03-10 23:36:09 +01:00
new = [ ]
for i in results :
new . extend ( i )
results = new
headline = [ ]
2010-03-15 16:08:00 +01:00
if kind == ' package ' or kind == ' published/binary/id ' :
2009-10-08 16:40:06 +02:00
headline = [ ' # Project ' , ' # Package ' ]
2007-07-15 15:49:13 +02:00
else :
2009-06-09 19:07:02 +02:00
headline = [ ' # Project ' ]
2011-02-11 15:11:50 +01:00
if opts . version and kind == ' package ' :
2010-12-26 21:14:40 +01:00
headline . append ( ' # Ver ' )
headline . append ( ' Rev ' )
headline . append ( ' Srcmd5 ' )
2009-06-09 19:07:02 +02:00
if opts . verbose :
headline . append ( ' # Title ' )
if opts . repos_baseurl :
headline . append ( ' # URL ' )
2010-03-15 16:08:00 +01:00
if opts . binary :
headline . append ( ' # filepath ' )
2009-06-09 19:07:02 +02:00
if not opts . csv :
2010-03-10 23:36:09 +01:00
if len ( what . keys ( ) ) > 1 :
2013-04-09 12:51:28 +02:00
print ( ' # ' * 68 )
print ( ' matches for \' %s \' in %s s: \n ' % ( role_filter or search_term , kind ) )
2010-03-10 23:36:09 +01:00
for row in build_table ( len ( headline ) , results , headline , 2 , csv = opts . csv ) :
2013-04-09 12:51:28 +02:00
print ( row )
2007-06-29 20:26:30 +02:00
2007-07-25 12:56:04 +02:00
2007-07-23 18:03:30 +02:00
@cmdln.option ( ' -p ' , ' --project ' , metavar = ' project ' ,
2009-12-25 18:16:35 +01:00
help = ' specify the path to a project ' )
2007-07-23 18:03:30 +02:00
@cmdln.option ( ' -n ' , ' --name ' , metavar = ' name ' ,
help = ' specify a package name ' )
@cmdln.option ( ' -t ' , ' --title ' , metavar = ' title ' ,
help = ' set a title ' )
@cmdln.option ( ' -d ' , ' --description ' , metavar = ' description ' ,
help = ' set the description of the package ' )
2007-07-30 13:12:42 +02:00
@cmdln.option ( ' ' , ' --delete-old-files ' , action = ' store_true ' ,
help = ' delete existing files from the server ' )
2007-07-30 20:11:52 +02:00
@cmdln.option ( ' -c ' , ' --commit ' , action = ' store_true ' ,
2007-08-08 17:44:14 +02:00
help = ' commit the new files ' )
2007-07-25 14:14:32 +02:00
def do_importsrcpkg ( self , subcmd , opts , srpm ) :
2007-12-10 15:23:58 +01:00
""" $ {cmd_name} : Import a new package from a src.rpm
2007-07-23 18:03:30 +02:00
A new package dir will be created inside the project dir
( if no project is specified and the current working dir is a
project dir the package will be created in this project ) . If
the package does not exist on the server it will be created
too otherwise the meta data of the existing package will be
updated ( < title / > and < description / > ) .
2008-11-29 14:32:25 +01:00
The src . rpm will be extracted into the package dir . The files
won ' t be committed unless you explicitly pass the --commit switch.
2007-07-23 18:03:30 +02:00
2007-07-25 14:21:46 +02:00
SRPM is the path of the src . rpm in the local filesystem ,
or an URL .
2007-07-25 14:14:32 +02:00
$ { cmd_usage }
2007-07-23 18:03:30 +02:00
$ { cmd_option_list }
"""
import glob
2013-04-09 11:35:53 +02:00
from . util import rpmquery
2007-07-23 18:03:30 +02:00
2008-03-10 19:04:23 +01:00
if opts . delete_old_files and conf . config [ ' do_package_tracking ' ] :
# IMHO the --delete-old-files option doesn't really fit into our
# package tracking strategy
2013-04-09 12:51:28 +02:00
print ( ' --delete-old-files is not supported anymore ' , file = sys . stderr )
print ( ' when do_package_tracking is enabled ' , file = sys . stderr )
2008-03-10 19:04:23 +01:00
sys . exit ( 1 )
2007-07-25 14:21:46 +02:00
if ' :// ' in srpm :
2013-04-09 12:51:28 +02:00
print ( ' trying to fetch ' , srpm )
2007-07-25 14:21:46 +02:00
import urlgrabber
urlgrabber . urlgrab ( srpm )
srpm = os . path . basename ( srpm )
2007-07-25 14:14:32 +02:00
srpm = os . path . abspath ( srpm )
2008-03-15 23:51:37 +01:00
if not os . path . isfile ( srpm ) :
2013-04-09 12:51:28 +02:00
print ( ' file \' %s \' does not exist ' % srpm , file = sys . stderr )
2008-03-15 23:51:37 +01:00
sys . exit ( 1 )
2007-07-23 18:03:30 +02:00
if opts . project :
project_dir = opts . project
else :
2008-03-10 19:04:23 +01:00
project_dir = os . curdir
2007-07-23 18:03:30 +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
if conf . config [ ' do_package_tracking ' ] :
project = Project ( project_dir )
2007-07-23 18:03:30 +02:00
else :
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
project = store_read_project ( project_dir )
2007-07-23 18:03:30 +02:00
2009-09-09 17:28:21 +02:00
rpmq = rpmquery . RpmQuery . query ( srpm )
title , pac , descr , url = rpmq . summary ( ) , rpmq . name ( ) , rpmq . description ( ) , rpmq . url ( )
if url is None :
url = ' '
2007-07-23 18:03:30 +02:00
if opts . title :
title = opts . title
if opts . name :
pac = opts . name
if opts . description :
descr = opts . description
2009-05-18 16:50:43 +02:00
2007-07-29 17:27:27 +02:00
# title and description can be empty
if not pac :
2013-04-09 12:51:28 +02:00
print ( ' please specify a package name with the \' --name \' option. ' \
' The automatic detection failed ' , file = sys . stderr )
2007-07-29 17:27:27 +02:00
sys . exit ( 1 )
2008-03-15 23:51:37 +01:00
if conf . config [ ' do_package_tracking ' ] :
2009-12-25 00:08:29 +01:00
createPackageDir ( os . path . join ( project . dir , pac ) , project )
2008-03-15 23:51:37 +01:00
else :
if not os . path . exists ( os . path . join ( project_dir , pac ) ) :
apiurl = store_read_apiurl ( project_dir )
user = conf . get_apiurl_usr ( apiurl )
2008-03-10 19:04:23 +01:00
data = meta_exists ( metatype = ' pkg ' ,
path_args = ( quote_plus ( project ) , quote_plus ( pac ) ) ,
template_args = ( {
' name ' : pac ,
2008-03-15 23:51:37 +01:00
' user ' : user } ) , apiurl = apiurl )
2008-03-10 19:04:23 +01:00
if data :
data = ET . fromstring ( ' ' . join ( data ) )
2010-08-30 14:05:06 +02:00
data . find ( ' title ' ) . text = ' ' . join ( title )
2008-03-10 19:04:23 +01:00
data . find ( ' description ' ) . text = ' ' . join ( descr )
2009-01-21 22:55:53 +01:00
data . find ( ' url ' ) . text = url
2013-04-10 11:34:59 +02:00
data = ET . tostring ( data , encoding = ET_ENCODING )
2008-03-10 19:04:23 +01:00
else :
2013-04-09 12:51:28 +02:00
print ( ' error - cannot get meta data ' , file = sys . stderr )
2008-03-10 19:04:23 +01:00
sys . exit ( 1 )
edit_meta ( metatype = ' pkg ' ,
path_args = ( quote_plus ( project ) , quote_plus ( pac ) ) ,
2008-03-15 23:51:37 +01:00
data = data , apiurl = apiurl )
2010-08-30 14:05:06 +02:00
Package . init_package ( apiurl , project , pac , os . path . join ( project_dir , pac ) )
2007-07-30 13:12:42 +02:00
else :
2013-04-09 12:51:28 +02:00
print ( ' error - local package already exists ' , file = sys . stderr )
2007-07-30 13:12:42 +02:00
sys . exit ( 1 )
2008-03-15 23:51:37 +01:00
2010-08-30 14:05:06 +02:00
unpack_srcrpm ( srpm , os . path . join ( project_dir , pac ) )
p = Package ( os . path . join ( project_dir , pac ) )
2008-03-15 23:51:37 +01:00
if len ( p . filenamelist ) == 0 and opts . commit :
2013-04-09 12:51:28 +02:00
print ( ' Adding files to working copy... ' )
2011-01-20 20:38:36 +01:00
addFiles ( glob . glob ( ' %s /* ' % os . path . join ( project_dir , pac ) ) )
2008-03-15 23:51:37 +01:00
if conf . config [ ' do_package_tracking ' ] :
project . commit ( ( pac , ) )
else :
p . update_datastructs ( )
p . commit ( )
elif opts . commit and opts . delete_old_files :
2010-08-20 14:34:41 +02:00
for filename in p . filenamelist :
p . delete_remote_source_file ( filename )
2008-03-15 23:51:37 +01:00
p . update_local_filesmeta ( )
2013-04-09 12:51:28 +02:00
print ( ' Adding files to working copy... ' )
2008-03-15 23:51:37 +01:00
addFiles ( glob . glob ( ' * ' ) )
p . update_datastructs ( )
p . commit ( )
2007-07-23 18:03:30 +02:00
else :
2013-04-09 12:51:28 +02:00
print ( ' No files were committed to the server. Please ' \
' commit them manually. ' )
print ( ' Package \' %s \' only imported locally ' % pac )
2007-07-23 18:03:30 +02:00
sys . exit ( 1 )
2013-04-09 12:51:28 +02:00
print ( ' Package \' %s \' imported successfully ' % pac )
2007-07-25 12:56:04 +02:00
2007-07-25 14:14:32 +02:00
2010-07-29 11:43:56 +02:00
@cmdln.option ( ' -X ' , ' -m ' , ' --method ' , default = ' GET ' , metavar = ' HTTP_METHOD ' ,
2007-07-25 12:56:04 +02:00
help = ' specify HTTP method to use (GET|PUT|DELETE|POST) ' )
2014-10-31 09:22:25 +01:00
@cmdln.option ( ' -e ' , ' --edit ' , default = None , action = ' store_true ' ,
help = ' GET, edit and PUT the location ' )
2007-07-25 12:56:04 +02:00
@cmdln.option ( ' -d ' , ' --data ' , default = None , metavar = ' STRING ' ,
help = ' specify string data for e.g. POST ' )
2010-07-29 11:43:56 +02:00
@cmdln.option ( ' -T ' , ' -f ' , ' --file ' , default = None , metavar = ' FILE ' ,
2011-09-23 12:11:14 +02:00
help = ' specify filename to upload, uses PUT mode by default ' )
2009-05-18 16:50:43 +02:00
@cmdln.option ( ' -a ' , ' --add-header ' , default = None , metavar = ' NAME STRING ' ,
2008-03-16 21:46:16 +01:00
nargs = 2 , action = ' append ' , dest = ' headers ' ,
help = ' add the specified header to the request ' )
2009-06-04 16:14:01 +02:00
def do_api ( self , subcmd , opts , url ) :
2007-07-25 12:56:04 +02:00
""" $ {cmd_name} : Issue an arbitrary request to the API
Useful for testing .
URL can be specified either partially ( only the path component ) , or fully
with URL scheme and hostname ( ' http://... ' ) .
Note the global - A and - H options ( see osc help ) .
Examples :
2009-06-04 16:14:01 +02:00
osc api / source / home : user
2010-07-29 11:43:56 +02:00
osc api - X PUT - T / etc / fstab source / home : user / test5 / myfstab
2014-10-31 14:14:06 +01:00
osc api - e / configuration
2007-07-25 12:56:04 +02:00
$ { cmd_usage }
$ { cmd_option_list }
"""
2010-07-29 17:29:07 +02:00
apiurl = self . get_api_url ( )
2007-07-25 12:56:04 +02:00
if not opts . method in [ ' GET ' , ' PUT ' , ' POST ' , ' DELETE ' ] :
sys . exit ( ' unknown method %s ' % opts . method )
2011-09-23 12:11:14 +02:00
# default is PUT when uploading files
if opts . file and opts . method == ' GET ' :
opts . method = ' PUT '
2007-07-25 12:56:04 +02:00
if not url . startswith ( ' http ' ) :
if not url . startswith ( ' / ' ) :
url = ' / ' + url
2010-07-29 17:29:07 +02:00
url = apiurl + url
2007-07-25 12:56:04 +02:00
2008-03-16 21:46:16 +01:00
if opts . headers :
opts . headers = dict ( opts . headers )
2009-05-18 16:50:43 +02:00
r = http_request ( opts . method ,
url ,
data = opts . data ,
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
file = opts . file ,
2009-05-18 16:50:43 +02:00
headers = opts . headers )
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
out = r . read ( )
2007-07-25 12:56:04 +02:00
2014-10-31 09:22:25 +01:00
if opts . edit :
text = edit_text ( out )
r = http_request ( " PUT " ,
url ,
data = text ,
headers = opts . headers )
out = r . read ( )
sys . stdout . write ( out )
2009-10-22 11:43:58 +02:00
2009-12-25 17:19:44 +01:00
@cmdln.option ( ' -b ' , ' --bugowner-only ' , action = ' store_true ' ,
2009-06-18 18:20:49 +02:00
help = ' Show only the bugowner ' )
2009-10-22 11:43:58 +02:00
@cmdln.option ( ' -B ' , ' --bugowner ' , action = ' store_true ' ,
help = ' Show only the bugowner if defined, or maintainer otherwise ' )
2007-09-03 12:17:26 +02:00
@cmdln.option ( ' -e ' , ' --email ' , action = ' store_true ' ,
help = ' show email addresses instead of user names ' )
2009-06-18 18:20:49 +02:00
@cmdln.option ( ' --nodevelproject ' , action = ' store_true ' ,
help = ' do not follow a defined devel project ' \
' (primary project where a package is developed) ' )
2007-09-03 18:18:37 +02:00
@cmdln.option ( ' -v ' , ' --verbose ' , action = ' store_true ' ,
help = ' show more information ' )
2008-05-20 10:29:54 +02:00
@cmdln.option ( ' -D ' , ' --devel-project ' , metavar = ' devel_project ' ,
help = ' define the project where this package is primarily developed ' )
2007-09-12 20:01:13 +02:00
@cmdln.option ( ' -a ' , ' --add ' , metavar = ' user ' ,
2012-11-23 12:52:05 +01:00
help = ' add a new person for given role ( " maintainer " by default) ' )
@cmdln.option ( ' -A ' , ' --all ' , action = ' store_true ' ,
help = ' list all found entries not just the first one ' )
@cmdln.option ( ' -s ' , ' --set-bugowner ' , metavar = ' user ' ,
2014-01-24 17:01:35 +01:00
help = ' Set the bugowner to specified person (or group via group: prefix) ' )
2012-11-23 12:52:05 +01:00
@cmdln.option ( ' -S ' , ' --set-bugowner-request ' , metavar = ' user ' ,
2014-01-24 17:01:35 +01:00
help = ' Set the bugowner to specified person via a request (or group via group: prefix) ' )
2013-02-20 11:41:17 +01:00
@cmdln.option ( ' -U ' , ' --user ' , metavar = ' USER ' ,
help = ' All official maintained instances for the specified USER ' )
@cmdln.option ( ' -G ' , ' --group ' , metavar = ' GROUP ' ,
help = ' All official maintained instances for the specified GROUP ' )
2007-09-12 20:01:13 +02:00
@cmdln.option ( ' -d ' , ' --delete ' , metavar = ' user ' ,
2009-12-30 21:54:57 +01:00
help = ' delete a maintainer/bugowner (can be specified via --role) ' )
2009-12-25 17:31:13 +01:00
@cmdln.option ( ' -r ' , ' --role ' , metavar = ' role ' , action = ' append ' , default = [ ] ,
2009-06-19 15:57:27 +02:00
help = ' Specify user role ' )
2013-05-02 11:38:53 +02:00
@cmdln.option ( ' -m ' , ' --message ' ,
help = ' Define message as commit entry or request description ' )
2012-11-23 12:52:05 +01:00
@cmdln.alias ( ' bugowner ' )
2007-09-03 12:17:26 +02:00
def do_maintainer ( self , subcmd , opts , * args ) :
2013-03-06 11:49:22 +01:00
""" $ {cmd_name} : Show maintainers according to server side configuration
2009-05-18 16:50:43 +02:00
2013-02-20 11:41:17 +01:00
# Search for official maintained sources in OBS instance
2012-11-22 11:37:32 +01:00
osc maintainer BINARY < options >
2013-02-20 11:41:17 +01:00
osc maintainer - U < user > < options >
osc maintainer - G < group > < options >
2013-03-06 11:49:22 +01:00
# Lookup via containers
2013-02-20 11:41:17 +01:00
osc maintainer < options >
2007-09-12 20:01:13 +02:00
osc maintainer PRJ < options >
osc maintainer PRJ PKG < options >
2016-05-15 17:50:31 +02:00
2012-11-22 11:37:32 +01:00
The tool looks up the default responsible person for a certain project or package .
When using with an OBS 2.4 ( or later ) server it is doing the lookup for
a given binary according to the server side configuration of default owners .
2013-03-06 11:49:22 +01:00
The tool is also looking into devel packages and supports to fallback to the project
in case a package has no defined maintainer .
Please use " osc meta pkg " in case you need to know the definition in a specific container .
2010-09-10 14:20:42 +02:00
PRJ and PKG default to current working - copy path .
2009-05-18 16:50:43 +02:00
2007-09-03 12:17:26 +02:00
$ { cmd_usage }
$ { cmd_option_list }
"""
2014-02-11 11:56:44 +01:00
def get_maintainer_data ( apiurl , maintainer , verbose = False ) :
tags = ( ' email ' , )
if maintainer . startswith ( ' group: ' ) :
group = maintainer . replace ( ' group: ' , ' ' )
if verbose :
return [ maintainer ] + get_group_data ( apiurl , group , ' title ' , * tags )
return get_group_data ( apiurl , group , ' email ' )
if verbose :
tags = ( ' login ' , ' realname ' , ' email ' )
return get_user_data ( apiurl , maintainer , * tags )
2014-05-08 16:07:42 +02:00
def setBugownerHelper ( apiurl , project , package , bugowner ) :
try :
setBugowner ( apiurl , project , package , bugowner )
except HTTPError as e :
if e . code != 403 :
raise
print ( " No write permission in " , project , end = ' ' )
if package :
print ( " / " , package , end = ' ' )
print ( )
repl = raw_input ( ' \n Creating a request instead? (y/n) ' )
if repl . lower ( ) == ' y ' :
opts . set_bugowner_request = bugowner
opts . set_bugowner = None
2009-05-18 16:50:43 +02:00
2012-11-22 11:37:32 +01:00
binary = None
2010-09-10 14:20:42 +02:00
prj = None
2012-11-22 11:37:32 +01:00
pac = None
metaroot = None
searchresult = None
2009-12-25 17:19:44 +01:00
roles = [ ' bugowner ' , ' maintainer ' ]
2009-12-25 17:31:13 +01:00
if len ( opts . role ) :
roles = opts . role
2014-07-10 09:50:52 +02:00
elif opts . bugowner_only or opts . bugowner or subcmd == ' bugowner ' :
2009-06-18 18:20:49 +02:00
roles = [ ' bugowner ' ]
2013-01-08 22:32:27 +01:00
args = slash_split ( args )
2013-02-20 11:41:17 +01:00
if opts . user or opts . group :
if len ( args ) != 0 :
raise oscerr . WrongArgs ( ' Either search for user or for packages. ' )
elif len ( args ) == 0 :
2010-09-10 14:20:42 +02:00
try :
pac = store_read_package ( ' . ' )
except oscerr . NoWorkingCopy :
pass
prj = store_read_project ( ' . ' )
elif len ( args ) == 1 :
2012-11-22 11:37:32 +01:00
# it is unclear if one argument is a binary or a project, try binary first for new OBS 2.4
binary = prj = args [ 0 ]
2007-09-03 12:17:26 +02:00
elif len ( args ) == 2 :
2007-09-12 20:01:13 +02:00
prj = args [ 0 ]
pac = args [ 1 ]
2007-09-03 12:17:26 +02:00
else :
2010-02-02 16:14:00 +01:00
raise oscerr . WrongArgs ( ' Wrong number of arguments. ' )
2009-05-18 16:50:43 +02:00
2010-07-29 17:29:07 +02:00
apiurl = self . get_api_url ( )
2014-08-12 15:01:16 +02:00
# Try the OBS 2.4 way first.
2013-02-20 11:41:17 +01:00
if binary or opts . user or opts . group :
2013-05-27 12:41:50 +02:00
limit = None
2013-05-27 12:16:44 +02:00
if opts . all :
2013-05-27 12:41:50 +02:00
limit = 0
filterroles = roles
2013-05-27 12:16:44 +02:00
if filterroles == [ ' bugowner ' , ' maintainer ' ] :
# use server side configured default
2013-05-27 12:41:50 +02:00
filterroles = None
2013-05-27 12:16:44 +02:00
if binary :
searchresult = owner ( apiurl , binary , " binary " , usefilter = filterroles , devel = None , limit = limit )
2014-07-10 09:50:52 +02:00
if searchresult != None and len ( searchresult ) == 0 :
# We talk to an OBS 2.4 or later understanding the call
if opts . set_bugowner or opts . set_bugowner_request :
# filtered search did not succeed, but maybe we want to set an owner initially?
searchresult = owner ( apiurl , binary , " binary " , usefilter = " " , devel = None , limit = - 1 )
if searchresult :
print ( " WARNING: the binary exists, but has no matching maintainership roles defined. " )
print ( " Do you want to set it in the container where the binary appeared first? " )
result = searchresult . find ( ' owner ' )
print ( " This is: " + result . get ( ' project ' ) , end = ' ' )
if result . get ( ' package ' ) :
print ( " / " + result . get ( ' package ' ) )
repl = raw_input ( ' \n Use this container? (y/n) ' )
if repl . lower ( ) != ' y ' :
searchresult = None
else :
print ( " Empty search result, you may want to search with other or all roles via -r ' ' " )
return
2013-05-27 12:16:44 +02:00
elif opts . user :
searchresult = owner ( apiurl , opts . user , " user " , usefilter = filterroles , devel = None )
elif opts . group :
searchresult = owner ( apiurl , opts . group , " group " , usefilter = filterroles , devel = None )
else :
raise oscerr . WrongArgs ( ' osc bug, no valid search criteria ' )
2012-11-23 12:52:05 +01:00
2009-06-18 18:20:49 +02:00
if opts . add :
2012-11-23 12:52:05 +01:00
if searchresult :
for result in searchresult . findall ( ' owner ' ) :
for role in roles :
addPerson ( apiurl , result . get ( ' project ' ) , result . get ( ' package ' ) , opts . add , role )
else :
for role in roles :
addPerson ( apiurl , prj , pac , opts . add , role )
elif opts . set_bugowner or opts . set_bugowner_request :
bugowner = opts . set_bugowner or opts . set_bugowner_request
requestactionsxml = " "
if searchresult :
for result in searchresult . findall ( ' owner ' ) :
if opts . set_bugowner :
2014-05-08 16:07:42 +02:00
setBugownerHelper ( apiurl , result . get ( ' project ' ) , result . get ( ' package ' ) , opts . set_bugowner )
2012-11-23 12:52:05 +01:00
if opts . set_bugowner_request :
2014-05-08 16:07:42 +02:00
args = [ bugowner , result . get ( ' project ' ) ]
if result . get ( ' package ' ) :
args = args + [ result . get ( ' package ' ) ]
requestactionsxml + = self . _set_bugowner ( args , opts )
2012-11-23 12:52:05 +01:00
else :
2013-05-02 11:08:27 +02:00
if opts . set_bugowner :
2014-05-08 16:07:42 +02:00
setBugownerHelper ( apiurl , prj , pac , opts . set_bugowner )
2013-05-02 11:08:27 +02:00
if opts . set_bugowner_request :
2014-05-08 15:41:15 +02:00
args = [ bugowner , prj ]
if pac :
args = args + [ pac ]
requestactionsxml + = self . _set_bugowner ( args , opts )
2012-11-23 12:52:05 +01:00
if requestactionsxml != " " :
2013-05-02 11:38:53 +02:00
if opts . message :
message = opts . message
else :
message = edit_message ( )
2012-11-23 12:52:05 +01:00
import cgi
xml = """ <request> %s <state name= " new " /> <description> %s </description> </request> """ % \
( requestactionsxml , cgi . escape ( message or " " ) )
u = makeurl ( apiurl , [ ' request ' ] , query = ' cmd=create ' )
f = http_POST ( u , data = xml )
root = ET . parse ( f ) . getroot ( )
2013-04-09 12:51:28 +02:00
print ( " Request ID: " , root . get ( ' id ' ) )
2012-11-23 12:52:05 +01:00
2007-09-12 20:01:13 +02:00
elif opts . delete :
2012-11-23 12:52:05 +01:00
if searchresult :
for result in searchresult . findall ( ' owner ' ) :
for role in roles :
2014-05-08 15:26:29 +02:00
delPerson ( apiurl , result . get ( ' project ' ) , result . get ( ' package ' ) , opts . delete , role )
2012-11-23 12:52:05 +01:00
else :
for role in roles :
delPerson ( apiurl , prj , pac , opts . delete , role )
2008-05-20 10:29:54 +02:00
elif opts . devel_project :
2009-12-25 17:19:44 +01:00
# XXX: does it really belong to this command?
2010-07-29 17:29:07 +02:00
setDevelProject ( apiurl , prj , pac , opts . devel_project )
2009-06-23 12:06:31 +02:00
else :
2010-02-02 16:14:00 +01:00
if pac :
2010-07-29 17:29:07 +02:00
m = show_package_meta ( apiurl , prj , pac )
2012-11-22 11:37:32 +01:00
metaroot = ET . fromstring ( ' ' . join ( m ) )
2010-02-02 16:14:00 +01:00
if not opts . nodevelproject :
2012-11-22 11:37:32 +01:00
while metaroot . findall ( ' devel ' ) :
d = metaroot . find ( ' devel ' )
2010-02-02 16:14:00 +01:00
prj = d . get ( ' project ' , prj )
pac = d . get ( ' package ' , pac )
if opts . verbose :
2013-04-09 12:51:28 +02:00
print ( " Following to the development space: %s / %s " % ( prj , pac ) )
2010-07-29 17:29:07 +02:00
m = show_package_meta ( apiurl , prj , pac )
2012-11-22 11:37:32 +01:00
metaroot = ET . fromstring ( ' ' . join ( m ) )
2014-01-24 17:01:35 +01:00
if not metaroot . findall ( ' person ' ) and not metaroot . findall ( ' group ' ) :
2010-02-02 16:14:00 +01:00
if opts . verbose :
2013-04-09 12:51:28 +02:00
print ( " No dedicated persons in package defined, showing the project persons. " )
2010-02-02 16:14:00 +01:00
pac = None
2010-07-29 17:29:07 +02:00
m = show_project_meta ( apiurl , prj )
2012-11-22 11:37:32 +01:00
metaroot = ET . fromstring ( ' ' . join ( m ) )
2010-02-02 16:14:00 +01:00
else :
2012-11-22 11:37:32 +01:00
# fallback to project lookup for old servers
2013-02-20 11:41:17 +01:00
if prj and not searchresult :
2013-05-27 12:16:44 +02:00
m = show_project_meta ( apiurl , prj )
metaroot = ET . fromstring ( ' ' . join ( m ) )
2012-11-22 11:37:32 +01:00
# extract the maintainers
projects = [ ]
# from owner search
if searchresult :
for result in searchresult . findall ( ' owner ' ) :
maintainers = { }
maintainers . setdefault ( " project " , result . get ( ' project ' ) )
maintainers . setdefault ( " package " , result . get ( ' package ' ) )
for person in result . findall ( ' person ' ) :
maintainers . setdefault ( person . get ( ' role ' ) , [ ] ) . append ( person . get ( ' name ' ) )
2013-04-22 17:09:33 +02:00
for group in result . findall ( ' group ' ) :
maintainers . setdefault ( group . get ( ' role ' ) , [ ] ) . append ( " group: " + group . get ( ' name ' ) )
2012-11-22 11:37:32 +01:00
projects = projects + [ maintainers ]
# from meta data
if metaroot :
# we have just one result
maintainers = { }
for person in metaroot . findall ( ' person ' ) :
maintainers . setdefault ( person . get ( ' role ' ) , [ ] ) . append ( person . get ( ' userid ' ) )
2013-04-22 17:09:33 +02:00
for group in metaroot . findall ( ' group ' ) :
maintainers . setdefault ( group . get ( ' role ' ) , [ ] ) . append ( " group: " + group . get ( ' groupid ' ) )
2012-11-22 11:37:32 +01:00
projects = [ maintainers ]
2010-02-02 16:14:00 +01:00
2009-06-18 18:20:49 +02:00
# showing the maintainers
2012-11-22 11:37:32 +01:00
for maintainers in projects :
2013-05-27 12:41:50 +02:00
indent = " "
2013-05-27 13:38:49 +02:00
definingproject = maintainers . get ( " project " )
2013-05-27 12:16:44 +02:00
if definingproject :
2013-05-27 13:38:49 +02:00
definingpackage = maintainers . get ( " package " )
2013-05-27 12:41:50 +02:00
indent = " "
2013-05-27 12:16:44 +02:00
if definingpackage :
2013-05-27 13:38:49 +02:00
print ( " Defined in package: %s / %s " % ( definingproject , definingpackage ) )
2013-05-27 12:16:44 +02:00
else :
print ( " Defined in project: " , definingproject )
2014-08-12 15:01:16 +02:00
if prj :
2013-05-27 12:16:44 +02:00
# not for user/group search
for role in roles :
if opts . bugowner and not len ( maintainers . get ( role , [ ] ) ) :
role = ' maintainer '
if pac :
print ( " %s %s of %s / %s : " % ( indent , role , prj , pac ) )
else :
print ( " %s %s of %s : " % ( indent , role , prj ) )
if opts . email :
emails = [ ]
for maintainer in maintainers . get ( role , [ ] ) :
2014-02-11 11:56:44 +01:00
user = get_maintainer_data ( apiurl , maintainer , verbose = False )
2013-05-27 12:16:44 +02:00
if len ( user ) :
emails . append ( ' ' . join ( user ) )
print ( indent , end = ' ' )
print ( ' , ' . join ( emails ) or ' - ' )
elif opts . verbose :
userdata = [ ]
for maintainer in maintainers . get ( role , [ ] ) :
2014-02-11 11:56:44 +01:00
user = get_maintainer_data ( apiurl , maintainer , verbose = True )
2013-05-27 12:16:44 +02:00
userdata . append ( user [ 0 ] )
if user [ 1 ] != ' - ' :
userdata . append ( " %s < %s > " % ( user [ 1 ] , user [ 2 ] ) )
else :
userdata . append ( user [ 2 ] )
for row in build_table ( 2 , userdata , None , 3 ) :
print ( indent , end = ' ' )
print ( row )
else :
print ( indent , end = ' ' )
print ( ' , ' . join ( maintainers . get ( role , [ ] ) ) or ' - ' )
print ( )
2007-09-03 12:17:26 +02:00
2011-04-11 20:48:59 +02:00
@cmdln.alias ( ' who ' )
@cmdln.alias ( ' user ' )
2011-09-20 15:24:46 +02:00
def do_whois ( self , subcmd , opts , * usernames ) :
2011-04-11 20:48:59 +02:00
""" $ {cmd_name} : Show fullname and email of a buildservice user
$ { cmd_usage }
$ { cmd_option_list }
"""
apiurl = self . get_api_url ( )
2011-09-20 15:24:46 +02:00
if len ( usernames ) < 1 :
2013-04-09 11:33:25 +02:00
if ' user ' not in conf . config [ ' api_host_options ' ] [ apiurl ] :
2011-04-11 20:48:59 +02:00
raise oscerr . WrongArgs ( ' your .oscrc does not have your user name. ' )
2011-09-20 15:24:46 +02:00
usernames = ( conf . config [ ' api_host_options ' ] [ apiurl ] [ ' user ' ] , )
for name in usernames :
user = get_user_data ( apiurl , name , ' login ' , ' realname ' , ' email ' )
if len ( user ) == 3 :
2013-04-09 12:51:28 +02:00
print ( " %s : \" %s \" < %s > " % ( user [ 0 ] , user [ 1 ] , user [ 2 ] ) )
2011-04-11 20:48:59 +02:00
2007-09-03 12:17:26 +02:00
2008-01-15 19:58:58 +01:00
@cmdln.option ( ' -r ' , ' --revision ' , metavar = ' rev ' ,
help = ' print out the specified revision ' )
2009-08-20 21:28:05 +02:00
@cmdln.option ( ' -e ' , ' --expand ' , action = ' store_true ' ,
2010-03-08 10:56:29 +01:00
help = ' force expansion of linked packages. ' )
@cmdln.option ( ' -u ' , ' --unexpand ' , action = ' store_true ' ,
help = ' always work with unexpanded packages. ' )
2011-06-08 10:25:15 +02:00
@cmdln.option ( ' -M ' , ' --meta ' , action = ' store_true ' ,
help = ' list meta data files ' )
2011-01-12 17:04:22 +01:00
@cmdln.alias ( ' less ' )
2007-11-02 19:18:30 +01:00
def do_cat ( self , subcmd , opts , * args ) :
2007-12-10 15:23:58 +01:00
""" $ {cmd_name} : Output the content of a file to standard output
2007-07-25 12:56:04 +02:00
2007-11-02 19:18:30 +01:00
Examples :
osc cat project package file
osc cat project / package / file
2009-09-03 19:28:27 +02:00
osc cat http : / / api . opensuse . org / build / . . . / _log
osc cat http : / / api . opensuse . org / source / . . / _link
2007-11-02 19:18:30 +01:00
$ { cmd_usage }
$ { cmd_option_list }
"""
2009-09-03 19:28:27 +02:00
if len ( args ) == 1 and ( args [ 0 ] . startswith ( ' http:// ' ) or
args [ 0 ] . startswith ( ' https:// ' ) ) :
2009-10-20 16:30:15 +02:00
opts . method = ' GET '
opts . headers = None
opts . data = None
opts . file = None
return self . do_api ( ' list ' , opts , * args )
2009-09-03 19:28:27 +02:00
2007-11-02 19:18:30 +01:00
args = slash_split ( args )
if len ( args ) != 3 :
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
raise oscerr . WrongArgs ( ' Wrong number of arguments. ' )
2008-01-15 19:58:58 +01:00
rev , dummy = parseRevisionOption ( opts . revision )
2010-07-29 17:29:07 +02:00
apiurl = self . get_api_url ( )
2007-12-10 15:23:58 +01:00
2009-08-20 21:28:05 +02:00
query = { }
2011-06-08 10:25:15 +02:00
if opts . meta :
query [ ' meta ' ] = 1
2009-04-09 17:52:59 +02:00
if opts . revision :
2009-08-20 21:28:05 +02:00
query [ ' rev ' ] = opts . revision
if opts . expand :
2011-06-08 10:25:15 +02:00
query [ ' rev ' ] = show_upstream_srcmd5 ( apiurl , args [ 0 ] , args [ 1 ] , expand = True , revision = opts . revision , meta = opts . meta )
2010-07-29 17:29:07 +02:00
u = makeurl ( apiurl , [ ' source ' , args [ 0 ] , args [ 1 ] , args [ 2 ] ] , query = query )
2010-03-08 01:31:36 +01:00
try :
2011-01-22 16:41:06 +01:00
if subcmd == ' less ' :
2011-01-12 17:04:22 +01:00
f = http_GET ( u )
run_pager ( ' ' . join ( f . readlines ( ) ) )
else :
for data in streamfile ( u ) :
sys . stdout . write ( data )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2010-03-08 10:56:29 +01:00
if e . code == 404 and not opts . expand and not opts . unexpand :
2013-04-09 12:51:28 +02:00
print ( ' expanding link... ' , file = sys . stderr )
2010-07-29 17:29:07 +02:00
query [ ' rev ' ] = show_upstream_srcmd5 ( apiurl , args [ 0 ] , args [ 1 ] , expand = True , revision = opts . revision )
u = makeurl ( apiurl , [ ' source ' , args [ 0 ] , args [ 1 ] , args [ 2 ] ] , query = query )
2011-01-21 11:04:47 +01:00
if subcmd == " less " :
2011-01-12 17:04:22 +01:00
f = http_GET ( u )
run_pager ( ' ' . join ( f . readlines ( ) ) )
else :
2011-01-22 16:41:06 +01:00
for data in streamfile ( u ) :
sys . stdout . write ( data )
2010-03-08 01:31:36 +01:00
else :
e . osc_msg = ' If linked, try: cat -e '
raise e
2007-12-10 15:23:58 +01:00
2009-04-21 18:52:26 +02:00
# helper function to download a file from a specific revision
def download ( self , name , md5 , dir , destfile ) :
2009-05-22 17:00:31 +02:00
o = open ( destfile , ' wb ' )
2009-04-22 11:06:13 +02:00
if md5 != ' ' :
query = { ' rev ' : dir [ ' srcmd5 ' ] }
u = makeurl ( dir [ ' apiurl ' ] , [ ' source ' , dir [ ' project ' ] , dir [ ' package ' ] , pathname2url ( name ) ] , query = query )
for buf in streamfile ( u , http_GET , BUFSIZE ) :
o . write ( buf )
2010-05-03 16:06:33 +02:00
o . close ( )
2009-04-21 18:52:26 +02:00
2009-04-23 10:58:21 +02:00
2009-04-21 18:52:26 +02:00
@cmdln.option ( ' -d ' , ' --destdir ' , default = ' repairlink ' , metavar = ' DIR ' ,
2009-04-22 11:06:13 +02:00
help = ' destination directory ' )
2009-04-23 10:58:21 +02:00
def do_repairlink ( self , subcmd , opts , * args ) :
2009-04-22 11:06:13 +02:00
""" $ {cmd_name} : Repair a broken source link
2009-04-23 10:58:21 +02:00
This command checks out a package with merged source changes . It uses
a 3 - way merge to resolve file conflicts . After reviewing / repairing
2009-10-20 16:30:15 +02:00
the merge , use ' osc resolved ... ' and ' osc ci ' to re - create a
2009-08-20 21:28:05 +02:00
working source link .
2009-04-23 10:58:21 +02:00
2009-05-18 16:50:43 +02:00
usage :
2009-05-04 11:13:35 +02:00
* For merging conflicting changes of a checkout package :
2009-04-23 10:58:21 +02:00
osc repairlink
2009-05-04 11:13:35 +02:00
* Check out a package and merge changes :
2009-04-23 10:58:21 +02:00
osc repairlink PROJECT PACKAGE
2009-05-04 11:13:35 +02:00
* Pull conflicting changes from one project into another one :
osc repairlink PROJECT PACKAGE INTO_PROJECT [ INTO_PACKAGE ]
2009-04-22 11:06:13 +02:00
$ { cmd_option_list }
"""
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2012-11-01 20:02:14 +01:00
args = slash_split ( args )
2009-05-07 20:43:04 +02:00
if len ( args ) > = 3 and len ( args ) < = 4 :
2009-04-23 10:58:21 +02:00
prj = args [ 0 ]
2009-05-04 11:13:35 +02:00
package = target_package = args [ 1 ]
target_prj = args [ 2 ]
if len ( args ) == 4 :
2009-10-20 16:30:15 +02:00
target_package = args [ 3 ]
2009-05-07 20:43:04 +02:00
elif len ( args ) == 2 :
2009-05-04 11:13:35 +02:00
target_prj = prj = args [ 0 ]
target_package = package = args [ 1 ]
2009-05-07 20:43:04 +02:00
elif is_package_dir ( os . getcwd ( ) ) :
target_prj = prj = store_read_project ( os . getcwd ( ) )
target_package = package = store_read_package ( os . getcwd ( ) )
2009-04-23 10:58:21 +02:00
else :
2009-05-07 20:43:04 +02:00
raise oscerr . WrongArgs ( ' Please specify project and package ' )
2009-04-22 11:06:13 +02:00
2009-04-27 12:09:38 +02:00
# first try stored reference, then lastworking
query = { ' rev ' : ' latest ' }
2009-04-22 11:06:13 +02:00
u = makeurl ( apiurl , [ ' source ' , prj , package ] , query = query )
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
linkinfo = root . find ( ' linkinfo ' )
if linkinfo == None :
raise oscerr . APIError ( ' package is not a source link ' )
if linkinfo . get ( ' error ' ) == None :
raise oscerr . APIError ( ' source link is not broken ' )
2009-04-27 12:09:38 +02:00
workingrev = None
2015-10-23 11:08:30 +02:00
if linkinfo . get ( ' baserev ' ) :
query = { ' rev ' : ' latest ' , ' linkrev ' : ' base ' }
2009-04-27 12:09:38 +02:00
u = makeurl ( apiurl , [ ' source ' , prj , package ] , query = query )
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
linkinfo = root . find ( ' linkinfo ' )
if linkinfo . get ( ' error ' ) == None :
workingrev = linkinfo . get ( ' xsrcmd5 ' )
if workingrev == None :
query = { ' lastworking ' : 1 }
u = makeurl ( apiurl , [ ' source ' , prj , package ] , query = query )
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
linkinfo = root . find ( ' linkinfo ' )
if linkinfo == None :
raise oscerr . APIError ( ' package is not a source link ' )
if linkinfo . get ( ' error ' ) == None :
raise oscerr . APIError ( ' source link is not broken ' )
workingrev = linkinfo . get ( ' lastworking ' )
if workingrev == None :
raise oscerr . APIError ( ' source link never worked ' )
2013-04-09 12:51:28 +02:00
print ( " using last working link target " )
2009-04-27 12:09:38 +02:00
else :
2013-04-09 12:51:28 +02:00
print ( " using link target of last commit " )
2009-04-22 11:06:13 +02:00
query = { ' expand ' : 1 , ' emptylink ' : 1 }
u = makeurl ( apiurl , [ ' source ' , prj , package ] , query = query )
f = http_GET ( u )
meta = f . readlines ( )
2009-12-26 14:22:34 +01:00
root_new = ET . fromstring ( ' ' . join ( meta ) )
2009-04-22 15:14:17 +02:00
dir_new = { ' apiurl ' : apiurl , ' project ' : prj , ' package ' : package }
2009-04-22 11:06:13 +02:00
dir_new [ ' srcmd5 ' ] = root_new . get ( ' srcmd5 ' )
2009-05-07 21:13:50 +02:00
dir_new [ ' entries ' ] = [ [ n . get ( ' name ' ) , n . get ( ' md5 ' ) ] for n in root_new . findall ( ' entry ' ) ]
2009-04-22 11:06:13 +02:00
2009-04-27 12:09:38 +02:00
query = { ' rev ' : workingrev }
2009-04-22 11:06:13 +02:00
u = makeurl ( apiurl , [ ' source ' , prj , package ] , query = query )
f = http_GET ( u )
root_oldpatched = ET . parse ( f ) . getroot ( )
linkinfo_oldpatched = root_oldpatched . find ( ' linkinfo ' )
if linkinfo_oldpatched == None :
2009-04-27 12:09:38 +02:00
raise oscerr . APIError ( ' working rev is not a source link? ' )
2009-04-22 11:06:13 +02:00
if linkinfo_oldpatched . get ( ' error ' ) != None :
2009-04-27 12:09:38 +02:00
raise oscerr . APIError ( ' working rev is not working? ' )
2009-04-22 15:14:17 +02:00
dir_oldpatched = { ' apiurl ' : apiurl , ' project ' : prj , ' package ' : package }
2009-04-22 11:06:13 +02:00
dir_oldpatched [ ' srcmd5 ' ] = root_oldpatched . get ( ' srcmd5 ' )
2009-05-07 21:13:50 +02:00
dir_oldpatched [ ' entries ' ] = [ [ n . get ( ' name ' ) , n . get ( ' md5 ' ) ] for n in root_oldpatched . findall ( ' entry ' ) ]
2009-04-22 11:06:13 +02:00
query = { }
query [ ' rev ' ] = linkinfo_oldpatched . get ( ' srcmd5 ' )
u = makeurl ( apiurl , [ ' source ' , linkinfo_oldpatched . get ( ' project ' ) , linkinfo_oldpatched . get ( ' package ' ) ] , query = query )
f = http_GET ( u )
root_old = ET . parse ( f ) . getroot ( )
2009-04-22 15:14:17 +02:00
dir_old = { ' apiurl ' : apiurl }
2009-04-22 11:06:13 +02:00
dir_old [ ' project ' ] = linkinfo_oldpatched . get ( ' project ' )
dir_old [ ' package ' ] = linkinfo_oldpatched . get ( ' package ' )
2009-04-22 15:14:17 +02:00
dir_old [ ' srcmd5 ' ] = root_old . get ( ' srcmd5 ' )
2009-05-07 21:13:50 +02:00
dir_old [ ' entries ' ] = [ [ n . get ( ' name ' ) , n . get ( ' md5 ' ) ] for n in root_old . findall ( ' entry ' ) ]
2009-04-22 11:06:13 +02:00
entries_old = dict ( dir_old [ ' entries ' ] )
entries_oldpatched = dict ( dir_oldpatched [ ' entries ' ] )
entries_new = dict ( dir_new [ ' entries ' ] )
entries = { }
entries . update ( entries_old )
entries . update ( entries_oldpatched )
entries . update ( entries_new )
destdir = opts . destdir
if os . path . isdir ( destdir ) :
shutil . rmtree ( destdir )
os . mkdir ( destdir )
2010-08-30 13:46:49 +02:00
Package . init_package ( apiurl , target_prj , target_package , destdir )
2010-08-30 14:20:12 +02:00
store_write_string ( destdir , ' _files ' , ' ' . join ( meta ) + ' \n ' )
2009-10-20 16:30:15 +02:00
store_write_string ( destdir , ' _linkrepair ' , ' ' )
2009-04-22 11:06:13 +02:00
pac = Package ( destdir )
storedir = os . path . join ( destdir , store )
for name in sorted ( entries . keys ( ) ) :
md5_old = entries_old . get ( name , ' ' )
md5_new = entries_new . get ( name , ' ' )
md5_oldpatched = entries_oldpatched . get ( name , ' ' )
if md5_new != ' ' :
self . download ( name , md5_new , dir_new , os . path . join ( storedir , name ) )
if md5_old == md5_new :
if md5_oldpatched == ' ' :
pac . put_on_deletelist ( name )
continue
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' ' , name ) )
2009-04-22 11:06:13 +02:00
self . download ( name , md5_oldpatched , dir_oldpatched , os . path . join ( destdir , name ) )
continue
if md5_old == md5_oldpatched :
if md5_new == ' ' :
continue
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' U ' , name ) )
2009-04-22 11:06:13 +02:00
shutil . copy2 ( os . path . join ( storedir , name ) , os . path . join ( destdir , name ) )
continue
if md5_new == md5_oldpatched :
if md5_new == ' ' :
continue
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' G ' , name ) )
2009-04-22 11:06:13 +02:00
shutil . copy2 ( os . path . join ( storedir , name ) , os . path . join ( destdir , name ) )
continue
self . download ( name , md5_oldpatched , dir_oldpatched , os . path . join ( destdir , name + ' .mine ' ) )
if md5_new != ' ' :
shutil . copy2 ( os . path . join ( storedir , name ) , os . path . join ( destdir , name + ' .new ' ) )
else :
self . download ( name , md5_new , dir_new , os . path . join ( destdir , name + ' .new ' ) )
self . download ( name , md5_old , dir_old , os . path . join ( destdir , name + ' .old ' ) )
2009-04-23 11:03:59 +02:00
if binary_file ( os . path . join ( destdir , name + ' .mine ' ) ) or \
binary_file ( os . path . join ( destdir , name + ' .old ' ) ) or \
binary_file ( os . path . join ( destdir , name + ' .new ' ) ) :
shutil . copy2 ( os . path . join ( destdir , name + ' .new ' ) , os . path . join ( destdir , name ) )
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' C ' , name ) )
2009-04-23 11:03:59 +02:00
pac . put_on_conflictlist ( name )
continue
2009-05-22 17:00:31 +02:00
o = open ( os . path . join ( destdir , name ) , ' wb ' )
2013-03-08 00:56:57 +01:00
code = run_external ( ' diff3 ' , ' -m ' , ' -E ' ,
2009-04-22 11:06:13 +02:00
' -L ' , ' .mine ' ,
2009-04-21 18:52:26 +02:00
os . path . join ( destdir , name + ' .mine ' ) ,
2009-04-22 11:06:13 +02:00
' -L ' , ' .old ' ,
2009-04-21 18:52:26 +02:00
os . path . join ( destdir , name + ' .old ' ) ,
2009-04-22 11:06:13 +02:00
' -L ' , ' .new ' ,
2009-04-21 18:52:26 +02:00
os . path . join ( destdir , name + ' .new ' ) ,
2013-03-08 00:56:57 +01:00
stdout = o )
2009-04-22 11:06:13 +02:00
if code == 0 :
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' G ' , name ) )
2009-04-27 12:09:38 +02:00
os . unlink ( os . path . join ( destdir , name + ' .mine ' ) )
os . unlink ( os . path . join ( destdir , name + ' .old ' ) )
os . unlink ( os . path . join ( destdir , name + ' .new ' ) )
2009-04-22 11:06:13 +02:00
elif code == 1 :
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' C ' , name ) )
2009-04-22 11:06:13 +02:00
pac . put_on_conflictlist ( name )
else :
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' ? ' , name ) )
2009-04-22 11:06:13 +02:00
pac . put_on_conflictlist ( name )
pac . write_deletelist ( )
pac . write_conflictlist ( )
2013-04-09 12:51:28 +02:00
print ( )
print ( ' Please change into the \' %s \' directory, ' % destdir )
print ( ' fix the conflicts (files marked with \' C \' above), ' )
print ( ' run \' osc resolved ... \' , and commit the changes. ' )
2009-04-21 18:52:26 +02:00
2009-10-16 16:16:25 +02:00
2009-12-17 17:16:56 +01:00
def do_pull ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : merge the changes of the link target into your working copy.
$ { cmd_option_list }
"""
if not is_package_dir ( ' . ' ) :
2009-12-17 20:20:35 +01:00
raise oscerr . NoWorkingCopy ( ' Error: \' %s \' is not an osc working copy. ' % os . path . abspath ( ' . ' ) )
p = Package ( ' . ' )
2009-12-17 17:16:56 +01:00
# check if everything is committed
2009-12-17 20:20:35 +01:00
for filename in p . filenamelist :
2010-07-28 12:08:40 +02:00
state = p . status ( filename )
if state != ' ' and state != ' S ' :
2009-12-17 20:20:35 +01:00
raise oscerr . WrongArgs ( ' Please commit your local changes first! ' )
2009-12-17 17:16:56 +01:00
# check if we need to update
upstream_rev = p . latest_rev ( )
2011-02-14 12:26:51 +01:00
if not ( p . isfrozen ( ) or p . ispulled ( ) ) :
raise oscerr . WrongArgs ( ' osc pull makes only sense with a detached head, did you mean osc up? ' )
2009-12-17 17:16:56 +01:00
if p . rev != upstream_rev :
2009-12-17 20:20:35 +01:00
raise oscerr . WorkingCopyOutdated ( ( p . absdir , p . rev , upstream_rev ) )
elif not p . islink ( ) :
raise oscerr . WrongArgs ( ' osc pull only works on linked packages. ' )
elif not p . isexpanded ( ) :
raise oscerr . WrongArgs ( ' osc pull only works on expanded links. ' )
2010-01-11 17:00:24 +01:00
linkinfo = p . linkinfo
baserev = linkinfo . baserev
if baserev == None :
raise oscerr . WrongArgs ( ' osc pull only works on links containing a base revision. ' )
2009-12-17 20:20:35 +01:00
2010-01-11 17:00:24 +01:00
# get revisions we need
query = { ' expand ' : 1 , ' emptylink ' : 1 }
u = makeurl ( p . apiurl , [ ' source ' , p . prjname , p . name ] , query = query )
f = http_GET ( u )
meta = f . readlines ( )
root_new = ET . fromstring ( ' ' . join ( meta ) )
linkinfo_new = root_new . find ( ' linkinfo ' )
if linkinfo_new == None :
raise oscerr . APIError ( ' link is not a really a link? ' )
if linkinfo_new . get ( ' error ' ) != None :
raise oscerr . APIError ( ' link target is broken ' )
2010-01-14 20:16:10 +01:00
if linkinfo_new . get ( ' srcmd5 ' ) == baserev :
2013-04-09 12:51:28 +02:00
print ( " Already up-to-date. " )
2010-01-20 17:55:44 +01:00
p . unmark_frozen ( )
2010-01-11 17:00:24 +01:00
return
dir_new = { ' apiurl ' : p . apiurl , ' project ' : p . prjname , ' package ' : p . name }
dir_new [ ' srcmd5 ' ] = root_new . get ( ' srcmd5 ' )
dir_new [ ' entries ' ] = [ [ n . get ( ' name ' ) , n . get ( ' md5 ' ) ] for n in root_new . findall ( ' entry ' ) ]
2009-12-17 17:16:56 +01:00
2010-01-11 17:00:24 +01:00
dir_oldpatched = { ' apiurl ' : p . apiurl , ' project ' : p . prjname , ' package ' : p . name , ' srcmd5 ' : p . srcmd5 }
2010-01-14 20:16:10 +01:00
dir_oldpatched [ ' entries ' ] = [ [ f . name , f . md5 ] for f in p . filelist ]
2010-02-28 02:30:13 +01:00
2010-01-11 17:00:24 +01:00
query = { ' rev ' : linkinfo . srcmd5 }
u = makeurl ( p . apiurl , [ ' source ' , linkinfo . project , linkinfo . package ] , query = query )
f = http_GET ( u )
root_old = ET . parse ( f ) . getroot ( )
dir_old = { ' apiurl ' : p . apiurl , ' project ' : linkinfo . project , ' package ' : linkinfo . package , ' srcmd5 ' : linkinfo . srcmd5 }
dir_old [ ' entries ' ] = [ [ n . get ( ' name ' ) , n . get ( ' md5 ' ) ] for n in root_old . findall ( ' entry ' ) ]
# now do 3-way merge
entries_old = dict ( dir_old [ ' entries ' ] )
entries_oldpatched = dict ( dir_oldpatched [ ' entries ' ] )
entries_new = dict ( dir_new [ ' entries ' ] )
entries = { }
entries . update ( entries_old )
entries . update ( entries_oldpatched )
entries . update ( entries_new )
for name in sorted ( entries . keys ( ) ) :
2011-03-17 15:35:22 +01:00
if name . startswith ( ' _service: ' ) or name . startswith ( ' _service_ ' ) :
2013-04-09 14:22:45 +02:00
continue
2010-01-11 17:00:24 +01:00
md5_old = entries_old . get ( name , ' ' )
md5_new = entries_new . get ( name , ' ' )
md5_oldpatched = entries_oldpatched . get ( name , ' ' )
if md5_old == md5_new or md5_oldpatched == md5_new :
2010-01-14 20:16:10 +01:00
continue
2010-01-11 17:00:24 +01:00
if md5_old == md5_oldpatched :
if md5_new == ' ' :
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' D ' , name ) )
2010-01-11 17:00:24 +01:00
p . put_on_deletelist ( name )
2010-01-14 20:16:10 +01:00
os . unlink ( name )
2010-10-29 17:41:39 +02:00
elif md5_old == ' ' :
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' A ' , name ) )
2010-10-29 17:41:39 +02:00
self . download ( name , md5_new , dir_new , name )
p . put_on_addlist ( name )
2010-01-11 17:00:24 +01:00
else :
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' U ' , name ) )
2010-01-11 17:00:24 +01:00
self . download ( name , md5_new , dir_new , name )
2010-01-14 20:16:10 +01:00
continue
# need diff3 to resolve issue
if md5_oldpatched == ' ' :
open ( name , ' w ' ) . write ( ' ' )
os . rename ( name , name + ' .mine ' )
self . download ( name , md5_new , dir_new , name + ' .new ' )
2010-01-11 17:00:24 +01:00
self . download ( name , md5_old , dir_old , name + ' .old ' )
if binary_file ( name + ' .mine ' ) or binary_file ( name + ' .old ' ) or binary_file ( name + ' .new ' ) :
shutil . copy2 ( name + ' .new ' , name )
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' C ' , name ) )
2010-01-11 17:00:24 +01:00
p . put_on_conflictlist ( name )
continue
o = open ( name , ' wb ' )
2013-03-08 00:56:57 +01:00
code = run_external ( ' diff3 ' , ' -m ' , ' -E ' ,
2010-01-11 17:00:24 +01:00
' -L ' , ' .mine ' , name + ' .mine ' ,
' -L ' , ' .old ' , name + ' .old ' ,
' -L ' , ' .new ' , name + ' .new ' ,
2013-03-08 00:56:57 +01:00
stdout = o )
2010-01-11 17:00:24 +01:00
if code == 0 :
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' G ' , name ) )
2010-01-11 17:00:24 +01:00
os . unlink ( name + ' .mine ' )
os . unlink ( name + ' .old ' )
os . unlink ( name + ' .new ' )
elif code == 1 :
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' C ' , name ) )
2010-01-11 17:00:24 +01:00
p . put_on_conflictlist ( name )
else :
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' ? ' , name ) )
2010-01-11 17:00:24 +01:00
p . put_on_conflictlist ( name )
p . write_deletelist ( )
2010-10-29 17:41:39 +02:00
p . write_addlist ( )
2010-01-11 17:00:24 +01:00
p . write_conflictlist ( )
# store new linkrev
2010-08-30 14:20:12 +02:00
store_write_string ( p . absdir , ' _pulled ' , linkinfo_new . get ( ' srcmd5 ' ) + ' \n ' )
2010-01-20 17:55:44 +01:00
p . unmark_frozen ( )
2013-04-09 12:51:28 +02:00
print ( )
2010-01-14 20:16:10 +01:00
if len ( p . in_conflict ) :
2013-04-09 12:51:28 +02:00
print ( ' Please fix the conflicts (files marked with \' C \' above), ' )
print ( ' run \' osc resolved ... \' , and commit the changes ' )
print ( ' to update the link information. ' )
2010-01-14 20:16:10 +01:00
else :
2013-04-09 12:51:28 +02:00
print ( ' Please commit the changes to update the link information. ' )
2009-12-17 17:16:56 +01:00
2009-10-16 16:12:55 +02:00
@cmdln.option ( ' --create ' , action = ' store_true ' , default = False ,
help = ' create new gpg signing key for this project ' )
2010-07-13 13:53:47 +02:00
@cmdln.option ( ' --extend ' , action = ' store_true ' , default = False ,
help = ' extend expiration date of the gpg public key for this project ' )
2009-10-16 16:12:55 +02:00
@cmdln.option ( ' --delete ' , action = ' store_true ' , default = False ,
help = ' delete the gpg signing key in this project ' )
2009-11-26 11:56:28 +01:00
@cmdln.option ( ' --notraverse ' , action = ' store_true ' , default = False ,
help = ' don \' traverse projects upwards to find key ' )
2013-08-30 09:41:13 +02:00
@cmdln.option ( ' --sslcert ' , action = ' store_true ' , default = False ,
help = ' fetch SSL certificate instead of GPG key ' )
2009-10-16 16:12:55 +02:00
def do_signkey ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Manage Project Signing Key
2010-07-13 13:53:47 +02:00
osc signkey [ - - create | - - delete | - - extend ] < PROJECT >
2009-11-26 11:56:28 +01:00
osc signkey [ - - notraverse ] < PROJECT >
2009-10-16 16:12:55 +02:00
This command is for managing gpg keys . It shows the public key
2009-10-20 16:30:15 +02:00
by default . There is no way to download or upload the private
2009-10-16 16:12:55 +02:00
part of a key by design .
However you can create a new own key . You may want to consider
to sign the public key with your own existing key .
If a project has no key , the key from upper level project will
be used ( eg . when dropping " KDE:KDE4:Community " key , the one from
" KDE:KDE4 " will be used ) .
2009-10-16 16:33:55 +02:00
WARNING : THE OLD KEY WILL NOT BE RESTORABLE WHEN USING DELETE OR CREATE
2009-10-16 16:12:55 +02:00
$ { cmd_usage }
$ { cmd_option_list }
"""
2010-04-30 17:13:21 +02:00
apiurl = self . get_api_url ( )
2009-10-16 16:12:55 +02:00
f = None
2009-11-26 11:56:28 +01:00
prj = None
if len ( args ) == 0 :
2010-08-20 14:34:41 +02:00
cwd = os . getcwd ( )
if is_project_dir ( cwd ) or is_package_dir ( cwd ) :
prj = store_read_project ( cwd )
2009-10-16 16:12:55 +02:00
if len ( args ) == 1 :
prj = args [ 0 ]
2009-11-26 11:56:28 +01:00
if not prj :
2009-10-16 16:12:55 +02:00
raise oscerr . WrongArgs ( ' Please specify just the project ' )
if opts . create :
2009-10-20 16:30:15 +02:00
url = makeurl ( apiurl , [ ' source ' , prj ] , query = ' cmd=createkey ' )
f = http_POST ( url )
2010-07-13 13:53:47 +02:00
elif opts . extend :
2010-07-13 14:53:25 +02:00
url = makeurl ( apiurl , [ ' source ' , prj ] , query = ' cmd=extendkey ' )
2010-07-13 13:53:47 +02:00
f = http_POST ( url )
2009-10-16 16:12:55 +02:00
elif opts . delete :
2009-10-20 16:30:15 +02:00
url = makeurl ( apiurl , [ ' source ' , prj , " _pubkey " ] )
f = http_DELETE ( url )
2009-10-16 16:12:55 +02:00
else :
2010-08-08 23:45:04 +02:00
while True :
2009-11-26 11:56:28 +01:00
try :
2010-08-08 23:45:04 +02:00
url = makeurl ( apiurl , [ ' source ' , prj , ' _pubkey ' ] )
2013-08-30 09:41:13 +02:00
if opts . sslcert :
2013-09-05 14:54:15 +02:00
url = makeurl ( apiurl , [ ' source ' , prj , ' _project ' , ' _sslcert ' ] , ' meta=1 ' )
2009-11-26 11:56:28 +01:00
f = http_GET ( url )
break
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2009-11-26 11:56:28 +01:00
l = prj . rsplit ( ' : ' , 1 )
# try key from parent project
2010-08-08 23:45:04 +02:00
if not opts . notraverse and len ( l ) > 1 and l [ 0 ] and l [ 1 ] and e . code == 404 :
2013-04-09 12:51:28 +02:00
print ( ' %s has no key, trying %s ' % ( prj , l [ 0 ] ) )
2010-08-08 23:45:04 +02:00
prj = l [ 0 ]
2009-11-26 11:56:28 +01:00
else :
2009-12-12 15:02:58 +01:00
raise
2009-10-16 16:12:55 +02:00
2010-03-17 15:28:10 +01:00
while True :
2009-10-16 16:12:55 +02:00
buf = f . read ( 16384 )
2010-03-17 15:28:10 +01:00
if not buf :
break
sys . stdout . write ( buf )
2009-10-16 16:12:55 +02:00
2009-04-20 15:40:33 +02:00
@cmdln.option ( ' -m ' , ' --message ' ,
2014-02-05 17:50:31 +01:00
help = ' add MESSAGE to changes (do not open an editor) ' )
@cmdln.option ( ' -F ' , ' --file ' , metavar = ' FILE ' ,
help = ' read changes message from FILE (do not open an editor) ' )
2009-04-22 16:44:17 +02:00
@cmdln.option ( ' -e ' , ' --just-edit ' , action = ' store_true ' , default = False ,
2009-04-27 12:09:38 +02:00
help = ' just open changes (cannot be used with -m) ' )
2009-04-20 15:40:33 +02:00
def do_vc ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : Edit the changes file
2009-04-22 16:44:17 +02:00
osc vc [ - m MESSAGE | - e ] [ filename [ . changes ] | path [ file_with_comment ] ]
2009-04-20 15:40:33 +02:00
If no < filename > is given , exactly one * . changes or * . spec file has to
be in the cwd or in path .
2010-01-02 12:25:37 +01:00
The email address used in . changes file is read from BuildService
2009-04-20 15:40:33 +02:00
instance , or should be defined in ~ / . oscrc
[ https : / / api . opensuse . org / ]
user = login
pass = password
email = user @defined.email
or can be specified via mailaddr environment variable .
$ { cmd_usage }
$ { cmd_option_list }
"""
2009-05-18 16:50:43 +02:00
2010-07-26 16:46:21 +02:00
from subprocess import Popen
2014-02-05 17:50:31 +01:00
if opts . message and opts . file :
raise oscerr . WrongOptions ( ' \' --message \' and \' --file \' are mutually exclusive ' )
elif opts . message and opts . just_edit :
raise oscerr . WrongOptions ( ' \' --message \' and \' --just-edit \' are mutually exclusive ' )
elif opts . file and opts . just_edit :
raise oscerr . WrongOptions ( ' \' --file \' and \' --just-edit \' are mutually exclusive ' )
2010-08-20 13:00:57 +02:00
meego_style = False
if not args :
import glob , re
try :
fn_changelog = glob . glob ( ' *.changes ' ) [ 0 ]
fp = file ( fn_changelog )
titleline = fp . readline ( )
fp . close ( )
if re . match ( ' ^ \ * \ W+(.+ \ W+ \ d { 1,2} \ W+20 \ d {2} ) \ W+(.+) \ W+<(.+)> \ W+(.+)$ ' , titleline ) :
meego_style = True
except IndexError :
pass
2009-04-20 15:40:33 +02:00
2014-10-01 14:45:48 +02:00
cmd_list = [ conf . config [ ' vc-cmd ' ] ]
2010-08-20 13:00:57 +02:00
if meego_style :
if not os . path . exists ( ' /usr/bin/vc ' ) :
2013-04-09 12:51:28 +02:00
print ( ' Error: you need meego-packaging-tools for /usr/bin/vc command ' , file = sys . stderr )
2010-08-20 13:00:57 +02:00
return 1
2010-08-23 10:08:09 +02:00
cmd_list = [ ' /usr/bin/vc ' ]
2014-10-01 14:45:48 +02:00
elif which ( cmd_list [ 0 ] ) is None :
print ( ' Error: vc ( \' %s \' ) command not found ' % cmd_list [ 0 ] , file = sys . stderr )
print ( ' Install the build package from http://download.opensuse.org/repositories/openSUSE:/Tools/ ' , file = sys . stderr )
return 1
2009-04-20 15:40:33 +02:00
2016-09-23 16:37:23 +02:00
if args and is_package_dir ( args [ 0 ] ) :
apiurl = store_read_apiurl ( args [ 0 ] )
else :
apiurl = self . get_api_url ( )
2009-04-20 15:40:33 +02:00
2016-09-23 16:37:23 +02:00
# set user's email if the mailaddr env variable is not set
if ' mailaddr ' in os . environ :
pass
elif ' email ' in conf . config [ ' api_host_options ' ] [ apiurl ] :
os . environ [ ' mailaddr ' ] = conf . config [ ' api_host_options ' ] [ apiurl ] [ ' email ' ]
else :
2009-04-22 19:38:14 +02:00
user = conf . get_apiurl_usr ( apiurl )
2011-12-20 18:41:43 +01:00
data = get_user_data ( apiurl , user , ' email ' )
2011-11-18 22:48:50 +01:00
if data :
os . environ [ ' mailaddr ' ] = data [ 0 ]
else :
2013-04-09 12:51:28 +02:00
print ( ' Try env mailaddr=... ' , file = sys . stderr )
2010-08-20 13:00:57 +02:00
if meego_style :
if opts . message or opts . just_edit :
2013-04-09 12:51:28 +02:00
print ( ' Warning: to edit MeeGo style changelog, opts will be ignored. ' , file = sys . stderr )
2010-08-20 13:00:57 +02:00
else :
if opts . message :
cmd_list . append ( " -m " )
cmd_list . append ( opts . message )
2014-02-05 17:50:31 +01:00
if opts . file :
if not os . path . isfile ( opts . file ) :
raise oscerr . WrongOptions ( ' \' %s \' : is no file ' % opts . file )
cmd_list . append ( " -m " )
cmd_list . append ( open ( opts . file ) . read ( ) . strip ( ) )
2009-04-20 15:40:33 +02:00
2010-08-20 13:00:57 +02:00
if opts . just_edit :
cmd_list . append ( " -e " )
2009-04-22 16:44:17 +02:00
2010-08-23 10:08:09 +02:00
cmd_list . extend ( args )
2009-04-20 15:40:33 +02:00
vc = Popen ( cmd_list )
vc . wait ( )
sys . exit ( vc . returncode )
2009-11-24 17:25:48 +01:00
@cmdln.option ( ' -f ' , ' --force ' , action = ' store_true ' ,
help = ' forces removal of entire package and its files ' )
def do_mv ( self , subcmd , opts , source , dest ) :
""" $ {cmd_name} : Move SOURCE file to DEST and keep it under version control
$ { cmd_usage }
$ { cmd_option_list }
"""
if not os . path . isfile ( source ) :
2015-09-10 11:25:14 +02:00
raise oscerr . WrongArgs ( " Source file ' %s ' does not exist or is not a file " % source )
2009-11-24 17:25:48 +01:00
if not opts . force and os . path . isfile ( dest ) :
2013-02-28 00:30:05 +01:00
raise oscerr . WrongArgs ( " Dest file ' %s ' already exists " % dest )
if os . path . isdir ( dest ) :
dest = os . path . join ( dest , os . path . basename ( source ) )
2012-09-20 01:18:38 +02:00
src_pkg = findpacs ( [ source ] )
tgt_pkg = findpacs ( [ dest ] )
if not src_pkg :
raise oscerr . NoWorkingCopy ( " Error: \" %s \" is not located in an osc working copy. " % os . path . abspath ( source ) )
if not tgt_pkg :
raise oscerr . NoWorkingCopy ( " Error: \" %s \" does not point to an osc working copy. " % os . path . abspath ( dest ) )
2009-11-24 17:25:48 +01:00
os . rename ( source , dest )
2012-09-20 01:18:38 +02:00
try :
tgt_pkg [ 0 ] . addfile ( os . path . basename ( dest ) )
except oscerr . PackageFileConflict :
# file is already tracked
pass
src_pkg [ 0 ] . delete_file ( os . path . basename ( source ) , force = opts . force )
2009-11-24 17:25:48 +01:00
2010-03-07 22:50:11 +01:00
@cmdln.option ( ' -d ' , ' --delete ' , action = ' store_true ' ,
help = ' delete option from config or reset option to the default) ' )
2010-10-16 12:24:21 +02:00
@cmdln.option ( ' -s ' , ' --stdin ' , action = ' store_true ' ,
help = ' indicates that the config value should be read from stdin ' )
@cmdln.option ( ' -p ' , ' --prompt ' , action = ' store_true ' ,
help = ' prompt for a value ' )
@cmdln.option ( ' --no-echo ' , action = ' store_true ' ,
help = ' prompt for a value but do not echo entered characters ' )
2010-12-18 17:16:43 +01:00
@cmdln.option ( ' --dump ' , action = ' store_true ' ,
help = ' dump the complete configuration (without \' pass \' and \' passx \' options) ' )
@cmdln.option ( ' --dump-full ' , action = ' store_true ' ,
help = ' dump the complete configuration (including \' pass \' and \' passx \' options) ' )
def do_config ( self , subcmd , opts , * args ) :
2010-03-07 22:50:11 +01:00
""" $ {cmd_name} : get/set a config option
Examples :
osc config section option ( get current value )
osc config section option value ( set to value )
osc config section option - - delete ( delete option / reset to the default )
2010-10-16 12:24:21 +02:00
( section is either an apiurl or an alias or ' general ' )
2010-12-18 17:16:43 +01:00
osc config - - dump ( dump the complete configuration )
2010-03-07 22:50:11 +01:00
$ { cmd_usage }
$ { cmd_option_list }
"""
2010-12-18 17:16:43 +01:00
if len ( args ) < 2 and not ( opts . dump or opts . dump_full ) :
raise oscerr . WrongArgs ( ' Too few arguments ' )
elif opts . dump or opts . dump_full :
cp = conf . get_configParser ( conf . config [ ' conffile ' ] )
for sect in cp . sections ( ) :
2013-04-09 12:51:28 +02:00
print ( ' [ %s ] ' % sect )
2010-12-18 17:16:43 +01:00
for opt in sorted ( cp . options ( sect ) ) :
if sect == ' general ' and opt in conf . api_host_options or \
sect != ' general ' and not opt in conf . api_host_options :
continue
if opt in ( ' pass ' , ' passx ' ) and not opts . dump_full :
continue
val = str ( cp . get ( sect , opt , raw = True ) )
# special handling for continuation lines
val = ' \n ' . join ( val . split ( ' \n ' ) )
2013-04-09 12:51:28 +02:00
print ( ' %s = %s ' % ( opt , val ) )
print ( )
2010-12-18 17:16:43 +01:00
return
section , opt , val = args [ 0 ] , args [ 1 ] , args [ 2 : ]
2010-10-16 12:24:21 +02:00
if len ( val ) and ( opts . delete or opts . stdin or opts . prompt or opts . no_echo ) :
raise oscerr . WrongOptions ( ' Sorry, \' --delete \' or \' --stdin \' or \' --prompt \' or \' --no-echo \' ' \
' and the specification of a value argument are mutually exclusive ' )
elif ( opts . prompt or opts . no_echo ) and opts . stdin :
raise oscerr . WrongOptions ( ' Sorry, \' --prompt \' or \' --no-echo \' and \' --stdin \' are mutually exclusive ' )
elif opts . stdin :
# strip lines
val = [ i . strip ( ) for i in sys . stdin . readlines ( ) if i . strip ( ) ]
if not len ( val ) :
raise oscerr . WrongArgs ( ' error: read empty value from stdin ' )
elif opts . no_echo or opts . prompt :
if opts . no_echo :
import getpass
inp = getpass . getpass ( ' Value: ' ) . strip ( )
else :
inp = raw_input ( ' Value: ' ) . strip ( )
if not inp :
raise oscerr . WrongArgs ( ' error: no value was entered ' )
val = [ inp ]
2010-11-14 13:08:26 +01:00
opt , newval = conf . config_set_option ( section , opt , ' ' . join ( val ) , delete = opts . delete , update = True )
2010-03-07 22:50:11 +01:00
if newval is None and opts . delete :
2013-04-09 12:51:28 +02:00
print ( ' \' %s \' : \' %s \' got removed ' % ( section , opt ) )
2010-03-07 22:50:11 +01:00
elif newval is None :
2013-04-09 12:51:28 +02:00
print ( ' \' %s \' : \' %s \' is not set ' % ( section , opt ) )
2010-03-07 22:50:11 +01:00
else :
2010-10-16 12:32:21 +02:00
if opts . no_echo :
# supress value
2013-04-09 12:51:28 +02:00
print ( ' \' %s \' : set \' %s \' ' % ( section , opt ) )
2010-11-14 13:08:26 +01:00
elif opt == ' pass ' and not conf . config [ ' plaintext_passwd ' ] and newval == ' your_password ' :
opt , newval = conf . config_set_option ( section , ' passx ' )
2013-04-09 12:51:28 +02:00
print ( ' \' %s \' : \' pass \' was rewritten to \' passx \' : \' %s \' ' % ( section , newval ) )
2010-10-16 12:32:21 +02:00
else :
2013-04-09 12:51:28 +02:00
print ( ' \' %s \' : \' %s \' is set to \' %s \' ' % ( section , opt , newval ) )
2009-11-24 17:25:48 +01:00
2010-08-23 16:15:05 +02:00
def do_revert ( self , subcmd , opts , * files ) :
2011-09-09 19:40:11 +02:00
""" $ {cmd_name} : Restore changed files or the entire working copy.
2010-08-23 16:15:05 +02:00
Examples :
osc revert < modified file ( s ) >
2011-09-09 19:40:11 +02:00
ose revert .
2011-09-09 19:55:19 +02:00
Note : this only works for package working copies
2010-08-23 16:15:05 +02:00
$ { cmd_usage }
$ { cmd_option_list }
"""
pacs = findpacs ( files )
for p in pacs :
if not len ( p . todo ) :
2011-09-09 17:30:50 +02:00
p . todo = p . filenamelist + p . to_be_added
2010-08-23 16:15:05 +02:00
for f in p . todo :
p . revert ( f )
2010-09-08 18:56:15 +02:00
2010-12-07 20:35:12 +01:00
@cmdln.option ( ' --force-apiurl ' , action = ' store_true ' ,
help = ' ask once for an apiurl and force this apiurl for all inconsistent projects/packages ' )
2010-09-08 18:56:15 +02:00
def do_repairwc ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : try to repair an inconsistent working copy
Examples :
osc repairwc < path >
2010-09-14 14:51:18 +02:00
Note : if < path > is omitted it defaults to ' . ' ( < path > can be
a project or package working copy )
2010-09-08 18:56:15 +02:00
Warning : This command might delete some files in the storedir
( . osc ) . Please check the state of the wc afterwards ( via ' osc status ' ) .
$ { cmd_usage }
$ { cmd_option_list }
"""
2010-10-10 21:40:31 +02:00
def get_apiurl ( apiurls ) :
2013-04-09 12:51:28 +02:00
print ( ' No apiurl is defined for this working copy. \n ' \
' Please choose one from the following list (enter the number): ' )
2010-10-10 21:40:31 +02:00
for i in range ( len ( apiurls ) ) :
2013-04-09 12:51:28 +02:00
print ( ' %d ) %s ' % ( i , apiurls [ i ] ) )
2010-10-10 21:40:31 +02:00
num = raw_input ( ' > ' )
try :
num = int ( num )
except ValueError :
raise oscerr . WrongArgs ( ' \' %s \' is not a number. Aborting ' % num )
if num < 0 or num > = len ( apiurls ) :
raise oscerr . WrongArgs ( ' number \' %s \' out of range. Aborting ' % num )
return apiurls [ num ]
2010-09-08 18:56:15 +02:00
args = parseargs ( args )
2010-09-14 14:40:18 +02:00
pacs = [ ]
2013-04-09 11:25:19 +02:00
apiurls = list ( conf . config [ ' api_host_options ' ] . keys ( ) )
2010-12-07 20:35:12 +01:00
apiurl = ' '
2010-09-14 14:40:18 +02:00
for i in args :
if is_project_dir ( i ) :
2010-10-10 21:40:31 +02:00
try :
prj = Project ( i , getPackageList = False )
2013-04-09 11:27:02 +02:00
except oscerr . WorkingCopyInconsistent as e :
2010-12-07 20:35:12 +01:00
if ' _apiurl ' in e . dirty_files and ( not apiurl or not opts . force_apiurl ) :
2010-10-10 21:40:31 +02:00
apiurl = get_apiurl ( apiurls )
prj = Project ( i , getPackageList = False , wc_check = False )
prj . wc_repair ( apiurl )
2010-09-14 14:40:18 +02:00
for p in prj . pacs_have :
if p in prj . pacs_broken :
continue
try :
Package ( os . path . join ( i , p ) )
except oscerr . WorkingCopyInconsistent :
pacs . append ( os . path . join ( i , p ) )
elif is_package_dir ( i ) :
pacs . append ( i )
else :
2013-04-09 12:51:28 +02:00
print ( ' \' %s \' is neither a project working copy ' \
' nor a package working copy ' % i , file = sys . stderr )
2010-09-28 23:07:33 +02:00
for pdir in pacs :
2010-09-14 14:40:18 +02:00
try :
2010-09-28 23:07:33 +02:00
p = Package ( pdir )
2013-04-09 11:27:02 +02:00
except oscerr . WorkingCopyInconsistent as e :
2010-12-07 20:35:12 +01:00
if ' _apiurl ' in e . dirty_files and ( not apiurl or not opts . force_apiurl ) :
2010-10-10 21:40:31 +02:00
apiurl = get_apiurl ( apiurls )
2010-09-28 23:07:33 +02:00
p = Package ( pdir , wc_check = False )
p . wc_repair ( apiurl )
2013-04-09 12:51:28 +02:00
print ( ' done. Please check the state of the wc (via \' osc status %s \' ). ' % i )
2010-09-14 14:40:18 +02:00
else :
2013-04-09 12:51:28 +02:00
print ( ' osc: working copy \' %s \' is not inconsistent ' % i , file = sys . stderr )
2009-05-18 16:50:43 +02:00
2013-09-12 16:13:18 +02:00
@cmdln.option ( ' -n ' , ' --dry-run ' , action = ' store_true ' ,
help = ' print the results without actually removing a file ' )
def do_clean ( self , subcmd , opts , * args ) :
""" $ {cmd_name} : removes all untracked files from the package working copy
Examples :
osc clean < path >
Note : if < path > is omitted it defaults to ' . ' ( < path > has to
be a package working copy )
Warning : This command removes all files with status ' ? ' .
$ { cmd_usage }
$ { cmd_option_list }
"""
pacs = parseargs ( args )
# do a sanity check first
for pac in pacs :
if not is_package_dir ( pac ) :
raise oscerr . WrongArgs ( ' \' %s \' is no package working copy ' % pac )
for pdir in pacs :
p = Package ( pdir )
pdir = getTransActPath ( pdir )
for filename in ( fname for st , fname in p . get_status ( ) if st == ' ? ' ) :
print ( ' Removing: %s ' % os . path . join ( pdir , filename ) )
if not opts . dry_run :
os . unlink ( os . path . join ( p . absdir , filename ) )
2013-06-13 19:57:34 +02:00
def _load_plugins ( self ) :
plugin_dirs = [
' /usr/lib/osc-plugins ' ,
' /usr/local/lib/osc-plugins ' ,
' /var/lib/osc-plugins ' , # Kept for backward compatibility
os . path . expanduser ( ' ~/.osc-plugins ' ) ]
for plugin_dir in plugin_dirs :
if not os . path . isdir ( plugin_dir ) :
continue
2007-06-29 20:26:30 +02:00
for extfile in os . listdir ( plugin_dir ) :
if not extfile . endswith ( ' .py ' ) :
continue
2011-03-21 18:53:05 +01:00
try :
2013-06-13 19:57:34 +02:00
modname = os . path . splitext ( extfile ) [ 0 ]
mod = imp . load_source ( modname , os . path . join ( plugin_dir , extfile ) )
# restore the old exec semantic
mod . __dict__ . update ( globals ( ) )
for name in dir ( mod ) :
2013-08-15 17:26:07 +02:00
data = getattr ( mod , name )
# Add all functions (which are defined in the imported module)
2013-07-23 12:10:31 +02:00
# to the class (filtering only methods which start with "do_"
2013-08-15 17:26:07 +02:00
# breaks the old behavior).
# Also add imported modules (needed for backward compatibility).
# New plugins should not use "self.<imported modname>.<something>"
# to refer to the imported module. Instead use
# "<imported modname>.<something>".
if ( inspect . isfunction ( data ) and inspect . getmodule ( data ) == mod
or inspect . ismodule ( data ) ) :
setattr ( self . __class__ , name , data )
2014-05-06 18:51:12 +02:00
except ( SyntaxError , NameError , ImportError ) as e :
2011-03-21 18:53:05 +01:00
if ( os . environ . get ( ' OSC_PLUGIN_FAIL_IGNORE ' ) ) :
2013-06-06 11:55:50 +02:00
print ( " %s : %s \n " % ( os . path . join ( plugin_dir , extfile ) , e ) , file = sys . stderr )
2011-03-21 18:53:05 +01:00
else :
import traceback
traceback . print_exc ( file = sys . stderr )
2013-06-06 11:55:50 +02:00
print ( ' \n %s : %s ' % ( os . path . join ( plugin_dir , extfile ) , e ) , file = sys . stderr )
2013-04-09 12:51:28 +02:00
print ( " \n Try ' env OSC_PLUGIN_FAIL_IGNORE=1 osc ... ' " , file = sys . stderr )
2011-03-21 18:53:05 +01:00
sys . exit ( 1 )
2013-06-13 19:57:34 +02:00
# fini!
###############################################################################
2007-06-29 20:26:30 +02:00
2010-02-25 09:52:47 +01:00
# vim: sw=4 et