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
2010-12-06 19:14:02 +01:00
__version__ = ' 0.130git '
2009-10-02 14:06:46 +02:00
2008-05-19 16:56:59 +02:00
# __store_version__ is to be incremented when the format of the working copy
# "store" changes in an incompatible way. Please add any needed migration
# functionality to check_store_version().
__store_version__ = ' 1.0 '
2006-04-20 16:26:50 +02:00
import os
2009-06-19 10:32:56 +02:00
import os . path
2006-04-20 16:26:50 +02:00
import sys
import urllib2
2009-08-20 21:28:05 +02:00
from urllib import pathname2url , quote_plus , urlencode , unquote
2007-05-04 23:51:54 +02:00
from urlparse import urlsplit , urlunsplit
2006-05-02 10:17:45 +02:00
from cStringIO import StringIO
2006-05-30 12:07:16 +02:00
import shutil
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 oscerr
2006-10-10 16:04:34 +02:00
import conf
2008-10-11 22:26:45 +02:00
import subprocess
2009-04-16 15:48:37 +02:00
import re
2009-05-08 20:54:26 +02:00
import socket
2007-03-13 00:17:34 +01:00
try :
from xml . etree import cElementTree as ET
except ImportError :
import cElementTree as ET
2006-04-20 16:26:50 +02:00
2009-08-26 16:58:53 +02:00
DISTURL_RE = re . compile ( r " ^(?P<bs>.*)://(?P<apiurl>.*?)/(?P<project>.*?)/(?P<repository>.*?)/(?P<revision>.*)-(?P<source>.*)$ " )
2010-01-28 20:00:34 +01:00
BUILDLOGURL_RE = re . compile ( r " ^(?P<apiurl>https?://.*?)/build/(?P<project>.*?)/(?P<repository>.*?)/(?P<arch>.*?)/(?P<package>.*?)/_log$ " )
2006-04-20 16:26:50 +02:00
BUFSIZE = 1024 * 1024
store = ' .osc '
2006-05-23 17:27:43 +02:00
new_project_templ = """ \
2008-03-07 10:13:30 +01:00
< project name = " %(name)s " >
2006-06-23 12:35:20 +02:00
2010-01-22 08:57:47 +01:00
< title > < / title > < ! - - Short title of NewProject - - >
< description >
< ! - - This is for a longer description of the purpose of the project - - >
< / description >
2006-06-23 12:35:20 +02:00
2008-03-07 10:13:30 +01:00
< person role = " maintainer " userid = " %(user)s " / >
< person role = " bugowner " userid = " %(user)s " / >
2007-07-04 14:59:18 +02:00
< ! - - remove this block to publish your packages on the mirrors - - >
< publish >
< disable / >
< / publish >
< build >
< enable / >
< / build >
< debuginfo >
< disable / >
< / debuginfo >
2006-06-23 12:35:20 +02:00
< ! - - remove this comment to enable one or more build targets
2007-07-04 19:48:50 +02:00
< repository name = " openSUSE_Factory " >
< path project = " openSUSE:Factory " repository = " standard " / >
2006-06-23 12:35:20 +02:00
< arch > x86_64 < / arch >
< arch > i586 < / arch >
< / repository >
2009-10-16 17:55:29 +02:00
< repository name = " openSUSE_11.2 " >
< path project = " openSUSE:11.2 " repository = " standard " / >
< arch > x86_64 < / arch >
< arch > i586 < / arch >
< / repository >
2009-02-18 17:34:30 +01:00
< repository name = " openSUSE_11.1 " >
< path project = " openSUSE:11.1 " repository = " standard " / >
2007-07-04 14:59:18 +02:00
< arch > x86_64 < / arch >
< arch > i586 < / arch >
< / repository >
2010-05-22 08:22:12 +02:00
< repository name = " Fedora_12 " >
< path project = " Fedora:12 " repository = " standard " / >
2009-04-09 10:21:12 +02:00
< arch > x86_64 < / arch >
< arch > i586 < / arch >
< / repository >
< repository name = " SLE_11 " >
< path project = " SUSE:SLE-11 " repository = " standard " / >
2006-06-23 12:35:20 +02:00
< arch > x86_64 < / arch >
< arch > i586 < / arch >
< / repository >
- - >
2009-10-20 16:30:15 +02:00
2006-05-23 17:27:43 +02:00
< / project >
2007-06-26 15:17:38 +02:00
"""
2006-05-23 17:27:43 +02:00
new_package_templ = """ \
2008-03-07 10:13:30 +01:00
< package name = " %(name)s " >
2006-06-23 12:35:20 +02:00
2010-01-22 08:57:47 +01:00
< title > < / title > < ! - - Title of package - - >
2006-06-23 12:35:20 +02:00
2008-08-15 19:38:08 +02:00
< description >
2010-01-22 08:57:47 +01:00
< ! - - for long description - - >
2006-06-23 12:35:20 +02:00
< / description >
2008-03-07 10:13:30 +01:00
< person role = " maintainer " userid = " %(user)s " / >
< person role = " bugowner " userid = " %(user)s " / >
2010-01-22 08:57:47 +01:00
< ! - -
2008-08-15 19:38:08 +02:00
< url > PUT_UPSTREAM_URL_HERE < / url >
2010-01-22 08:57:47 +01:00
- - >
2006-06-23 12:35:20 +02:00
2009-10-20 16:30:15 +02:00
< ! - -
use one of the examples below to disable building of this package
on a certain architecture , in a certain repository ,
2006-06-23 12:35:20 +02:00
or a combination thereof :
2009-10-20 16:30:15 +02:00
2006-06-23 12:35:20 +02:00
< disable arch = " x86_64 " / >
2006-12-12 02:59:44 +01:00
< disable repository = " SUSE_SLE-10 " / >
< disable repository = " SUSE_SLE-10 " arch = " x86_64 " / >
2006-06-23 12:35:20 +02:00
2008-08-15 19:38:08 +02:00
Possible sections where you can use the tags above :
< build >
< / build >
< debuginfo >
< / debuginfo >
< publish >
< / publish >
< useforbuild >
< / useforbuild >
2009-10-20 16:30:15 +02:00
Please have a look at :
2010-07-27 15:20:35 +02:00
http : / / en . opensuse . org / Restricted_formats
2009-10-20 16:30:15 +02:00
Packages containing formats listed there are NOT allowed to
2008-08-15 19:38:08 +02:00
be packaged in the openSUSE Buildservice and will be deleted !
2006-06-23 12:35:20 +02:00
- - >
2006-05-23 17:27:43 +02:00
< / package >
"""
2009-10-30 10:40:46 +01:00
new_attribute_templ = """ \
< attributes >
< attribute namespace = " " name = " " >
< value > < value >
< / attribute >
< / attributes >
"""
2006-10-12 15:22:56 +02:00
new_user_template = """ \
< person >
2008-03-07 10:13:30 +01:00
< login > % ( user ) s < / login >
2006-10-12 15:22:56 +02:00
< email > PUT_EMAIL_ADDRESS_HERE < / email >
< realname > PUT_REAL_NAME_HERE < / realname >
< watchlist >
2008-03-07 10:13:30 +01:00
< project name = " home: %(user)s " / >
2006-10-12 15:22:56 +02:00
< / watchlist >
< / person >
"""
2006-05-23 17:27:43 +02:00
2007-05-04 23:51:54 +02:00
info_templ = """ \
2008-05-21 15:44:49 +02:00
Project name : % s
Package name : % s
2007-05-04 23:51:54 +02:00
Path : % s
API URL : % s
2008-05-21 15:44:49 +02:00
Source URL : % s
2008-03-22 18:37:17 +01:00
srcmd5 : % s
2007-05-04 23:51:54 +02:00
Revision : % s
2008-03-22 18:37:17 +01:00
Link info : % s
2007-05-04 23:51:54 +02:00
"""
2007-07-19 12:08:42 +02:00
new_pattern_template = """ \
< ! - - See http : / / svn . opensuse . org / svn / zypp / trunk / libzypp / zypp / parser / yum / schema / patterns . rng - - >
< pattern >
< / pattern >
"""
2006-09-25 17:11:03 +02:00
buildstatus_symbols = { ' succeeded ' : ' . ' ,
' disabled ' : ' ' ,
2010-05-22 08:22:12 +02:00
' expansion error ' : ' U ' , # obsolete with OBS 2.0
2010-04-23 14:38:00 +02:00
' unresolvable ' : ' U ' ,
2006-09-25 17:11:03 +02:00
' failed ' : ' F ' ,
' broken ' : ' B ' ,
' blocked ' : ' b ' ,
' building ' : ' % ' ,
2008-05-15 20:09:24 +02:00
' finished ' : ' f ' ,
2006-09-25 17:11:03 +02:00
' scheduled ' : ' s ' ,
2009-07-20 11:43:01 +02:00
' excluded ' : ' x ' ,
' dispatching ' : ' d ' ,
2010-08-08 21:09:18 +02:00
' signing ' : ' S ' ,
2006-09-25 17:11:03 +02:00
}
2010-05-14 16:44:42 +02:00
# our own xml writer function to write xml nice, but with correct syntax
# This function is from http://ronrothman.com/public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/
from xml . dom import minidom
def fixed_writexml ( self , writer , indent = " " , addindent = " " , newl = " " ) :
# indent = current indentation
# addindent = indentation to add to higher levels
# newl = newline string
writer . write ( indent + " < " + self . tagName )
attrs = self . _get_attributes ( )
a_names = attrs . keys ( )
a_names . sort ( )
for a_name in a_names :
writer . write ( " %s = \" " % a_name )
minidom . _write_data ( writer , attrs [ a_name ] . value )
writer . write ( " \" " )
if self . childNodes :
if len ( self . childNodes ) == 1 \
and self . childNodes [ 0 ] . nodeType == minidom . Node . TEXT_NODE :
writer . write ( " > " )
self . childNodes [ 0 ] . writexml ( writer , " " , " " , " " )
writer . write ( " </ %s > %s " % ( self . tagName , newl ) )
return
writer . write ( " > %s " % ( newl ) )
for node in self . childNodes :
node . writexml ( writer , indent + addindent , addindent , newl )
writer . write ( " %s </ %s > %s " % ( indent , self . tagName , newl ) )
else :
writer . write ( " /> %s " % ( newl ) )
# replace minidom's function with ours
minidom . Element . writexml = fixed_writexml
2009-05-20 18:32:45 +02:00
# os.path.samefile is available only under Unix
def os_path_samefile ( path1 , path2 ) :
2009-10-20 16:30:15 +02:00
try :
return os . path . samefile ( path1 , path2 )
except :
return os . path . realpath ( path1 ) == os . path . realpath ( path2 )
2006-09-25 17:11:03 +02:00
2006-05-19 22:13:29 +02:00
class File :
""" represent a file, including its metadata """
2010-08-23 11:29:57 +02:00
def __init__ ( self , name , md5 , size , mtime , skipped = False ) :
2006-05-19 22:13:29 +02:00
self . name = name
self . md5 = md5
self . size = size
self . mtime = mtime
2010-08-23 11:29:57 +02:00
self . skipped = skipped
2010-08-19 18:10:32 +02:00
def __repr__ ( self ) :
return self . name
2006-05-19 22:13:29 +02:00
def __str__ ( self ) :
return self . name
2009-09-03 16:56:48 +02:00
class Serviceinfo :
""" Source service content
"""
def __init__ ( self ) :
""" creates an empty serviceinfo instance """
self . commands = None
def read ( self , serviceinfo_node ) :
""" read in the source services <services> element passed as
elementtree node .
"""
if serviceinfo_node == None :
return
self . commands = [ ]
services = serviceinfo_node . findall ( ' service ' )
for service in services :
name = service . get ( ' name ' )
try :
for param in service . findall ( ' param ' ) :
2009-10-20 16:30:15 +02:00
option = param . get ( ' name ' , None )
value = param . text
name + = " -- " + option + " ' " + value + " ' "
2009-09-03 16:56:48 +02:00
self . commands . append ( name )
except :
2010-05-14 16:44:42 +02:00
msg = ' invalid service format: \n %s ' % ET . tostring ( serviceinfo_node )
2009-09-03 16:56:48 +02:00
raise oscerr . APIError ( msg )
2010-05-17 19:24:00 +02:00
def addVerifyFile ( self , serviceinfo_node , filename ) :
import hashlib
f = open ( filename , ' r ' )
digest = hashlib . sha256 ( f . read ( ) ) . hexdigest ( )
f . close ( )
r = serviceinfo_node
s = ET . Element ( " service " , name = " verify_file " )
ET . SubElement ( s , " param " , name = " file " ) . text = filename
ET . SubElement ( s , " param " , name = " verifier " ) . text = " sha256 "
2010-05-18 16:33:11 +02:00
ET . SubElement ( s , " param " , name = " checksum " ) . text = digest
2010-05-17 19:24:00 +02:00
r . append ( s )
return r
2010-05-14 16:44:42 +02:00
def addDownloadUrl ( self , serviceinfo_node , url_string ) :
from urlparse import urlparse
url = urlparse ( url_string )
protocol = url . scheme
host = url . netloc
path = url . path
r = serviceinfo_node
s = ET . Element ( " service " , name = " download_url " )
ET . SubElement ( s , " param " , name = " protocol " ) . text = protocol
ET . SubElement ( s , " param " , name = " host " ) . text = host
ET . SubElement ( s , " param " , name = " path " ) . text = path
r . append ( s )
return r
2010-09-20 11:09:43 +02:00
def addGitUrl ( self , serviceinfo_node , url_string ) :
r = serviceinfo_node
s = ET . Element ( " service " , name = " git_pull " )
ET . SubElement ( s , " param " , name = " url " ) . text = url_string
r . append ( s )
return r
2010-05-14 16:44:42 +02:00
2009-09-03 16:56:48 +02:00
def execute ( self , dir ) :
import tempfile
2011-01-06 15:03:18 +01:00
# cleanup existing generated files
for filename in os . listdir ( dir ) :
if filename . startswith ( ' _service: ' ) or filename . startswith ( ' _service_ ' ) :
os . unlink ( os . path . join ( dir , filename ) )
# recreate files
2009-09-03 16:56:48 +02:00
for call in self . commands :
temp_dir = tempfile . mkdtemp ( )
name = call . split ( None , 1 ) [ 0 ]
if not os . path . exists ( " /usr/lib/obs/service/ " + name ) :
2010-05-21 11:29:52 +02:00
msg = " ERROR: service is not installed! \n "
2010-06-07 14:30:36 +02:00
msg + = " Maybe try this: zypper in obs-service- " + name
2009-10-20 16:30:15 +02:00
raise oscerr . APIError ( msg )
2009-09-03 16:56:48 +02:00
c = " /usr/lib/obs/service/ " + call + " --outdir " + temp_dir
2010-05-26 16:35:20 +02:00
if conf . config [ ' verbose ' ] > 1 :
print " Run source service: " , c
2009-09-03 16:56:48 +02:00
ret = subprocess . call ( c , shell = True )
if ret != 0 :
2009-10-20 16:30:15 +02:00
print " ERROR: service call failed: " + c
2010-05-26 16:25:20 +02:00
# FIXME: addDownloadUrlService calls si.execute after
# updating _services.
print " (your _services file may be corrupt now) "
2009-09-03 16:56:48 +02:00
2010-08-20 14:34:41 +02:00
for filename in os . listdir ( temp_dir ) :
shutil . move ( os . path . join ( temp_dir , filename ) , os . path . join ( dir , " _service: " + name + " : " + filename ) )
2009-09-03 16:56:48 +02:00
os . rmdir ( temp_dir )
2008-03-22 14:37:59 +01:00
class Linkinfo :
2008-03-22 18:37:17 +01:00
""" linkinfo metadata (which is part of the xml representing a directory
2008-03-22 14:37:59 +01:00
"""
def __init__ ( self ) :
""" creates an empty linkinfo instance """
self . project = None
self . package = None
self . xsrcmd5 = None
2008-03-22 18:37:17 +01:00
self . lsrcmd5 = None
self . srcmd5 = None
2008-07-16 17:14:57 +02:00
self . error = None
2009-03-09 14:44:14 +01:00
self . rev = None
2010-01-11 17:00:24 +01:00
self . baserev = None
2008-03-22 14:37:59 +01:00
def read ( self , linkinfo_node ) :
""" read in the linkinfo metadata from the <linkinfo> element passed as
elementtree node .
If the passed element is None , the method does nothing .
"""
if linkinfo_node == None :
return
self . project = linkinfo_node . get ( ' project ' )
self . package = linkinfo_node . get ( ' package ' )
self . xsrcmd5 = linkinfo_node . get ( ' xsrcmd5 ' )
2008-03-22 18:37:17 +01:00
self . lsrcmd5 = linkinfo_node . get ( ' lsrcmd5 ' )
self . srcmd5 = linkinfo_node . get ( ' srcmd5 ' )
2008-07-16 17:14:57 +02:00
self . error = linkinfo_node . get ( ' error ' )
2009-03-09 14:44:14 +01:00
self . rev = linkinfo_node . get ( ' rev ' )
2010-01-11 17:00:24 +01:00
self . baserev = linkinfo_node . get ( ' baserev ' )
2008-03-22 14:37:59 +01:00
def islink ( self ) :
""" returns True if the linkinfo is not empty, otherwise False """
2008-03-22 18:37:17 +01:00
if self . xsrcmd5 or self . lsrcmd5 :
2008-03-22 14:37:59 +01:00
return True
2008-03-22 18:37:17 +01:00
return False
def isexpanded ( self ) :
""" returns True if the package is an expanded link """
if self . lsrcmd5 and not self . xsrcmd5 :
return True
return False
2008-03-22 14:37:59 +01:00
2008-07-16 17:14:57 +02:00
def haserror ( self ) :
""" returns True if the link is in error state (could not be applied) """
if self . error :
return True
return False
2008-03-22 14:37:59 +01:00
def __str__ ( self ) :
""" return an informatory string representation """
2008-03-22 18:37:17 +01:00
if self . islink ( ) and not self . isexpanded ( ) :
2009-03-09 14:44:14 +01:00
return ' project %s , package %s , xsrcmd5 %s , rev %s ' \
% ( self . project , self . package , self . xsrcmd5 , self . rev )
2008-03-22 18:37:17 +01:00
elif self . islink ( ) and self . isexpanded ( ) :
2008-07-16 17:14:57 +02:00
if self . haserror ( ) :
return ' broken link to project %s , package %s , srcmd5 %s , lsrcmd5 %s : %s ' \
% ( self . project , self . package , self . srcmd5 , self . lsrcmd5 , self . error )
else :
return ' expanded link to project %s , package %s , srcmd5 %s , lsrcmd5 %s ' \
% ( self . project , self . package , self . srcmd5 , self . lsrcmd5 )
2008-03-22 14:37:59 +01:00
else :
return ' None '
2010-08-04 11:46:30 +02:00
# http://effbot.org/zone/element-lib.htm#prettyprint
def xmlindent ( elem , level = 0 ) :
i = " \n " + level * " "
if len ( elem ) :
if not elem . text or not elem . text . strip ( ) :
elem . text = i + " "
for e in elem :
xmlindent ( e , level + 1 )
if not e . tail or not e . tail . strip ( ) :
e . tail = i + " "
if not e . tail or not e . tail . strip ( ) :
e . tail = i
else :
if level and ( not elem . tail or not elem . tail . strip ( ) ) :
elem . tail = i
2006-05-22 12:50:37 +02:00
class Project :
""" represent a project directory, holding packages """
2010-10-10 21:40:31 +02:00
REQ_STOREFILES = ( ' _project ' , ' _apiurl ' )
if conf . config [ ' do_package_tracking ' ] :
REQ_STOREFILES + = ( ' _packages ' , )
def __init__ ( self , dir , getPackageList = True , progress_obj = None , wc_check = True ) :
2008-03-31 16:42:11 +02:00
import fnmatch
2006-05-22 12:50:37 +02:00
self . dir = dir
2006-06-06 12:50:40 +02:00
self . absdir = os . path . abspath ( dir )
2010-02-09 20:57:10 +01:00
self . progress_obj = progress_obj
2006-05-22 12:50:37 +02:00
self . name = store_read_project ( self . dir )
2010-10-10 21:40:31 +02:00
self . apiurl = store_read_apiurl ( self . dir , defaulturl = not wc_check )
dirty_files = [ ]
if wc_check :
dirty_files = self . wc_check ( )
if dirty_files :
msg = ' Your working copy \' %s \' is in an inconsistent state. \n ' \
' Please run \' osc repairwc %s \' and check the state \n ' \
' of the working copy afterwards (via \' osc status %s \' ) ' % ( self . dir , self . dir , self . dir )
2010-12-23 02:17:19 +01:00
raise oscerr . WorkingCopyInconsistent ( self . name , None , dirty_files , msg )
2006-05-22 12:50:37 +02:00
2008-03-10 19:04:23 +01:00
if getPackageList :
self . pacs_available = meta_get_packagelist ( self . apiurl , self . name )
else :
self . pacs_available = [ ]
2009-10-20 16:30:15 +02:00
2008-03-10 19:04:23 +01:00
if conf . config [ ' do_package_tracking ' ] :
self . pac_root = self . read_packages ( ) . getroot ( )
self . pacs_have = [ pac . get ( ' name ' ) for pac in self . pac_root . findall ( ' package ' ) ]
2009-08-21 21:39:12 +02:00
self . pacs_excluded = [ i for i in os . listdir ( self . dir )
for j in conf . config [ ' exclude_glob ' ]
2008-03-31 16:42:11 +02:00
if fnmatch . fnmatch ( i , j ) ]
self . pacs_unvers = [ i for i in os . listdir ( self . dir ) if i not in self . pacs_have and i not in self . pacs_excluded ]
2008-03-10 19:04:23 +01:00
# store all broken packages (e.g. packages which where removed by a non-osc cmd)
# in the self.pacs_broken list
self . pacs_broken = [ ]
for p in self . pacs_have :
if not os . path . isdir ( os . path . join ( self . absdir , p ) ) :
# all states will be replaced with the '!'-state
# (except it is already marked as deleted ('D'-state))
self . pacs_broken . append ( p )
else :
self . pacs_have = [ i for i in os . listdir ( self . dir ) if i in self . pacs_available ]
2006-05-22 12:50:37 +02:00
2006-06-26 17:11:22 +02:00
self . pacs_missing = [ i for i in self . pacs_available if i not in self . pacs_have ]
2006-05-22 12:50:37 +02:00
2010-10-10 21:40:31 +02:00
def wc_check ( self ) :
global store
dirty_files = [ ]
for fname in Project . REQ_STOREFILES :
if not os . path . exists ( os . path . join ( self . absdir , store , fname ) ) :
dirty_files . append ( fname )
return dirty_files
def wc_repair ( self , apiurl = None ) :
global store
2010-12-07 20:35:12 +01:00
if not os . path . exists ( os . path . join ( self . dir , store , ' _apiurl ' ) ) or apiurl :
2010-10-10 21:40:31 +02:00
if apiurl is None :
msg = ' cannot repair wc: the \' _apiurl \' file is missing but ' \
' no \' apiurl \' was passed to wc_repair '
# hmm should we raise oscerr.WrongArgs?
raise oscerr . WorkingCopyInconsistent ( self . prjname , self . name , [ ] , msg )
2010-12-09 20:36:06 +01:00
# sanity check
conf . parse_apisrv_url ( None , apiurl )
2010-10-10 21:40:31 +02:00
store_write_apiurl ( self . dir , apiurl )
self . apiurl = store_read_apiurl ( self . dir , defaulturl = False )
2009-08-19 15:07:58 +02:00
def checkout_missing_pacs ( self , expand_link = False ) :
2006-05-22 12:50:37 +02:00
for pac in self . pacs_missing :
2008-03-10 19:04:23 +01:00
if conf . config [ ' do_package_tracking ' ] and pac in self . pacs_unvers :
# pac is not under version control but a local file/dir exists
Merged revisions 3774-3775,3779,3781-3782,3787,3789-3793,3798,3802,3805,3817-3822,3827,3829-3830,3837-3839,3841-3842,3848-3850 via svnmerge from
https://forgesvn1.novell.com/svn/opensuse/branches/buildservice/osc-exception-handling
........
r3774 | poeml | 2008-04-22 17:39:45 +0200 (Tue, 22 Apr 2008) | 3 lines
A first draft on implement systematic exception handling:
Add errors.py with some exceptions defined, and babysitter.py to handle them
........
r3775 | poeml | 2008-04-22 22:34:12 +0200 (Tue, 22 Apr 2008) | 9 lines
- new global options:
--debugger jump into the debugger before executing anything
--post-mortem jump into the debugger in case of errors
-t, --traceback print call trace in case of errors
- traceback and post_mortem can also be set in .oscrc.
- catch more errors (HTTPError).
- make config accessible from outside of the Osc instance, by making it a class
attribute
........
r3779 | poeml | 2008-04-23 00:55:49 +0200 (Wed, 23 Apr 2008) | 5 lines
- new global option:
-d, --debug print info useful for debugging
- catch some more errors (HTTPError), with OscHTTPError which isn't very
advanced yet.
........
r3781 | Marcus_H | 2008-04-23 01:02:00 +0200 (Wed, 23 Apr 2008) | 2 lines
- added OscConfigError class (just for testing).
- small change in the signature of the OscBaseError constructor (actually we should get rid of the 'args' tuple because it will be deprecated sooner or later
........
r3782 | Marcus_H | 2008-04-23 02:02:13 +0200 (Wed, 23 Apr 2008) | 2 lines
- access the prg.conf.config dict in a save way - this way we avoid AttributeErrors if the prg.conf.config dict doesn't exist
- in case of an configparser error we have to use the prg.options object directly (this was removed in r3781 by accident)
........
r3787 | poeml | 2008-04-23 09:23:56 +0200 (Wed, 23 Apr 2008) | 4 lines
- remove local exception handling from do_req
- for HTTPError, print details (headers and response) when in debug mode
- catch AttributeError
........
r3789 | poeml | 2008-04-23 16:23:14 +0200 (Wed, 23 Apr 2008) | 4 lines
- errors: add two new classes named OscWrongOptionsError and OscWrongArgsError
- commandline: raise instances of the new errors in a number of places
- commandline: add get_cmd_help() to Osc instance which returns the formatted help of a subcommand
........
r3790 | Marcus_H | 2008-04-23 16:48:28 +0200 (Wed, 23 Apr 2008) | 4 lines
- added 2 new exception classes: OscNoConfigfileError and OscIOError
- added new method write_config() to the conf.py module: This method writes osc's configuration file
- minor cleanups in the conf module
........
r3791 | poeml | 2008-04-23 17:11:07 +0200 (Wed, 23 Apr 2008) | 3 lines
small compatibility fix for r3790: try-except-finally isn't supported in
python-2.4.2, thus do the same as try-except inside a try-finally.
........
r3792 | poeml | 2008-04-23 17:37:53 +0200 (Wed, 23 Apr 2008) | 2 lines
fix up the remaining places regarding handling of errors related to commandline parsing
........
r3793 | poeml | 2008-04-23 17:40:34 +0200 (Wed, 23 Apr 2008) | 3 lines
raise a NoWorkingCopyError in osc.core.store_read_project() in case of an
IOError
........
r3798 | Marcus_H | 2008-04-23 23:55:24 +0200 (Wed, 23 Apr 2008) | 1 line
ported -r3797 from trunk
........
r3802 | Marcus_H | 2008-04-24 11:00:55 +0200 (Thu, 24 Apr 2008) | 1 line
ported -r3801 from trunk
........
r3805 | poeml | 2008-04-24 12:52:30 +0200 (Thu, 24 Apr 2008) | 2 lines
raise OscHTTPError in show_pattern_meta(), replacing local error handling
........
r3817 | poeml | 2008-04-24 20:21:32 +0200 (Thu, 24 Apr 2008) | 9 lines
- remove errors.OscHTTPError again.
it seems simpler to use urllib2.HTTPError instead (and just add a specific
error text message where appropriate, and re-raise)
- for 404s, check out _which_ part was not found
it is very ugly, but may be considered Good for pragmatic reasons
- removed local exception handling and workaround for returned 500's from
delete_package() and delete_project(), thereby getting rid of 4 possible exit
points.
........
r3818 | Marcus_H | 2008-04-24 22:36:17 +0200 (Thu, 24 Apr 2008) | 1 line
- this check is superfluous because every HTTPError instance has a code attribute
........
r3819 | poeml | 2008-04-25 00:39:39 +0200 (Fri, 25 Apr 2008) | 1 line
remove a forgotten debug line from core.delete_project()
........
r3820 | poeml | 2008-04-25 10:07:58 +0200 (Fri, 25 Apr 2008) | 2 lines
- ditch local error handling from wipebinaries(), rebuild(), and abortbuild()
........
r3821 | poeml | 2008-04-25 10:56:38 +0200 (Fri, 25 Apr 2008) | 2 lines
It is never needed to import the exception module.
........
r3822 | poeml | 2008-04-25 11:13:39 +0200 (Fri, 25 Apr 2008) | 4 lines
- when going into the debugger with --post-mortem, always print a traceback before
(thus implying -t)
- do not jump into the debugger if not on a TTY, or working in interactive mode
........
r3827 | poeml | 2008-04-25 13:07:46 +0200 (Fri, 25 Apr 2008) | 9 lines
- add errors.OscWorkingCopyOutdated, which takes a tuple with three args:
path to working copy, current rev, expected rev
- add handler for urllib2.URLError errors to the babysitter
- simplify the OscWrongArgsError and OscWrongOptionsError handlers, by removing
the extra line "Sorry, wrong ..." that was printed before the messages given
when the error was raised.
- remove one more errors.OscHTTPError which was still there, and raise
urllib2.HTTPError instead (show_package_meta())
........
r3829 | poeml | 2008-04-25 14:19:10 +0200 (Fri, 25 Apr 2008) | 11 lines
- comment some methods in osc.core which are used by nearly all do_* methods in
osc.commandline
- improve "is not a package/project dir" error messages, by printing the
absolute path tried, instead of '.' for the cwd
- make core.store_read_package() raise a proper NoWorkingCopyError instead of
terminating
- give attribution to things in babysitter.py copied from mercurial
- prefix HTTPError exceptions with 'Server returned an error:'
- remove obsolete local error handling from do_prjresults(), do_importsrcpkg(),
do_repos()
........
r3830 | poeml | 2008-04-25 14:29:35 +0200 (Fri, 25 Apr 2008) | 1 line
catch IOError exceptions in the babysitter
........
r3837 | poeml | 2008-04-25 17:27:36 +0200 (Fri, 25 Apr 2008) | 5 lines
- do_remotebuildlog: raise errors for wrong arguments, remove exits
- raise AttributeError in make_meta_url() instead of exiting
- delete unused method core.delete_server_files()
- replace exit call inside make_meta_url() with an AttributeError
........
r3838 | poeml | 2008-04-25 17:49:18 +0200 (Fri, 25 Apr 2008) | 1 line
simplify the check in do_checkout if a project exists, by using show_project_meta() instead of meta_exists
........
r3839 | poeml | 2008-04-25 18:31:26 +0200 (Fri, 25 Apr 2008) | 6 lines
- commandline do_checkout(): change the order of the two checks, first do the
(cheaper) check for existing directory
- core.core checkout_package(): simplify the check in if the package
exists, by using show_package_meta() instead of meta_exists
Let it throw an exception, instead of using sys.exit().
........
r3841 | Marcus_H | 2008-04-27 15:48:06 +0200 (Sun, 27 Apr 2008) | 5 lines
- added 2 new exception classes: PackageError() and PackageExistsError. The PackageError() class is meant to be the base class for all subsequent package exceptions.
- get rid of 2 sys.exit(1) calls
- make the update() method of the Project() class safer: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- minor fix in delPackage(): use getTransActPath() when printing out the filename
........
r3842 | Marcus_H | 2008-04-27 16:52:55 +0200 (Sun, 27 Apr 2008) | 3 lines
- make the commit() method safe: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- removed another sys.exit(1): raise an exception if a package is missing when doing a commit. For now we use the PackageExistsError() exception but this might change in the future (updated description of PackageExistsError() according to this change)
........
r3848 | poeml | 2008-04-28 12:46:45 +0200 (Mon, 28 Apr 2008) | 3 lines
rename several error classes, dropping the "Osc" prefix, and "Error" suffix in
cases where they don't really make sense.
........
r3849 | poeml | 2008-04-28 12:57:32 +0200 (Mon, 28 Apr 2008) | 3 lines
- rename osc.errors module to osc.oscerr, to make it easier to import it from
other programs and have a crystal clear namespace
........
r3850 | poeml | 2008-04-28 13:26:12 +0200 (Mon, 28 Apr 2008) | 2 lines
split PackageExists exception class into PackageExists and PackageMissing
........
2008-04-28 18:37:44 +02:00
msg = ' can \' t add package \' %s \' : Object already exists ' % pac
raise oscerr . PackageExists ( self . name , pac , msg )
2008-03-10 19:04:23 +01:00
else :
print ' checking out new package %s ' % pac
2008-04-02 17:30:44 +02:00
checkout_package ( self . apiurl , self . name , pac , \
pathname = getTransActPath ( os . path . join ( self . dir , pac ) ) , \
2010-02-09 20:57:10 +01:00
prj_obj = self , prj_dir = self . dir , expand_link = expand_link , progress_obj = self . progress_obj )
2008-03-10 19:04:23 +01:00
2010-12-22 23:17:11 +01:00
def status ( self , pac ) :
exists = os . path . exists ( os . path . join ( self . absdir , pac ) )
st = self . get_state ( pac )
if st is None and exists :
return ' ? '
elif st is None :
raise oscerr . OscIOError ( None , ' osc: \' %s \' is not under version control ' % pac )
elif st in ( ' A ' , ' ' ) and not exists :
return ' ! '
elif st == ' D ' and not exists :
return ' D '
else :
return st
def get_status ( self , * exclude_states ) :
res = [ ]
for pac in self . pacs_have :
st = self . status ( pac )
if not st in exclude_states :
res . append ( ( st , pac ) )
if not ' ? ' in exclude_states :
res . extend ( [ ( ' ? ' , pac ) for pac in self . pacs_unvers ] )
return res
def get_pacobj ( self , pac , * pac_args , * * pac_kwargs ) :
try :
st = self . status ( pac )
if st in ( ' ? ' , ' ! ' ) or st == ' D ' and not os . path . exists ( os . path . join ( self . dir , pac ) ) :
return None
return Package ( os . path . join ( self . dir , pac ) , * pac_args , * * pac_kwargs )
except oscerr . OscIOError :
return None
2008-03-10 19:04:23 +01:00
def set_state ( self , pac , state ) :
node = self . get_package_node ( pac )
if node == None :
self . new_package_entry ( pac , state )
else :
node . attrib [ ' state ' ] = state
def get_package_node ( self , pac ) :
for node in self . pac_root . findall ( ' package ' ) :
if pac == node . get ( ' name ' ) :
return node
return None
def del_package_node ( self , pac ) :
for node in self . pac_root . findall ( ' package ' ) :
if pac == node . get ( ' name ' ) :
self . pac_root . remove ( node )
def get_state ( self , pac ) :
node = self . get_package_node ( pac )
if node != None :
return node . get ( ' state ' )
else :
return None
def new_package_entry ( self , name , state ) :
ET . SubElement ( self . pac_root , ' package ' , name = name , state = state )
def read_packages ( self ) :
2010-08-31 14:43:43 +02:00
global store
2009-10-30 16:19:57 +01:00
packages_file = os . path . join ( self . absdir , store , ' _packages ' )
if os . path . isfile ( packages_file ) and os . path . getsize ( packages_file ) :
return ET . parse ( packages_file )
2008-03-10 19:04:23 +01:00
else :
# scan project for existing packages and migrate them
cur_pacs = [ ]
for data in os . listdir ( self . dir ) :
pac_dir = os . path . join ( self . absdir , data )
# we cannot use self.pacs_available because we cannot guarantee that the package list
# was fetched from the server
if data in meta_get_packagelist ( self . apiurl , self . name ) and is_package_dir ( pac_dir ) \
and Package ( pac_dir ) . name == data :
cur_pacs . append ( ET . Element ( ' package ' , name = data , state = ' ' ) )
store_write_initial_packages ( self . absdir , self . name , cur_pacs )
return ET . parse ( os . path . join ( self . absdir , store , ' _packages ' ) )
def write_packages ( self ) :
2010-08-04 11:46:30 +02:00
xmlindent ( self . pac_root )
store_write_string ( self . absdir , ' _packages ' , ET . tostring ( self . pac_root ) )
2008-03-10 19:04:23 +01:00
def addPackage ( self , pac ) :
2008-04-03 12:46:18 +02:00
import fnmatch
2009-08-21 21:39:12 +02:00
for i in conf . config [ ' exclude_glob ' ] :
2008-04-03 12:46:18 +02:00
if fnmatch . fnmatch ( pac , i ) :
2009-12-25 00:08:29 +01:00
msg = ' invalid package name: \' %s \' (see \' exclude_glob \' config option) ' % pac
raise oscerr . OscIOError ( None , msg )
2008-03-10 19:04:23 +01:00
state = self . get_state ( pac )
if state == None or state == ' D ' :
self . new_package_entry ( pac , ' A ' )
self . write_packages ( )
# sometimes the new pac doesn't exist in the list because
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
# it would take too much time to update all data structs regularly
2008-03-10 19:04:23 +01:00
if pac in self . pacs_unvers :
self . pacs_unvers . remove ( pac )
else :
2009-12-25 00:08:29 +01:00
raise oscerr . PackageExists ( self . name , pac , ' package \' %s \' is already under version control ' % pac )
2008-03-10 19:04:23 +01:00
def delPackage ( self , pac , force = False ) :
state = self . get_state ( pac . name )
can_delete = True
if state == ' ' or state == ' D ' :
del_files = [ ]
2010-08-20 14:34:41 +02:00
for filename in pac . filenamelist + pac . filenamelist_unvers :
filestate = pac . status ( filename )
2008-03-10 19:04:23 +01:00
if filestate == ' M ' or filestate == ' C ' or \
filestate == ' A ' or filestate == ' ? ' :
can_delete = False
2009-10-20 16:30:15 +02:00
else :
2010-08-20 14:34:41 +02:00
del_files . append ( filename )
2008-03-10 19:04:23 +01:00
if can_delete or force :
2010-08-20 14:34:41 +02:00
for filename in del_files :
pac . delete_localfile ( filename )
if pac . status ( filename ) != ' ? ' :
pac . delete_storefile ( filename )
2008-03-10 19:04:23 +01:00
# this is not really necessary
2010-08-20 14:34:41 +02:00
pac . put_on_deletelist ( filename )
print statfrmt ( ' D ' , getTransActPath ( os . path . join ( pac . dir , filename ) ) )
2008-03-10 19:04:23 +01:00
print statfrmt ( ' D ' , getTransActPath ( os . path . join ( pac . dir , os . pardir , pac . name ) ) )
pac . write_deletelist ( )
self . set_state ( pac . name , ' D ' )
self . write_packages ( )
else :
print ' package \' %s \' has local modifications (see osc st for details) ' % pac . name
elif state == ' A ' :
if force :
delete_dir ( pac . absdir )
self . del_package_node ( pac . name )
self . write_packages ( )
print statfrmt ( ' D ' , pac . name )
else :
print ' package \' %s \' has local modifications (see osc st for details) ' % pac . name
elif state == None :
print ' package is not under version control '
else :
print ' unsupported state '
2009-09-03 16:56:48 +02:00
def update ( self , pacs = ( ) , expand_link = False , unexpand_link = False , service_files = False ) :
2008-03-10 19:04:23 +01:00
if len ( pacs ) :
for pac in pacs :
2010-02-09 20:57:10 +01:00
Package ( os . path . join ( self . dir , pac , progress_obj = self . progress_obj ) ) . update ( )
2008-03-10 19:04:23 +01: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
# we need to make sure that the _packages file will be written (even if an exception
# occurs)
try :
# update complete project
# packages which no longer exists upstream
upstream_del = [ pac for pac in self . pacs_have if not pac in self . pacs_available and self . get_state ( pac ) != ' A ' ]
2008-03-10 19:04:23 +01: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
for pac in upstream_del :
2008-03-24 21:24:49 +01:00
p = Package ( os . path . join ( self . dir , pac ) )
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
self . delPackage ( p , force = True )
delete_storedir ( p . storedir )
try :
os . rmdir ( pac )
except :
pass
self . pac_root . remove ( self . get_package_node ( p . name ) )
self . pacs_have . remove ( pac )
for pac in self . pacs_have :
state = self . get_state ( pac )
2008-03-10 19:04:23 +01:00
if pac in self . pacs_broken :
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 self . get_state ( pac ) != ' A ' :
checkout_package ( self . apiurl , self . name , pac ,
2010-02-09 20:57:10 +01:00
pathname = getTransActPath ( os . path . join ( self . dir , pac ) ) , prj_obj = self , \
prj_dir = self . dir , expand_link = not unexpand_link , progress_obj = self . progress_obj )
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
elif state == ' ' :
# do a simple update
2010-02-09 20:57:10 +01:00
p = Package ( os . path . join ( self . dir , pac ) , progress_obj = self . progress_obj )
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
rev = None
if expand_link and p . islink ( ) and not p . isexpanded ( ) :
2010-01-21 14:47:04 +01:00
if p . haslinkerror ( ) :
2010-01-22 14:29:26 +01:00
try :
rev = show_upstream_xsrcmd5 ( p . apiurl , p . prjname , p . name , revision = p . rev )
except :
rev = show_upstream_xsrcmd5 ( p . apiurl , p . prjname , p . name , revision = p . rev , linkrev = " base " )
p . mark_frozen ( )
2010-01-21 14:47:04 +01:00
else :
2010-01-22 14:29:26 +01:00
rev = p . linkinfo . xsrcmd5
2009-04-21 18:52:26 +02:00
print ' Expanding to rev ' , rev
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
elif unexpand_link and p . islink ( ) and p . isexpanded ( ) :
rev = p . linkinfo . lsrcmd5
2009-04-21 18:52:26 +02:00
print ' Unexpanding to rev ' , rev
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
elif p . islink ( ) and p . isexpanded ( ) :
2009-10-20 16:30:15 +02:00
rev = p . latest_rev ( )
2008-08-01 13:31:12 +02:00
print ' Updating %s ' % p . name
2009-09-03 16:56:48 +02:00
p . update ( rev , service_files )
2010-01-21 14:47:04 +01:00
if unexpand_link :
p . unmark_frozen ( )
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
elif state == ' D ' :
# TODO: Package::update has to fixed to behave like svn does
if pac in self . pacs_broken :
checkout_package ( self . apiurl , self . name , pac ,
2010-02-09 20:57:10 +01:00
pathname = getTransActPath ( os . path . join ( self . dir , pac ) ) , prj_obj = self , \
prj_dir = self . dir , expand_link = expand_link , progress_obj = self . progress_obj )
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
else :
2010-02-09 20:57:10 +01:00
Package ( os . path . join ( self . dir , pac , progress_obj = self . progress_obj ) ) . update ( )
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
elif state == ' A ' and pac in self . pacs_available :
# file/dir called pac already exists and is under version control
msg = ' can \' t add package \' %s \' : Object already exists ' % pac
raise oscerr . PackageExists ( self . name , pac , msg )
elif state == ' A ' :
# do nothing
pass
2008-03-10 19:04:23 +01: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
print ' unexpected state.. package \' %s \' ' % pac
2008-03-10 19:04:23 +01:00
2010-01-21 14:47:04 +01:00
self . checkout_missing_pacs ( expand_link = not unexpand_link )
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
finally :
self . write_packages ( )
2008-03-10 19:04:23 +01:00
2010-09-09 12:30:49 +02:00
def validate_pacs ( self , validators , verbose_validation = False , * pacs ) :
if len ( pacs ) == 0 :
for pac in self . pacs_broken :
if self . get_state ( pac ) != ' D ' :
msg = ' validation failed: package \' %s \' is missing ' % pac
raise oscerr . PackageMissing ( self . name , pac , msg )
pacs = self . pacs_have
for pac in pacs :
if pac in self . pacs_broken and self . get_state ( pac ) != ' D ' :
msg = ' validation failed: package \' %s \' is missing ' % pac
raise oscerr . PackageMissing ( self . name , pac , msg )
if os_path_samefile ( os . path . join ( self . dir , pac ) , os . getcwd ( ) ) :
p = Package ( ' . ' )
else :
p = Package ( os . path . join ( self . dir , pac ) )
p . validate ( validators , verbose_validation )
2010-09-09 12:49:53 +02:00
def commit ( self , pacs = ( ) , msg = ' ' , files = { } , validators_dir = None , verbose_validation = False ) :
2008-03-10 19:04:23 +01:00
if len ( pacs ) :
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 :
for pac in pacs :
todo = [ ]
if files . has_key ( pac ) :
todo = files [ pac ]
state = self . get_state ( pac )
if state == ' A ' :
2010-09-09 12:30:49 +02:00
self . commitNewPackage ( pac , msg , todo , validators_dir = validators_dir , verbose_validation = verbose_validation )
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
elif state == ' D ' :
self . commitDelPackage ( pac )
elif state == ' ' :
# display the correct dir when sending the changes
2009-05-20 18:32:45 +02:00
if os_path_samefile ( os . path . join ( self . dir , pac ) , os . getcwd ( ) ) :
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
p = Package ( ' . ' )
else :
p = Package ( os . path . join ( self . dir , pac ) )
p . todo = todo
2010-09-09 12:30:49 +02:00
p . commit ( msg , validators_dir = validators_dir , verbose_validation = verbose_validation )
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
elif pac in self . pacs_unvers and not is_package_dir ( os . path . join ( self . dir , pac ) ) :
print ' osc: \' %s \' is not under version control ' % pac
elif pac in self . pacs_broken :
print ' osc: \' %s \' package not found ' % pac
elif state == None :
2010-09-09 12:49:53 +02:00
self . commitExtPackage ( pac , msg , todo , validators_dir = validators_dir , verbose_validation = verbose_validation )
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
finally :
self . write_packages ( )
2008-03-10 19:04:23 +01:00
else :
# if we have packages marked as '!' we cannot commit
for pac in self . pacs_broken :
if self . get_state ( pac ) != ' D ' :
Merged revisions 3774-3775,3779,3781-3782,3787,3789-3793,3798,3802,3805,3817-3822,3827,3829-3830,3837-3839,3841-3842,3848-3850 via svnmerge from
https://forgesvn1.novell.com/svn/opensuse/branches/buildservice/osc-exception-handling
........
r3774 | poeml | 2008-04-22 17:39:45 +0200 (Tue, 22 Apr 2008) | 3 lines
A first draft on implement systematic exception handling:
Add errors.py with some exceptions defined, and babysitter.py to handle them
........
r3775 | poeml | 2008-04-22 22:34:12 +0200 (Tue, 22 Apr 2008) | 9 lines
- new global options:
--debugger jump into the debugger before executing anything
--post-mortem jump into the debugger in case of errors
-t, --traceback print call trace in case of errors
- traceback and post_mortem can also be set in .oscrc.
- catch more errors (HTTPError).
- make config accessible from outside of the Osc instance, by making it a class
attribute
........
r3779 | poeml | 2008-04-23 00:55:49 +0200 (Wed, 23 Apr 2008) | 5 lines
- new global option:
-d, --debug print info useful for debugging
- catch some more errors (HTTPError), with OscHTTPError which isn't very
advanced yet.
........
r3781 | Marcus_H | 2008-04-23 01:02:00 +0200 (Wed, 23 Apr 2008) | 2 lines
- added OscConfigError class (just for testing).
- small change in the signature of the OscBaseError constructor (actually we should get rid of the 'args' tuple because it will be deprecated sooner or later
........
r3782 | Marcus_H | 2008-04-23 02:02:13 +0200 (Wed, 23 Apr 2008) | 2 lines
- access the prg.conf.config dict in a save way - this way we avoid AttributeErrors if the prg.conf.config dict doesn't exist
- in case of an configparser error we have to use the prg.options object directly (this was removed in r3781 by accident)
........
r3787 | poeml | 2008-04-23 09:23:56 +0200 (Wed, 23 Apr 2008) | 4 lines
- remove local exception handling from do_req
- for HTTPError, print details (headers and response) when in debug mode
- catch AttributeError
........
r3789 | poeml | 2008-04-23 16:23:14 +0200 (Wed, 23 Apr 2008) | 4 lines
- errors: add two new classes named OscWrongOptionsError and OscWrongArgsError
- commandline: raise instances of the new errors in a number of places
- commandline: add get_cmd_help() to Osc instance which returns the formatted help of a subcommand
........
r3790 | Marcus_H | 2008-04-23 16:48:28 +0200 (Wed, 23 Apr 2008) | 4 lines
- added 2 new exception classes: OscNoConfigfileError and OscIOError
- added new method write_config() to the conf.py module: This method writes osc's configuration file
- minor cleanups in the conf module
........
r3791 | poeml | 2008-04-23 17:11:07 +0200 (Wed, 23 Apr 2008) | 3 lines
small compatibility fix for r3790: try-except-finally isn't supported in
python-2.4.2, thus do the same as try-except inside a try-finally.
........
r3792 | poeml | 2008-04-23 17:37:53 +0200 (Wed, 23 Apr 2008) | 2 lines
fix up the remaining places regarding handling of errors related to commandline parsing
........
r3793 | poeml | 2008-04-23 17:40:34 +0200 (Wed, 23 Apr 2008) | 3 lines
raise a NoWorkingCopyError in osc.core.store_read_project() in case of an
IOError
........
r3798 | Marcus_H | 2008-04-23 23:55:24 +0200 (Wed, 23 Apr 2008) | 1 line
ported -r3797 from trunk
........
r3802 | Marcus_H | 2008-04-24 11:00:55 +0200 (Thu, 24 Apr 2008) | 1 line
ported -r3801 from trunk
........
r3805 | poeml | 2008-04-24 12:52:30 +0200 (Thu, 24 Apr 2008) | 2 lines
raise OscHTTPError in show_pattern_meta(), replacing local error handling
........
r3817 | poeml | 2008-04-24 20:21:32 +0200 (Thu, 24 Apr 2008) | 9 lines
- remove errors.OscHTTPError again.
it seems simpler to use urllib2.HTTPError instead (and just add a specific
error text message where appropriate, and re-raise)
- for 404s, check out _which_ part was not found
it is very ugly, but may be considered Good for pragmatic reasons
- removed local exception handling and workaround for returned 500's from
delete_package() and delete_project(), thereby getting rid of 4 possible exit
points.
........
r3818 | Marcus_H | 2008-04-24 22:36:17 +0200 (Thu, 24 Apr 2008) | 1 line
- this check is superfluous because every HTTPError instance has a code attribute
........
r3819 | poeml | 2008-04-25 00:39:39 +0200 (Fri, 25 Apr 2008) | 1 line
remove a forgotten debug line from core.delete_project()
........
r3820 | poeml | 2008-04-25 10:07:58 +0200 (Fri, 25 Apr 2008) | 2 lines
- ditch local error handling from wipebinaries(), rebuild(), and abortbuild()
........
r3821 | poeml | 2008-04-25 10:56:38 +0200 (Fri, 25 Apr 2008) | 2 lines
It is never needed to import the exception module.
........
r3822 | poeml | 2008-04-25 11:13:39 +0200 (Fri, 25 Apr 2008) | 4 lines
- when going into the debugger with --post-mortem, always print a traceback before
(thus implying -t)
- do not jump into the debugger if not on a TTY, or working in interactive mode
........
r3827 | poeml | 2008-04-25 13:07:46 +0200 (Fri, 25 Apr 2008) | 9 lines
- add errors.OscWorkingCopyOutdated, which takes a tuple with three args:
path to working copy, current rev, expected rev
- add handler for urllib2.URLError errors to the babysitter
- simplify the OscWrongArgsError and OscWrongOptionsError handlers, by removing
the extra line "Sorry, wrong ..." that was printed before the messages given
when the error was raised.
- remove one more errors.OscHTTPError which was still there, and raise
urllib2.HTTPError instead (show_package_meta())
........
r3829 | poeml | 2008-04-25 14:19:10 +0200 (Fri, 25 Apr 2008) | 11 lines
- comment some methods in osc.core which are used by nearly all do_* methods in
osc.commandline
- improve "is not a package/project dir" error messages, by printing the
absolute path tried, instead of '.' for the cwd
- make core.store_read_package() raise a proper NoWorkingCopyError instead of
terminating
- give attribution to things in babysitter.py copied from mercurial
- prefix HTTPError exceptions with 'Server returned an error:'
- remove obsolete local error handling from do_prjresults(), do_importsrcpkg(),
do_repos()
........
r3830 | poeml | 2008-04-25 14:29:35 +0200 (Fri, 25 Apr 2008) | 1 line
catch IOError exceptions in the babysitter
........
r3837 | poeml | 2008-04-25 17:27:36 +0200 (Fri, 25 Apr 2008) | 5 lines
- do_remotebuildlog: raise errors for wrong arguments, remove exits
- raise AttributeError in make_meta_url() instead of exiting
- delete unused method core.delete_server_files()
- replace exit call inside make_meta_url() with an AttributeError
........
r3838 | poeml | 2008-04-25 17:49:18 +0200 (Fri, 25 Apr 2008) | 1 line
simplify the check in do_checkout if a project exists, by using show_project_meta() instead of meta_exists
........
r3839 | poeml | 2008-04-25 18:31:26 +0200 (Fri, 25 Apr 2008) | 6 lines
- commandline do_checkout(): change the order of the two checks, first do the
(cheaper) check for existing directory
- core.core checkout_package(): simplify the check in if the package
exists, by using show_package_meta() instead of meta_exists
Let it throw an exception, instead of using sys.exit().
........
r3841 | Marcus_H | 2008-04-27 15:48:06 +0200 (Sun, 27 Apr 2008) | 5 lines
- added 2 new exception classes: PackageError() and PackageExistsError. The PackageError() class is meant to be the base class for all subsequent package exceptions.
- get rid of 2 sys.exit(1) calls
- make the update() method of the Project() class safer: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- minor fix in delPackage(): use getTransActPath() when printing out the filename
........
r3842 | Marcus_H | 2008-04-27 16:52:55 +0200 (Sun, 27 Apr 2008) | 3 lines
- make the commit() method safe: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- removed another sys.exit(1): raise an exception if a package is missing when doing a commit. For now we use the PackageExistsError() exception but this might change in the future (updated description of PackageExistsError() according to this change)
........
r3848 | poeml | 2008-04-28 12:46:45 +0200 (Mon, 28 Apr 2008) | 3 lines
rename several error classes, dropping the "Osc" prefix, and "Error" suffix in
cases where they don't really make sense.
........
r3849 | poeml | 2008-04-28 12:57:32 +0200 (Mon, 28 Apr 2008) | 3 lines
- rename osc.errors module to osc.oscerr, to make it easier to import it from
other programs and have a crystal clear namespace
........
r3850 | poeml | 2008-04-28 13:26:12 +0200 (Mon, 28 Apr 2008) | 2 lines
split PackageExists exception class into PackageExists and PackageMissing
........
2008-04-28 18:37:44 +02:00
msg = ' commit failed: package \' %s \' is missing ' % pac
raise oscerr . PackageMissing ( self . name , pac , msg )
try :
for pac in self . pacs_have :
state = self . get_state ( pac )
if state == ' ' :
# do a simple commit
2010-09-09 12:30:49 +02:00
Package ( os . path . join ( self . dir , pac ) ) . commit ( msg , validators_dir = validators_dir , verbose_validation = verbose_validation )
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
elif state == ' D ' :
self . commitDelPackage ( pac )
elif state == ' A ' :
2010-09-09 12:30:49 +02:00
self . commitNewPackage ( pac , msg , validators_dir = validators_dir , verbose_validation = verbose_validation )
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
finally :
self . write_packages ( )
2008-03-10 19:04:23 +01:00
2010-09-09 12:49:53 +02:00
def commitNewPackage ( self , pac , msg = ' ' , files = [ ] , validators_dir = None , verbose_validation = False ) :
2008-03-10 19:04:23 +01:00
""" creates and commits a new package if it does not exist on the server """
if pac in self . pacs_available :
print ' package \' %s \' already exists ' % pac
else :
2008-03-15 23:51:37 +01:00
user = conf . get_apiurl_usr ( self . apiurl )
2008-03-10 19:04:23 +01:00
edit_meta ( metatype = ' pkg ' ,
path_args = ( quote_plus ( self . name ) , quote_plus ( pac ) ) ,
2009-04-21 18:52:26 +02:00
template_args = ( {
' name ' : pac ,
' user ' : user } ) ,
apiurl = self . apiurl )
2008-03-10 19:04:23 +01:00
# display the correct dir when sending the changes
2006-05-22 12:50:37 +02:00
olddir = os . getcwd ( )
2009-05-20 18:32:45 +02:00
if os_path_samefile ( os . path . join ( self . dir , pac ) , os . curdir ) :
2008-03-10 19:04:23 +01:00
os . chdir ( os . pardir )
p = Package ( pac )
else :
p = Package ( os . path . join ( self . dir , pac ) )
p . todo = files
print statfrmt ( ' Sending ' , os . path . normpath ( p . dir ) )
2010-09-09 12:30:49 +02:00
p . commit ( msg = msg , validators_dir = validators_dir , verbose_validation = verbose_validation )
2008-03-10 19:04:23 +01:00
self . set_state ( pac , ' ' )
2006-05-22 12:50:37 +02:00
os . chdir ( olddir )
2008-03-10 19:04:23 +01:00
def commitDelPackage ( self , pac ) :
""" deletes a package on the server and in the working copy """
try :
# display the correct dir when sending the changes
2009-05-20 18:32:45 +02:00
if os_path_samefile ( os . path . join ( self . dir , pac ) , os . curdir ) :
2008-03-10 19:04:23 +01:00
pac_dir = pac
else :
pac_dir = os . path . join ( self . dir , pac )
p = Package ( os . path . join ( self . dir , pac ) )
#print statfrmt('Deleting', os.path.normpath(os.path.join(p.dir, os.pardir, pac)))
delete_storedir ( p . storedir )
try :
os . rmdir ( p . dir )
except :
pass
except OSError :
pac_dir = os . path . join ( self . dir , pac )
#print statfrmt('Deleting', getTransActPath(os.path.join(self.dir, pac)))
print statfrmt ( ' Deleting ' , getTransActPath ( pac_dir ) )
delete_package ( self . apiurl , self . name , pac )
self . del_package_node ( pac )
2010-09-09 12:49:53 +02:00
def commitExtPackage ( self , pac , msg , files = [ ] , validators_dir = None , verbose_validation = False ) :
2008-03-10 19:04:23 +01:00
""" commits a package from an external project """
2009-05-20 18:32:45 +02:00
if os_path_samefile ( os . path . join ( self . dir , pac ) , os . getcwd ( ) ) :
2008-03-10 19:04:23 +01:00
pac_path = ' . '
else :
pac_path = os . path . join ( self . dir , pac )
2009-10-20 16:30:15 +02:00
2008-03-10 19:04:23 +01:00
project = store_read_project ( pac_path )
package = store_read_package ( pac_path )
2010-09-19 23:00:19 +02:00
apiurl = store_read_apiurl ( pac_path , defaulturl = False )
2010-09-09 12:49:53 +02:00
if not meta_exists ( metatype = ' pkg ' ,
path_args = ( quote_plus ( project ) , quote_plus ( package ) ) ,
template_args = None , create_new = False , apiurl = apiurl ) :
2008-03-15 23:51:37 +01:00
user = conf . get_apiurl_usr ( self . apiurl )
2008-03-10 19:04:23 +01:00
edit_meta ( metatype = ' pkg ' ,
path_args = ( quote_plus ( project ) , quote_plus ( package ) ) ,
2010-09-09 12:49:53 +02:00
template_args = ( { ' name ' : pac , ' user ' : user } ) , apiurl = apiurl )
p = Package ( pac_path )
p . todo = files
p . commit ( msg = msg , validators_dir = validators_dir , verbose_validation = verbose_validation )
2006-05-22 12:50:37 +02:00
def __str__ ( self ) :
r = [ ]
r . append ( ' ***************************************************** ' )
r . append ( ' Project %s (dir= %s , absdir= %s ) ' % ( self . name , self . dir , self . absdir ) )
r . append ( ' have pacs: \n %s ' % ' , ' . join ( self . pacs_have ) )
r . append ( ' missing pacs: \n %s ' % ' , ' . join ( self . pacs_missing ) )
r . append ( ' ***************************************************** ' )
return ' \n ' . join ( r )
2010-10-09 16:26:55 +02:00
@staticmethod
2010-12-23 02:15:58 +01:00
def init_project ( apiurl , dir , project , package_tracking = True , getPackageList = True , progress_obj = None , wc_check = True ) :
2010-10-09 16:26:55 +02:00
global store
if not os . path . exists ( dir ) :
# use makedirs (checkout_no_colon config option might be enabled)
os . makedirs ( dir )
elif not os . path . isdir ( dir ) :
raise oscerr . OscIOError ( None , ' error: \' %s \' is no directory ' % dir )
if os . path . exists ( os . path . join ( dir , store ) ) :
raise oscerr . OscIOError ( None , ' error: \' %s \' is already an initialized osc working copy ' % dir )
else :
os . mkdir ( os . path . join ( dir , store ) )
store_write_project ( dir , project )
store_write_apiurl ( dir , apiurl )
if package_tracking :
store_write_initial_packages ( dir , project , [ ] )
2010-12-23 02:15:58 +01:00
return Project ( dir , getPackageList , progress_obj , wc_check )
2006-05-22 12:50:37 +02:00
2006-05-19 22:13:29 +02:00
class Package :
""" represent a package (its directory) and read/keep/write its metadata """
2010-09-08 18:56:15 +02:00
# should _meta be a required file?
REQ_STOREFILES = ( ' _project ' , ' _package ' , ' _apiurl ' , ' _files ' , ' _osclib_version ' )
OPT_STOREFILES = ( ' _to_be_added ' , ' _to_be_deleted ' , ' _in_conflict ' , ' _in_update ' ,
2010-10-09 14:31:06 +02:00
' _in_commit ' , ' _meta ' , ' _meta_mode ' , ' _frozenlink ' , ' _pulled ' , ' _linkrepair ' ,
' _size_limit ' , ' _commit_msg ' )
2010-09-08 18:56:15 +02:00
def __init__ ( self , workingdir , progress_obj = None , size_limit = None , wc_check = True ) :
2010-08-31 14:43:43 +02:00
global store
2006-05-19 22:13:29 +02:00
self . dir = workingdir
2006-06-06 12:50:40 +02:00
self . absdir = os . path . abspath ( self . dir )
2007-11-26 19:13:51 +01:00
self . storedir = os . path . join ( self . absdir , store )
2010-02-09 20:57:10 +01:00
self . progress_obj = progress_obj
2010-09-03 14:51:20 +02:00
self . size_limit = size_limit
if size_limit and size_limit == 0 :
2010-09-19 23:00:19 +02:00
self . size_limit = None
2006-05-19 22:13:29 +02:00
check_store_version ( self . dir )
2010-04-09 15:47:07 +02:00
self . prjname = store_read_project ( self . dir )
2010-04-09 15:57:12 +02:00
self . name = store_read_package ( self . dir )
2010-09-28 23:07:33 +02:00
self . apiurl = store_read_apiurl ( self . dir , defaulturl = not wc_check )
2006-05-19 22:13:29 +02:00
2007-07-30 13:12:42 +02:00
self . update_datastructs ( )
2010-09-28 23:07:33 +02:00
dirty_files = [ ]
if wc_check :
dirty_files = self . wc_check ( )
if dirty_files :
2010-09-14 13:12:32 +02:00
msg = ' Your working copy \' %s \' is in an inconsistent state. \n ' \
2010-09-14 14:48:10 +02:00
' Please run \' osc repairwc %s \' (Note this might _remove_ \n ' \
2010-09-08 18:56:15 +02:00
' files from the .osc/ dir). Please check the state \n ' \
2010-09-14 14:48:10 +02:00
' of the working copy afterwards (via \' osc status %s \' ) ' % ( self . dir , self . dir , self . dir )
2010-09-28 23:07:33 +02:00
raise oscerr . WorkingCopyInconsistent ( self . prjname , self . name , dirty_files , msg )
2006-05-19 22:13:29 +02:00
self . todo = [ ]
2010-09-08 18:56:15 +02:00
def wc_check ( self ) :
2010-09-28 23:07:33 +02:00
dirty_files = [ ]
2010-09-08 18:56:15 +02:00
for fname in self . filenamelist :
if not os . path . exists ( os . path . join ( self . storedir , fname ) ) and not fname in self . skipped :
2010-09-28 23:07:33 +02:00
dirty_files . append ( fname )
2010-09-08 18:56:15 +02:00
for fname in Package . REQ_STOREFILES :
if not os . path . isfile ( os . path . join ( self . storedir , fname ) ) :
2010-09-28 23:07:33 +02:00
dirty_files . append ( fname )
2010-09-08 18:56:15 +02:00
for fname in os . listdir ( self . storedir ) :
if fname in Package . REQ_STOREFILES or fname in Package . OPT_STOREFILES or \
fname . startswith ( ' _build ' ) :
continue
elif fname in self . filenamelist and fname in self . skipped :
2010-09-28 23:07:33 +02:00
dirty_files . append ( fname )
2010-09-08 18:56:15 +02:00
elif not fname in self . filenamelist :
2010-09-28 23:07:33 +02:00
dirty_files . append ( fname )
2010-09-08 18:56:15 +02:00
for fname in self . to_be_deleted [ : ] :
if not fname in self . filenamelist :
2010-09-28 23:07:33 +02:00
dirty_files . append ( fname )
2010-09-08 18:56:15 +02:00
for fname in self . in_conflict [ : ] :
if not fname in self . filenamelist :
2010-09-28 23:07:33 +02:00
dirty_files . append ( fname )
return dirty_files
def wc_repair ( self , apiurl = None ) :
2010-12-07 20:35:12 +01:00
if not os . path . exists ( os . path . join ( self . storedir , ' _apiurl ' ) ) or apiurl :
2010-09-28 23:07:33 +02:00
if apiurl is None :
msg = ' cannot repair wc: the \' _apiurl \' file is missing but ' \
' no \' apiurl \' was passed to wc_repair '
# hmm should we raise oscerr.WrongArgs?
raise oscerr . WorkingCopyInconsistent ( self . prjname , self . name , [ ] , msg )
2010-12-09 20:36:06 +01:00
# sanity check
conf . parse_apisrv_url ( None , apiurl )
2010-09-28 23:07:33 +02:00
store_write_apiurl ( self . dir , apiurl )
self . apiurl = store_read_apiurl ( self . dir , defaulturl = False )
2010-09-08 18:56:15 +02:00
# all files which are present in the filelist have to exist in the storedir
for f in self . filelist :
# XXX: should we also check the md5?
if not os . path . exists ( os . path . join ( self . storedir , f . name ) ) and not f . name in self . skipped :
# if get_source_file fails we're screwed up...
get_source_file ( self . apiurl , self . prjname , self . name , f . name ,
targetfilename = os . path . join ( self . storedir , f . name ) , revision = self . rev ,
mtime = f . mtime )
for fname in os . listdir ( self . storedir ) :
if fname in Package . REQ_STOREFILES or fname in Package . OPT_STOREFILES or \
fname . startswith ( ' _build ' ) :
continue
elif not fname in self . filenamelist or fname in self . skipped :
# this file does not belong to the storedir so remove it
os . unlink ( os . path . join ( self . storedir , fname ) )
for fname in self . to_be_deleted [ : ] :
if not fname in self . filenamelist :
self . to_be_deleted . remove ( fname )
self . write_deletelist ( )
for fname in self . in_conflict [ : ] :
if not fname in self . filenamelist :
self . in_conflict . remove ( fname )
self . write_conflictlist ( )
2007-05-04 23:51:54 +02:00
def info ( self ) :
2009-10-20 16:30:15 +02:00
source_url = makeurl ( self . apiurl , [ ' source ' , self . prjname , self . name ] )
2008-05-21 15:44:49 +02:00
r = info_templ % ( self . prjname , self . name , self . absdir , self . apiurl , source_url , self . srcmd5 , self . rev , self . linkinfo )
2008-03-22 18:37:17 +01:00
return r
2007-05-04 23:51:54 +02:00
2006-05-19 22:13:29 +02:00
def addfile ( self , n ) :
2010-08-24 18:06:47 +02:00
if not os . path . exists ( os . path . join ( self . absdir , n ) ) :
2010-09-02 10:23:37 +02:00
raise oscerr . OscIOError ( None , ' error: file \' %s \' does not exist ' % n )
2010-08-24 18:06:47 +02:00
if n in self . to_be_deleted :
self . to_be_deleted . remove ( n )
# self.delete_storefile(n)
self . write_deletelist ( )
elif n in self . filenamelist or n in self . to_be_added :
raise oscerr . PackageFileConflict ( self . prjname , self . name , n , ' osc: warning: \' %s \' is already under version control ' % n )
# shutil.copyfile(os.path.join(self.dir, n), os.path.join(self.storedir, n))
if self . dir != ' . ' :
pathname = os . path . join ( self . dir , n )
else :
pathname = n
self . to_be_added . append ( n )
self . write_addlist ( )
print statfrmt ( ' A ' , pathname )
2009-07-15 23:10:38 +02:00
def delete_file ( self , n , force = False ) :
""" deletes a file if possible and marks the file as deleted """
2010-03-22 11:07:10 +01:00
state = ' ? '
try :
state = self . status ( n )
except IOError , ioe :
if not force :
raise ioe
2010-08-24 18:06:47 +02:00
if state in [ ' ? ' , ' A ' , ' M ' , ' R ' , ' C ' ] and not force :
2009-07-15 23:10:38 +02:00
return ( False , state )
self . delete_localfile ( n )
2010-09-06 15:28:23 +02:00
was_added = n in self . to_be_added
if state in ( ' A ' , ' R ' ) or state == ' ! ' and was_added :
2010-08-24 18:06:47 +02:00
self . to_be_added . remove ( n )
self . write_addlist ( )
elif state == ' C ' :
# don't remove "merge files" (*.r, *.mine...)
# that's why we don't use clear_from_conflictlist
self . in_conflict . remove ( n )
self . write_conflictlist ( )
2010-09-06 15:28:23 +02:00
if not state in ( ' A ' , ' ? ' ) and not ( state == ' ! ' and was_added ) :
2009-07-15 23:10:38 +02:00
self . put_on_deletelist ( n )
self . write_deletelist ( )
return ( True , state )
2007-03-19 14:30:59 +01:00
def delete_storefile ( self , n ) :
try : os . unlink ( os . path . join ( self . storedir , n ) )
except : pass
2006-05-30 12:07:16 +02:00
def delete_localfile ( self , n ) :
try : os . unlink ( os . path . join ( self . dir , n ) )
except : pass
2006-05-19 22:13:29 +02:00
def put_on_deletelist ( self , n ) :
if n not in self . to_be_deleted :
self . to_be_deleted . append ( n )
2006-05-22 16:12:06 +02:00
def put_on_conflictlist ( self , n ) :
if n not in self . in_conflict :
self . in_conflict . append ( n )
2010-08-24 18:06:47 +02:00
def put_on_addlist ( self , n ) :
if n not in self . to_be_added :
self . to_be_added . append ( n )
2006-05-22 16:12:06 +02:00
def clear_from_conflictlist ( self , n ) :
""" delete an entry from the file, and remove the file if it would be empty """
if n in self . in_conflict :
filename = os . path . join ( self . dir , n )
storefilename = os . path . join ( self . storedir , n )
myfilename = os . path . join ( self . dir , n + ' .mine ' )
2010-01-11 17:00:24 +01:00
if self . islinkrepair ( ) or self . ispulled ( ) :
2009-04-21 18:52:26 +02:00
upfilename = os . path . join ( self . dir , n + ' .new ' )
else :
upfilename = os . path . join ( self . dir , n + ' .r ' + self . rev )
2006-05-22 16:12:06 +02:00
2006-06-08 12:30:29 +02:00
try :
os . unlink ( myfilename )
# the working copy may be updated, so the .r* ending may be obsolete...
# then we don't care
os . unlink ( upfilename )
2010-01-11 17:00:24 +01:00
if self . islinkrepair ( ) or self . ispulled ( ) :
2009-04-22 15:14:17 +02:00
os . unlink ( os . path . join ( self . dir , n + ' .old ' ) )
2009-10-20 16:30:15 +02:00
except :
2006-06-08 12:30:29 +02:00
pass
2006-05-22 16:12:06 +02:00
self . in_conflict . remove ( n )
2006-05-23 15:59:29 +02:00
self . write_conflictlist ( )
2006-05-22 16:12:06 +02:00
2010-05-27 02:18:00 +02:00
# XXX: this isn't used at all
2010-05-22 08:22:12 +02:00
def write_meta_mode ( self ) :
2010-05-27 01:54:04 +02:00
# XXX: the "elif" is somehow a contradiction (with current and the old implementation
# it's not possible to "leave" the metamode again) (except if you modify pac.meta
# which is really ugly:) )
2010-05-22 08:22:12 +02:00
if self . meta :
2010-05-27 01:54:04 +02:00
store_write_string ( self . absdir , ' _meta_mode ' , ' ' )
elif self . ismetamode ( ) :
os . unlink ( os . path . join ( self . storedir , ' _meta_mode ' ) )
2010-05-22 08:22:12 +02:00
2010-04-22 15:27:54 +02:00
def write_sizelimit ( self ) :
if self . size_limit and self . size_limit < = 0 :
try :
os . unlink ( os . path . join ( self . storedir , ' _size_limit ' ) )
except :
pass
else :
2010-08-30 14:20:12 +02:00
store_write_string ( self . absdir , ' _size_limit ' , str ( self . size_limit ) + ' \n ' )
2010-04-22 15:27:54 +02:00
2010-08-24 18:06:47 +02:00
def write_addlist ( self ) :
self . __write_storelist ( ' _to_be_added ' , self . to_be_added )
2006-05-19 22:13:29 +02:00
def write_deletelist ( self ) :
2010-08-24 10:23:11 +02:00
self . __write_storelist ( ' _to_be_deleted ' , self . to_be_deleted )
2006-05-22 16:12:06 +02:00
2006-05-30 12:07:16 +02:00
def delete_source_file ( self , n ) :
2008-03-10 19:04:23 +01:00
""" delete local a source file """
2006-05-30 12:07:16 +02:00
self . delete_localfile ( n )
2007-03-19 14:30:59 +01:00
self . delete_storefile ( n )
2006-05-30 12:07:16 +02:00
2008-03-10 19:04:23 +01:00
def delete_remote_source_file ( self , n ) :
""" delete a remote source file (e.g. from the server) """
2008-04-21 17:07:34 +02:00
query = ' rev=upload '
u = makeurl ( self . apiurl , [ ' source ' , self . prjname , self . name , pathname2url ( n ) ] , query = query )
2008-03-10 19:04:23 +01:00
http_DELETE ( u )
2009-10-20 16:30:15 +02:00
2010-09-03 17:46:01 +02:00
def put_source_file ( self , n , copy_only = False ) :
cdir = os . path . join ( self . storedir , ' _in_commit ' )
try :
if not os . path . isdir ( cdir ) :
os . mkdir ( cdir )
query = ' rev=repository '
tmpfile = os . path . join ( cdir , n )
shutil . copyfile ( os . path . join ( self . dir , n ) , tmpfile )
# escaping '+' in the URL path (note: not in the URL query string) is
# only a workaround for ruby on rails, which swallows it otherwise
if not copy_only :
u = makeurl ( self . apiurl , [ ' source ' , self . prjname , self . name , pathname2url ( n ) ] , query = query )
http_PUT ( u , file = os . path . join ( self . dir , n ) )
os . rename ( tmpfile , os . path . join ( self . storedir , n ) )
finally :
if os . path . isdir ( cdir ) :
shutil . rmtree ( cdir )
2010-08-24 18:06:47 +02:00
if n in self . to_be_added :
self . to_be_added . remove ( n )
2006-05-30 12:07:16 +02:00
2010-09-03 17:46:01 +02:00
def __generate_commitlist ( self , todo_send ) :
root = ET . Element ( ' directory ' )
keys = todo_send . keys ( )
keys . sort ( )
for i in keys :
ET . SubElement ( root , ' entry ' , name = i , md5 = todo_send [ i ] )
return root
def __send_commitlog ( self , msg , local_filelist ) :
""" send the commitlog and the local filelist to the server """
query = { ' cmd ' : ' commitfilelist ' ,
' user ' : conf . get_apiurl_usr ( self . apiurl ) ,
' comment ' : msg }
if self . islink ( ) and self . isexpanded ( ) :
query [ ' keeplink ' ] = ' 1 '
if conf . config [ ' linkcontrol ' ] or self . isfrozen ( ) :
query [ ' linkrev ' ] = self . linkinfo . srcmd5
if self . ispulled ( ) :
query [ ' repairlink ' ] = ' 1 '
query [ ' linkrev ' ] = self . get_pulled_srcmd5 ( )
if self . islinkrepair ( ) :
query [ ' repairlink ' ] = ' 1 '
u = makeurl ( self . apiurl , [ ' source ' , self . prjname , self . name ] , query = query )
f = http_POST ( u , data = ET . tostring ( local_filelist ) )
root = ET . parse ( f ) . getroot ( )
return root
def __get_todo_send ( self , server_filelist ) :
""" parse todo from a previous __send_commitlog call """
error = server_filelist . get ( ' error ' )
if error is None :
return [ ]
elif error != ' missing ' :
raise oscerr . PackageInternalError ( self . prjname , self . name ,
' __get_todo_send: unexpected \' error \' attr: \' %s \' ' % error )
todo = [ ]
for n in server_filelist . findall ( ' entry ' ) :
name = n . get ( ' name ' )
if name is None :
raise oscerr . APIError ( ' missing \' name \' attribute: \n %s \n ' % ET . tostring ( server_filelist ) )
todo . append ( n . get ( ' name ' ) )
return todo
2010-09-09 12:30:49 +02:00
def validate ( self , validators_dir , verbose_validation = False ) :
import subprocess
import stat
if validators_dir is None or self . name . startswith ( ' _ ' ) :
return
for validator in sorted ( os . listdir ( validators_dir ) ) :
if validator . startswith ( ' . ' ) :
continue
fn = os . path . join ( validators_dir , validator )
mode = os . stat ( fn ) . st_mode
if stat . S_ISREG ( mode ) :
if verbose_validation :
print ' osc runs source validator: %s ' % fn
p = subprocess . Popen ( [ fn , ' --verbose ' ] , close_fds = True )
else :
p = subprocess . Popen ( [ fn ] , close_fds = True )
if p . wait ( ) != 0 :
raise oscerr . ExtRuntimeError ( ' ERROR: source_validator failed: \n %s ' % p . stdout , validator )
2010-09-09 12:49:53 +02:00
def commit ( self , msg = ' ' , validators_dir = None , verbose_validation = False ) :
2007-07-30 13:12:42 +02:00
# commit only if the upstream revision is the same as the working copy's
2009-10-20 16:30:15 +02:00
upstream_rev = self . latest_rev ( )
2007-07-30 13:12:42 +02:00
if self . rev != upstream_rev :
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 . WorkingCopyOutdated ( ( self . absdir , self . rev , upstream_rev ) )
2007-07-30 13:12:42 +02:00
2010-09-09 12:30:49 +02:00
if not validators_dir is None :
self . validate ( validators_dir , verbose_validation )
2007-07-30 13:12:42 +02:00
if not self . todo :
2010-09-03 17:46:01 +02:00
self . todo = [ i for i in self . to_be_added if not i in self . filenamelist ] + self . filenamelist
2009-10-20 16:30:15 +02:00
2008-03-10 19:04:23 +01:00
pathn = getTransActPath ( self . dir )
2007-07-30 13:12:42 +02:00
2010-09-03 17:46:01 +02:00
todo_send = { }
todo_delete = [ ]
real_send = [ ]
for filename in self . filenamelist + [ i for i in self . to_be_added if not i in self . filenamelist ] :
if filename . startswith ( ' _service: ' ) or filename . startswith ( ' _service_ ' ) :
continue
st = self . status ( filename )
if st == ' C ' :
print ' Please resolve all conflicts before committing using " osc resolved FILE " ! '
return 1
elif filename in self . todo :
if st in ( ' A ' , ' R ' , ' M ' ) :
todo_send [ filename ] = dgst ( os . path . join ( self . absdir , filename ) )
real_send . append ( filename )
2009-10-20 16:30:15 +02:00
print statfrmt ( ' Sending ' , os . path . join ( pathn , filename ) )
2010-09-03 17:46:01 +02:00
elif st in ( ' ' , ' ! ' , ' S ' ) :
2010-12-17 23:25:50 +01:00
if st == ' ! ' and filename in self . to_be_added :
print ' file \' %s \' is marked as \' A \' but does not exist ' % filename
return 1
2010-09-03 17:46:01 +02:00
f = self . findfilebyname ( filename )
if f is None :
raise oscerr . PackageInternalError ( self . prjname , self . name ,
' error: file \' %s \' with state \' %s \' is not known by meta ' \
% ( filename , st ) )
todo_send [ filename ] = f . md5
2009-10-20 16:30:15 +02:00
elif st == ' D ' :
2010-08-23 15:39:48 +02:00
todo_delete . append ( filename )
2009-10-20 16:30:15 +02:00
print statfrmt ( ' Deleting ' , os . path . join ( pathn , filename ) )
2010-09-03 17:46:01 +02:00
elif st in ( ' R ' , ' M ' , ' D ' , ' ' , ' ! ' , ' S ' ) :
2010-12-17 23:25:50 +01:00
# ignore missing new file (it's not part of the current commit)
if st == ' ! ' and filename in self . to_be_added :
continue
2010-09-03 17:46:01 +02:00
f = self . findfilebyname ( filename )
if f is None :
raise oscerr . PackageInternalError ( self . prjname , self . name ,
' error: file \' %s \' with state \' %s \' is not known by meta ' \
% ( filename , st ) )
todo_send [ filename ] = f . md5
if not real_send and not todo_delete and not self . islinkrepair ( ) and not self . ispulled ( ) :
2007-07-30 13:12:42 +02:00
print ' nothing to do for package %s ' % self . name
2008-05-08 13:55:32 +02:00
return 1
2007-07-30 13:12:42 +02:00
2009-10-20 16:30:15 +02:00
print ' Transmitting file data ' ,
2010-09-03 17:46:01 +02:00
filelist = self . __generate_commitlist ( todo_send )
sfilelist = self . __send_commitlog ( msg , filelist )
send = self . __get_todo_send ( sfilelist )
real_send = [ i for i in real_send if not i in send ]
# abort after 3 tries
tries = 3
while len ( send ) and tries :
for filename in send [ : ] :
2009-04-22 15:14:17 +02:00
sys . stdout . write ( ' . ' )
sys . stdout . flush ( )
self . put_source_file ( filename )
2010-09-03 17:46:01 +02:00
send . remove ( filename )
tries - = 1
sfilelist = self . __send_commitlog ( msg , filelist )
send = self . __get_todo_send ( sfilelist )
if len ( send ) :
raise oscerr . PackageInternalError ( self . prjname , self . name ,
' server does not accept filelist: \n %s \n missing: \n %s \n ' \
% ( ET . tostring ( filelist ) , ET . tostring ( sfilelist ) ) )
# these files already exist on the server
# just copy them into the storedir
for filename in real_send :
self . put_source_file ( filename , copy_only = True )
self . rev = sfilelist . get ( ' rev ' )
2007-08-14 12:30:39 +02:00
print
print ' Committed revision %s . ' % self . rev
2007-07-30 13:12:42 +02:00
2009-12-17 20:20:35 +01:00
if self . ispulled ( ) :
os . unlink ( os . path . join ( self . storedir , ' _pulled ' ) )
2009-04-21 18:52:26 +02:00
if self . islinkrepair ( ) :
os . unlink ( os . path . join ( self . storedir , ' _linkrepair ' ) )
self . linkrepair = False
# XXX: mark package as invalid?
2009-04-22 15:14:17 +02:00
print ' The source link has been repaired. This directory can now be removed. '
2010-09-03 17:46:01 +02:00
2008-04-02 14:37:56 +02:00
if self . islink ( ) and self . isexpanded ( ) :
2010-09-03 17:46:01 +02:00
li = Linkinfo ( )
li . read ( sfilelist . find ( ' linkinfo ' ) )
if li . xsrcmd5 is None :
raise oscerr . APIError ( ' linkinfo has no xsrcmd5 attr: \n %s \n ' % ET . tostring ( sfilelist ) )
sfilelist = ET . fromstring ( self . get_files_meta ( revision = li . xsrcmd5 ) )
for i in sfilelist . findall ( ' entry ' ) :
if i . get ( ' name ' ) in self . skipped :
i . set ( ' skipped ' , ' true ' )
store_write_string ( self . absdir , ' _files ' , ET . tostring ( sfilelist ) + ' \n ' )
for filename in todo_delete :
self . to_be_deleted . remove ( filename )
self . delete_storefile ( filename )
2007-07-30 13:12:42 +02:00
self . write_deletelist ( )
2010-08-30 18:29:24 +02:00
self . write_addlist ( )
2009-04-28 22:31:02 +02:00
self . update_datastructs ( )
2006-10-10 16:04:34 +02:00
2009-09-18 03:10:41 +02:00
print_request_list ( self . apiurl , self . prjname , self . name )
2009-07-10 20:10:41 +02:00
2010-08-24 10:23:11 +02:00
def __write_storelist ( self , name , data ) :
if len ( data ) == 0 :
2009-04-23 10:35:11 +02:00
try :
2010-08-24 10:23:11 +02:00
os . unlink ( os . path . join ( self . storedir , name ) )
2009-04-23 10:35:11 +02:00
except :
pass
2006-05-22 16:12:06 +02:00
else :
2010-08-24 10:23:11 +02:00
store_write_string ( self . absdir , name , ' %s \n ' % ' \n ' . join ( data ) )
def write_conflictlist ( self ) :
self . __write_storelist ( ' _in_conflict ' , self . in_conflict )
2006-05-19 22:13:29 +02:00
2010-08-19 18:10:32 +02:00
def updatefile ( self , n , revision , mtime = None ) :
2006-05-19 22:13:29 +02:00
filename = os . path . join ( self . dir , n )
storefilename = os . path . join ( self . storedir , n )
2010-08-26 10:05:15 +02:00
origfile_tmp = os . path . join ( self . storedir , ' _in_update ' , ' %s .copy ' % n )
2010-08-19 18:10:32 +02:00
origfile = os . path . join ( self . storedir , ' _in_update ' , n )
2010-09-07 10:54:42 +02:00
if os . path . isfile ( filename ) :
2010-08-26 10:05:15 +02:00
shutil . copyfile ( filename , origfile_tmp )
os . rename ( origfile_tmp , origfile )
2010-08-19 18:10:32 +02:00
else :
origfile = None
2006-05-19 22:13:29 +02:00
2010-08-19 18:10:32 +02:00
get_source_file ( self . apiurl , self . prjname , self . name , n , targetfilename = storefilename ,
2010-05-22 08:22:12 +02:00
revision = revision , progress_obj = self . progress_obj , mtime = mtime , meta = self . meta )
2006-05-19 22:13:29 +02:00
2010-08-19 18:10:32 +02:00
shutil . copyfile ( storefilename , filename )
if not origfile is None :
os . unlink ( origfile )
2006-05-19 22:13:29 +02:00
2010-08-19 18:10:32 +02:00
def mergefile ( self , n , revision , mtime = None ) :
2006-05-22 16:12:06 +02:00
filename = os . path . join ( self . dir , n )
storefilename = os . path . join ( self . storedir , n )
myfilename = os . path . join ( self . dir , n + ' .mine ' )
upfilename = os . path . join ( self . dir , n + ' .r ' + self . rev )
2010-08-26 10:05:15 +02:00
origfile_tmp = os . path . join ( self . storedir , ' _in_update ' , ' %s .copy ' % n )
2010-08-19 18:10:32 +02:00
origfile = os . path . join ( self . storedir , ' _in_update ' , n )
2010-08-26 10:05:15 +02:00
shutil . copyfile ( filename , origfile_tmp )
os . rename ( origfile_tmp , origfile )
2006-05-22 16:12:06 +02:00
os . rename ( filename , myfilename )
2009-10-20 16:30:15 +02:00
get_source_file ( self . apiurl , self . prjname , self . name , n ,
2010-08-19 18:10:32 +02:00
revision = revision , targetfilename = upfilename ,
2010-05-22 08:22:12 +02:00
progress_obj = self . progress_obj , mtime = mtime , meta = self . meta )
2006-06-22 14:54:58 +02:00
if binary_file ( myfilename ) or binary_file ( upfilename ) :
2009-10-20 16:30:15 +02:00
# don't try merging
2010-01-30 18:05:25 +01:00
shutil . copyfile ( upfilename , filename )
shutil . copyfile ( upfilename , storefilename )
2010-08-19 18:10:32 +02:00
os . unlink ( origfile )
2009-10-20 16:30:15 +02:00
self . in_conflict . append ( n )
self . write_conflictlist ( )
return ' C '
2006-05-22 16:12:06 +02:00
else :
2006-06-22 14:54:58 +02:00
# try merging
2007-01-23 07:55:43 +01:00
# diff3 OPTIONS... MINE OLDER YOURS
merge_cmd = ' diff3 -m -E %s %s %s > %s ' % ( myfilename , storefilename , upfilename , filename )
# we would rather use the subprocess module, but it is not availablebefore 2.4
2009-06-27 03:07:18 +02:00
ret = subprocess . call ( merge_cmd , shell = True )
2009-10-20 16:30:15 +02:00
2007-01-23 07:55:43 +01:00
# "An exit status of 0 means `diff3' was successful, 1 means some
# conflicts were found, and 2 means trouble."
2006-06-22 14:54:58 +02:00
if ret == 0 :
# merge was successful... clean up
2010-01-30 18:05:25 +01:00
shutil . copyfile ( upfilename , storefilename )
2007-01-23 07:55:43 +01:00
os . unlink ( upfilename )
2006-06-22 14:54:58 +02:00
os . unlink ( myfilename )
2010-08-19 18:10:32 +02:00
os . unlink ( origfile )
2006-06-22 14:54:58 +02:00
return ' G '
2007-01-23 07:55:43 +01:00
elif ret == 1 :
2006-06-22 14:54:58 +02:00
# unsuccessful merge
2010-01-30 18:05:25 +01:00
shutil . copyfile ( upfilename , storefilename )
2010-08-19 18:10:32 +02:00
os . unlink ( origfile )
2006-06-22 14:54:58 +02:00
self . in_conflict . append ( n )
self . write_conflictlist ( )
return ' C '
2007-01-23 07:55:43 +01:00
else :
2010-08-16 16:40:16 +02:00
raise oscerr . ExtRuntimeError ( ' diff3 failed with exit code: %s ' % ret , merge_cmd )
2006-05-22 16:12:06 +02:00
2007-07-16 15:40:58 +02:00
def update_local_filesmeta ( self , revision = None ) :
"""
Update the local _files file in the store .
It is replaced with the version pulled from upstream .
"""
2010-09-03 14:51:20 +02:00
meta = self . get_files_meta ( revision = revision )
2010-08-30 14:20:12 +02:00
store_write_string ( self . absdir , ' _files ' , meta + ' \n ' )
2007-07-30 13:12:42 +02:00
2010-09-03 14:51:20 +02:00
def get_files_meta ( self , revision = ' latest ' , skip_service = True ) :
fm = show_files_meta ( self . apiurl , self . prjname , self . name , revision = revision , meta = self . meta )
# look for "too large" files according to size limit and mark them
root = ET . fromstring ( fm )
for e in root . findall ( ' entry ' ) :
size = e . get ( ' size ' )
if size and self . size_limit and int ( size ) > self . size_limit \
or skip_service and ( e . get ( ' name ' ) . startswith ( ' _service: ' ) or e . get ( ' name ' ) . startswith ( ' _service_ ' ) ) :
e . set ( ' skipped ' , ' true ' )
return ET . tostring ( root )
2007-07-30 13:12:42 +02:00
def update_datastructs ( self ) :
"""
Update the internal data structures if the local _files
file has changed ( e . g . update_local_filesmeta ( ) has been
called ) .
"""
import fnmatch
files_tree = read_filemeta ( self . dir )
files_tree_root = files_tree . getroot ( )
self . rev = files_tree_root . get ( ' rev ' )
self . srcmd5 = files_tree_root . get ( ' srcmd5 ' )
2008-03-22 14:37:59 +01:00
self . linkinfo = Linkinfo ( )
self . linkinfo . read ( files_tree_root . find ( ' linkinfo ' ) )
2007-07-30 13:12:42 +02:00
self . filenamelist = [ ]
self . filelist = [ ]
2010-04-22 15:27:54 +02:00
self . skipped = [ ]
2007-07-30 13:12:42 +02:00
for node in files_tree_root . findall ( ' entry ' ) :
2009-10-20 16:30:15 +02:00
try :
f = File ( node . get ( ' name ' ) ,
node . get ( ' md5 ' ) ,
int ( node . get ( ' size ' ) ) ,
2007-07-30 13:12:42 +02:00
int ( node . get ( ' mtime ' ) ) )
2010-04-22 15:27:54 +02:00
if node . get ( ' skipped ' ) :
self . skipped . append ( f . name )
2010-08-23 11:29:57 +02:00
f . skipped = True
2009-10-20 16:30:15 +02:00
except :
# okay, a very old version of _files, which didn't contain any metadata yet...
2007-07-30 13:12:42 +02:00
f = File ( node . get ( ' name ' ) , ' ' , 0 , 0 )
self . filelist . append ( f )
self . filenamelist . append ( f . name )
2010-08-24 18:06:47 +02:00
self . to_be_added = read_tobeadded ( self . absdir )
self . to_be_deleted = read_tobedeleted ( self . absdir )
self . in_conflict = read_inconflict ( self . absdir )
2009-04-21 18:52:26 +02:00
self . linkrepair = os . path . isfile ( os . path . join ( self . storedir , ' _linkrepair ' ) )
2010-04-22 15:27:54 +02:00
self . size_limit = read_sizelimit ( self . dir )
2010-05-27 01:54:04 +02:00
self . meta = self . ismetamode ( )
2007-07-30 13:12:42 +02:00
# gather unversioned files, but ignore some stuff
2010-08-11 18:05:12 +02:00
self . excluded = [ ]
for i in os . listdir ( self . dir ) :
for j in conf . config [ ' exclude_glob ' ] :
if fnmatch . fnmatch ( i , j ) :
self . excluded . append ( i )
break
2007-07-30 13:12:42 +02:00
self . filenamelist_unvers = [ i for i in os . listdir ( self . dir )
if i not in self . excluded
if i not in self . filenamelist ]
2008-03-22 14:37:59 +01:00
def islink ( self ) :
2009-10-20 16:30:15 +02:00
""" tells us if the package is a link (has ' linkinfo ' ).
2008-03-22 14:37:59 +01:00
A package with linkinfo is a package which links to another package .
Returns True if the package is a link , otherwise False . """
return self . linkinfo . islink ( )
2008-03-22 18:37:17 +01:00
def isexpanded ( self ) :
2009-10-20 16:30:15 +02:00
""" tells us if the package is a link which is expanded.
2008-03-22 18:37:17 +01:00
Returns True if the package is expanded , otherwise False . """
return self . linkinfo . isexpanded ( )
2009-04-21 18:52:26 +02:00
def islinkrepair ( self ) :
""" tells us if we are repairing a broken source link. """
return self . linkrepair
2009-12-17 17:16:56 +01:00
def ispulled ( self ) :
""" tells us if we have pulled a link. """
return os . path . isfile ( os . path . join ( self . storedir , ' _pulled ' ) )
2010-01-12 17:22:47 +01:00
def isfrozen ( self ) :
""" tells us if the link is frozen. """
return os . path . isfile ( os . path . join ( self . storedir , ' _frozenlink ' ) )
2010-05-27 01:54:04 +02:00
def ismetamode ( self ) :
""" tells us if the package is in meta mode """
return os . path . isfile ( os . path . join ( self . storedir , ' _meta_mode ' ) )
2010-01-12 17:22:47 +01:00
def get_pulled_srcmd5 ( self ) :
pulledrev = None
for line in open ( os . path . join ( self . storedir , ' _pulled ' ) , ' r ' ) :
pulledrev = line . strip ( )
return pulledrev
2009-04-06 22:08:14 +02:00
def haslinkerror ( self ) :
"""
Returns True if the link is broken otherwise False .
If the package is not a link it returns False .
"""
return self . linkinfo . haserror ( )
def linkerror ( self ) :
"""
Returns an error message if the link is broken otherwise None .
If the package is not a link it returns None .
"""
return self . linkinfo . error
2007-07-16 15:40:58 +02:00
def update_local_pacmeta ( self ) :
"""
Update the local _meta file in the store .
It is replaced with the version pulled from upstream .
"""
2007-05-04 23:51:54 +02:00
meta = ' ' . join ( show_package_meta ( self . apiurl , self . prjname , self . name ) )
2010-08-30 14:20:12 +02:00
store_write_string ( self . absdir , ' _meta ' , meta + ' \n ' )
2006-05-19 22:13:29 +02:00
def findfilebyname ( self , n ) :
for i in self . filelist :
if i . name == n :
return i
2010-12-22 23:17:11 +01:00
def get_status ( self , excluded = False , * exclude_states ) :
global store
todo = self . todo
if not todo :
todo = self . filenamelist + self . to_be_added + \
[ i for i in self . filenamelist_unvers if not os . path . isdir ( os . path . join ( self . absdir , i ) ) ]
if excluded :
todo . extend ( [ i for i in self . excluded if i != store ] )
todo = set ( todo )
res = [ ]
for fname in sorted ( todo ) :
st = self . status ( fname )
if not st in exclude_states :
res . append ( ( st , fname ) )
return res
2006-05-19 22:13:29 +02:00
def status ( self , n ) :
"""
status can be :
file storefile file present STATUS
exists exists in _files
2010-08-24 18:06:47 +02:00
x - - ' A ' and listed in _to_be_added
x x - ' R ' and listed in _to_be_added
2006-05-22 16:12:06 +02:00
x x x ' ' if digest differs : ' M '
and if in conflicts file : ' C '
2006-05-19 22:13:29 +02:00
x - - ' ? '
2010-08-19 18:10:32 +02:00
- x x ' D ' and listed in _to_be_deleted
x x x ' D ' and listed in _to_be_deleted ( e . g . if deleted file was modified )
x x x ' C ' and listed in _in_conflict
2010-08-23 15:30:31 +02:00
x - x ' S ' and listed in self . skipped
- - x ' S ' and listed in self . skipped
2006-05-19 22:13:29 +02:00
- x x ' ! '
- - - NOT DEFINED
"""
known_by_meta = False
exists = False
exists_in_store = False
if n in self . filenamelist :
known_by_meta = True
2007-11-26 19:13:51 +01:00
if os . path . exists ( os . path . join ( self . absdir , n ) ) :
2006-05-19 22:13:29 +02:00
exists = True
if os . path . exists ( os . path . join ( self . storedir , n ) ) :
exists_in_store = True
2010-08-19 18:10:32 +02:00
if n in self . to_be_deleted :
2006-05-19 22:13:29 +02:00
state = ' D '
2006-05-22 16:12:06 +02:00
elif n in self . in_conflict :
state = ' C '
2010-08-23 14:56:50 +02:00
elif n in self . skipped :
2010-08-19 18:10:32 +02:00
state = ' S '
2010-09-02 18:40:18 +02:00
elif n in self . to_be_added and exists and exists_in_store :
2010-08-24 18:06:47 +02:00
state = ' R '
2010-08-26 13:46:10 +02:00
elif n in self . to_be_added and exists :
2010-08-19 18:10:32 +02:00
state = ' A '
2006-05-19 22:13:29 +02:00
elif exists and exists_in_store and known_by_meta :
2007-11-26 19:13:51 +01:00
if dgst ( os . path . join ( self . absdir , n ) ) != self . findfilebyname ( n ) . md5 :
2006-05-19 22:13:29 +02:00
state = ' M '
else :
state = ' '
2010-08-26 13:46:10 +02:00
elif n in self . to_be_added and not exists :
state = ' ! '
2010-08-19 18:10:32 +02:00
elif not exists and exists_in_store and known_by_meta and not n in self . to_be_deleted :
state = ' ! '
2006-05-19 22:13:29 +02:00
elif exists and not exists_in_store and not known_by_meta :
state = ' ? '
2010-08-23 16:28:49 +02:00
elif not exists_in_store and known_by_meta :
2010-08-23 17:39:01 +02:00
# XXX: this codepath shouldn't be reached (we restore the storefile
# in update_datastructs)
2010-08-23 16:28:49 +02:00
raise oscerr . PackageInternalError ( self . prjname , self . name ,
' error: file \' %s \' is known by meta but no storefile exists. \n '
' This might be caused by an old wc format. Please backup your current \n '
' wc and checkout the package again. Afterwards copy all files (except the \n '
2010-09-03 19:59:14 +02:00
' .osc/ dir) into the new package wc. ' % n )
2010-08-19 18:10:32 +02:00
else :
2009-02-12 14:11:32 +01:00
# this case shouldn't happen (except there was a typo in the filename etc.)
2010-09-02 10:23:37 +02:00
raise oscerr . OscIOError ( None , ' osc: \' %s \' is not under version control ' % n )
2009-10-20 16:30:15 +02:00
2006-05-19 22:13:29 +02:00
return state
2010-08-27 16:24:12 +02:00
def get_diff ( self , revision = None , ignoreUnversioned = False ) :
import tempfile
diff_hdr = ' Index: %s \n '
diff_hdr + = ' =================================================================== \n '
kept = [ ]
added = [ ]
deleted = [ ]
def diff_add_delete ( fname , add , revision ) :
diff = [ ]
2010-08-31 11:20:34 +02:00
diff . append ( diff_hdr % fname )
2010-08-27 16:24:12 +02:00
tmpfile = None
2010-08-31 11:20:34 +02:00
origname = fname
2010-08-27 16:24:12 +02:00
if add :
diff . append ( ' --- %s \t (revision 0) \n ' % fname )
rev = ' revision 0 '
if revision and not fname in self . to_be_added :
rev = ' working copy '
diff . append ( ' +++ %s \t ( %s ) \n ' % ( fname , rev ) )
fname = os . path . join ( self . absdir , fname )
else :
diff . append ( ' --- %s \t (revision %s ) \n ' % ( fname , revision or self . rev ) )
diff . append ( ' +++ %s \t (working copy) \n ' % fname )
fname = os . path . join ( self . storedir , fname )
try :
if revision is not None and not add :
( fd , tmpfile ) = tempfile . mkstemp ( prefix = ' osc_diff ' )
2010-08-31 11:20:34 +02:00
get_source_file ( self . apiurl , self . prjname , self . name , origname , tmpfile , revision )
2010-08-27 16:24:12 +02:00
fname = tmpfile
2010-08-31 11:20:34 +02:00
if binary_file ( fname ) :
what = ' added '
if not add :
what = ' deleted '
diff = diff [ : 1 ]
diff . append ( ' Binary file \' %s \' %s . \n ' % ( origname , what ) )
return diff
2010-08-27 16:24:12 +02:00
tmpl = ' + %s '
2010-08-31 17:30:31 +02:00
ltmpl = ' @@ -0,0 +1, %d @@ \n '
2010-08-27 16:24:12 +02:00
if not add :
tmpl = ' - %s '
2010-08-31 17:30:31 +02:00
ltmpl = ' @@ -1, %d +0,0 @@ \n '
2010-08-27 16:24:12 +02:00
lines = [ tmpl % i for i in open ( fname , ' r ' ) . readlines ( ) ]
if len ( lines ) :
diff . append ( ltmpl % len ( lines ) )
if not lines [ - 1 ] . endswith ( ' \n ' ) :
lines . append ( ' \n \\ No newline at end of file \n ' )
diff . extend ( lines )
finally :
if tmpfile is not None :
os . close ( fd )
os . unlink ( tmpfile )
return diff
if revision is None :
2010-09-02 13:41:20 +02:00
todo = self . todo or [ i for i in self . filenamelist if not i in self . to_be_added ] + self . to_be_added
2010-08-27 16:24:12 +02:00
for fname in todo :
if fname in self . to_be_added and self . status ( fname ) == ' A ' :
added . append ( fname )
elif fname in self . to_be_deleted :
deleted . append ( fname )
elif fname in self . filenamelist :
kept . append ( self . findfilebyname ( fname ) )
2010-09-02 13:41:20 +02:00
elif fname in self . to_be_added and self . status ( fname ) == ' ! ' :
raise oscerr . OscIOError ( None , ' file \' %s \' is marked as \' A \' but does not exist \n ' \
' (either add the missing file or revert it) ' % fname )
2010-08-27 16:24:12 +02:00
elif not ignoreUnversioned :
2010-09-02 10:23:37 +02:00
raise oscerr . OscIOError ( None , ' file \' %s \' is not under version control ' % fname )
2010-08-27 16:24:12 +02:00
else :
2010-09-03 14:51:20 +02:00
fm = self . get_files_meta ( revision = revision )
2010-08-27 16:24:12 +02:00
root = ET . fromstring ( fm )
rfiles = self . __get_files ( root )
# swap added and deleted
kept , deleted , added , services = self . __get_rev_changes ( rfiles )
added = [ f . name for f in added ]
added . extend ( [ f for f in self . to_be_added if not f in kept ] )
deleted = [ f . name for f in deleted ]
deleted . extend ( self . to_be_deleted )
for f in added [ : ] :
if f in deleted :
added . remove ( f )
deleted . remove ( f )
# print kept, added, deleted
for f in kept :
state = self . status ( f . name )
if state in ( ' S ' , ' ? ' , ' ! ' ) :
continue
elif state == ' ' and revision is None :
continue
elif revision and self . findfilebyname ( f . name ) . md5 == f . md5 and state != ' M ' :
continue
yield [ diff_hdr % f . name ]
if revision is None :
yield get_source_file_diff ( self . absdir , f . name , self . rev )
else :
tmpfile = None
2010-12-15 12:23:43 +01:00
diff = [ ]
2010-08-27 16:24:12 +02:00
try :
( fd , tmpfile ) = tempfile . mkstemp ( prefix = ' osc_diff ' )
get_source_file ( self . apiurl , self . prjname , self . name , f . name , tmpfile , revision )
2010-12-15 12:23:43 +01:00
diff = get_source_file_diff ( self . absdir , f . name , revision ,
2010-08-27 16:24:12 +02:00
os . path . basename ( tmpfile ) , os . path . dirname ( tmpfile ) , f . name )
finally :
if tmpfile is not None :
os . close ( fd )
os . unlink ( tmpfile )
2010-12-15 12:23:43 +01:00
yield diff
2010-08-27 16:24:12 +02:00
for f in added :
yield diff_add_delete ( f , True , revision )
for f in deleted :
yield diff_add_delete ( f , False , revision )
2006-05-19 22:13:29 +02:00
def merge ( self , otherpac ) :
self . todo + = otherpac . todo
def __str__ ( self ) :
r = """
name : % s
prjname : % s
workingdir : % s
localfilelist : % s
2008-03-22 14:37:59 +01:00
linkinfo : % s
2006-05-19 22:13:29 +02:00
rev : % s
' todo ' files : % s
2009-10-20 16:30:15 +02:00
""" % (self.name,
self . prjname ,
self . dir ,
' \n ' . join ( self . filenamelist ) ,
self . linkinfo ,
self . rev ,
2006-05-19 22:13:29 +02:00
self . todo )
return r
2007-06-30 17:39:47 +02:00
def read_meta_from_spec ( self , spec = None ) :
2007-07-04 15:48:24 +02:00
import glob
2007-06-30 17:39:47 +02:00
if spec :
specfile = spec
else :
2007-07-04 15:48:24 +02:00
# scan for spec files
speclist = glob . glob ( os . path . join ( self . dir , ' *.spec ' ) )
if len ( speclist ) == 1 :
specfile = speclist [ 0 ]
elif len ( speclist ) > 1 :
print ' the following specfiles were found: '
2010-08-20 14:34:41 +02:00
for filename in speclist :
print filename
2007-07-04 15:48:24 +02:00
print ' please specify one with --specfile '
sys . exit ( 1 )
else :
print ' no specfile was found - please specify one ' \
' with --specfile '
2009-10-20 16:30:15 +02:00
sys . exit ( 1 )
2007-07-04 15:48:24 +02:00
2008-08-03 21:36:07 +02:00
data = read_meta_from_spec ( specfile , ' Summary ' , ' Url ' , ' %d escription ' )
2010-07-02 22:28:53 +02:00
self . summary = data . get ( ' Summary ' , ' ' )
self . url = data . get ( ' Url ' , ' ' )
self . descr = data . get ( ' %d escription ' , ' ' )
2006-05-31 14:13:26 +02:00
2009-07-10 16:20:02 +02:00
def update_package_meta ( self , force = False ) :
2007-07-16 15:40:58 +02:00
"""
for the updatepacmetafromspec subcommand
2009-07-10 16:20:02 +02:00
argument force supress the confirm question
2007-07-16 15:40:58 +02:00
"""
2006-05-31 14:13:26 +02:00
2007-07-16 15:40:58 +02:00
m = ' ' . join ( show_package_meta ( self . apiurl , self . prjname , self . name ) )
2006-05-31 14:13:26 +02:00
2009-12-26 14:22:34 +01:00
root = ET . fromstring ( m )
root . find ( ' title ' ) . text = self . summary
root . find ( ' description ' ) . text = ' ' . join ( self . descr )
url = root . find ( ' url ' )
2008-08-21 14:03:42 +02:00
if url == None :
2009-12-26 14:22:34 +01:00
url = ET . SubElement ( root , ' url ' )
2008-08-03 21:36:07 +02:00
url . text = self . url
2009-10-20 16:30:15 +02:00
2009-06-19 10:47:06 +02:00
u = makeurl ( self . apiurl , [ ' source ' , self . prjname , self . name , ' _meta ' ] )
2009-12-26 14:22:34 +01:00
mf = metafile ( u , ET . tostring ( root ) )
2006-05-31 14:13:26 +02:00
2009-07-10 16:20:02 +02:00
if not force :
print ' * ' * 36 , ' old ' , ' * ' * 36
print m
print ' * ' * 36 , ' new ' , ' * ' * 36
2009-12-26 14:22:34 +01:00
print ET . tostring ( root )
2009-07-10 16:20:02 +02:00
print ' * ' * 72
repl = raw_input ( ' Write? (y/N/e) ' )
else :
repl = ' y '
2006-05-31 14:13:26 +02:00
if repl == ' y ' :
2009-06-19 10:32:56 +02:00
mf . sync ( )
2009-06-19 10:59:39 +02:00
elif repl == ' e ' :
mf . edit ( )
2006-05-31 14:13:26 +02:00
2009-06-19 10:32:56 +02:00
mf . discard ( )
2006-05-31 14:13:26 +02:00
2010-01-20 17:55:44 +01:00
def mark_frozen ( self ) :
store_write_string ( self . absdir , ' _frozenlink ' , ' ' )
print
2010-03-09 01:40:32 +01:00
print " The link in this package is currently broken. Checking "
print " out the last working version instead; please use ' osc pull ' "
2010-01-20 17:55:44 +01:00
print " to repair the link. "
print
def unmark_frozen ( self ) :
if os . path . exists ( os . path . join ( self . storedir , ' _frozenlink ' ) ) :
os . unlink ( os . path . join ( self . storedir , ' _frozenlink ' ) )
2009-04-21 18:52:26 +02:00
def latest_rev ( self ) :
if self . islinkrepair ( ) :
2010-05-25 13:59:46 +02:00
upstream_rev = show_upstream_xsrcmd5 ( self . apiurl , self . prjname , self . name , linkrepair = 1 , meta = self . meta )
2009-04-21 18:52:26 +02:00
elif self . islink ( ) and self . isexpanded ( ) :
2010-01-12 17:22:47 +01:00
if self . isfrozen ( ) or self . ispulled ( ) :
2010-05-25 13:59:46 +02:00
upstream_rev = show_upstream_xsrcmd5 ( self . apiurl , self . prjname , self . name , linkrev = self . linkinfo . srcmd5 , meta = self . meta )
2009-12-17 20:20:35 +01:00
else :
2010-01-12 17:22:47 +01:00
try :
2010-05-25 13:59:46 +02:00
upstream_rev = show_upstream_xsrcmd5 ( self . apiurl , self . prjname , self . name , meta = self . meta )
2010-01-12 17:22:47 +01:00
except :
2010-01-20 17:55:44 +01:00
try :
2010-05-25 13:59:46 +02:00
upstream_rev = show_upstream_xsrcmd5 ( self . apiurl , self . prjname , self . name , linkrev = self . linkinfo . srcmd5 , meta = self . meta )
2010-01-20 17:55:44 +01:00
except :
2010-05-25 13:59:46 +02:00
upstream_rev = show_upstream_xsrcmd5 ( self . apiurl , self . prjname , self . name , linkrev = " base " , meta = self . meta )
2010-07-23 16:17:39 +02:00
self . mark_frozen ( )
2009-04-21 18:52:26 +02:00
else :
2010-05-25 13:59:46 +02:00
upstream_rev = show_upstream_rev ( self . apiurl , self . prjname , self . name , meta = self . meta )
2009-04-21 18:52:26 +02:00
return upstream_rev
2010-08-23 11:48:33 +02:00
def __get_files ( self , fmeta_root ) :
2010-08-19 18:10:32 +02:00
f = [ ]
2010-09-06 17:57:30 +02:00
if fmeta_root . get ( ' rev ' ) is None and len ( fmeta_root . findall ( ' entry ' ) ) > 0 :
2010-08-23 11:48:33 +02:00
raise oscerr . APIError ( ' missing rev attribute in _files: \n %s ' % ' ' . join ( ET . tostring ( fmeta_root ) ) )
for i in fmeta_root . findall ( ' entry ' ) :
2010-08-23 11:29:57 +02:00
skipped = i . get ( ' skipped ' ) is not None
2010-08-19 18:10:32 +02:00
f . append ( File ( i . get ( ' name ' ) , i . get ( ' md5 ' ) ,
2010-08-23 11:29:57 +02:00
int ( i . get ( ' size ' ) ) , int ( i . get ( ' mtime ' ) ) , skipped ) )
2010-08-19 18:10:32 +02:00
return f
def __get_rev_changes ( self , revfiles ) :
kept = [ ]
added = [ ]
deleted = [ ]
2010-08-23 14:56:50 +02:00
services = [ ]
2010-08-19 18:10:32 +02:00
revfilenames = [ ]
for f in revfiles :
revfilenames . append ( f . name )
2010-08-23 11:29:57 +02:00
# treat skipped like deleted files
if f . skipped :
2010-08-23 14:56:50 +02:00
if f . name . startswith ( ' _service: ' ) :
services . append ( f )
else :
deleted . append ( f )
2010-08-23 11:29:57 +02:00
continue
# treat skipped like added files
# problem: this overwrites existing files during the update
# (because skipped files aren't in self.filenamelist_unvers)
if f . name in self . filenamelist and not f . name in self . skipped :
2010-08-19 18:10:32 +02:00
kept . append ( f )
else :
added . append ( f )
for f in self . filelist :
if not f . name in revfilenames :
deleted . append ( f )
2008-03-10 19:04:23 +01:00
2010-08-23 14:56:50 +02:00
return kept , added , deleted , services
2008-03-10 19:04:23 +01:00
2010-09-03 14:51:20 +02:00
def update ( self , rev = None , service_files = False , size_limit = None ) :
2010-08-19 18:10:32 +02:00
import tempfile
rfiles = [ ]
2010-09-03 14:51:20 +02:00
# size_limit is only temporary for this update
old_size_limit = self . size_limit
if not size_limit is None :
2010-09-03 16:09:56 +02:00
self . size_limit = int ( size_limit )
2010-08-19 18:10:32 +02:00
if os . path . isfile ( os . path . join ( self . storedir , ' _in_update ' , ' _files ' ) ) :
print ' resuming broken update... '
root = ET . parse ( os . path . join ( self . storedir , ' _in_update ' , ' _files ' ) ) . getroot ( )
2010-08-23 11:48:33 +02:00
rfiles = self . __get_files ( root )
2010-08-23 14:56:50 +02:00
kept , added , deleted , services = self . __get_rev_changes ( rfiles )
2010-08-19 18:10:32 +02:00
# check if we aborted in the middle of a file update
broken_file = os . listdir ( os . path . join ( self . storedir , ' _in_update ' ) )
broken_file . remove ( ' _files ' )
if len ( broken_file ) == 1 :
origfile = os . path . join ( self . storedir , ' _in_update ' , broken_file [ 0 ] )
wcfile = os . path . join ( self . absdir , broken_file [ 0 ] )
origfile_md5 = dgst ( origfile )
origfile_meta = self . findfilebyname ( broken_file [ 0 ] )
2010-08-26 10:05:15 +02:00
if origfile . endswith ( ' .copy ' ) :
# ok it seems we aborted at some point during the copy process
# (copy process == copy wcfile to the _in_update dir). remove file+continue
os . unlink ( origfile )
elif self . findfilebyname ( broken_file [ 0 ] ) is None :
2010-08-19 18:10:32 +02:00
# should we remove this file from _in_update? if we don't
# the user has no chance to continue without removing the file manually
raise oscerr . PackageInternalError ( self . prjname , self . name ,
' \' %s \' is not known by meta but exists in \' _in_update \' dir ' )
elif os . path . isfile ( wcfile ) and dgst ( wcfile ) != origfile_md5 :
( fd , tmpfile ) = tempfile . mkstemp ( dir = self . absdir , prefix = broken_file [ 0 ] + ' . ' )
os . close ( fd )
os . rename ( wcfile , tmpfile )
os . rename ( origfile , wcfile )
print ' warning: it seems you modified \' %s \' after the broken ' \
' update. Restored original file and saved modified version ' \
' to \' %s \' . ' % ( wcfile , tmpfile )
elif not os . path . isfile ( wcfile ) :
# this is strange... because it existed before the update. restore it
os . rename ( origfile , wcfile )
else :
# everything seems to be ok
os . unlink ( origfile )
elif len ( broken_file ) > 1 :
raise oscerr . PackageInternalError ( self . prjname , self . name , ' too many files in \' _in_update \' dir ' )
tmp = rfiles [ : ]
for f in tmp :
if os . path . exists ( os . path . join ( self . storedir , f . name ) ) :
2010-08-26 10:05:15 +02:00
if dgst ( os . path . join ( self . storedir , f . name ) ) == f . md5 :
2010-08-19 18:10:32 +02:00
if f in kept :
kept . remove ( f )
elif f in added :
added . remove ( f )
# this can't happen
elif f in deleted :
deleted . remove ( f )
2010-08-23 14:56:50 +02:00
if not service_files :
services = [ ]
self . __update ( kept , added , deleted , services , ET . tostring ( root ) , root . get ( ' rev ' ) )
2010-08-19 18:10:32 +02:00
os . unlink ( os . path . join ( self . storedir , ' _in_update ' , ' _files ' ) )
os . rmdir ( os . path . join ( self . storedir , ' _in_update ' ) )
# ok everything is ok (hopefully)...
2010-09-03 14:51:20 +02:00
fm = self . get_files_meta ( revision = rev )
2010-08-23 11:48:33 +02:00
root = ET . fromstring ( fm )
rfiles = self . __get_files ( root )
2010-08-30 14:20:12 +02:00
store_write_string ( self . absdir , ' _files ' , fm + ' \n ' , subdir = ' _in_update ' )
2010-08-23 14:56:50 +02:00
kept , added , deleted , services = self . __get_rev_changes ( rfiles )
if not service_files :
services = [ ]
self . __update ( kept , added , deleted , services , fm , root . get ( ' rev ' ) )
2010-08-19 18:10:32 +02:00
os . unlink ( os . path . join ( self . storedir , ' _in_update ' , ' _files ' ) )
if os . path . isdir ( os . path . join ( self . storedir , ' _in_update ' ) ) :
os . rmdir ( os . path . join ( self . storedir , ' _in_update ' ) )
2010-09-03 14:51:20 +02:00
self . size_limit = old_size_limit
2010-08-19 18:10:32 +02:00
2010-08-23 14:56:50 +02:00
def __update ( self , kept , added , deleted , services , fm , rev ) :
2008-03-10 19:04:23 +01:00
pathn = getTransActPath ( self . dir )
2010-08-19 18:10:32 +02:00
# check for conflicts with existing files
for f in added :
if f . name in self . filenamelist_unvers :
raise oscerr . PackageFileConflict ( self . prjname , self . name , f . name ,
' failed to add file \' %s \' file/dir with the same name already exists ' % f . name )
# ok, the update can't fail due to existing files
for f in added :
self . updatefile ( f . name , rev , f . mtime )
print statfrmt ( ' A ' , os . path . join ( pathn , f . name ) )
for f in deleted :
# if the storefile doesn't exist we're resuming an aborted update:
# the file was already deleted but we cannot know this
2010-08-23 14:56:50 +02:00
# OR we're processing a _service: file (simply keep the file)
2010-08-19 18:10:32 +02:00
if os . path . isfile ( os . path . join ( self . storedir , f . name ) ) and self . status ( f . name ) != ' M ' :
# if self.status(f.name) != 'M':
self . delete_localfile ( f . name )
self . delete_storefile ( f . name )
print statfrmt ( ' D ' , os . path . join ( pathn , f . name ) )
if f . name in self . to_be_deleted :
self . to_be_deleted . remove ( f . name )
self . write_deletelist ( )
for f in kept :
state = self . status ( f . name )
# print f.name, state
if state == ' M ' and self . findfilebyname ( f . name ) . md5 == f . md5 :
# remote file didn't change
2009-09-03 16:56:48 +02:00
pass
2008-03-10 19:04:23 +01:00
elif state == ' M ' :
2010-08-19 18:10:32 +02:00
# try to merge changes
merge_status = self . mergefile ( f . name , rev , f . mtime )
print statfrmt ( merge_status , os . path . join ( pathn , f . name ) )
2008-03-10 19:04:23 +01:00
elif state == ' ! ' :
2010-08-19 18:10:32 +02:00
self . updatefile ( f . name , rev , f . mtime )
print ' Restored \' %s \' ' % os . path . join ( pathn , f . name )
elif state == ' C ' :
get_source_file ( self . apiurl , self . prjname , self . name , f . name ,
targetfilename = os . path . join ( self . storedir , f . name ) , revision = rev ,
progress_obj = self . progress_obj , mtime = f . mtime , meta = self . meta )
print ' skipping \' %s \' (this is due to conflicts) ' % f . name
elif state == ' D ' and self . findfilebyname ( f . name ) . md5 != f . md5 :
# XXX: in the worst case we might end up with f.name being
# in _to_be_deleted and in _in_conflict... this needs to be checked
if os . path . exists ( os . path . join ( self . absdir , f . name ) ) :
merge_status = self . mergefile ( f . name , rev , f . mtime )
print statfrmt ( merge_status , os . path . join ( pathn , f . name ) )
if merge_status == ' C ' :
# state changes from delete to conflict
self . to_be_deleted . remove ( f . name )
self . write_deletelist ( )
else :
# XXX: we cannot recover this case because we've no file
# to backup
self . updatefile ( f . name , rev , f . mtime )
print statfrmt ( ' U ' , os . path . join ( pathn , f . name ) )
elif state == ' ' and self . findfilebyname ( f . name ) . md5 != f . md5 :
self . updatefile ( f . name , rev , f . mtime )
print statfrmt ( ' U ' , os . path . join ( pathn , f . name ) )
2010-08-23 14:56:50 +02:00
# checkout service files
for f in services :
get_source_file ( self . apiurl , self . prjname , self . name , f . name ,
targetfilename = os . path . join ( self . absdir , f . name ) , revision = rev ,
progress_obj = self . progress_obj , mtime = f . mtime , meta = self . meta )
print statfrmt ( ' A ' , os . path . join ( pathn , f . name ) )
2010-08-30 14:20:12 +02:00
store_write_string ( self . absdir , ' _files ' , fm + ' \n ' )
2010-08-31 16:54:44 +02:00
if not self . meta :
self . update_local_pacmeta ( )
2010-08-19 18:10:32 +02:00
self . update_datastructs ( )
2008-03-10 19:04:23 +01:00
print ' At revision %s . ' % self . rev
2009-08-03 15:03:24 +02:00
2009-09-03 16:56:48 +02:00
def run_source_services ( self ) :
2011-01-07 14:41:00 +01:00
if self . filenamelist . count ( ' _service ' ) or self . filenamelist_unvers . count ( ' _service ' ) :
2009-10-20 16:30:15 +02:00
service = ET . parse ( os . path . join ( self . absdir , ' _service ' ) ) . getroot ( )
si = Serviceinfo ( )
si . read ( service )
si . execute ( self . absdir )
2009-09-03 16:56:48 +02:00
2009-08-03 15:03:24 +02:00
def prepare_filelist ( self ) :
""" Prepare a list of files, which will be processed by process_filelist
method . This allows easy modifications of a file list in commit
phase .
"""
if not self . todo :
self . todo = self . filenamelist + self . filenamelist_unvers
self . todo . sort ( )
ret = " "
2010-03-21 23:40:13 +01:00
for f in [ f for f in self . todo if not os . path . isdir ( f ) ] :
2009-08-03 17:20:17 +02:00
action = ' leave '
status = self . status ( f )
2010-04-22 15:27:54 +02:00
if status == ' S ' :
continue
2009-08-03 17:20:17 +02:00
if status == ' ! ' :
action = ' remove '
ret + = " %s %s %s \n " % ( action , status , f )
2009-08-03 15:03:24 +02:00
ret + = """
2010-03-25 20:08:03 +01:00
# Edit a filelist for package \'%s\'
2009-08-03 15:03:24 +02:00
# Commands:
# l, leave = leave a file as is
# r, remove = remove a file
# a, add = add a file
#
# If you remove file from a list, it will be unchanged
2010-03-25 20:08:03 +01:00
# If you remove all, commit will be aborted""" % self.name
2009-08-03 15:03:24 +02:00
return ret
def edit_filelist ( self ) :
2010-04-22 15:27:54 +02:00
""" Opens a package list in editor for editing. This allows easy
2009-08-03 15:03:24 +02:00
modifications of it just by simple text editing
"""
2009-10-20 16:30:15 +02:00
2009-08-03 15:03:24 +02:00
import tempfile
2009-10-24 14:47:21 +02:00
( fd , filename ) = tempfile . mkstemp ( prefix = ' osc-filelist ' , suffix = ' .txt ' )
2009-08-03 15:03:24 +02:00
f = os . fdopen ( fd , ' w ' )
f . write ( self . prepare_filelist ( ) )
f . close ( )
mtime_orig = os . stat ( filename ) . st_mtime
while 1 :
2010-04-28 11:49:31 +02:00
run_editor ( filename )
2009-08-03 15:03:24 +02:00
mtime = os . stat ( filename ) . st_mtime
if mtime_orig < mtime :
filelist = open ( filename ) . readlines ( )
os . unlink ( filename )
break
else :
raise oscerr . UserAbort ( )
return self . process_filelist ( filelist )
def process_filelist ( self , filelist ) :
""" Process a filelist - it add/remove or leave files. This depends on
user input . If no file is processed , it raises an ValueError
"""
loop = False
2010-03-21 23:40:13 +01:00
for line in [ l . strip ( ) for l in filelist if ( l [ 0 ] != " # " or l . strip ( ) != ' ' ) ] :
2009-08-03 15:03:24 +02:00
foo = line . split ( ' ' )
if len ( foo ) == 4 :
action , state , name = ( foo [ 0 ] , ' ' , foo [ 3 ] )
elif len ( foo ) == 3 :
action , state , name = ( foo [ 0 ] , foo [ 1 ] , foo [ 2 ] )
else :
break
action = action . lower ( )
loop = True
if action in ( ' r ' , ' remove ' ) :
if self . status ( name ) == ' ? ' :
os . unlink ( name )
if name in self . todo :
self . todo . remove ( name )
else :
self . delete_file ( name , True )
elif action in ( ' a ' , ' add ' ) :
if self . status ( name ) != ' ? ' :
print " Cannot add file %s with state %s , skipped " % ( name , self . status ( name ) )
else :
self . addfile ( name )
elif action in ( ' l ' , ' leave ' ) :
pass
else :
raise ValueError ( " Unknow action ` %s ' " % action )
if not loop :
raise ValueError ( " Empty filelist " )
2006-05-31 14:13:26 +02:00
2010-08-23 16:15:05 +02:00
def revert ( self , filename ) :
2010-08-24 18:06:47 +02:00
if not filename in self . filenamelist and not filename in self . to_be_added :
2010-09-02 10:23:37 +02:00
raise oscerr . OscIOError ( None , ' file \' %s \' is not under version control ' % filename )
2010-08-25 13:50:49 +02:00
elif filename in self . skipped :
2010-09-02 10:23:37 +02:00
raise oscerr . OscIOError ( None , ' file \' %s \' is marked as skipped and cannot be reverted ' )
2010-08-24 18:06:47 +02:00
if filename in self . filenamelist and not os . path . exists ( os . path . join ( self . storedir , filename ) ) :
2010-08-23 16:15:05 +02:00
raise oscerr . PackageInternalError ( ' file \' %s \' is listed in filenamelist but no storefile exists ' % filename )
state = self . status ( filename )
2010-08-26 13:46:10 +02:00
if not ( state == ' A ' or state == ' ! ' and filename in self . to_be_added ) :
2010-08-24 18:06:47 +02:00
shutil . copyfile ( os . path . join ( self . storedir , filename ) , os . path . join ( self . absdir , filename ) )
2010-08-23 16:15:05 +02:00
if state == ' D ' :
self . to_be_deleted . remove ( filename )
self . write_deletelist ( )
elif state == ' C ' :
self . clear_from_conflictlist ( filename )
2010-08-26 13:46:10 +02:00
elif state in ( ' A ' , ' R ' ) or state == ' ! ' and filename in self . to_be_added :
2010-08-24 18:06:47 +02:00
self . to_be_added . remove ( filename )
self . write_addlist ( )
2010-08-23 16:15:05 +02:00
2010-08-30 13:46:49 +02:00
@staticmethod
2010-09-03 14:51:20 +02:00
def init_package ( apiurl , project , package , dir , size_limit = None , meta = False , progress_obj = None ) :
2010-08-31 14:43:43 +02:00
global store
2010-08-30 13:46:49 +02:00
if not os . path . exists ( dir ) :
os . mkdir ( dir )
elif not os . path . isdir ( dir ) :
2010-09-02 10:23:37 +02:00
raise oscerr . OscIOError ( None , ' error: \' %s \' is no directory ' % dir )
2010-08-30 13:46:49 +02:00
if os . path . exists ( os . path . join ( dir , store ) ) :
2010-09-02 10:23:37 +02:00
raise oscerr . OscIOError ( None , ' error: \' %s \' is already an initialized osc working copy ' % dir )
2010-08-30 13:46:49 +02:00
else :
os . mkdir ( os . path . join ( dir , store ) )
store_write_project ( dir , project )
store_write_string ( dir , ' _package ' , package + ' \n ' )
store_write_apiurl ( dir , apiurl )
if meta :
store_write_string ( dir , ' _meta_mode ' , ' ' )
2010-09-03 14:51:20 +02:00
if size_limit :
store_write_string ( dir , ' _size_limit ' , str ( size_limit ) + ' \n ' )
2010-08-30 13:46:49 +02:00
store_write_string ( dir , ' _files ' , ' <directory /> ' + ' \n ' )
store_write_string ( dir , ' _osclib_version ' , __store_version__ + ' \n ' )
2010-09-03 14:51:20 +02:00
return Package ( dir , progress_obj = progress_obj , size_limit = size_limit )
2010-08-30 13:46:49 +02:00
2010-12-30 02:30:37 +01:00
class AbstractState :
"""
Base class which represents state - like objects ( < review / > , < state / > ) .
"""
def __init__ ( self , tag ) :
self . __tag = tag
def get_node_attrs ( self ) :
""" return attributes for the tag/element """
raise NotImplementedError ( )
def get_node_name ( self ) :
""" return tag/element name """
return self . __tag
def get_comment ( self ) :
""" return data from <comment /> tag """
raise NotImplementedError ( )
def to_xml ( self ) :
""" serialize object to XML """
root = ET . Element ( self . get_node_name ( ) )
for attr in self . get_node_attrs ( ) :
val = getattr ( self , attr )
if not val is None :
root . set ( attr , val )
if self . get_comment ( ) :
ET . SubElement ( root , ' comment ' ) . text = self . get_comment ( )
return root
def to_str ( self ) :
""" return " pretty " XML data """
root = self . to_xml ( )
xmlindent ( root )
return ET . tostring ( root )
class ReviewState ( AbstractState ) :
""" Represents the review state in a request """
def __init__ ( self , review_node ) :
if not review_node . get ( ' state ' ) :
raise oscerr . APIError ( ' invalid review node (state attr expected): %s ' % \
ET . tostring ( review_node ) )
AbstractState . __init__ ( self , review_node . tag )
self . state = review_node . get ( ' state ' )
self . by_user = review_node . get ( ' by_user ' )
self . by_group = review_node . get ( ' by_group ' )
self . who = review_node . get ( ' who ' )
self . when = review_node . get ( ' when ' )
self . comment = ' '
if not review_node . find ( ' comment ' ) is None and \
review_node . find ( ' comment ' ) . text :
self . comment = review_node . find ( ' comment ' ) . text . strip ( )
def get_node_attrs ( self ) :
return ( ' state ' , ' by_user ' , ' by_group ' , ' who ' , ' when ' )
def get_comment ( self ) :
return self . comment
class RequestState ( AbstractState ) :
""" Represents the state of a request """
def __init__ ( self , state_node ) :
if not state_node . get ( ' name ' ) :
raise oscerr . APIError ( ' invalid request state node (name attr expected): %s ' % \
ET . tostring ( state_node ) )
AbstractState . __init__ ( self , state_node . tag )
self . name = state_node . get ( ' name ' )
self . who = state_node . get ( ' who ' )
self . when = state_node . get ( ' when ' )
self . comment = ' '
if not state_node . find ( ' comment ' ) is None and \
state_node . find ( ' comment ' ) . text :
self . comment = state_node . find ( ' comment ' ) . text . strip ( )
def get_node_attrs ( self ) :
return ( ' name ' , ' who ' , ' when ' )
def get_comment ( self ) :
return self . comment
2008-03-06 11:25:45 +01:00
2009-06-02 15:14:46 +02:00
class Action :
2010-12-30 02:30:37 +01:00
"""
Represents a < action / > element of a Request .
This class is quite common so that it can be used for all different
action types . Note : instances only provide attributes for their specific
type .
Examples :
r = Action ( ' set_bugowner ' , tgt_project = ' foo ' , person_name = ' buguser ' )
# available attributes: r.type (== 'set_bugowner'), r.tgt_project (== 'foo'), r.tgt_package (== None)
r . to_str ( ) - >
< action type = " set_bugowner " >
< target project = " foo " / >
< person name = " buguser " / >
< / action >
##
r = Action ( ' delete ' , tgt_project = ' foo ' , tgt_package = ' bar ' )
# available attributes: r.type (== 'delete'), r.tgt_project (== 'foo'), r.tgt_package (=='bar')
r . to_str ( ) - >
< action type = " delete " >
< target package = " bar " project = " foo " / >
< / action >
"""
# allowed types + the corresponding (allowed) attributes
type_args = { ' submit ' : ( ' src_project ' , ' src_package ' , ' src_rev ' , ' tgt_project ' , ' tgt_package ' , ' opt_sourceupdate ' , ' opt_updatelink ' ) ,
' add_role ' : ( ' tgt_project ' , ' tgt_package ' , ' person_name ' , ' person_role ' , ' group_name ' , ' group_role ' ) ,
' set_bugowner ' : ( ' tgt_project ' , ' tgt_package ' , ' person_name ' ) ,
' delete ' : ( ' tgt_project ' , ' tgt_package ' ) ,
' change_devel ' : ( ' src_project ' , ' src_package ' , ' tgt_project ' , ' tgt_package ' ) }
# attribute prefix to element name map (only needed for abbreviated attributes)
prefix_to_elm = { ' src ' : ' source ' , ' tgt ' : ' target ' , ' opt ' : ' options ' }
def __init__ ( self , type , * * kwargs ) :
if not type in Action . type_args . keys ( ) :
raise oscerr . WrongArgs ( ' invalid action type: \' %s \' ' % type )
2009-06-02 15:14:46 +02:00
self . type = type
2010-12-30 02:30:37 +01:00
for i in kwargs . keys ( ) :
if not i in Action . type_args [ type ] :
raise oscerr . WrongArgs ( ' invalid argument: \' %s \' ' % i )
# set all type specific attributes
for i in Action . type_args [ type ] :
if kwargs . has_key ( i ) :
setattr ( self , i , kwargs [ i ] )
else :
setattr ( self , i , None )
2009-06-02 15:14:46 +02:00
2010-12-30 02:30:37 +01:00
def to_xml ( self ) :
"""
Serialize object to XML .
The xml tag names and attributes are constructed from the instance ' s attributes.
Example :
self . group_name - > tag name is " group " , attribute name is " name "
self . src_project - > tag name is " source " ( translated via prefix_to_elm dict ) ,
attribute name is " project "
Attributes prefixed with " opt_ " need a special handling , the resulting xml should
look like this : opt_updatelink - > < options > < updatelink > value < / updatelink > < / options > .
Attributes which are " None " will be skipped .
"""
root = ET . Element ( ' action ' , type = self . type )
for i in Action . type_args [ self . type ] :
prefix , attr = i . split ( ' _ ' , 1 )
val = getattr ( self , i )
if val is None :
continue
elm = root . find ( Action . prefix_to_elm . get ( prefix , prefix ) )
if elm is None :
elm = ET . Element ( Action . prefix_to_elm . get ( prefix , prefix ) )
root . append ( elm )
if prefix == ' opt ' :
ET . SubElement ( elm , attr ) . text = val
else :
elm . set ( attr , val )
return root
2008-03-05 00:41:00 +01:00
2010-12-30 02:30:37 +01:00
def to_str ( self ) :
""" return " pretty " XML data """
root = self . to_xml ( )
xmlindent ( root )
return ET . tostring ( root )
2008-03-05 00:41:00 +01:00
2010-12-30 02:30:37 +01:00
@staticmethod
def from_xml ( action_node ) :
""" create action from XML """
if action_node is None or \
not action_node . get ( ' type ' ) in Action . type_args . keys ( ) or \
not action_node . tag in ( ' action ' , ' submit ' ) :
raise oscerr . WrongArgs ( ' invalid argument ' )
elm_to_prefix = dict ( [ ( i [ 1 ] , i [ 0 ] ) for i in Action . prefix_to_elm . items ( ) ] )
kwargs = { }
for node in action_node :
prefix = elm_to_prefix . get ( node . tag , node . tag )
if prefix == ' opt ' :
data = [ ( ' opt_ %s ' % opt . tag , opt . text . strip ( ) ) for opt in node if opt . text ]
else :
data = [ ( ' %s _ %s ' % ( prefix , k ) , v ) for k , v in node . items ( ) ]
kwargs . update ( dict ( data ) )
return Action ( action_node . get ( ' type ' ) , * * kwargs )
2008-03-05 00:41:00 +01:00
2008-03-06 11:25:45 +01:00
2010-12-30 02:30:37 +01:00
class Request :
""" Represents a request (<request />) """
2008-03-05 00:41:00 +01:00
2010-12-30 02:30:37 +01:00
def __init__ ( self ) :
self . reqid = None
self . title = ' '
self . description = ' '
self . state = None
self . actions = [ ]
self . statehistory = [ ]
self . reviews = [ ]
self . readonly = False
def read ( self , root ) :
""" read in a request """
self . readonly = True
if not root . get ( ' id ' ) :
raise oscerr . APIError ( ' invalid request: %s \n ' % ET . tostring ( root ) )
self . reqid = root . get ( ' id ' )
if root . find ( ' state ' ) is None :
raise oscerr . APIError ( ' invalid request (state expected): %s \n ' % ET . tostring ( root ) )
self . state = RequestState ( root . find ( ' state ' ) )
action_nodes = root . findall ( ' action ' )
if not action_nodes :
# check for old-style requests
for i in root . findall ( ' submit ' ) :
i . set ( ' type ' , ' submit ' )
action_nodes . append ( i )
for action in action_nodes :
self . actions . append ( Action . from_xml ( action ) )
for review in root . findall ( ' review ' ) :
self . reviews . append ( ReviewState ( review ) )
for hist_state in root . findall ( ' history ' ) :
self . statehistory . append ( RequestState ( hist_state ) )
if not root . find ( ' title ' ) is None :
self . title = root . find ( ' title ' ) . text . strip ( )
if not root . find ( ' description ' ) is None and root . find ( ' description ' ) . text :
self . description = root . find ( ' description ' ) . text . strip ( )
def add_action ( self , type , * * kwargs ) :
""" add a new action to the request """
self . actions . append ( Action ( type , * * kwargs ) )
2008-03-05 00:41:00 +01:00
2010-11-14 18:32:02 +01:00
def get_creator ( self ) :
2010-12-30 02:30:37 +01:00
""" return the creator of the request """
2010-11-14 18:32:02 +01:00
if len ( self . statehistory ) :
2010-12-30 02:30:37 +01:00
return self . statehistory [ 0 ] . who
2010-11-14 18:32:02 +01:00
return self . state . who
2010-12-30 02:30:37 +01:00
def to_xml ( self ) :
""" serialize object to XML """
root = ET . Element ( ' request ' )
if not self . reqid is None :
root . set ( ' id ' , self . reqid )
for action in self . actions :
root . append ( action . to_xml ( ) )
if not self . state is None :
root . append ( self . state . to_xml ( ) )
for review in self . reviews :
root . append ( review . to_xml ( ) )
for hist in self . statehistory :
root . append ( hist . to_xml ( ) )
if self . title :
ET . SubElement ( root , ' title ' ) . text = self . title
if self . description :
ET . SubElement ( root , ' description ' ) . text = self . description
return root
2008-06-27 18:36:16 +02:00
2010-12-30 02:30:37 +01:00
def to_str ( self ) :
""" return " pretty " XML data """
root = self . to_xml ( )
xmlindent ( root )
return ET . tostring ( root )
2008-06-27 18:36:16 +02:00
2010-12-30 02:30:37 +01:00
def _format_action ( self , action , show_srcupdate = False ) :
"""
format an action depending on the action ' s type.
A formatted str is returned .
"""
def prj_pkg_join ( prj , pkg ) :
if not pkg :
return prj or ' '
return ' %s / %s ' % ( prj , pkg )
d = { ' type ' : ' %s : ' % action . type }
if action . type == ' set_bugowner ' :
d [ ' source ' ] = action . person_name
d [ ' target ' ] = prj_pkg_join ( action . tgt_project , action . tgt_package )
elif action . type == ' change_devel ' :
d [ ' source ' ] = prj_pkg_join ( action . tgt_project , action . tgt_package )
d [ ' target ' ] = ' developed in %s ' % prj_pkg_join ( action . src_project , action . src_package )
elif action . type == ' submit ' :
srcupdate = ' '
if action . opt_sourceupdate and show_srcupdate :
srcupdate = ' ( %s ) ' % action . opt_sourceupdate
d [ ' source ' ] = ' %s %s -> ' % ( prj_pkg_join ( action . src_project , action . src_package ) , srcupdate )
tgt_package = action . tgt_package
if action . src_package == action . tgt_package :
tgt_package = ' '
d [ ' target ' ] = prj_pkg_join ( action . tgt_project , tgt_package )
elif action . type == ' add_role ' :
roles = [ ]
if action . person_name and action . person_role :
roles . append ( ' person: %s as %s ' % ( action . person_name , action . person_role ) )
if action . group_name and action . group_role :
roles . append ( ' group: %s as %s ' % ( action . group_name , action . group_role ) )
d [ ' source ' ] = ' , ' . join ( roles )
d [ ' target ' ] = prj_pkg_join ( action . tgt_project , action . tgt_package )
elif action . type == ' delete ' :
d [ ' source ' ] = ' '
d [ ' target ' ] = prj_pkg_join ( action . tgt_project , action . tgt_package )
return d
def list_view ( self ) :
""" return " list view " format """
import textwrap , locale
lines = [ ' %6s State: %-10s By: %-12s When: %-19s ' % ( self . reqid , self . state . name , self . state . who , self . state . when ) ]
tmpl = ' %(type)-16s %(source)-50s %(target)s '
for action in self . actions :
lines . append ( tmpl % self . _format_action ( action ) )
history = [ ' %s ( %s ) ' % ( hist . name , hist . who ) for hist in self . statehistory ]
if history :
lines . append ( ' From: %s ' % ' -> ' . join ( history ) )
if self . description :
descr = self . description . encode ( locale . getpreferredencoding ( ) , ' replace ' )
lines . append ( textwrap . fill ( descr , width = 80 , initial_indent = ' Descr: ' ,
subsequent_indent = ' ' ) )
return ' \n ' . join ( lines )
2008-03-05 00:41:00 +01:00
def __str__ ( self ) :
2010-12-30 02:30:37 +01:00
""" return " detailed " format """
import locale
lines = [ ' Request: # %s \n ' % self . reqid ]
2009-06-23 16:14:07 +02:00
for action in self . actions :
2010-12-30 02:30:37 +01:00
tmpl = ' %(type)-13s %(source)s %(target)s '
if action . type == ' delete ' :
# remove 1 whitespace because source is empty
tmpl = ' %(type)-12s %(source)s %(target)s '
lines . append ( tmpl % self . _format_action ( action , show_srcupdate = True ) )
lines . append ( ' \n \n Message: ' )
if self . description :
lines . append ( self . description . encode ( locale . getpreferredencoding ( ) , ' replace ' ) )
else :
lines . append ( ' <no message> ' )
lines . append ( ' \n State: %-10s %-12s %s ' % ( self . state . name , self . state . when , self . state . who ) )
lines . append ( ' Comment: %s ' % ( self . state . comment or ' <no comment> ' ) )
indent = ' \n '
tmpl = ' %(state)-10s %(by_user)s %(by_group)s %(when)-12s %(who)s %(comment)s '
reviews = [ ]
for review in reversed ( self . reviews ) :
d = { ' state ' : review . state }
d [ ' by_user ' ] = review . by_user or ' <no by_user> '
d [ ' by_group ' ] = review . by_group or ' <no by_group> '
d [ ' when ' ] = review . when
d [ ' who ' ] = review . who
d [ ' comment ' ] = review . comment
reviews . append ( tmpl % d )
if reviews :
lines . append ( ' \n Review: %s ' % indent . join ( reviews ) )
tmpl = ' %(name)-10s %(when)-12s %(who)s '
histories = [ ]
for hist in reversed ( self . statehistory ) :
d = { ' name ' : hist . name , ' when ' : hist . when ,
' who ' : hist . who }
histories . append ( tmpl % d )
if histories :
lines . append ( ' \n History: %s ' % indent . join ( histories ) )
return ' \n ' . join ( lines )
2008-03-06 11:25:45 +01:00
2010-12-30 02:30:37 +01:00
def __cmp__ ( self , other ) :
return cmp ( self . reqid , other . reqid )
2008-03-05 00:41:00 +01:00
2007-06-26 15:17:38 +02:00
def shorttime ( t ) :
""" format time as Apr 02 18:19
or Apr 02 2005
depending on whether it is in the current year
"""
import time
if time . localtime ( ) [ 0 ] == time . localtime ( t ) [ 0 ] :
# same year
return time . strftime ( ' % b %d % H: % M ' , time . localtime ( t ) )
else :
return time . strftime ( ' % b %d % Y ' , time . localtime ( t ) )
2006-05-31 14:13:26 +02:00
2006-05-22 12:50:37 +02:00
def is_project_dir ( d ) :
2010-08-31 14:43:43 +02:00
global store
2007-05-04 23:51:54 +02:00
return os . path . exists ( os . path . join ( d , store , ' _project ' ) ) and not \
os . path . exists ( os . path . join ( d , store , ' _package ' ) )
2006-05-22 12:50:37 +02:00
2009-10-20 16:30:15 +02:00
2006-09-29 15:15:41 +02:00
def is_package_dir ( d ) :
2010-08-31 14:43:43 +02:00
global store
2007-05-04 23:51:54 +02:00
return os . path . exists ( os . path . join ( d , store , ' _project ' ) ) and \
os . path . exists ( os . path . join ( d , store , ' _package ' ) )
2006-09-29 15:15:41 +02:00
2009-08-26 16:58:53 +02:00
def parse_disturl ( disturl ) :
""" Parse a disturl, returns tuple (apiurl, project, source, repository,
revision ) , else raises an oscerr . WrongArgs exception
"""
2010-08-31 14:43:43 +02:00
global DISTURL_RE
2009-08-26 16:58:53 +02:00
m = DISTURL_RE . match ( disturl )
if not m :
2010-01-28 13:22:44 +01:00
raise oscerr . WrongArgs ( " ` %s ' does not look like disturl " % disturl )
2009-08-26 16:58:53 +02:00
apiurl = m . group ( ' apiurl ' )
if apiurl . split ( ' . ' ) [ 0 ] != ' api ' :
apiurl = ' https://api. ' + " . " . join ( apiurl . split ( ' . ' ) [ 1 : ] )
return ( apiurl , m . group ( ' project ' ) , m . group ( ' source ' ) , m . group ( ' repository ' ) , m . group ( ' revision ' ) )
2010-01-28 13:20:11 +01:00
def parse_buildlogurl ( buildlogurl ) :
""" Parse a build log url, returns a tuple (apiurl, project, package,
repository , arch ) , else raises oscerr . WrongArgs exception """
global BUILDLOGURL_RE
m = BUILDLOGURL_RE . match ( buildlogurl )
if not m :
2010-01-28 20:00:34 +01:00
raise oscerr . WrongArgs ( ' \' %s \' does not look like url with a build log ' % buildlogurl )
2010-02-28 02:30:13 +01:00
2010-01-28 13:20:11 +01:00
return ( m . group ( ' apiurl ' ) , m . group ( ' project ' ) , m . group ( ' package ' ) , m . group ( ' repository ' ) , m . group ( ' arch ' ) )
2009-10-20 16:30:15 +02:00
2007-06-26 15:17:38 +02:00
def slash_split ( l ) :
""" Split command line arguments like ' foo/bar ' into ' foo ' ' bar ' .
This is handy to allow copy / paste a project / package combination in this form .
2008-12-12 11:02:41 +01:00
2009-10-20 16:30:15 +02:00
Trailing slashes are removed before the split , because the split would
2008-12-12 11:02:41 +01:00
otherwise give an additional empty string .
2007-06-26 15:17:38 +02:00
"""
r = [ ]
for i in l :
2008-12-12 11:02:41 +01:00
i = i . rstrip ( ' / ' )
2007-06-26 15:17:38 +02:00
r + = i . split ( ' / ' )
return r
2009-09-28 21:50:57 +02:00
def expand_proj_pack ( args , idx = 0 , howmany = 0 ) :
""" looks for occurance of ' . ' at the position idx.
2009-10-20 16:30:15 +02:00
If howmany is 2 , both proj and pack are expanded together
2009-09-28 21:50:57 +02:00
using the current directory , or none of them , if not possible .
If howmany is 0 , proj is expanded if possible , then , if there
2009-10-20 16:30:15 +02:00
is no idx + 1 element in args ( or args [ idx + 1 ] == ' . ' ) , pack is also
2009-09-28 21:50:57 +02:00
expanded , if possible .
If howmany is 1 , only proj is expanded if possible .
If args [ idx ] does not exists , an implicit ' . ' is assumed .
if not enough elements up to idx exist , an error is raised .
2009-10-08 16:40:06 +02:00
See also parseargs ( args ) , slash_split ( args ) , findpacs ( args )
All these need unification , somehow .
2009-09-28 21:50:57 +02:00
"""
# print args,idx,howmany
if len ( args ) < idx :
raise oscerr . WrongArgs ( ' not enough argument, expected at least %d ' % idx )
2009-10-20 16:30:15 +02:00
2009-09-28 21:50:57 +02:00
if len ( args ) == idx :
args + = ' . '
if args [ idx + 0 ] == ' . ' :
if howmany == 0 and len ( args ) > idx + 1 :
if args [ idx + 1 ] == ' . ' :
# we have two dots.
# remove one dot and make sure to expand both proj and pack
args . pop ( idx + 1 )
howmany = 2
else :
howmany = 1
# print args,idx,howmany
args [ idx + 0 ] = store_read_project ( ' . ' )
if howmany == 0 :
try :
package = store_read_package ( ' . ' )
args . insert ( idx + 1 , package )
except :
pass
elif howmany == 2 :
package = store_read_package ( ' . ' )
args . insert ( idx + 1 , package )
return args
2007-06-26 15:17:38 +02:00
2010-02-09 20:57:10 +01:00
def findpacs ( files , progress_obj = None ) :
Merged revisions 3774-3775,3779,3781-3782,3787,3789-3793,3798,3802,3805,3817-3822,3827,3829-3830,3837-3839,3841-3842,3848-3850 via svnmerge from
https://forgesvn1.novell.com/svn/opensuse/branches/buildservice/osc-exception-handling
........
r3774 | poeml | 2008-04-22 17:39:45 +0200 (Tue, 22 Apr 2008) | 3 lines
A first draft on implement systematic exception handling:
Add errors.py with some exceptions defined, and babysitter.py to handle them
........
r3775 | poeml | 2008-04-22 22:34:12 +0200 (Tue, 22 Apr 2008) | 9 lines
- new global options:
--debugger jump into the debugger before executing anything
--post-mortem jump into the debugger in case of errors
-t, --traceback print call trace in case of errors
- traceback and post_mortem can also be set in .oscrc.
- catch more errors (HTTPError).
- make config accessible from outside of the Osc instance, by making it a class
attribute
........
r3779 | poeml | 2008-04-23 00:55:49 +0200 (Wed, 23 Apr 2008) | 5 lines
- new global option:
-d, --debug print info useful for debugging
- catch some more errors (HTTPError), with OscHTTPError which isn't very
advanced yet.
........
r3781 | Marcus_H | 2008-04-23 01:02:00 +0200 (Wed, 23 Apr 2008) | 2 lines
- added OscConfigError class (just for testing).
- small change in the signature of the OscBaseError constructor (actually we should get rid of the 'args' tuple because it will be deprecated sooner or later
........
r3782 | Marcus_H | 2008-04-23 02:02:13 +0200 (Wed, 23 Apr 2008) | 2 lines
- access the prg.conf.config dict in a save way - this way we avoid AttributeErrors if the prg.conf.config dict doesn't exist
- in case of an configparser error we have to use the prg.options object directly (this was removed in r3781 by accident)
........
r3787 | poeml | 2008-04-23 09:23:56 +0200 (Wed, 23 Apr 2008) | 4 lines
- remove local exception handling from do_req
- for HTTPError, print details (headers and response) when in debug mode
- catch AttributeError
........
r3789 | poeml | 2008-04-23 16:23:14 +0200 (Wed, 23 Apr 2008) | 4 lines
- errors: add two new classes named OscWrongOptionsError and OscWrongArgsError
- commandline: raise instances of the new errors in a number of places
- commandline: add get_cmd_help() to Osc instance which returns the formatted help of a subcommand
........
r3790 | Marcus_H | 2008-04-23 16:48:28 +0200 (Wed, 23 Apr 2008) | 4 lines
- added 2 new exception classes: OscNoConfigfileError and OscIOError
- added new method write_config() to the conf.py module: This method writes osc's configuration file
- minor cleanups in the conf module
........
r3791 | poeml | 2008-04-23 17:11:07 +0200 (Wed, 23 Apr 2008) | 3 lines
small compatibility fix for r3790: try-except-finally isn't supported in
python-2.4.2, thus do the same as try-except inside a try-finally.
........
r3792 | poeml | 2008-04-23 17:37:53 +0200 (Wed, 23 Apr 2008) | 2 lines
fix up the remaining places regarding handling of errors related to commandline parsing
........
r3793 | poeml | 2008-04-23 17:40:34 +0200 (Wed, 23 Apr 2008) | 3 lines
raise a NoWorkingCopyError in osc.core.store_read_project() in case of an
IOError
........
r3798 | Marcus_H | 2008-04-23 23:55:24 +0200 (Wed, 23 Apr 2008) | 1 line
ported -r3797 from trunk
........
r3802 | Marcus_H | 2008-04-24 11:00:55 +0200 (Thu, 24 Apr 2008) | 1 line
ported -r3801 from trunk
........
r3805 | poeml | 2008-04-24 12:52:30 +0200 (Thu, 24 Apr 2008) | 2 lines
raise OscHTTPError in show_pattern_meta(), replacing local error handling
........
r3817 | poeml | 2008-04-24 20:21:32 +0200 (Thu, 24 Apr 2008) | 9 lines
- remove errors.OscHTTPError again.
it seems simpler to use urllib2.HTTPError instead (and just add a specific
error text message where appropriate, and re-raise)
- for 404s, check out _which_ part was not found
it is very ugly, but may be considered Good for pragmatic reasons
- removed local exception handling and workaround for returned 500's from
delete_package() and delete_project(), thereby getting rid of 4 possible exit
points.
........
r3818 | Marcus_H | 2008-04-24 22:36:17 +0200 (Thu, 24 Apr 2008) | 1 line
- this check is superfluous because every HTTPError instance has a code attribute
........
r3819 | poeml | 2008-04-25 00:39:39 +0200 (Fri, 25 Apr 2008) | 1 line
remove a forgotten debug line from core.delete_project()
........
r3820 | poeml | 2008-04-25 10:07:58 +0200 (Fri, 25 Apr 2008) | 2 lines
- ditch local error handling from wipebinaries(), rebuild(), and abortbuild()
........
r3821 | poeml | 2008-04-25 10:56:38 +0200 (Fri, 25 Apr 2008) | 2 lines
It is never needed to import the exception module.
........
r3822 | poeml | 2008-04-25 11:13:39 +0200 (Fri, 25 Apr 2008) | 4 lines
- when going into the debugger with --post-mortem, always print a traceback before
(thus implying -t)
- do not jump into the debugger if not on a TTY, or working in interactive mode
........
r3827 | poeml | 2008-04-25 13:07:46 +0200 (Fri, 25 Apr 2008) | 9 lines
- add errors.OscWorkingCopyOutdated, which takes a tuple with three args:
path to working copy, current rev, expected rev
- add handler for urllib2.URLError errors to the babysitter
- simplify the OscWrongArgsError and OscWrongOptionsError handlers, by removing
the extra line "Sorry, wrong ..." that was printed before the messages given
when the error was raised.
- remove one more errors.OscHTTPError which was still there, and raise
urllib2.HTTPError instead (show_package_meta())
........
r3829 | poeml | 2008-04-25 14:19:10 +0200 (Fri, 25 Apr 2008) | 11 lines
- comment some methods in osc.core which are used by nearly all do_* methods in
osc.commandline
- improve "is not a package/project dir" error messages, by printing the
absolute path tried, instead of '.' for the cwd
- make core.store_read_package() raise a proper NoWorkingCopyError instead of
terminating
- give attribution to things in babysitter.py copied from mercurial
- prefix HTTPError exceptions with 'Server returned an error:'
- remove obsolete local error handling from do_prjresults(), do_importsrcpkg(),
do_repos()
........
r3830 | poeml | 2008-04-25 14:29:35 +0200 (Fri, 25 Apr 2008) | 1 line
catch IOError exceptions in the babysitter
........
r3837 | poeml | 2008-04-25 17:27:36 +0200 (Fri, 25 Apr 2008) | 5 lines
- do_remotebuildlog: raise errors for wrong arguments, remove exits
- raise AttributeError in make_meta_url() instead of exiting
- delete unused method core.delete_server_files()
- replace exit call inside make_meta_url() with an AttributeError
........
r3838 | poeml | 2008-04-25 17:49:18 +0200 (Fri, 25 Apr 2008) | 1 line
simplify the check in do_checkout if a project exists, by using show_project_meta() instead of meta_exists
........
r3839 | poeml | 2008-04-25 18:31:26 +0200 (Fri, 25 Apr 2008) | 6 lines
- commandline do_checkout(): change the order of the two checks, first do the
(cheaper) check for existing directory
- core.core checkout_package(): simplify the check in if the package
exists, by using show_package_meta() instead of meta_exists
Let it throw an exception, instead of using sys.exit().
........
r3841 | Marcus_H | 2008-04-27 15:48:06 +0200 (Sun, 27 Apr 2008) | 5 lines
- added 2 new exception classes: PackageError() and PackageExistsError. The PackageError() class is meant to be the base class for all subsequent package exceptions.
- get rid of 2 sys.exit(1) calls
- make the update() method of the Project() class safer: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- minor fix in delPackage(): use getTransActPath() when printing out the filename
........
r3842 | Marcus_H | 2008-04-27 16:52:55 +0200 (Sun, 27 Apr 2008) | 3 lines
- make the commit() method safe: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- removed another sys.exit(1): raise an exception if a package is missing when doing a commit. For now we use the PackageExistsError() exception but this might change in the future (updated description of PackageExistsError() according to this change)
........
r3848 | poeml | 2008-04-28 12:46:45 +0200 (Mon, 28 Apr 2008) | 3 lines
rename several error classes, dropping the "Osc" prefix, and "Error" suffix in
cases where they don't really make sense.
........
r3849 | poeml | 2008-04-28 12:57:32 +0200 (Mon, 28 Apr 2008) | 3 lines
- rename osc.errors module to osc.oscerr, to make it easier to import it from
other programs and have a crystal clear namespace
........
r3850 | poeml | 2008-04-28 13:26:12 +0200 (Mon, 28 Apr 2008) | 2 lines
split PackageExists exception class into PackageExists and PackageMissing
........
2008-04-28 18:37:44 +02:00
""" collect Package objects belonging to the given files
and make sure each Package is returned only once """
2006-05-19 22:13:29 +02:00
pacs = [ ]
for f in files :
2010-02-09 20:57:10 +01:00
p = filedir_to_pac ( f , progress_obj )
2006-05-19 22:13:29 +02:00
known = None
for i in pacs :
if i . name == p . name :
known = i
break
if known :
i . merge ( p )
else :
pacs . append ( p )
return pacs
2009-10-20 16:30:15 +02:00
2006-05-19 22:13:29 +02:00
2010-04-09 15:47:07 +02:00
def filedir_to_pac ( f , progress_obj = None ) :
""" Takes a working copy path, or a path to a file inside a working copy,
and returns a Package object instance
If the argument was a filename , add it onto the " todo " list of the Package """
if os . path . isdir ( f ) :
wd = f
p = Package ( wd , progress_obj = progress_obj )
else :
wd = os . path . dirname ( f ) or os . curdir
p = Package ( wd , progress_obj = progress_obj )
p . todo = [ os . path . basename ( f ) ]
return p
2006-05-19 22:13:29 +02:00
def read_filemeta ( dir ) :
2010-08-31 14:43:43 +02:00
global store
2010-08-31 14:52:46 +02:00
msg = ' \' %s \' is not a valid working copy. \n ' % dir
2010-08-31 15:37:11 +02:00
if not is_package_dir ( dir ) :
2010-08-31 14:52:46 +02:00
raise oscerr . NoWorkingCopy ( msg )
filesmeta = os . path . join ( dir , store , ' _files ' )
if not os . path . isfile ( filesmeta ) :
2011-01-05 16:31:02 +01:00
print >> sys . stderr , " Warning: file _files is missing, creating a default one "
2010-08-31 14:52:46 +02:00
store_write_string ( os . path . join ( dir , store ) , ' _files ' , ' <directory \ > ' )
2008-06-10 12:15:49 +02:00
try :
2010-08-31 14:52:46 +02:00
r = ET . parse ( filesmeta )
2008-06-10 12:15:49 +02:00
except SyntaxError , e :
2010-08-31 14:52:46 +02:00
raise oscerr . NoWorkingCopy ( msg +
2008-06-10 12:15:49 +02:00
' When parsing .osc/_files, the following error was encountered: \n '
' %s ' % ( dir , e ) )
return r
2006-05-19 22:13:29 +02:00
2010-08-24 10:23:11 +02:00
def store_readlist ( dir , name ) :
2010-08-31 14:43:43 +02:00
global store
2006-05-19 22:13:29 +02:00
r = [ ]
2010-08-24 10:23:11 +02:00
if os . path . exists ( os . path . join ( dir , store , name ) ) :
r = [ line . strip ( ) for line in open ( os . path . join ( dir , store , name ) , ' r ' ) ]
2006-05-19 22:13:29 +02:00
return r
2010-08-24 18:06:47 +02:00
def read_tobeadded ( dir ) :
return store_readlist ( dir , ' _to_be_added ' )
2010-08-24 10:23:11 +02:00
def read_tobedeleted ( dir ) :
return store_readlist ( dir , ' _to_be_deleted ' )
2006-05-19 22:13:29 +02:00
2010-04-22 15:27:54 +02:00
def read_sizelimit ( dir ) :
2010-08-31 14:43:43 +02:00
global store
2010-04-22 15:27:54 +02:00
r = None
fname = os . path . join ( dir , store , ' _size_limit ' )
if os . path . exists ( fname ) :
2010-09-03 16:09:56 +02:00
r = open ( fname ) . readline ( ) . strip ( )
2010-04-22 15:27:54 +02:00
2010-04-22 20:05:40 +02:00
if r is None or not r . isdigit ( ) :
2010-04-22 15:27:54 +02:00
return None
return int ( r )
2006-05-22 16:12:06 +02:00
def read_inconflict ( dir ) :
2010-08-24 10:23:11 +02:00
return store_readlist ( dir , ' _in_conflict ' )
2006-05-22 16:12:06 +02:00
2006-05-23 15:48:58 +02:00
def parseargs ( list_of_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
""" Convenience method osc ' s commandline argument parsing.
2009-10-20 16:30:15 +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 called with an empty tuple ( or list ) , return a list containing the current directory .
Otherwise , return a list of the arguments . """
if list_of_args :
return list ( list_of_args )
else :
return [ os . curdir ]
2006-05-11 09:27:50 +02:00
2006-05-19 22:13:29 +02:00
def statfrmt ( statusletter , filename ) :
return ' %s %s ' % ( statusletter , filename )
2006-09-29 15:15:41 +02:00
def pathjoin ( a , * p ) :
""" Join two or more pathname components, inserting ' / ' as needed. Cut leading ./ """
path = os . path . join ( a , * p )
if path . startswith ( ' ./ ' ) :
path = path [ 2 : ]
return path
2007-05-09 11:36:55 +02:00
def makeurl ( baseurl , l , query = [ ] ) :
2008-03-17 22:10:34 +01:00
""" Given a list of path compoments, construct a complete URL.
Optional parameters for a query string can be given as a list , as a
dictionary , or as an already assembled string .
In case of a dictionary , the parameters will be urlencoded by this
function . In case of a list not - - this is to be backwards compatible .
"""
2007-05-04 23:51:54 +02:00
2009-11-10 01:56:52 +01:00
if conf . config [ ' verbose ' ] > 1 :
print ' makeurl: ' , baseurl , l , query
2008-03-17 22:10:34 +01:00
if type ( query ) == type ( list ( ) ) :
query = ' & ' . join ( query )
elif type ( query ) == type ( dict ( ) ) :
query = urlencode ( query )
2007-05-04 23:51:54 +02:00
scheme , netloc = urlsplit ( baseurl ) [ 0 : 2 ]
2009-10-20 16:30:15 +02:00
return urlunsplit ( ( scheme , netloc , ' / ' . join ( l ) , query , ' ' ) )
2006-04-20 16:26:50 +02:00
2009-05-05 17:56:23 +02:00
def http_request ( method , url , headers = { } , data = None , file = None , timeout = 100 ) :
2007-04-19 10:47:22 +02:00
""" wrapper around urllib2.urlopen for error handling,
and to support additional ( PUT , DELETE ) methods """
2007-04-19 11:12:39 +02:00
filefd = None
2007-04-25 01:00:12 +02:00
if conf . config [ ' http_debug ' ] :
2010-08-30 13:13:20 +02:00
print >> sys . stderr , ' \n \n -- ' , method , url
2007-04-19 10:47:22 +02:00
if method == ' POST ' and not file and not data :
# adding data to an urllib2 request transforms it into a POST
data = ' '
2009-10-20 16:30:15 +02:00
2007-04-19 10:47:22 +02:00
req = urllib2 . Request ( url )
2010-04-07 03:06:03 +02:00
api_host_options = { }
2010-09-01 15:53:37 +02:00
if conf . is_known_apiurl ( url ) :
# ok no external request
2010-08-26 14:14:23 +02:00
urllib2 . install_opener ( conf . _build_opener ( url ) )
2010-04-07 03:06:03 +02:00
api_host_options = conf . get_apiurl_api_host_options ( url )
for header , value in api_host_options [ ' http_headers ' ] :
req . add_header ( header , value )
2008-08-20 11:45:49 +02:00
2007-04-19 10:47:22 +02:00
req . get_method = lambda : method
2007-06-21 17:14:15 +02:00
# POST requests are application/x-www-form-urlencoded per default
# since we change the request into PUT, we also need to adjust the content type header
2009-09-10 14:04:41 +02:00
if method == ' PUT ' or ( method == ' POST ' and data ) :
2007-06-21 17:14:15 +02:00
req . add_header ( ' Content-Type ' , ' application/octet-stream ' )
2008-03-16 21:46:16 +01:00
if type ( headers ) == type ( { } ) :
for i in headers . keys ( ) :
print headers [ i ]
req . add_header ( i , headers [ i ] )
2007-04-19 11:12:39 +02:00
if file and not data :
size = os . path . getsize ( file )
if size < 1024 * 512 :
2009-05-22 17:00:31 +02:00
data = open ( file , ' rb ' ) . read ( )
2007-04-19 11:12:39 +02:00
else :
import mmap
2009-05-22 17:00:31 +02:00
filefd = open ( file , ' rb ' )
2008-03-16 20:02:38 +01:00
try :
2009-05-20 18:42:17 +02:00
if sys . platform [ : 3 ] != ' win ' :
data = mmap . mmap ( filefd . fileno ( ) , os . path . getsize ( file ) , mmap . MAP_SHARED , mmap . PROT_READ )
else :
data = mmap . mmap ( filefd . fileno ( ) , os . path . getsize ( file ) )
2009-03-10 19:36:12 +01:00
data = buffer ( data )
2008-03-16 20:02:38 +01:00
except EnvironmentError , e :
if e . errno == 19 :
sys . exit ( ' \n \n %s \n The file \' %s \' could not be memory mapped. It is ' \
' \n on a filesystem which does not support this. ' % ( e , file ) )
2009-05-22 16:43:39 +02:00
elif hasattr ( e , ' winerror ' ) and e . winerror == 5 :
# falling back to the default io
2009-05-22 17:00:31 +02:00
data = open ( file , ' rb ' ) . read ( )
2008-03-16 20:02:38 +01:00
else :
raise
2010-08-30 13:06:17 +02:00
if conf . config [ ' debug ' ] : print >> sys . stderr , method , url
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
2009-05-08 20:54:26 +02:00
old_timeout = socket . getdefaulttimeout ( )
2009-10-02 13:26:07 +02:00
# XXX: dirty hack as timeout doesn't work with python-m2crypto
2010-04-07 03:06:03 +02:00
if old_timeout != timeout and not api_host_options . get ( ' sslcertck ' ) :
2009-10-02 13:26:07 +02:00
socket . setdefaulttimeout ( timeout )
2008-04-12 10:04:41 +02:00
try :
2009-05-08 20:54:26 +02:00
fd = urllib2 . urlopen ( req , data = data )
2009-02-25 02:29:58 +01:00
finally :
2010-04-07 03:06:03 +02:00
if old_timeout != timeout and not api_host_options . get ( ' sslcertck ' ) :
2009-10-02 13:26:07 +02:00
socket . setdefaulttimeout ( old_timeout )
2009-02-28 16:56:32 +01:00
if hasattr ( conf . cookiejar , ' save ' ) :
conf . cookiejar . save ( ignore_discard = True )
2007-04-19 12:40:18 +02:00
2007-04-19 11:12:39 +02:00
if filefd : filefd . close ( )
2008-03-11 17:39:47 +01:00
2007-04-19 10:47:22 +02:00
return fd
def http_GET ( * args , * * kwargs ) : return http_request ( ' GET ' , * args , * * kwargs )
def http_POST ( * args , * * kwargs ) : return http_request ( ' POST ' , * args , * * kwargs )
def http_PUT ( * args , * * kwargs ) : return http_request ( ' PUT ' , * args , * * kwargs )
def http_DELETE ( * args , * * kwargs ) : return http_request ( ' DELETE ' , * args , * * kwargs )
2006-05-19 22:13:29 +02:00
def check_store_version ( dir ) :
2010-08-31 14:43:43 +02:00
global store
2006-05-19 22:13:29 +02:00
versionfile = os . path . join ( dir , store , ' _osclib_version ' )
2006-04-28 17:37:25 +02:00
try :
2006-05-19 22:13:29 +02:00
v = open ( versionfile ) . read ( ) . strip ( )
2006-04-28 17:37:25 +02:00
except :
v = ' '
2006-05-19 22:13:29 +02:00
if v == ' ' :
2010-04-09 15:57:12 +02:00
msg = ' Error: " %s " is not an osc package working copy. ' % os . path . abspath ( dir )
2009-08-20 21:28:05 +02:00
if os . path . exists ( os . path . join ( dir , ' .svn ' ) ) :
msg = msg + ' \n Try svn instead of 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
raise oscerr . NoWorkingCopy ( msg )
2006-05-19 22:13:29 +02:00
2008-05-19 16:56:59 +02:00
if v != __store_version__ :
if v in [ ' 0.2 ' , ' 0.3 ' , ' 0.4 ' , ' 0.5 ' , ' 0.6 ' , ' 0.7 ' , ' 0.8 ' , ' 0.9 ' , ' 0.95 ' , ' 0.96 ' , ' 0.97 ' , ' 0.98 ' , ' 0.99 ' ] :
2006-05-22 16:23:13 +02:00
# version is fine, no migration needed
2006-05-19 22:13:29 +02:00
f = open ( versionfile , ' w ' )
2008-05-19 16:56:59 +02:00
f . write ( __store_version__ + ' \n ' )
2006-05-19 22:13:29 +02:00
f . close ( )
2009-10-20 16:30:15 +02:00
return
Merged revisions 3774-3775,3779,3781-3782,3787,3789-3793,3798,3802,3805,3817-3822,3827,3829-3830,3837-3839,3841-3842,3848-3850 via svnmerge from
https://forgesvn1.novell.com/svn/opensuse/branches/buildservice/osc-exception-handling
........
r3774 | poeml | 2008-04-22 17:39:45 +0200 (Tue, 22 Apr 2008) | 3 lines
A first draft on implement systematic exception handling:
Add errors.py with some exceptions defined, and babysitter.py to handle them
........
r3775 | poeml | 2008-04-22 22:34:12 +0200 (Tue, 22 Apr 2008) | 9 lines
- new global options:
--debugger jump into the debugger before executing anything
--post-mortem jump into the debugger in case of errors
-t, --traceback print call trace in case of errors
- traceback and post_mortem can also be set in .oscrc.
- catch more errors (HTTPError).
- make config accessible from outside of the Osc instance, by making it a class
attribute
........
r3779 | poeml | 2008-04-23 00:55:49 +0200 (Wed, 23 Apr 2008) | 5 lines
- new global option:
-d, --debug print info useful for debugging
- catch some more errors (HTTPError), with OscHTTPError which isn't very
advanced yet.
........
r3781 | Marcus_H | 2008-04-23 01:02:00 +0200 (Wed, 23 Apr 2008) | 2 lines
- added OscConfigError class (just for testing).
- small change in the signature of the OscBaseError constructor (actually we should get rid of the 'args' tuple because it will be deprecated sooner or later
........
r3782 | Marcus_H | 2008-04-23 02:02:13 +0200 (Wed, 23 Apr 2008) | 2 lines
- access the prg.conf.config dict in a save way - this way we avoid AttributeErrors if the prg.conf.config dict doesn't exist
- in case of an configparser error we have to use the prg.options object directly (this was removed in r3781 by accident)
........
r3787 | poeml | 2008-04-23 09:23:56 +0200 (Wed, 23 Apr 2008) | 4 lines
- remove local exception handling from do_req
- for HTTPError, print details (headers and response) when in debug mode
- catch AttributeError
........
r3789 | poeml | 2008-04-23 16:23:14 +0200 (Wed, 23 Apr 2008) | 4 lines
- errors: add two new classes named OscWrongOptionsError and OscWrongArgsError
- commandline: raise instances of the new errors in a number of places
- commandline: add get_cmd_help() to Osc instance which returns the formatted help of a subcommand
........
r3790 | Marcus_H | 2008-04-23 16:48:28 +0200 (Wed, 23 Apr 2008) | 4 lines
- added 2 new exception classes: OscNoConfigfileError and OscIOError
- added new method write_config() to the conf.py module: This method writes osc's configuration file
- minor cleanups in the conf module
........
r3791 | poeml | 2008-04-23 17:11:07 +0200 (Wed, 23 Apr 2008) | 3 lines
small compatibility fix for r3790: try-except-finally isn't supported in
python-2.4.2, thus do the same as try-except inside a try-finally.
........
r3792 | poeml | 2008-04-23 17:37:53 +0200 (Wed, 23 Apr 2008) | 2 lines
fix up the remaining places regarding handling of errors related to commandline parsing
........
r3793 | poeml | 2008-04-23 17:40:34 +0200 (Wed, 23 Apr 2008) | 3 lines
raise a NoWorkingCopyError in osc.core.store_read_project() in case of an
IOError
........
r3798 | Marcus_H | 2008-04-23 23:55:24 +0200 (Wed, 23 Apr 2008) | 1 line
ported -r3797 from trunk
........
r3802 | Marcus_H | 2008-04-24 11:00:55 +0200 (Thu, 24 Apr 2008) | 1 line
ported -r3801 from trunk
........
r3805 | poeml | 2008-04-24 12:52:30 +0200 (Thu, 24 Apr 2008) | 2 lines
raise OscHTTPError in show_pattern_meta(), replacing local error handling
........
r3817 | poeml | 2008-04-24 20:21:32 +0200 (Thu, 24 Apr 2008) | 9 lines
- remove errors.OscHTTPError again.
it seems simpler to use urllib2.HTTPError instead (and just add a specific
error text message where appropriate, and re-raise)
- for 404s, check out _which_ part was not found
it is very ugly, but may be considered Good for pragmatic reasons
- removed local exception handling and workaround for returned 500's from
delete_package() and delete_project(), thereby getting rid of 4 possible exit
points.
........
r3818 | Marcus_H | 2008-04-24 22:36:17 +0200 (Thu, 24 Apr 2008) | 1 line
- this check is superfluous because every HTTPError instance has a code attribute
........
r3819 | poeml | 2008-04-25 00:39:39 +0200 (Fri, 25 Apr 2008) | 1 line
remove a forgotten debug line from core.delete_project()
........
r3820 | poeml | 2008-04-25 10:07:58 +0200 (Fri, 25 Apr 2008) | 2 lines
- ditch local error handling from wipebinaries(), rebuild(), and abortbuild()
........
r3821 | poeml | 2008-04-25 10:56:38 +0200 (Fri, 25 Apr 2008) | 2 lines
It is never needed to import the exception module.
........
r3822 | poeml | 2008-04-25 11:13:39 +0200 (Fri, 25 Apr 2008) | 4 lines
- when going into the debugger with --post-mortem, always print a traceback before
(thus implying -t)
- do not jump into the debugger if not on a TTY, or working in interactive mode
........
r3827 | poeml | 2008-04-25 13:07:46 +0200 (Fri, 25 Apr 2008) | 9 lines
- add errors.OscWorkingCopyOutdated, which takes a tuple with three args:
path to working copy, current rev, expected rev
- add handler for urllib2.URLError errors to the babysitter
- simplify the OscWrongArgsError and OscWrongOptionsError handlers, by removing
the extra line "Sorry, wrong ..." that was printed before the messages given
when the error was raised.
- remove one more errors.OscHTTPError which was still there, and raise
urllib2.HTTPError instead (show_package_meta())
........
r3829 | poeml | 2008-04-25 14:19:10 +0200 (Fri, 25 Apr 2008) | 11 lines
- comment some methods in osc.core which are used by nearly all do_* methods in
osc.commandline
- improve "is not a package/project dir" error messages, by printing the
absolute path tried, instead of '.' for the cwd
- make core.store_read_package() raise a proper NoWorkingCopyError instead of
terminating
- give attribution to things in babysitter.py copied from mercurial
- prefix HTTPError exceptions with 'Server returned an error:'
- remove obsolete local error handling from do_prjresults(), do_importsrcpkg(),
do_repos()
........
r3830 | poeml | 2008-04-25 14:29:35 +0200 (Fri, 25 Apr 2008) | 1 line
catch IOError exceptions in the babysitter
........
r3837 | poeml | 2008-04-25 17:27:36 +0200 (Fri, 25 Apr 2008) | 5 lines
- do_remotebuildlog: raise errors for wrong arguments, remove exits
- raise AttributeError in make_meta_url() instead of exiting
- delete unused method core.delete_server_files()
- replace exit call inside make_meta_url() with an AttributeError
........
r3838 | poeml | 2008-04-25 17:49:18 +0200 (Fri, 25 Apr 2008) | 1 line
simplify the check in do_checkout if a project exists, by using show_project_meta() instead of meta_exists
........
r3839 | poeml | 2008-04-25 18:31:26 +0200 (Fri, 25 Apr 2008) | 6 lines
- commandline do_checkout(): change the order of the two checks, first do the
(cheaper) check for existing directory
- core.core checkout_package(): simplify the check in if the package
exists, by using show_package_meta() instead of meta_exists
Let it throw an exception, instead of using sys.exit().
........
r3841 | Marcus_H | 2008-04-27 15:48:06 +0200 (Sun, 27 Apr 2008) | 5 lines
- added 2 new exception classes: PackageError() and PackageExistsError. The PackageError() class is meant to be the base class for all subsequent package exceptions.
- get rid of 2 sys.exit(1) calls
- make the update() method of the Project() class safer: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- minor fix in delPackage(): use getTransActPath() when printing out the filename
........
r3842 | Marcus_H | 2008-04-27 16:52:55 +0200 (Sun, 27 Apr 2008) | 3 lines
- make the commit() method safe: in any case we have to write the _packages file otherwise the package tracking will be screwed up.
- removed another sys.exit(1): raise an exception if a package is missing when doing a commit. For now we use the PackageExistsError() exception but this might change in the future (updated description of PackageExistsError() according to this change)
........
r3848 | poeml | 2008-04-28 12:46:45 +0200 (Mon, 28 Apr 2008) | 3 lines
rename several error classes, dropping the "Osc" prefix, and "Error" suffix in
cases where they don't really make sense.
........
r3849 | poeml | 2008-04-28 12:57:32 +0200 (Mon, 28 Apr 2008) | 3 lines
- rename osc.errors module to osc.oscerr, to make it easier to import it from
other programs and have a crystal clear namespace
........
r3850 | poeml | 2008-04-28 13:26:12 +0200 (Mon, 28 Apr 2008) | 2 lines
split PackageExists exception class into PackageExists and PackageMissing
........
2008-04-28 18:37:44 +02:00
msg = ' The osc metadata of your working copy " %s " ' % dir
2008-05-19 16:56:59 +02:00
msg + = ' \n has __store_version__ = %s , but it should be %s ' % ( v , __store_version__ )
msg + = ' \n Please do a fresh checkout or update your client. Sorry about the inconvenience. '
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 . WorkingCopyWrongVersion , msg
2009-10-20 16:30:15 +02:00
2006-04-28 17:37:25 +02:00
2010-05-22 08:22:12 +02:00
def meta_get_packagelist ( apiurl , prj , deleted = None ) :
query = { }
if deleted :
query [ ' deleted ' ] = 1
2006-04-20 16:26:50 +02:00
2010-05-22 08:22:12 +02:00
u = makeurl ( apiurl , [ ' source ' , prj ] , query )
2007-04-19 10:47:22 +02:00
f = http_GET ( u )
2006-10-10 16:04:34 +02:00
root = ET . parse ( f ) . getroot ( )
2006-08-07 12:08:54 +02:00
return [ node . get ( ' name ' ) for node in root . findall ( ' entry ' ) ]
2006-04-20 16:26:50 +02:00
2009-04-09 13:44:32 +02:00
def meta_get_filelist ( apiurl , prj , package , verbose = False , expand = False , revision = None ) :
2007-06-26 15:17:38 +02:00
""" return a list of file names,
or a list File ( ) instances if verbose = True """
2006-04-20 16:26:50 +02:00
2009-04-09 13:44:32 +02:00
query = { }
2009-03-31 00:17:18 +02:00
if expand :
2009-04-09 13:44:32 +02:00
query [ ' expand ' ] = 1
if revision :
query [ ' rev ' ] = revision
2009-04-22 15:14:17 +02:00
else :
query [ ' rev ' ] = ' latest '
2009-04-09 10:21:12 +02:00
2009-04-09 13:44:32 +02:00
u = makeurl ( apiurl , [ ' source ' , prj , package ] , query = query )
2007-04-19 10:47:22 +02:00
f = http_GET ( u )
2006-06-26 17:11:22 +02:00
root = ET . parse ( f ) . getroot ( )
2007-06-26 15:17:38 +02:00
if not verbose :
2008-03-13 22:45:24 +01:00
return [ node . get ( ' name ' ) for node in root . findall ( ' entry ' ) ]
2007-06-26 15:17:38 +02:00
else :
l = [ ]
2009-08-20 21:28:05 +02:00
# rev = int(root.get('rev')) # don't force int. also allow srcmd5 here.
rev = root . get ( ' rev ' )
2008-03-13 22:45:24 +01:00
for node in root . findall ( ' entry ' ) :
2009-10-20 16:30:15 +02:00
f = File ( node . get ( ' name ' ) ,
node . get ( ' md5 ' ) ,
int ( node . get ( ' size ' ) ) ,
2007-06-26 15:17:38 +02:00
int ( node . get ( ' mtime ' ) ) )
f . rev = rev
l . append ( f )
return l
2006-04-20 16:26:50 +02:00
2010-05-25 14:53:20 +02:00
def meta_get_project_list ( apiurl , deleted = None ) :
2010-05-22 08:22:12 +02:00
query = { }
if deleted :
query [ ' deleted ' ] = 1
u = makeurl ( apiurl , [ ' source ' ] , query )
2007-04-19 10:47:22 +02:00
f = http_GET ( u )
2006-10-10 16:04:34 +02:00
root = ET . parse ( f ) . getroot ( )
2010-11-10 12:18:17 +01:00
return sorted ( [ node . get ( ' name ' ) for node in root if node . get ( ' name ' ) ] )
2006-04-20 16:26:50 +02:00
2006-05-19 22:13:29 +02:00
2007-05-04 23:51:54 +02:00
def show_project_meta ( apiurl , prj ) :
url = makeurl ( apiurl , [ ' source ' , prj , ' _meta ' ] )
2007-04-19 10:47:22 +02:00
f = http_GET ( url )
2006-04-20 16:26:50 +02:00
return f . readlines ( )
2007-06-26 15:17:38 +02:00
def show_project_conf ( apiurl , prj ) :
url = makeurl ( apiurl , [ ' source ' , prj , ' _config ' ] )
f = http_GET ( url )
return f . readlines ( )
2009-12-09 07:53:33 +01:00
def show_package_trigger_reason ( apiurl , prj , pac , repo , arch ) :
url = makeurl ( apiurl , [ ' build ' , prj , repo , arch , pac , ' _reason ' ] )
try :
f = http_GET ( url )
return f . read ( )
except urllib2 . HTTPError , e :
e . osc_msg = ' Error getting trigger reason for project \' %s \' package \' %s \' ' % ( prj , pac )
raise
2010-05-27 02:18:00 +02:00
def show_package_meta ( apiurl , prj , pac , meta = False ) :
2010-05-25 14:53:20 +02:00
query = { }
if meta :
query [ ' meta ' ] = 1
2010-06-18 11:43:42 +02:00
# packages like _pattern and _project do not have a _meta file
if pac . startswith ( ' _pattern ' ) or pac . startswith ( ' _project ' ) :
2010-05-25 14:53:20 +02:00
return " "
url = makeurl ( apiurl , [ ' source ' , prj , pac , ' _meta ' ] , query )
2006-07-05 14:09:09 +02:00
try :
2007-04-19 10:47:22 +02:00
f = http_GET ( url )
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
return f . readlines ( )
2006-07-05 14:09:09 +02:00
except urllib2 . HTTPError , e :
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
e . osc_msg = ' Error getting meta for project \' %s \' package \' %s \' ' % ( prj , pac )
2008-07-23 22:56:20 +02:00
raise
2006-04-20 16:26:50 +02:00
2007-05-04 23:51:54 +02:00
2009-10-30 11:18:44 +01:00
def show_attribute_meta ( apiurl , prj , pac , subpac , attribute , with_defaults , with_project ) :
2009-10-30 10:40:46 +01:00
path = [ ]
path . append ( ' source ' )
path . append ( prj )
if pac :
2010-02-27 20:11:15 +01:00
path . append ( pac )
2009-10-30 10:40:46 +01:00
if pac and subpac :
2010-02-27 20:11:15 +01:00
path . append ( subpac )
2009-10-30 10:40:46 +01:00
path . append ( ' _attribute ' )
if attribute :
2010-02-27 20:11:15 +01:00
path . append ( attribute )
2009-10-30 11:18:44 +01:00
query = [ ]
if with_defaults :
2010-02-27 20:11:15 +01:00
query . append ( " with_default=1 " )
2009-10-30 11:18:44 +01:00
if with_project :
2010-02-27 20:11:15 +01:00
query . append ( " with_project=1 " )
2009-10-30 11:18:44 +01:00
url = makeurl ( apiurl , path , query )
2009-10-30 10:40:46 +01:00
try :
f = http_GET ( url )
return f . readlines ( )
except urllib2 . HTTPError , e :
e . osc_msg = ' Error getting meta for project \' %s \' package \' %s \' ' % ( prj , pac )
raise
2008-06-03 17:01:01 +02:00
def show_develproject ( apiurl , prj , pac ) :
m = show_package_meta ( apiurl , prj , pac )
try :
2009-12-26 14:22:34 +01:00
return ET . fromstring ( ' ' . join ( m ) ) . find ( ' devel ' ) . get ( ' project ' )
2008-06-03 17:01:01 +02:00
except :
return None
2010-07-12 14:56:08 +02:00
def show_package_disabled_repos ( apiurl , prj , pac ) :
m = show_package_meta ( apiurl , prj , pac )
2010-07-29 17:45:13 +02:00
#FIXME: don't work if all repos of a project are disabled and only some are enabled since <disable/> is empty
2010-07-12 14:56:08 +02:00
try :
root = ET . fromstring ( ' ' . join ( m ) )
elm = root . find ( ' build ' )
r = [ node . get ( ' repository ' ) for node in elm . findall ( ' disable ' ) ]
return r
except :
return None
2007-07-19 12:08:42 +02:00
def show_pattern_metalist ( apiurl , prj ) :
url = makeurl ( apiurl , [ ' source ' , prj , ' _pattern ' ] )
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 :
f = http_GET ( url )
tree = ET . parse ( f )
except urllib2 . HTTPError , e :
e . osc_msg = ' show_pattern_metalist: Error getting pattern list for project \' %s \' ' % prj
raise
2007-07-19 12:08:42 +02:00
r = [ node . get ( ' name ' ) for node in tree . getroot ( ) ]
r . sort ( )
return r
def show_pattern_meta ( apiurl , prj , pattern ) :
url = makeurl ( apiurl , [ ' source ' , prj , ' _pattern ' , pattern ] )
try :
f = http_GET ( url )
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
return f . readlines ( )
2007-07-19 12:08:42 +02:00
except urllib2 . HTTPError , e :
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
e . osc_msg = ' show_pattern_meta: Error getting pattern \' %s \' for project \' %s \' ' % ( pattern , prj )
raise
2007-07-19 12:08:42 +02:00
2007-01-12 04:52:13 +01:00
class metafile :
""" metafile that can be manipulated and is stored back after manipulation. """
2008-05-20 11:23:57 +02:00
def __init__ ( self , url , input , change_is_required = False , file_ext = ' .xml ' ) :
2007-01-12 04:52:13 +01:00
import tempfile
2006-05-19 22:13:29 +02:00
2007-07-16 18:20:09 +02:00
self . url = url
2007-01-12 04:52:13 +01:00
self . change_is_required = change_is_required
2009-10-24 14:47:21 +02:00
( fd , self . filename ) = tempfile . mkstemp ( prefix = ' osc_metafile. ' , suffix = file_ext )
2007-01-12 04:52:13 +01:00
f = os . fdopen ( fd , ' w ' )
2007-07-16 18:20:09 +02:00
f . write ( ' ' . join ( input ) )
2007-01-12 04:52:13 +01:00
f . close ( )
2007-07-13 18:01:02 +02:00
self . hash_orig = dgst ( self . filename )
2006-05-23 17:27:43 +02:00
2007-01-12 04:52:13 +01:00
def sync ( self ) :
2010-08-20 14:34:41 +02:00
if self . change_is_required and self . hash_orig == dgst ( self . filename ) :
2007-01-12 04:52:13 +01:00
print ' File unchanged. Not saving. '
os . unlink ( self . filename )
2010-02-22 15:43:02 +01:00
return
2006-05-23 17:27:43 +02:00
2008-05-20 18:03:08 +02:00
print ' Sending meta data... '
# don't do any exception handling... it's up to the caller what to do in case
# of an exception
http_PUT ( self . url , file = self . filename )
os . unlink ( self . filename )
print ' Done. '
2009-06-19 10:32:56 +02:00
2009-06-19 10:56:33 +02:00
def edit ( self ) :
2010-02-11 21:22:07 +01:00
try :
while 1 :
2010-04-28 11:49:31 +02:00
run_editor ( self . filename )
2009-06-19 10:56:33 +02:00
try :
self . sync ( )
2010-02-11 21:22:07 +01:00
break
2009-06-19 10:56:33 +02:00
except urllib2 . HTTPError , e :
error_help = " %d " % e . code
if e . headers . get ( ' X-Opensuse-Errorcode ' ) :
error_help = " %s ( %d ) " % ( e . headers . get ( ' X-Opensuse-Errorcode ' ) , e . code )
print >> sys . stderr , ' BuildService API error: ' , error_help
# examine the error - we can't raise an exception because we might want
# to try again
data = e . read ( )
if ' <summary> ' in data :
print >> sys . stderr , data . split ( ' <summary> ' ) [ 1 ] . split ( ' </summary> ' ) [ 0 ]
2010-08-20 14:34:41 +02:00
ri = raw_input ( ' Try again? ([y/N]): ' )
if ri not in [ ' y ' , ' Y ' ] :
2009-06-19 10:56:33 +02:00
break
2010-02-11 21:22:07 +01:00
finally :
self . discard ( )
2009-06-19 10:56:33 +02:00
2009-06-19 10:32:56 +02:00
def discard ( self ) :
if os . path . exists ( self . filename ) :
2010-02-11 21:22:07 +01:00
print ' discarding %s ' % self . filename
2009-06-19 10:32:56 +02:00
os . unlink ( self . filename )
2009-10-20 16:30:15 +02:00
2007-07-13 18:01:02 +02:00
# different types of metadata
metatypes = { ' prj ' : { ' path ' : ' source/ %s /_meta ' ,
' template ' : new_project_templ ,
2008-05-20 11:23:57 +02:00
' file_ext ' : ' .xml '
2007-07-13 18:01:02 +02:00
} ,
' pkg ' : { ' path ' : ' source/ %s / %s /_meta ' ,
' template ' : new_package_templ ,
2008-05-20 11:23:57 +02:00
' file_ext ' : ' .xml '
2007-07-13 18:01:02 +02:00
} ,
2009-10-30 10:40:46 +01:00
' attribute ' : { ' path ' : ' source/ %s / %s /_meta ' ,
' template ' : new_attribute_templ ,
' file_ext ' : ' .xml '
} ,
2007-07-13 18:01:02 +02:00
' prjconf ' : { ' path ' : ' source/ %s /_config ' ,
' template ' : ' ' ,
2008-05-20 11:23:57 +02:00
' file_ext ' : ' .txt '
2007-07-13 18:01:02 +02:00
} ,
' user ' : { ' path ' : ' person/ %s ' ,
' template ' : new_user_template ,
2008-05-20 11:23:57 +02:00
' file_ext ' : ' .xml '
2007-07-13 18:01:02 +02:00
} ,
2007-07-19 12:08:42 +02:00
' pattern ' : { ' path ' : ' source/ %s /_pattern/ %s ' ,
' template ' : new_pattern_template ,
2008-05-20 11:23:57 +02:00
' file_ext ' : ' .xml '
2007-07-19 12:08:42 +02:00
} ,
2007-07-13 18:01:02 +02:00
}
2007-07-23 18:03:30 +02:00
def meta_exists ( metatype ,
path_args = None ,
template_args = None ,
2008-02-18 14:44:20 +01:00
create_new = True ,
apiurl = None ) :
2007-07-23 18:03:30 +02:00
2010-08-31 14:43:43 +02:00
global metatypes
2008-02-18 14:44:20 +01:00
if not apiurl :
apiurl = conf . config [ ' apiurl ' ]
url = make_meta_url ( metatype , path_args , apiurl )
2007-07-23 18:03:30 +02:00
try :
data = http_GET ( url ) . readlines ( )
except urllib2 . HTTPError , e :
2008-05-20 18:03:08 +02:00
if e . code == 404 and create_new :
data = metatypes [ metatype ] [ ' template ' ]
if template_args :
2009-12-25 14:02:04 +01:00
data = StringIO ( data % template_args ) . readlines ( )
2007-07-23 18:03:30 +02:00
else :
2008-05-20 18:03:08 +02:00
raise e
2007-08-04 23:11:31 +02:00
return data
2007-07-16 18:20:09 +02:00
2008-02-18 14:44:20 +01:00
def make_meta_url ( metatype , path_args = None , apiurl = None ) :
2010-08-31 14:43:43 +02:00
global metatypes
2008-02-18 14:44:20 +01:00
if not apiurl :
apiurl = conf . config [ ' apiurl ' ]
2007-07-16 18:20:09 +02:00
if metatype 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 AttributeError ( ' make_meta_url(): Unknown meta type \' %s \' ' % metatype )
2007-07-13 18:01:02 +02:00
path = metatypes [ metatype ] [ ' path ' ]
2007-07-23 18:03:30 +02:00
2007-07-13 18:01:02 +02:00
if path_args :
path = path % path_args
2008-02-18 14:44:20 +01:00
return makeurl ( apiurl , [ path ] )
2007-07-23 18:03:30 +02:00
2009-10-20 16:30:15 +02:00
def edit_meta ( metatype ,
path_args = None ,
data = None ,
template_args = None ,
2007-07-23 18:03:30 +02:00
edit = False ,
2008-03-10 19:04:23 +01:00
change_is_required = False ,
apiurl = None ) :
2006-05-23 17:27:43 +02:00
2010-08-31 14:43:43 +02:00
global metatypes
2008-03-10 19:04:23 +01:00
if not apiurl :
apiurl = conf . config [ ' apiurl ' ]
2007-07-16 18:20:09 +02:00
if not data :
2007-07-23 18:03:30 +02:00
data = meta_exists ( metatype ,
path_args ,
template_args ,
2010-01-07 19:11:02 +01:00
create_new = metatype != ' prjconf ' , # prjconf always exists, 404 => unknown prj
2008-03-10 19:04:23 +01:00
apiurl = apiurl )
2007-07-16 18:20:09 +02:00
if edit :
change_is_required = True
2008-03-10 19:04:23 +01:00
url = make_meta_url ( metatype , path_args , apiurl )
2008-05-20 11:23:57 +02:00
f = metafile ( url , data , change_is_required , metatypes [ metatype ] [ ' file_ext ' ] )
2007-07-16 18:20:09 +02:00
if edit :
2009-06-19 10:56:33 +02:00
f . edit ( )
2007-07-16 18:20:09 +02:00
else :
f . sync ( )
2006-05-23 17:27:43 +02:00
2007-06-26 15:17:38 +02:00
2010-09-03 14:51:20 +02:00
def show_files_meta ( apiurl , prj , pac , revision = None , expand = False , linkrev = None , linkrepair = False , meta = False ) :
2009-04-22 15:14:17 +02:00
query = { }
2007-07-04 14:55:26 +02:00
if revision :
2009-04-22 15:14:17 +02:00
query [ ' rev ' ] = revision
else :
query [ ' rev ' ] = ' latest '
2009-04-21 18:52:26 +02:00
if linkrev :
2009-04-22 15:14:17 +02:00
query [ ' linkrev ' ] = linkrev
2009-12-17 17:16:56 +01:00
elif conf . config [ ' linkcontrol ' ] :
query [ ' linkrev ' ] = ' base '
2010-05-22 08:22:12 +02:00
if meta :
query [ ' meta ' ] = 1
2009-04-21 18:52:26 +02:00
if expand :
2009-04-22 15:14:17 +02:00
query [ ' expand ' ] = 1
2009-04-21 18:52:26 +02:00
if linkrepair :
2009-04-22 15:14:17 +02:00
query [ ' emptylink ' ] = 1
2007-07-04 14:55:26 +02:00
f = http_GET ( makeurl ( apiurl , [ ' source ' , prj , pac ] , query = query ) )
2010-09-03 14:51:20 +02:00
return f . read ( )
2006-05-19 22:13:29 +02:00
2010-05-27 02:18:00 +02:00
def show_upstream_srcmd5 ( apiurl , prj , pac , expand = False , revision = None , meta = False ) :
2010-05-25 13:59:46 +02:00
m = show_files_meta ( apiurl , prj , pac , expand = expand , revision = revision , meta = meta )
2009-12-26 14:22:34 +01:00
return ET . fromstring ( ' ' . join ( m ) ) . get ( ' srcmd5 ' )
2008-03-13 00:37:35 +01:00
2010-05-27 02:18:00 +02:00
def show_upstream_xsrcmd5 ( apiurl , prj , pac , revision = None , linkrev = None , linkrepair = False , meta = False ) :
2010-05-25 13:59:46 +02:00
m = show_files_meta ( apiurl , prj , pac , revision = revision , linkrev = linkrev , linkrepair = linkrepair , meta = meta )
2008-03-24 21:24:49 +01:00
try :
# only source link packages have a <linkinfo> element.
2009-12-26 14:22:34 +01:00
li_node = ET . fromstring ( ' ' . join ( m ) ) . find ( ' linkinfo ' )
2008-03-24 21:24:49 +01:00
except :
return None
2008-07-16 17:14:57 +02:00
li = Linkinfo ( )
li . read ( li_node )
if li . haserror ( ) :
2009-05-15 21:08:14 +02:00
raise oscerr . LinkExpandError ( prj , pac , li . error )
2009-04-21 18:52:26 +02:00
return li . xsrcmd5
2008-07-16 17:14:57 +02:00
2008-03-24 21:24:49 +01:00
2010-05-27 02:18:00 +02:00
def show_upstream_rev ( apiurl , prj , pac , meta = False ) :
2010-05-25 13:59:46 +02:00
m = show_files_meta ( apiurl , prj , pac , meta = meta )
2009-12-26 14:22:34 +01:00
return ET . fromstring ( ' ' . join ( m ) ) . get ( ' rev ' )
2006-06-06 12:50:40 +02:00
2007-07-23 18:03:30 +02:00
def read_meta_from_spec ( specfile , * args ) :
2008-08-03 21:36:07 +02:00
import codecs , locale , re
2007-07-23 18:03:30 +02:00
"""
Read tags and sections from spec file . To read out
2008-08-03 21:36:07 +02:00
a tag the passed argument mustn ' t end with a colon. To
2007-07-23 18:03:30 +02:00
read out a section the passed argument must start with
a ' % ' .
This method returns a dictionary which contains the
requested data .
"""
2006-05-19 22:13:29 +02:00
if not os . path . isfile ( specfile ) :
2010-09-02 10:23:37 +02:00
raise oscerr . OscIOError ( None , ' \' %s \' is not a regular file ' % specfile )
2006-05-19 22:13:29 +02:00
2007-07-11 23:14:58 +02:00
try :
lines = codecs . open ( specfile , ' r ' , locale . getpreferredencoding ( ) ) . readlines ( )
except UnicodeDecodeError :
lines = open ( specfile ) . readlines ( )
2006-06-26 17:11:22 +02:00
2007-07-23 18:03:30 +02:00
tags = [ ]
sections = [ ]
spec_data = { }
for itm in args :
2008-08-03 21:36:07 +02:00
if itm . startswith ( ' % ' ) :
2007-07-23 18:03:30 +02:00
sections . append ( itm )
else :
2008-08-03 21:36:07 +02:00
tags . append ( itm )
2007-07-23 18:03:30 +02:00
2008-08-03 21:36:07 +02:00
tag_pat = ' (?P<tag>^ %s ) \ s*: \ s*(?P<val>.*) '
2007-07-23 18:03:30 +02:00
for tag in tags :
2008-08-03 21:36:07 +02:00
m = re . compile ( tag_pat % tag , re . I | re . M ) . search ( ' ' . join ( lines ) )
if m and m . group ( ' val ' ) :
spec_data [ tag ] = m . group ( ' val ' ) . strip ( )
2007-07-23 18:03:30 +02:00
2009-01-09 12:04:51 +01:00
section_pat = ' ^ %s \ s*?$ '
2007-07-23 18:03:30 +02:00
for section in sections :
2008-08-03 21:36:07 +02:00
m = re . compile ( section_pat % section , re . I | re . M ) . search ( ' ' . join ( lines ) )
if m :
2009-01-09 12:04:51 +01:00
start = lines . index ( m . group ( ) + ' \n ' ) + 1
2007-07-23 18:03:30 +02:00
data = [ ]
for line in lines [ start : ] :
if line . startswith ( ' % ' ) :
break
data . append ( line )
spec_data [ section ] = data
return spec_data
2006-05-19 22:13:29 +02:00
2010-06-09 14:20:48 +02:00
def get_default_editor ( ) :
import platform
system = platform . system ( )
if system == ' Windows ' :
return ' notepad '
if system == ' Linux ' :
try :
# Python 2.6
2010-06-09 14:48:11 +02:00
dist = platform . linux_distribution ( ) [ 0 ]
2010-06-09 14:20:48 +02:00
except AttributeError :
dist = platform . dist ( ) [ 0 ]
if dist == ' debian ' :
return ' editor '
2010-07-14 17:28:48 +02:00
elif dist == ' fedora ' :
2010-07-01 14:48:15 +02:00
return ' vi '
2010-06-09 14:20:48 +02:00
return ' vim '
return ' vi '
def get_default_pager ( ) :
import platform
system = platform . system ( )
if system == ' Windows ' :
return ' less '
if system == ' Linux ' :
try :
# Python 2.6
2010-06-09 14:48:11 +02:00
dist = platform . linux_distribution ( ) [ 0 ]
2010-06-09 14:20:48 +02:00
except AttributeError :
dist = platform . dist ( ) [ 0 ]
if dist == ' debian ' :
return ' pager '
return ' less '
return ' more '
2010-05-03 10:05:36 +02:00
def run_pager ( message ) :
2010-05-09 21:47:21 +02:00
import tempfile , sys
2010-05-03 10:05:36 +02:00
2010-09-10 17:28:45 +02:00
if not message :
return
2010-05-09 21:47:21 +02:00
if not sys . stdout . isatty ( ) :
print message
else :
tmpfile = tempfile . NamedTemporaryFile ( )
tmpfile . write ( message )
tmpfile . flush ( )
2010-06-09 14:22:46 +02:00
pager = os . getenv ( ' PAGER ' , default = get_default_pager ( ) )
2010-07-08 21:43:39 +02:00
try :
try :
subprocess . call ( ' %s %s ' % ( pager , tmpfile . name ) , shell = True )
except OSError , e :
2010-08-16 16:27:00 +02:00
raise oscerr . ExtRuntimeError ( ' cannot run pager \' %s \' : %s ' % ( pager , e . strerror ) , pager )
2010-07-08 21:43:39 +02:00
finally :
tmpfile . close ( )
2010-05-03 10:05:36 +02:00
2010-04-28 11:49:31 +02:00
def run_editor ( filename ) :
2010-06-09 14:22:46 +02:00
editor = os . getenv ( ' EDITOR ' , default = get_default_editor ( ) )
2010-07-02 11:32:07 +02:00
cmd = editor . split ( ' ' )
cmd . append ( filename )
2010-07-08 21:43:39 +02:00
try :
return subprocess . call ( cmd )
except OSError , e :
2010-08-16 16:27:00 +02:00
raise oscerr . ExtRuntimeError ( ' cannot run editor \' %s \' : %s ' % ( editor , e . strerror ) , editor )
2006-05-19 22:13:29 +02:00
2010-05-09 21:36:51 +02:00
def edit_message ( footer = ' ' , template = ' ' , templatelen = 30 ) :
2010-02-24 13:42:48 +01:00
delim = ' --This line, and those below, will be ignored-- \n '
2008-05-21 15:44:49 +02:00
import tempfile
2009-10-24 14:47:21 +02:00
( fd , filename ) = tempfile . mkstemp ( prefix = ' osc-commitmsg ' , suffix = ' .diff ' )
2008-05-21 15:44:49 +02:00
f = os . fdopen ( fd , ' w ' )
2009-04-28 09:15:57 +02:00
if template != ' ' :
2010-05-09 21:36:51 +02:00
if not templatelen is None :
lines = template . splitlines ( )
template = ' \n ' . join ( lines [ : templatelen ] )
if lines [ templatelen : ] :
footer = ' %s \n \n %s ' % ( ' \n ' . join ( lines [ templatelen : ] ) , footer )
2009-04-28 09:15:57 +02:00
f . write ( template )
2009-06-17 20:18:12 +02:00
f . write ( ' \n ' )
2008-05-21 15:44:49 +02:00
f . write ( delim )
2010-02-24 13:42:48 +01:00
f . write ( ' \n ' )
f . write ( footer )
2008-05-21 15:44:49 +02:00
f . close ( )
2010-02-11 21:22:07 +01:00
try :
while 1 :
2010-04-28 11:49:31 +02:00
run_editor ( filename )
2010-02-11 21:22:07 +01:00
msg = open ( filename ) . read ( ) . split ( delim ) [ 0 ] . rstrip ( )
2010-02-11 12:46:20 +01:00
2010-02-11 21:22:07 +01:00
if len ( msg ) :
2010-02-11 12:46:20 +01:00
break
2010-02-11 21:22:07 +01:00
else :
2010-08-20 14:34:41 +02:00
ri = raw_input ( ' Log message not specified \n '
' a)bort, c)ontinue, e)dit: ' )
if ri in ' aA ' :
2010-02-11 21:22:07 +01:00
raise oscerr . UserAbort ( )
2010-08-20 14:34:41 +02:00
elif ri in ' cC ' :
2010-02-11 21:22:07 +01:00
break
2010-08-20 14:34:41 +02:00
elif ri in ' eE ' :
2010-02-11 21:22:07 +01:00
pass
finally :
os . unlink ( filename )
2010-02-11 12:46:20 +01:00
return msg
2008-05-21 15:44:49 +02:00
2009-06-02 15:14:46 +02:00
def create_delete_request ( apiurl , project , package , message ) :
import cgi
if package :
2009-10-20 16:30:15 +02:00
package = """ package= " %s " """ % ( package )
2009-06-02 15:14:46 +02:00
else :
2009-10-20 16:30:15 +02:00
package = " "
2009-06-02 15:14:46 +02:00
xml = """ \
< request >
< action type = " delete " >
< target project = " %s " % s / >
< / action >
< state name = " new " / >
< description > % s < / description >
< / request >
""" % (project, package,
cgi . escape ( message or ' ' ) )
u = makeurl ( apiurl , [ ' request ' ] , query = ' cmd=create ' )
f = http_POST ( u , data = xml )
root = ET . parse ( f ) . getroot ( )
return root . get ( ' id ' )
2009-10-20 16:30:15 +02:00
def create_change_devel_request ( apiurl ,
devel_project , devel_package ,
2009-06-02 15:14:46 +02:00
project , package ,
message ) :
import cgi
xml = """ \
< request >
< action type = " change_devel " >
< source project = " %s " package = " %s " / >
< target project = " %s " package = " %s " / >
< / action >
< state name = " new " / >
< description > % s < / description >
< / request >
2009-10-20 16:30:15 +02:00
""" % (devel_project,
2009-06-02 15:14:46 +02:00
devel_package ,
2009-10-20 16:30:15 +02:00
project ,
2009-06-02 15:14:46 +02:00
package ,
cgi . escape ( message or ' ' ) )
u = makeurl ( apiurl , [ ' request ' ] , query = ' cmd=create ' )
f = http_POST ( u , data = xml )
root = ET . parse ( f ) . getroot ( )
return root . get ( ' id ' )
2010-10-26 15:34:32 +02:00
def clone_request ( apiurl , reqid , msg = None ) :
query = { ' cmd ' : ' branch ' , ' request ' : reqid }
url = makeurl ( apiurl , [ ' source ' ] , query )
r = http_POST ( url , data = msg )
return r . read ( )
2009-06-02 15:14:46 +02:00
2009-11-13 09:58:37 +01:00
# This creates an old style submit request for server api 1.0
2009-10-20 16:30:15 +02:00
def create_submit_request ( apiurl ,
src_project , src_package ,
2009-11-13 09:58:37 +01:00
dst_project = None , dst_package = None ,
message = None , orev = None , src_update = None ) :
2008-03-05 00:41:00 +01:00
2008-03-06 11:25:45 +01:00
import cgi
2009-09-10 10:48:44 +02:00
options_block = " "
if src_update :
2009-10-20 16:30:15 +02:00
options_block = """ <options><sourceupdate> %s </sourceupdate></options> """ % ( src_update )
2009-09-05 15:46:55 +02:00
2009-11-13 09:58:37 +01:00
# Yes, this kind of xml construction is horrible
targetxml = " "
if dst_project :
2010-02-27 20:11:15 +01:00
packagexml = " "
if dst_package :
packagexml = """ package= " %s " """ % ( dst_package )
targetxml = """ <target project= " %s " %s /> """ % ( dst_project , packagexml )
2009-06-02 15:14:46 +02:00
# XXX: keep the old template for now in order to work with old obs instances
2008-03-05 00:41:00 +01:00
xml = """ \
2008-03-20 20:17:40 +01:00
< request type = " submit " >
< submit >
2009-09-10 10:48:44 +02:00
< source project = " %s " package = " %s " rev = " %s " / >
2009-11-13 09:58:37 +01:00
% s
2009-09-10 10:48:44 +02:00
% s
2008-03-20 20:17:40 +01:00
< / submit >
2008-03-05 00:41:00 +01:00
< state name = " new " / >
< description > % s < / description >
< / request >
2009-10-20 16:30:15 +02:00
""" % (src_project,
2009-06-02 15:14:46 +02:00
src_package ,
orev or show_upstream_rev ( apiurl , src_project , src_package ) ,
2009-11-13 09:58:37 +01:00
targetxml ,
2009-09-10 10:48:44 +02:00
options_block ,
2009-11-13 09:58:37 +01:00
cgi . escape ( message or " " ) )
2008-03-05 00:41:00 +01:00
2008-04-02 16:07:40 +02:00
u = makeurl ( apiurl , [ ' request ' ] , query = ' cmd=create ' )
2008-03-05 00:41:00 +01:00
f = http_POST ( u , data = xml )
root = ET . parse ( f ) . getroot ( )
return root . get ( ' id ' )
2009-06-02 15:14:46 +02:00
def get_request ( apiurl , reqid ) :
2008-03-05 00:41:00 +01:00
u = makeurl ( apiurl , [ ' request ' , reqid ] )
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
2009-06-02 15:14:46 +02:00
r = Request ( )
2008-03-05 00:41:00 +01:00
r . read ( root )
return r
2010-12-21 14:17:12 +01:00
def change_review_state ( apiurl , reqid , newstate , by_user = ' ' , by_group = ' ' , message = ' ' , supersed = None ) :
query = { ' cmd ' : ' changereviewstate ' , ' newstate ' : newstate , ' by_user ' : by_user }
2010-12-15 14:31:18 +01:00
if by_group :
query [ ' by_group ' ] = by_group
2010-12-21 14:17:12 +01:00
if supersed :
query [ ' superseded_by ' ] = supersed
2010-12-15 14:31:18 +01:00
u = makeurl ( apiurl , [ ' request ' , reqid ] , query = query )
2009-11-17 17:59:17 +01:00
f = http_POST ( u , data = message )
2010-02-26 09:55:58 +01:00
root = ET . parse ( f ) . getroot ( )
return root . attrib [ ' code ' ]
2009-11-17 17:59:17 +01:00
2010-12-21 14:17:12 +01:00
def change_request_state ( apiurl , reqid , newstate , message = ' ' , supersed = None ) :
query = { ' cmd ' : ' changestate ' , ' newstate ' : newstate }
if supersed :
query [ ' superseded_by ' ] = supersed
2009-10-20 16:30:15 +02:00
u = makeurl ( apiurl ,
2010-12-21 14:17:12 +01:00
[ ' request ' , reqid ] , query = query )
2008-03-06 11:25:45 +01:00
f = http_POST ( u , data = message )
2010-08-18 16:17:34 +02:00
r = f . read ( )
if r . startswith ( ' <status code= " ' ) :
r = r . split ( ' <status code= " ' ) [ 1 ]
r = r . split ( ' " /> ' ) [ 0 ]
return r
2008-03-06 11:25:45 +01:00
2010-11-14 18:32:02 +01:00
def change_request_state_template ( req , newstate ) :
if not len ( req . actions ) :
return ' '
action = req . actions [ 0 ]
tmpl_name = ' %s request_ %s _template ' % ( action . type , newstate )
tmpl = conf . config . get ( tmpl_name , ' ' )
tmpl = tmpl . replace ( ' \\ t ' , ' \t ' ) . replace ( ' \\ n ' , ' \n ' )
data = { ' reqid ' : req . reqid , ' type ' : action . type , ' who ' : req . get_creator ( ) }
if req . actions [ 0 ] . type == ' submit ' :
data . update ( { ' src_project ' : action . src_project ,
' src_package ' : action . src_package , ' src_rev ' : action . src_rev ,
2010-12-30 21:02:42 +01:00
' dst_project ' : action . tgt_project , ' dst_package ' : action . tgt_package ,
2010-12-30 20:58:00 +01:00
' tgt_project ' : action . tgt_project , ' tgt_package ' : action . tgt_package } )
2010-11-14 18:32:02 +01:00
try :
return tmpl % data
except KeyError , e :
print >> sys . stderr , ' error: cannot interpolate \' %s \' in \' %s \' ' % ( e . args [ 0 ] , tmpl_name )
return ' '
2010-07-29 13:45:44 +02:00
def get_review_list ( apiurl , project = ' ' , package = ' ' , user = ' ' , group = ' ' , states = ( ' new ' ) ) :
xpath = ' '
xpath = xpath_join ( xpath , ' state/@name= \' review \' ' , inner = True )
if not ' all ' in states :
for state in states :
xpath = xpath_join ( xpath , ' review/@state= \' %s \' ' % state , inner = True )
if user :
2010-11-09 16:08:26 +01:00
xpath = xpath_join ( xpath , ' review/@by_user= \' %s \' ' % user , op = ' and ' )
2010-07-29 13:45:44 +02:00
if group :
2010-11-09 16:08:26 +01:00
xpath = xpath_join ( xpath , ' review/@by_group= \' %s \' ' % group , op = ' and ' )
2010-07-29 13:45:44 +02:00
# XXX: we cannot use the '|' in the xpath expression because it is not supported
# in the backend
todo = { }
if project :
todo [ ' project ' ] = project
if package :
todo [ ' package ' ] = package
for kind , val in todo . iteritems ( ) :
xpath = xpath_join ( xpath , ' (action/target/@ %(kind)s = \' %(val)s \' or ' \
' action/source/@ %(kind)s = \' %(val)s \' or ' \
' submit/target/@ %(kind)s = \' %(val)s \' or ' \
' submit/source/@ %(kind)s = \' %(val)s \' ) ' % { ' kind ' : kind , ' val ' : val } , op = ' and ' )
if conf . config [ ' verbose ' ] > 1 :
print ' [ %s ] ' % xpath
res = search ( apiurl , request = xpath )
collection = res [ ' request ' ]
requests = [ ]
for root in collection . findall ( ' request ' ) :
r = Request ( )
r . read ( root )
requests . append ( r )
return requests
2010-03-13 13:55:53 +01:00
def get_request_list ( apiurl , project = ' ' , package = ' ' , req_who = ' ' , req_state = ( ' new ' , ) , req_type = None , exclude_target_projects = [ ] ) :
2010-03-11 00:24:38 +01:00
xpath = ' '
2010-02-25 22:56:21 +01:00
if not ' all ' in req_state :
2009-10-20 16:30:15 +02:00
for state in req_state :
2010-03-11 00:24:38 +01:00
xpath = xpath_join ( xpath , ' state/@name= \' %s \' ' % state , inner = True )
2009-06-09 11:29:24 +02:00
if req_who :
2010-03-11 00:24:38 +01:00
xpath = xpath_join ( xpath , ' (state/@who= \' %(who)s \' or history/@who= \' %(who)s \' ) ' % { ' who ' : req_who } , op = ' and ' )
2009-06-09 11:29:24 +02:00
2009-06-02 15:14:46 +02:00
# XXX: we cannot use the '|' in the xpath expression because it is not supported
# in the backend
2010-02-25 22:56:21 +01:00
todo = { }
if project :
todo [ ' project ' ] = project
if package :
todo [ ' package ' ] = package
for kind , val in todo . iteritems ( ) :
2010-03-11 00:24:38 +01:00
xpath = xpath_join ( xpath , ' (action/target/@ %(kind)s = \' %(val)s \' or ' \
' action/source/@ %(kind)s = \' %(val)s \' or ' \
' submit/target/@ %(kind)s = \' %(val)s \' or ' \
' submit/source/@ %(kind)s = \' %(val)s \' ) ' % { ' kind ' : kind , ' val ' : val } , op = ' and ' )
2010-02-25 22:56:21 +01:00
if req_type :
2010-03-11 00:24:38 +01:00
xpath = xpath_join ( xpath , ' action/@type= \' %s \' ' % req_type , op = ' and ' )
2010-02-25 22:56:21 +01:00
for i in exclude_target_projects :
2010-03-11 00:24:38 +01:00
xpath = xpath_join ( xpath , ' (not(action/target/@project= \' %(prj)s \' or ' \
' submit/target/@project= \' %(prj)s \' )) ' % { ' prj ' : i } , op = ' and ' )
2010-02-25 22:56:21 +01:00
if conf . config [ ' verbose ' ] > 1 :
2010-03-11 00:24:38 +01:00
print ' [ %s ] ' % xpath
res = search ( apiurl , request = xpath )
collection = res [ ' request ' ]
2010-02-25 22:56:21 +01:00
requests = [ ]
for root in collection . findall ( ' request ' ) :
r = Request ( )
r . read ( root )
requests . append ( r )
2008-03-05 00:41:00 +01:00
return requests
2010-03-13 21:06:18 +01:00
def get_user_projpkgs_request_list ( apiurl , user , req_state = ( ' new ' , ) , req_type = None , exclude_projects = [ ] , projpkgs = { } ) :
""" Return all new requests for all projects/packages where is user is involved """
if not projpkgs :
res = get_user_projpkgs ( apiurl , user , exclude_projects = exclude_projects )
2010-03-20 12:59:32 +01:00
for i in res [ ' project_id ' ] . findall ( ' project ' ) :
2010-03-13 21:06:18 +01:00
projpkgs [ i . get ( ' name ' ) ] = [ ]
2010-03-20 12:59:32 +01:00
for i in res [ ' package_id ' ] . findall ( ' package ' ) :
2010-03-13 21:06:18 +01:00
if not i . get ( ' project ' ) in projpkgs . keys ( ) :
projpkgs . setdefault ( i . get ( ' project ' ) , [ ] ) . append ( i . get ( ' name ' ) )
xpath = ' '
for prj , pacs in projpkgs . iteritems ( ) :
if not len ( pacs ) :
xpath = xpath_join ( xpath , ' action/target/@project= \' %s \' ' % prj , inner = True )
else :
xp = ' '
for p in pacs :
xp = xpath_join ( xp , ' action/target/@package= \' %s \' ' % p , inner = True )
xp = xpath_join ( xp , ' action/target/@project= \' %s \' ' % prj , op = ' and ' )
xpath = xpath_join ( xpath , xp , inner = True )
if req_type :
xpath = xpath_join ( xpath , ' action/@type= \' %s \' ' % req_type , op = ' and ' )
if not ' all ' in req_state :
xp = ' '
for state in req_state :
2010-03-15 13:15:50 +01:00
xp = xpath_join ( xp , ' state/@name= \' %s \' ' % state , inner = True )
2010-03-15 13:34:38 +01:00
xpath = xpath_join ( xp , ' ( %s ) ' % xpath , op = ' and ' )
2010-03-13 21:06:18 +01:00
res = search ( apiurl , request = xpath )
result = [ ]
for root in res [ ' request ' ] . findall ( ' request ' ) :
r = Request ( )
r . read ( root )
result . append ( r )
return result
2008-03-05 00:41:00 +01:00
2009-06-02 15:14:46 +02:00
def get_request_log ( apiurl , reqid ) :
2010-07-26 16:46:21 +02:00
r = get_request ( apiurl , reqid )
2008-08-19 16:18:05 +02:00
data = [ ]
frmt = ' - ' * 76 + ' \n %s | %s | %s \n \n %s '
2010-12-30 03:04:10 +01:00
r . statehistory . reverse ( )
2009-06-02 15:14:46 +02:00
# the description of the request is used for the initial log entry
2008-08-19 21:15:29 +02:00
# otherwise its comment attribute would contain None
if len ( r . statehistory ) > = 1 :
2010-12-30 03:04:10 +01:00
r . statehistory [ - 1 ] . comment = r . description
2008-08-19 21:15:29 +02:00
else :
2010-12-30 03:04:10 +01:00
r . state . comment = r . description
2008-08-19 16:18:05 +02:00
for state in [ r . state ] + r . statehistory :
s = frmt % ( state . name , state . who , state . when , str ( state . comment ) )
data . append ( s )
return data
2011-01-11 20:02:48 +01:00
def get_group ( apiurl , group ) :
u = makeurl ( apiurl , [ ' group ' , quote_plus ( group ) ] )
try :
f = http_GET ( u )
return ' ' . join ( f . readlines ( ) )
except urllib2 . HTTPError :
print ' user \' %s \' not found ' % group
return None
2007-05-04 23:51:54 +02:00
def get_user_meta ( apiurl , user ) :
u = makeurl ( apiurl , [ ' person ' , quote_plus ( user ) ] )
2006-05-22 16:57:11 +02:00
try :
2007-04-19 10:47:22 +02:00
f = http_GET ( u )
2006-05-22 16:57:11 +02:00
return ' ' . join ( f . readlines ( ) )
except urllib2 . HTTPError :
print ' user \' %s \' not found ' % user
return None
2006-04-20 16:26:50 +02:00
2007-09-03 18:18:37 +02:00
def get_user_data ( apiurl , user , * tags ) :
""" get specified tags from the user meta """
meta = get_user_meta ( apiurl , user )
data = [ ]
if meta != None :
root = ET . fromstring ( meta )
for tag in tags :
try :
if root . find ( tag ) . text != None :
data . append ( root . find ( tag ) . text )
else :
# tag is empty
data . append ( ' - ' )
except AttributeError :
# this part is reached if the tags tuple contains an invalid tag
print ' The xml file for user \' %s \' seems to be broken ' % user
2009-12-12 15:02:58 +01:00
return [ ]
return data
2007-09-03 12:17:04 +02:00
2010-05-12 15:55:36 +02:00
def download ( url , filename , progress_obj = None , mtime = None ) :
2010-02-04 20:32:59 +01:00
import tempfile , shutil
2010-08-31 14:43:43 +02:00
global BUFSIZE
2010-02-04 20:32:59 +01:00
o = None
try :
2010-04-30 15:14:00 +02:00
prefix = os . path . basename ( filename )
2010-09-08 17:41:14 +02:00
path = os . path . dirname ( filename )
( fd , tmpfile ) = tempfile . mkstemp ( dir = path , prefix = prefix , suffix = ' .osctmp ' )
2010-04-30 15:14:00 +02:00
os . chmod ( tmpfile , 0644 )
2010-02-05 15:17:45 +01:00
try :
o = os . fdopen ( fd , ' wb ' )
2010-02-25 10:42:29 +01:00
for buf in streamfile ( url , http_GET , BUFSIZE , progress_obj = progress_obj ) :
2010-02-05 15:17:45 +01:00
o . write ( buf )
o . close ( )
2010-09-08 17:41:14 +02:00
os . rename ( tmpfile , filename )
2010-02-05 15:17:45 +01:00
except :
os . unlink ( tmpfile )
raise
finally :
2010-02-04 20:32:59 +01:00
if o is not None :
o . close ( )
2006-04-20 16:26:50 +02:00
2010-05-12 15:55:36 +02:00
if mtime :
os . utime ( filename , ( - 1 , mtime ) )
2010-05-27 02:18:00 +02:00
def get_source_file ( apiurl , prj , package , filename , targetfilename = None , revision = None , progress_obj = None , mtime = None , meta = False ) :
2010-02-25 10:42:29 +01:00
targetfilename = targetfilename or filename
2010-05-22 08:22:12 +02:00
query = { }
if meta :
query [ ' rev ' ] = 1
2010-02-25 10:42:29 +01:00
if revision :
2010-05-22 08:22:12 +02:00
query [ ' rev ' ] = revision
2010-02-25 10:42:29 +01:00
u = makeurl ( apiurl , [ ' source ' , prj , package , pathname2url ( filename ) ] , query = query )
2010-05-12 15:55:36 +02:00
download ( u , targetfilename , progress_obj , mtime )
2010-02-25 10:42:29 +01:00
2009-10-20 16:30:15 +02:00
def get_binary_file ( apiurl , prj , repo , arch ,
filename ,
2008-09-30 16:54:08 +02:00
package = None ,
2009-10-20 16:30:15 +02:00
target_filename = None ,
2008-09-30 16:54:08 +02:00
target_mtime = None ,
progress_meter = False ) :
2010-02-25 10:42:29 +01:00
progress_obj = None
if progress_meter :
from meter import TextMeter
progress_obj = TextMeter ( )
2008-09-30 16:54:08 +02:00
target_filename = target_filename or filename
2007-08-16 20:15:08 +02:00
where = package or ' _repository '
u = makeurl ( apiurl , [ ' build ' , prj , repo , arch , where , filename ] )
2010-05-12 15:55:36 +02:00
download ( u , target_filename , progress_obj , target_mtime )
2007-08-16 20:15:08 +02:00
2009-04-16 15:48:37 +02:00
def dgst_from_string ( str ) :
2009-06-05 13:29:11 +02:00
# Python 2.5 depracates the md5 modules
# Python 2.4 doesn't have hashlib yet
2009-04-16 15:48:37 +02:00
try :
import hashlib
2009-06-05 13:29:11 +02:00
md5_hash = hashlib . md5 ( )
2009-04-16 15:48:37 +02:00
except ImportError :
import md5
2009-06-05 13:29:11 +02:00
md5_hash = md5 . new ( )
md5_hash . update ( str )
return md5_hash . hexdigest ( )
2007-08-16 20:15:08 +02:00
2006-04-20 16:26:50 +02:00
def dgst ( file ) :
2006-05-19 22:13:29 +02:00
#if not os.path.exists(file):
#return None
2006-04-20 16:26:50 +02:00
2010-08-31 14:43:43 +02:00
global BUFSIZE
2008-09-21 16:44:20 +02:00
try :
import hashlib
md5 = hashlib
except ImportError :
import md5
md5 = md5
s = md5 . md5 ( )
2009-05-22 17:00:31 +02:00
f = open ( file , ' rb ' )
2006-04-20 16:26:50 +02:00
while 1 :
buf = f . read ( BUFSIZE )
if not buf : break
s . update ( buf )
2006-05-19 22:13:29 +02:00
return s . hexdigest ( )
2007-07-13 18:01:02 +02:00
f . close ( )
2006-04-20 16:26:50 +02:00
2006-06-08 12:30:29 +02:00
def binary ( s ) :
""" return true if a string is binary data using diff ' s heuristic """
if s and ' \0 ' in s [ : 4096 ] :
return True
return False
2006-04-20 16:26:50 +02:00
2006-06-22 14:54:58 +02:00
def binary_file ( fn ) :
""" read 4096 bytes from a file named fn, and call binary() on the data """
2009-05-22 17:00:31 +02:00
return binary ( open ( fn , ' rb ' ) . read ( 4096 ) )
2006-06-22 14:54:58 +02:00
2007-07-04 14:55:26 +02:00
def get_source_file_diff ( dir , filename , rev , oldfilename = None , olddir = None , origfilename = None ) :
"""
This methods diffs oldfilename against filename ( so filename will
be shown as the new file ) .
The variable origfilename is used if filename and oldfilename differ
in their names ( for instance if a tempfile is used for filename etc . )
"""
2006-05-19 22:13:29 +02:00
import difflib
2010-08-31 14:43:43 +02:00
global store
2007-07-04 14:55:26 +02:00
if not oldfilename :
oldfilename = filename
if not olddir :
olddir = os . path . join ( dir , store )
if not origfilename :
origfilename = filename
2007-11-26 19:13:51 +01:00
2007-07-04 14:55:26 +02:00
file1 = os . path . join ( olddir , oldfilename ) # old/stored original
2006-05-19 22:28:04 +02:00
file2 = os . path . join ( dir , filename ) # working copy
2010-08-27 16:24:12 +02:00
if binary_file ( file1 ) or binary_file ( file2 ) :
2010-08-31 11:20:34 +02:00
return [ ' Binary file \' %s \' has changed. \n ' % origfilename ]
2006-05-19 22:13:29 +02:00
2010-08-27 16:24:12 +02:00
f1 = f2 = None
try :
f1 = open ( file1 , ' rb ' )
s1 = f1 . readlines ( )
f1 . close ( )
2006-06-08 12:30:29 +02:00
2010-08-27 16:24:12 +02:00
f2 = open ( file2 , ' rb ' )
s2 = f2 . readlines ( )
f2 . close ( )
finally :
if f1 :
f1 . close ( )
if f2 :
f2 . close ( )
d = difflib . unified_diff ( s1 , s2 ,
fromfile = ' %s \t (revision %s ) ' % ( origfilename , rev ) , \
tofile = ' %s \t (working copy) ' % origfilename )
2010-09-08 12:08:00 +02:00
d = list ( d )
# python2.7's difflib slightly changed the format
# adapt old format to the new format
2010-10-29 17:30:56 +02:00
if len ( d ) > 1 :
d [ 0 ] = d [ 0 ] . replace ( ' \n ' , ' \n ' )
d [ 1 ] = d [ 1 ] . replace ( ' \n ' , ' \n ' )
2010-08-27 16:24:12 +02:00
# if file doesn't end with newline, we need to append one in the diff result
for i , line in enumerate ( d ) :
if not line . endswith ( ' \n ' ) :
d [ i ] + = ' \n \\ No newline at end of file '
if i + 1 != len ( d ) :
d [ i ] + = ' \n '
return d
2006-05-19 22:13:29 +02:00
2009-01-16 15:43:45 +01:00
def server_diff ( apiurl ,
2007-11-29 18:22:57 +01:00
old_project , old_package , old_revision ,
2010-10-19 15:25:25 +02:00
new_project , new_package , new_revision , unified = False , missingok = False , meta = False , expand = True ) :
query = { ' cmd ' : ' diff ' }
if expand :
query [ ' expand ' ] = 1
2007-11-29 18:22:57 +01:00
if old_project :
2008-03-17 22:39:27 +01:00
query [ ' oproject ' ] = old_project
2007-11-29 18:22:57 +01:00
if old_package :
2008-03-17 22:39:27 +01:00
query [ ' opackage ' ] = old_package
2007-11-29 18:22:57 +01:00
if old_revision :
2008-03-17 22:39:27 +01:00
query [ ' orev ' ] = old_revision
2007-11-29 18:22:57 +01:00
if new_revision :
2008-03-17 22:39:27 +01:00
query [ ' rev ' ] = new_revision
2009-01-16 15:43:45 +01:00
if unified :
query [ ' unified ' ] = 1
2010-04-10 15:44:15 +02:00
if missingok :
query [ ' missingok ' ] = 1
2010-05-22 08:22:12 +02:00
if meta :
query [ ' meta ' ] = 1
2007-11-29 18:22:57 +01:00
u = makeurl ( apiurl , [ ' source ' , new_project , new_package ] , query = query )
f = http_POST ( u )
return f . read ( )
2010-09-02 10:29:28 +02:00
def request_diff ( apiurl , reqid ) :
u = makeurl ( apiurl , [ ' request ' , reqid ] , query = { ' cmd ' : ' diff ' } )
f = http_POST ( u )
return f . read ( )
2010-10-09 16:26:55 +02:00
def make_dir ( apiurl , project , package , pathname = None , prj_dir = None , package_tracking = True ) :
2008-04-02 17:30:44 +02:00
"""
creates the plain directory structure for a package dir .
The ' apiurl ' parameter is needed for the project dir initialization .
The ' project ' and ' package ' parameters specify the name of the
project and the package . The optional ' pathname ' parameter is used
for printing out the message that a new dir was created ( default : ' prj_dir/package ' ) .
The optional ' prj_dir ' parameter specifies the path to the project dir ( default : ' project ' ) .
"""
prj_dir = prj_dir or project
2009-08-20 21:28:05 +02:00
# FIXME: carefully test each patch component of prj_dir,
# if we have a .osc/_files entry at that level.
# -> if so, we have a package/project clash,
# and should rename this path component by appending '.proj'
# and give user a warning message, to discourage such clashes
2008-04-02 17:30:44 +02:00
pathname = pathname or getTransActPath ( os . path . join ( prj_dir , package ) )
2009-08-21 18:43:46 +02:00
if is_package_dir ( prj_dir ) :
2009-10-20 16:30:15 +02:00
# we want this to become a project directory,
2009-08-20 21:28:05 +02:00
# but it already is a package directory.
2009-08-21 18:43:46 +02:00
raise oscerr . OscIOError ( None , ' checkout_package: package/project clash. Moving myself away not implemented ' )
2009-08-20 21:28:05 +02:00
2009-08-21 18:43:46 +02:00
if not is_project_dir ( prj_dir ) :
2009-10-20 16:30:15 +02:00
# this directory could exist as a parent direory for one of our earlier
2009-08-20 21:28:05 +02:00
# checked out sub-projects. in this case, we still need to initialize it.
2008-04-02 17:30:44 +02:00
print statfrmt ( ' A ' , prj_dir )
2010-10-09 16:26:55 +02:00
Project . init_project ( apiurl , prj_dir , project , package_tracking )
2009-08-21 18:43:46 +02:00
if is_project_dir ( os . path . join ( prj_dir , package ) ) :
2009-08-20 21:28:05 +02:00
# the thing exists, but is a project directory and not a package directory
# FIXME: this should be a warning message to discourage package/project clashes
2009-08-21 18:43:46 +02:00
raise oscerr . OscIOError ( None , ' checkout_package: package/project clash. Moving project away not implemented ' )
2008-04-02 17:30:44 +02:00
if not os . path . exists ( os . path . join ( prj_dir , package ) ) :
2008-03-10 19:04:23 +01:00
print statfrmt ( ' A ' , pathname )
2008-04-02 17:30:44 +02:00
os . mkdir ( os . path . join ( prj_dir , package ) )
2010-08-30 13:46:49 +02:00
# os.mkdir(os.path.join(prj_dir, package, store))
2006-04-20 16:26:50 +02:00
2010-08-30 13:46:49 +02:00
return os . path . join ( prj_dir , package )
2006-04-20 16:26:50 +02:00
2009-10-20 16:30:15 +02:00
def checkout_package ( apiurl , project , package ,
2008-03-24 21:24:49 +01:00
revision = None , pathname = None , prj_obj = None ,
2010-09-03 14:51:20 +02:00
expand_link = False , prj_dir = None , server_service_files = None , service_files = None , progress_obj = None , size_limit = None , meta = False ) :
2008-07-16 17:04:37 +02:00
try :
# the project we're in might be deleted.
# that'll throw an error then.
olddir = os . getcwd ( )
except :
olddir = os . environ . get ( " PWD " )
if not prj_dir :
prj_dir = olddir
2009-05-15 13:40:50 +02:00
else :
if sys . platform [ : 3 ] == ' win ' :
prj_dir = prj_dir [ : 2 ] + prj_dir [ 2 : ] . replace ( ' : ' , ' ; ' )
2009-08-20 21:28:05 +02:00
else :
if conf . config [ ' checkout_no_colon ' ] :
prj_dir = prj_dir . replace ( ' : ' , ' / ' )
2009-10-20 16:30:15 +02:00
2010-12-27 23:03:17 +01:00
root_dots = ' . '
if conf . config [ ' checkout_rooted ' ] :
if prj_dir [ : 1 ] == ' / ' :
if conf . config [ ' verbose ' ] > 1 :
print " checkout_rooted ignored for %s " % prj_dir
# ?? should we complain if not is_project_dir(prj_dir) ??
else :
# if we are inside a project or package dir, ascend to parent
# directories, so that all projects are checked out relative to
# the same root.
if is_project_dir ( " .. " ) :
# if we are in a package dir, goto parent.
# Hmm, with 'checkout_no_colon' in effect, we have directory levels that
# do not easily reveal the fact, that they are part of a project path.
# At least this test should find that the parent of 'home/username/branches'
# is a project (hack alert). Also goto parent in this case.
root_dots = " ../ "
elif is_project_dir ( " ../.. " ) :
# testing two levels is better than one.
# May happen in case of checkout_no_colon, or
# if project roots were previously inconsistent
root_dots = " ../../ "
if is_project_dir ( root_dots ) :
if conf . config [ ' checkout_no_colon ' ] :
oldproj = store_read_project ( root_dots )
n = len ( oldproj . split ( ' : ' ) )
else :
n = 1
root_dots = root_dots + " ../ " * n
if root_dots != ' . ' :
if conf . config [ ' verbose ' ] :
print " found root of %s at %s " % ( oldproj , root_dots )
prj_dir = root_dots + prj_dir
2008-03-10 19:04:23 +01:00
if not pathname :
2008-04-02 17:30:44 +02:00
pathname = getTransActPath ( os . path . join ( prj_dir , package ) )
2006-04-20 16:26:50 +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
# before we create directories and stuff, check if the package actually
# exists
2010-05-25 13:59:46 +02:00
show_package_meta ( apiurl , project , package , meta )
2009-10-20 16:30:15 +02:00
2010-08-30 13:46:49 +02:00
isfrozen = False
2008-03-24 21:24:49 +01:00
if expand_link :
# try to read from the linkinfo
2009-04-21 18:52:26 +02:00
# if it is a link we use the xsrcmd5 as the revision to be
# checked out
2010-01-12 17:22:47 +01:00
try :
2010-05-25 13:59:46 +02:00
x = show_upstream_xsrcmd5 ( apiurl , project , package , revision = revision , meta = meta )
2010-01-12 17:22:47 +01:00
except :
2010-05-25 13:59:46 +02:00
x = show_upstream_xsrcmd5 ( apiurl , project , package , revision = revision , meta = meta , linkrev = ' base ' )
2010-01-12 17:22:47 +01:00
if x :
2010-08-30 13:46:49 +02:00
isfrozen = True
2008-03-24 21:24:49 +01:00
if x :
revision = x
2010-10-09 16:26:55 +02:00
directory = make_dir ( apiurl , project , package , pathname , prj_dir , conf . config [ ' do_package_tracking ' ] )
2010-09-03 14:51:20 +02:00
p = Package . init_package ( apiurl , project , package , directory , size_limit , meta , progress_obj )
2010-01-12 17:22:47 +01:00
if isfrozen :
2010-01-20 17:55:44 +01:00
p . mark_frozen ( )
2008-03-10 19:04:23 +01:00
if conf . config [ ' do_package_tracking ' ] :
# check if we can re-use an existing project object
2010-08-30 13:46:49 +02:00
if prj_obj is None :
prj_obj = Project ( prj_dir )
2008-03-10 19:04:23 +01:00
prj_obj . set_state ( p . name , ' ' )
prj_obj . write_packages ( )
2010-09-03 14:51:20 +02:00
p . update ( revision , server_service_files , size_limit )
2010-06-08 11:24:10 +02:00
if service_files :
2010-08-30 13:46:49 +02:00
print ' Running local source services '
2010-06-08 11:24:10 +02:00
p . run_source_services ( )
2006-04-20 16:26:50 +02:00
2009-03-11 16:23:23 +01:00
def replace_pkg_meta ( pkgmeta , new_name , new_prj , keep_maintainers = False ,
dst_userid = None , keep_develproject = False ) :
2007-11-09 19:03:19 +01:00
"""
update pkgmeta with new new_name and new_prj and set calling user as the
2009-03-11 16:23:23 +01:00
only maintainer ( unless keep_maintainers is set ) . Additionally remove the
develproject entry ( < devel / > ) unless keep_develproject is true .
2007-11-09 19:03:19 +01:00
"""
root = ET . fromstring ( ' ' . join ( pkgmeta ) )
root . set ( ' name ' , new_name )
root . set ( ' project ' , new_prj )
2008-04-30 14:28:25 +02:00
if not keep_maintainers :
for person in root . findall ( ' person ' ) :
root . remove ( person )
2009-03-11 16:23:23 +01:00
if not keep_develproject :
for dp in root . findall ( ' devel ' ) :
root . remove ( dp )
2007-11-09 19:03:19 +01:00
return ET . tostring ( root )
2010-01-14 12:24:48 +01:00
def link_to_branch ( apiurl , project , package ) :
2010-01-11 16:36:33 +01:00
"""
convert a package with a _link + project . diff to a branch
"""
2010-02-18 14:14:31 +01:00
if ' _link ' in meta_get_filelist ( apiurl , project , package ) :
2010-01-14 12:24:48 +01:00
u = makeurl ( apiurl , [ ' source ' , project , package ] , ' cmd=linktobranch ' )
2010-01-11 16:36:33 +01:00
http_POST ( u )
else :
2010-01-11 18:59:49 +01:00
raise oscerr . OscIOError ( None , ' no _link file inside project \' %s \' package \' %s \' ' % ( project , package ) )
2010-01-11 16:36:33 +01:00
2009-12-21 14:24:33 +01:00
def link_pac ( src_project , src_package , dst_project , dst_package , force , rev = ' ' , cicount = ' ' , disable_publish = False ) :
2006-08-07 12:08:54 +02:00
"""
create a linked package
- " src " is the original package
- " dst " is the " link " package that we are creating here
"""
2009-12-21 14:24:33 +01:00
meta_change = False
dst_meta = ' '
2010-07-27 16:06:49 +02:00
apiurl = conf . config [ ' apiurl ' ]
2009-12-21 14:24:33 +01:00
try :
dst_meta = meta_exists ( metatype = ' pkg ' ,
path_args = ( quote_plus ( dst_project ) , quote_plus ( dst_package ) ) ,
template_args = None ,
2010-07-27 16:06:49 +02:00
create_new = False , apiurl = apiurl )
2010-04-29 15:37:47 +02:00
root = ET . fromstring ( ' ' . join ( dst_meta ) )
print root . attrib [ ' project ' ]
if root . attrib [ ' project ' ] != dst_project :
# The source comes from a different project via a project link, we need to create this instance
meta_change = True
2009-07-30 11:42:09 +02:00
except :
2010-04-29 15:37:47 +02:00
meta_change = True
if meta_change :
2010-07-27 16:06:49 +02:00
src_meta = show_package_meta ( apiurl , src_project , src_package )
2009-12-21 14:24:33 +01:00
dst_meta = replace_pkg_meta ( src_meta , dst_package , dst_project )
if disable_publish :
meta_change = True
root = ET . fromstring ( ' ' . join ( dst_meta ) )
elm = root . find ( ' publish ' )
if not elm :
elm = ET . SubElement ( root , ' publish ' )
elm . clear ( )
ET . SubElement ( elm , ' disable ' )
dst_meta = ET . tostring ( root )
2010-04-29 15:37:47 +02:00
2009-12-21 14:24:33 +01:00
if meta_change :
2009-07-30 11:42:09 +02:00
edit_meta ( ' pkg ' ,
2009-10-20 16:30:15 +02:00
path_args = ( dst_project , dst_package ) ,
2009-12-21 14:24:33 +01:00
data = dst_meta )
2006-08-07 12:08:54 +02:00
# create the _link file
# but first, make sure not to overwrite an existing one
2010-07-27 16:06:49 +02:00
if ' _link ' in meta_get_filelist ( apiurl , dst_project , dst_package ) :
2009-06-15 17:19:16 +02:00
if force :
print >> sys . stderr , ' forced overwrite of existing _link file '
else :
print >> sys . stderr
print >> sys . stderr , ' _link file already exists...! Aborting '
sys . exit ( 1 )
2009-10-20 16:30:15 +02:00
2008-06-26 12:47:58 +02:00
if rev :
rev = ' rev= " %s " ' % rev
else :
rev = ' '
2009-04-21 18:52:26 +02:00
2009-05-13 09:59:01 +02:00
if cicount :
cicount = ' cicount= " %s " ' % cicount
else :
cicount = ' '
2006-08-07 12:08:54 +02:00
print ' Creating _link... ' ,
2010-11-04 14:41:40 +01:00
2010-11-25 22:45:51 +01:00
project = ' '
if src_project != dst_project :
project = ' project= " %s " ' % src_project
2010-11-04 14:41:40 +01:00
2006-08-07 12:08:54 +02:00
link_template = """ \
2010-11-25 22:45:51 +01:00
< link % s package = " %s " % s % s >
2006-08-07 12:08:54 +02:00
< patches >
2009-03-17 17:13:04 +01:00
< ! - - < apply name = " patch " / > apply a patch on the source directory - - >
< ! - - < topadd > % % define build_with_feature_x 1 < / topadd > add a line on the top ( spec file only ) - - >
< ! - - < add > file . patch < / add > add a patch to be applied after % % setup ( spec file only ) - - >
< ! - - < delete > filename < / delete > delete a file - - >
2006-08-07 12:08:54 +02:00
< / patches >
< / link >
2010-11-25 22:45:51 +01:00
""" % (project, src_package, rev, cicount)
2006-08-07 12:08:54 +02:00
2010-07-27 16:06:49 +02:00
u = makeurl ( apiurl , [ ' source ' , dst_project , dst_package , ' _link ' ] )
2007-04-19 10:47:22 +02:00
http_PUT ( u , data = link_template )
2006-08-07 12:08:54 +02:00
print ' Done. '
2010-07-20 14:48:27 +02:00
def aggregate_pac ( src_project , src_package , dst_project , dst_package , repo_map = { } , disable_publish = False , nosources = False ) :
2007-10-30 14:45:54 +01:00
"""
aggregate package
- " src " is the original package
- " dst " is the " aggregate " package that we are creating here
2009-07-31 16:31:20 +02:00
- " map " is a dictionary SRC = > TARGET repository mappings
2007-10-30 14:45:54 +01:00
"""
2009-12-21 14:24:33 +01:00
meta_change = False
dst_meta = ' '
2010-07-27 16:06:49 +02:00
apiurl = conf . config [ ' apiurl ' ]
2009-12-21 14:24:33 +01:00
try :
dst_meta = meta_exists ( metatype = ' pkg ' ,
path_args = ( quote_plus ( dst_project ) , quote_plus ( dst_package ) ) ,
template_args = None ,
2010-07-27 16:06:49 +02:00
create_new = False , apiurl = apiurl )
2009-12-21 14:24:33 +01:00
except :
2010-07-27 16:06:49 +02:00
src_meta = show_package_meta ( apiurl , src_project , src_package )
2009-12-21 14:24:33 +01:00
dst_meta = replace_pkg_meta ( src_meta , dst_package , dst_project )
meta_change = True
if disable_publish :
meta_change = True
root = ET . fromstring ( ' ' . join ( dst_meta ) )
elm = root . find ( ' publish ' )
if not elm :
elm = ET . SubElement ( root , ' publish ' )
elm . clear ( )
ET . SubElement ( elm , ' disable ' )
dst_meta = ET . tostring ( root )
if meta_change :
edit_meta ( ' pkg ' ,
path_args = ( dst_project , dst_package ) ,
data = dst_meta )
2007-10-30 14:45:54 +01:00
# create the _aggregate file
# but first, make sure not to overwrite an existing one
2010-07-27 16:06:49 +02:00
if ' _aggregate ' in meta_get_filelist ( apiurl , dst_project , dst_package ) :
2007-10-30 14:45:54 +01:00
print >> sys . stderr
print >> sys . stderr , ' _aggregate file already exists...! Aborting '
sys . exit ( 1 )
print ' Creating _aggregate... ' ,
aggregate_template = """ \
< aggregatelist >
< aggregate project = " %s " >
2009-07-31 16:31:20 +02:00
""" % (src_project)
aggregate_template + = """ \
2007-10-30 14:45:54 +01:00
< package > % s < / package >
2010-07-20 14:48:27 +02:00
""" % ( src_package)
2010-12-21 14:09:25 +01:00
2010-07-20 14:48:27 +02:00
if nosources :
aggregate_template + = """ \
< nosources / >
"""
2010-12-21 14:09:25 +01:00
for src , tgt in repo_map . iteritems ( ) :
aggregate_template + = """ \
< repository target = " %s " source = " %s " / >
""" % (tgt, src)
2010-07-20 14:48:27 +02:00
aggregate_template + = """ \
2007-10-30 14:45:54 +01:00
< / aggregate >
< / aggregatelist >
2010-07-20 14:48:27 +02:00
"""
2007-10-30 14:45:54 +01:00
2010-07-27 16:06:49 +02:00
u = makeurl ( apiurl , [ ' source ' , dst_project , dst_package , ' _aggregate ' ] )
2007-10-30 14:45:54 +01:00
http_PUT ( u , data = aggregate_template )
print ' Done. '
2006-08-07 12:08:54 +02:00
2009-11-02 09:32:15 +01:00
2010-05-17 20:14:49 +02:00
def attribute_branch_pkg ( apiurl , attribute , maintained_update_project_attribute , package , targetproject , return_existing = False , force = False ) :
2009-11-02 09:32:15 +01:00
"""
Branch packages defined via attributes ( via API call )
"""
query = { ' cmd ' : ' branch ' }
query [ ' attribute ' ] = attribute
if targetproject :
query [ ' target_project ' ] = targetproject
2010-05-17 20:14:49 +02:00
if force :
query [ ' force ' ] = " 1 "
2009-11-02 09:32:15 +01:00
if package :
query [ ' package ' ] = package
if maintained_update_project_attribute :
query [ ' update_project_attribute ' ] = maintained_update_project_attribute
u = makeurl ( apiurl , [ ' source ' ] , query = query )
2009-11-10 10:56:34 +01:00
f = None
2009-11-02 09:32:15 +01:00
try :
f = http_POST ( u )
except urllib2 . HTTPError , e :
msg = ' ' . join ( e . readlines ( ) )
msg = msg . split ( ' <summary> ' ) [ 1 ]
msg = msg . split ( ' </summary> ' ) [ 0 ]
2010-04-08 11:24:13 +02:00
raise oscerr . APIError ( msg )
2009-11-02 09:32:15 +01:00
r = f . read ( )
r = r . split ( ' targetproject " > ' ) [ 1 ]
r = r . split ( ' </data> ' ) [ 0 ]
return r
2010-05-19 10:47:01 +02:00
def branch_pkg ( apiurl , src_project , src_package , nodevelproject = False , rev = None , target_project = None , target_package = None , return_existing = False , msg = ' ' , force = False ) :
2008-05-21 17:49:00 +02:00
"""
Branch a package ( via API call )
"""
2008-06-03 15:16:55 +02:00
query = { ' cmd ' : ' branch ' }
if nodevelproject :
2009-02-10 21:22:39 +01:00
query [ ' ignoredevel ' ] = ' 1 '
2010-05-19 10:47:01 +02:00
if force :
query [ ' force ' ] = ' 1 '
2009-02-10 16:49:34 +01:00
if rev :
query [ ' rev ' ] = rev
2009-04-17 14:02:02 +02:00
if target_project :
query [ ' target_project ' ] = target_project
if target_package :
query [ ' target_package ' ] = target_package
2010-03-02 01:34:17 +01:00
if msg :
query [ ' comment ' ] = msg
2009-05-08 21:37:06 +02:00
u = makeurl ( apiurl , [ ' source ' , src_project , src_package ] , query = query )
2009-08-20 21:28:05 +02:00
try :
f = http_POST ( u )
except urllib2 . HTTPError , e :
if not return_existing :
raise
msg = ' ' . join ( e . readlines ( ) )
msg = msg . split ( ' <summary> ' ) [ 1 ]
msg = msg . split ( ' </summary> ' ) [ 0 ]
2010-02-08 19:58:14 +01:00
m = re . match ( r " branch target package already exists: ( \ S+)/( \ S+) " , msg )
2009-08-20 21:28:05 +02:00
if not m :
e . msg + = ' \n ' + msg
raise
2010-02-08 19:58:14 +01:00
return ( True , m . group ( 1 ) , m . group ( 2 ) , None , None )
2008-06-03 14:43:52 +02:00
2010-02-08 19:58:14 +01:00
data = { }
for i in ET . fromstring ( f . read ( ) ) . findall ( ' data ' ) :
data [ i . get ( ' name ' ) ] = i . text
return ( False , data . get ( ' targetproject ' , None ) , data . get ( ' targetpackage ' , None ) ,
data . get ( ' sourceproject ' , None ) , data . get ( ' sourcepackage ' , None ) )
2008-05-21 17:49:00 +02:00
2009-10-20 16:30:15 +02:00
def 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 = False ,
2009-03-11 16:23:23 +01:00
keep_maintainers = False ,
2009-03-31 00:17:18 +02:00
keep_develproject = False ,
2009-05-14 13:50:53 +02:00
expand = False ,
revision = None ,
comment = None ) :
2006-09-21 16:33:24 +02:00
"""
2008-03-17 22:46:42 +01:00
Create a copy of a package .
2006-09-21 16:33:24 +02:00
2008-03-17 22:46:42 +01:00
Copying can be done by downloading the files from one package and commit
them into the other by uploading them ( client - side copy ) - -
or by the server , in a single api call .
"""
2006-09-21 16:33:24 +02:00
2007-05-04 23:51:54 +02:00
src_meta = show_package_meta ( src_apiurl , src_project , src_package )
2008-06-30 16:07:11 +02:00
dst_userid = conf . get_apiurl_usr ( dst_apiurl )
2009-03-11 16:23:23 +01:00
src_meta = replace_pkg_meta ( src_meta , dst_package , dst_project , keep_maintainers ,
dst_userid , keep_develproject )
2006-09-21 16:33:24 +02:00
print ' Sending meta data... '
2007-05-04 23:51:54 +02:00
u = makeurl ( dst_apiurl , [ ' source ' , dst_project , dst_package , ' _meta ' ] )
2007-04-19 10:47:22 +02:00
http_PUT ( u , data = src_meta )
2006-09-21 16:33:24 +02:00
print ' Copying files... '
2008-04-02 16:36:23 +02:00
if not client_side_copy :
2008-03-17 22:46:42 +01:00
query = { ' cmd ' : ' copy ' , ' oproject ' : src_project , ' opackage ' : src_package }
2009-03-31 00:17:18 +02:00
if expand :
query [ ' expand ' ] = ' 1 '
2009-05-14 13:50:53 +02:00
if revision :
query [ ' orev ' ] = revision
if comment :
query [ ' comment ' ] = comment
2008-03-17 22:46:42 +01:00
u = makeurl ( dst_apiurl , [ ' source ' , dst_project , dst_package ] , query = query )
f = http_POST ( u )
return f . read ( )
else :
# copy one file after the other
import tempfile
2009-07-15 20:53:47 +02:00
query = { ' rev ' : ' upload ' }
2010-08-11 22:42:16 +02:00
revision = show_upstream_srcmd5 ( src_apiurl , src_project , src_package , expand = expand , revision = revision )
for n in meta_get_filelist ( src_apiurl , src_project , src_package , expand = expand , revision = revision ) :
2010-12-18 23:18:15 +01:00
if n . startswith ( ' _service: ' ) or n . startswith ( ' _service_ ' ) :
continue
2008-03-17 22:46:42 +01:00
print ' ' , n
2010-08-11 22:50:10 +02:00
tmpfile = None
try :
( fd , tmpfile ) = tempfile . mkstemp ( prefix = ' osc-copypac ' )
get_source_file ( src_apiurl , src_project , src_package , n , targetfilename = tmpfile , revision = revision )
u = makeurl ( dst_apiurl , [ ' source ' , dst_project , dst_package , pathname2url ( n ) ] , query = query )
2010-08-26 12:51:45 +02:00
http_PUT ( u , file = tmpfile )
2010-08-11 22:50:10 +02:00
finally :
if not tmpfile is None :
os . unlink ( tmpfile )
2009-07-15 20:53:47 +02:00
if comment :
query [ ' comment ' ] = comment
query [ ' cmd ' ] = ' commit '
u = makeurl ( dst_apiurl , [ ' source ' , dst_project , dst_package ] , query = query )
http_POST ( u )
2008-03-17 22:46:42 +01:00
return ' Done. '
2006-09-21 16:33:24 +02:00
2010-05-21 19:02:42 +02:00
def undelete_package ( apiurl , prj , pac ) :
2010-05-22 08:22:12 +02:00
u = makeurl ( apiurl , [ ' source ' , prj , pac ] , query = { ' comment ' : ' undeleted via osc ' , ' cmd ' : ' undelete ' } )
2010-05-21 19:02:42 +02:00
http_POST ( u )
def undelete_project ( apiurl , prj ) :
2010-05-22 08:22:12 +02:00
u = makeurl ( apiurl , [ ' source ' , prj ] , query = { ' comment ' : ' undeleted via osc ' , ' cmd ' : ' undelete ' } )
2010-05-21 19:02:42 +02:00
http_POST ( u )
2007-05-04 23:51:54 +02:00
def delete_package ( apiurl , prj , pac ) :
u = makeurl ( apiurl , [ ' source ' , prj , pac ] )
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
http_DELETE ( u )
2006-08-11 12:37:29 +02:00
2007-05-04 23:51:54 +02:00
def delete_project ( apiurl , prj ) :
u = makeurl ( apiurl , [ ' source ' , prj ] )
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
http_DELETE ( u )
2006-09-25 17:11:03 +02:00
2009-07-01 13:19:55 +02:00
def delete_files ( apiurl , prj , pac , files ) :
2010-08-20 14:34:41 +02:00
for filename in files :
u = makeurl ( apiurl , [ ' source ' , prj , pac , filename ] , query = { ' comment ' : ' removed %s ' % ( filename , ) } )
2009-07-01 13:19:55 +02:00
http_DELETE ( u )
2006-09-25 17:11:03 +02:00
2010-05-21 19:02:42 +02:00
2009-09-08 10:14:27 +02:00
# old compat lib call
2007-05-04 23:51:54 +02:00
def get_platforms ( apiurl ) :
2009-09-08 10:14:27 +02:00
return get_repositories ( apiurl )
def get_repositories ( apiurl ) :
2007-05-04 23:51:54 +02:00
f = http_GET ( makeurl ( apiurl , [ ' platform ' ] ) )
2006-05-02 10:17:45 +02:00
tree = ET . parse ( f )
2006-06-26 17:11:22 +02:00
r = [ node . get ( ' name ' ) for node in tree . getroot ( ) ]
2006-05-02 10:17:45 +02:00
r . sort ( )
2006-04-20 16:26:50 +02:00
return r
2006-05-02 10:17:45 +02:00
2010-07-28 16:04:27 +02:00
def get_distibutions ( apiurl , discon = False ) :
r = [ ]
2010-07-29 07:37:54 +02:00
# FIXME: this is just a naming convention on api.opensuse.org, but not a general valid apparoach
2010-07-28 16:04:27 +02:00
if discon :
result_line_templ = ' %(name)-25s %(project)s '
f = http_GET ( makeurl ( apiurl , [ ' build ' ] ) )
root = ET . fromstring ( ' ' . join ( f ) )
for node in root . findall ( ' entry ' ) :
if node . get ( ' name ' ) . startswith ( ' DISCONTINUED: ' ) :
rmap = { }
rmap [ ' name ' ] = node . get ( ' name ' ) . replace ( ' DISCONTINUED: ' , ' ' ) . replace ( ' : ' , ' ' )
rmap [ ' project ' ] = node . get ( ' name ' )
r . append ( result_line_templ % rmap )
r . insert ( 0 , ' distribution project ' )
r . insert ( 1 , ' ------------ ------- ' )
else :
2010-08-13 00:30:05 +02:00
result_line_templ = ' %(name)-25s %(project)-25s %(repository)-25s %(reponame)s '
2010-07-28 16:04:27 +02:00
f = http_GET ( makeurl ( apiurl , [ ' distributions ' ] ) )
root = ET . fromstring ( ' ' . join ( f ) )
for node in root . findall ( ' distribution ' ) :
rmap = { }
for node2 in node . findall ( ' name ' ) :
rmap [ ' name ' ] = node2 . text
for node3 in node . findall ( ' project ' ) :
rmap [ ' project ' ] = node3 . text
2010-07-29 07:37:54 +02:00
for node4 in node . findall ( ' repository ' ) :
rmap [ ' repository ' ] = node4 . text
for node5 in node . findall ( ' reponame ' ) :
rmap [ ' reponame ' ] = node5 . text
2010-07-28 16:04:27 +02:00
r . append ( result_line_templ % rmap )
2010-07-29 07:37:54 +02:00
r . insert ( 0 , ' distribution project repository reponame ' )
r . insert ( 1 , ' ------------ ------- ---------- -------- ' )
2010-07-28 16:04:27 +02:00
return r
2009-09-08 10:14:27 +02:00
# old compat lib call
2007-05-04 23:51:54 +02:00
def get_platforms_of_project ( apiurl , prj ) :
2009-09-08 10:14:27 +02:00
return get_repositories_of_project ( apiurl , prj )
def get_repositories_of_project ( apiurl , prj ) :
2007-05-04 23:51:54 +02:00
f = show_project_meta ( apiurl , prj )
2009-12-26 14:22:34 +01:00
root = ET . fromstring ( ' ' . join ( f ) )
2006-04-20 16:26:50 +02:00
2009-12-26 14:22:34 +01:00
r = [ node . get ( ' name ' ) for node in root . findall ( ' repository ' ) ]
2006-04-20 16:26:50 +02:00
return r
2006-05-02 10:17:45 +02:00
2009-11-17 14:39:46 +01:00
class Repo :
repo_line_templ = ' %-15s %-10s '
def __init__ ( self , name , arch ) :
self . name = name
self . arch = arch
def __str__ ( self ) :
return self . repo_line_templ % ( self . name , self . arch )
2007-05-04 23:51:54 +02:00
def get_repos_of_project ( apiurl , prj ) :
f = show_project_meta ( apiurl , prj )
2009-12-26 14:22:34 +01:00
root = ET . fromstring ( ' ' . join ( f ) )
2006-07-05 12:25:31 +02:00
2009-12-26 14:22:34 +01:00
for node in root . findall ( ' repository ' ) :
2006-07-05 12:25:31 +02:00
for node2 in node . findall ( ' arch ' ) :
2009-11-17 14:39:46 +01:00
yield Repo ( node . get ( ' name ' ) , node2 . text )
2006-07-05 12:25:31 +02:00
2008-09-30 16:54:08 +02:00
def get_binarylist ( apiurl , prj , repo , arch , package = None , verbose = False ) :
2007-08-16 19:12:46 +02:00
what = package or ' _repository '
u = makeurl ( apiurl , [ ' build ' , prj , repo , arch , what ] )
2007-08-16 12:28:32 +02:00
f = http_GET ( u )
2007-08-16 19:12:46 +02:00
tree = ET . parse ( f )
2008-09-30 16:54:08 +02:00
if not verbose :
return [ node . get ( ' filename ' ) for node in tree . findall ( ' binary ' ) ]
else :
l = [ ]
for node in tree . findall ( ' binary ' ) :
2009-10-20 16:30:15 +02:00
f = File ( node . get ( ' filename ' ) ,
None ,
int ( node . get ( ' size ' ) ) ,
2008-09-30 16:54:08 +02:00
int ( node . get ( ' mtime ' ) ) )
l . append ( f )
return l
2007-08-16 12:28:32 +02:00
2007-08-16 19:12:46 +02:00
def get_binarylist_published ( apiurl , prj , repo , arch ) :
u = makeurl ( apiurl , [ ' published ' , prj , repo , arch ] )
f = http_GET ( u )
tree = ET . parse ( f )
r = [ node . get ( ' name ' ) for node in tree . findall ( ' entry ' ) ]
return r
2009-05-15 09:16:26 +02:00
def show_results_meta ( apiurl , prj , package = None , lastbuild = None , repository = [ ] , arch = [ ] ) :
2009-02-18 11:22:06 +01:00
query = { }
2007-08-11 14:29:38 +02:00
if package :
2009-02-18 11:22:06 +01:00
query [ ' package ' ] = package
2009-02-18 10:53:38 +01:00
if lastbuild :
query [ ' lastbuild ' ] = 1
2007-08-11 14:29:38 +02:00
u = makeurl ( apiurl , [ ' build ' , prj , ' _result ' ] , query = query )
2009-05-15 09:16:26 +02:00
for repo in repository :
u = u + ' &repository= %s ' % repo
for a in arch :
u = u + ' &arch= %s ' % a
2007-04-19 10:47:22 +02:00
f = http_GET ( u )
2006-04-20 16:26:50 +02:00
return f . readlines ( )
2006-05-02 10:17:45 +02:00
2007-05-04 23:51:54 +02:00
def show_prj_results_meta ( apiurl , prj ) :
u = makeurl ( apiurl , [ ' build ' , prj , ' _result ' ] )
2007-04-19 10:47:22 +02:00
f = http_GET ( u )
2006-09-25 17:11:03 +02:00
return f . readlines ( )
2010-04-20 14:18:02 +02:00
def get_package_results ( apiurl , prj , package , lastbuild = None , repository = [ ] , arch = [ ] ) :
""" return a package results as a list of dicts """
2006-04-29 22:44:09 +02:00
r = [ ]
2009-05-15 09:16:26 +02:00
f = show_results_meta ( apiurl , prj , package , lastbuild , repository , arch )
2009-12-26 14:22:34 +01:00
root = ET . fromstring ( ' ' . join ( f ) )
2006-05-02 10:17:45 +02:00
2007-03-13 00:21:34 +01:00
for node in root . findall ( ' result ' ) :
rmap = { }
2010-04-20 14:37:28 +02:00
rmap [ ' project ' ] = rmap [ ' prj ' ] = prj
rmap [ ' pkg ' ] = rmap [ ' package ' ] = rmap [ ' pac ' ] = package
rmap [ ' repository ' ] = rmap [ ' repo ' ] = rmap [ ' rep ' ] = node . get ( ' repository ' )
2006-05-02 10:17:45 +02:00
rmap [ ' arch ' ] = node . get ( ' arch ' )
2010-01-13 13:35:45 +01:00
rmap [ ' state ' ] = node . get ( ' state ' )
rmap [ ' dirty ' ] = node . get ( ' dirty ' )
2006-05-02 10:17:45 +02:00
2010-04-20 14:18:02 +02:00
rmap [ ' details ' ] = ' '
2010-05-03 10:53:12 +02:00
statusnode = node . find ( ' status ' )
if statusnode != None :
rmap [ ' code ' ] = statusnode . get ( ' code ' , ' ' )
else :
rmap [ ' code ' ] = ' '
2006-05-02 10:17:45 +02:00
2010-04-23 14:38:00 +02:00
if rmap [ ' code ' ] in ( ' unresolvable ' , ' expansion error ' , ' broken ' , ' blocked ' , ' finished ' ) :
2010-03-01 13:44:37 +01:00
details = statusnode . find ( ' details ' )
if details != None :
2010-04-20 14:18:02 +02:00
rmap [ ' details ' ] = details . text
rmap [ ' dirty ' ] = rmap [ ' dirty ' ] == ' true '
r . append ( rmap )
return r
2010-04-20 14:38:14 +02:00
def format_results ( results , format ) :
""" apply selected format on each dict in results and return it as a list of strings """
2010-04-22 20:13:58 +02:00
return [ format % r for r in results ]
2010-04-20 14:38:14 +02:00
2010-05-06 14:23:27 +02:00
def get_results ( apiurl , prj , package , lastbuild = None , repository = [ ] , arch = [ ] , verbose = False ) :
2010-04-20 14:18:02 +02:00
r = [ ]
result_line_templ = ' %(rep)-20s %(arch)-10s %(status)s '
2010-06-18 17:55:06 +02:00
for res in get_package_results ( apiurl , prj , package , lastbuild , repository , arch ) :
2010-04-20 14:18:02 +02:00
res [ ' status ' ] = res [ ' code ' ]
2010-05-06 14:23:27 +02:00
if verbose and res [ ' details ' ] != ' ' :
if res [ ' status ' ] in ( ' unresolvable ' , ' expansion error ' ) :
lines = res [ ' details ' ] . split ( ' , ' )
res [ ' status ' ] + = ' : ' + ' \n ' . join ( lines )
else :
res [ ' status ' ] + = ' : %s ' % ( res [ ' details ' ] , )
2010-04-20 14:18:02 +02:00
if res [ ' dirty ' ] :
2010-05-06 14:23:27 +02:00
if verbose :
2010-10-23 14:49:28 +02:00
res [ ' status ' ] = ' outdated (was: %s ) ' % res [ ' status ' ]
2010-05-06 14:23:27 +02:00
else :
res [ ' status ' ] + = ' * '
2006-05-02 10:17:45 +02:00
2010-04-20 14:18:02 +02:00
r . append ( result_line_templ % res )
2010-01-13 13:35:45 +01:00
2006-04-29 22:44:09 +02:00
return r
2010-08-04 17:16:59 +02:00
def get_prj_results ( apiurl , prj , hide_legend = False , csv = False , status_filter = None , name_filter = None , arch = None , repo = None , vertical = None , show_excluded = None ) :
2006-09-25 17:11:03 +02:00
#print '----------------------------------------'
2010-08-31 14:43:43 +02:00
global buildstatus_symbols
2006-09-25 17:11:03 +02:00
r = [ ]
2007-05-04 23:51:54 +02:00
f = show_prj_results_meta ( apiurl , prj )
2009-12-26 14:22:34 +01:00
root = ET . fromstring ( ' ' . join ( f ) )
2006-09-25 17:11:03 +02:00
pacs = [ ]
2008-02-12 13:45:06 +01:00
# sequence of (repo,arch) tuples
targets = [ ]
# {package: {(repo,arch): status}}
status = { }
2010-05-27 17:05:40 +02:00
if root . find ( ' result ' ) == None :
2007-06-26 16:32:49 +02:00
return [ ]
2010-05-27 17:05:40 +02:00
for results in root . findall ( ' result ' ) :
2010-06-09 14:34:04 +02:00
for node in results :
pacs . append ( node . get ( ' package ' ) )
2010-05-27 17:05:40 +02:00
pacs = sorted ( list ( set ( pacs ) ) )
2008-02-12 13:45:06 +01:00
for node in root . findall ( ' result ' ) :
2009-10-15 16:24:12 +02:00
# filter architecture and repository
2010-06-21 17:10:25 +02:00
if arch != None and node . get ( ' arch ' ) not in arch :
2009-10-15 16:24:12 +02:00
continue
2010-06-21 17:10:25 +02:00
if repo != None and node . get ( ' repository ' ) not in repo :
2009-10-15 16:24:12 +02:00
continue
2010-01-13 13:35:45 +01:00
if node . get ( ' dirty ' ) == " true " :
state = " outdated "
else :
state = node . get ( ' state ' )
tg = ( node . get ( ' repository ' ) , node . get ( ' arch ' ) , state )
2008-02-12 13:45:06 +01:00
targets . append ( tg )
for pacnode in node . findall ( ' status ' ) :
pac = pacnode . get ( ' package ' )
if pac not in status :
status [ pac ] = { }
status [ pac ] [ tg ] = pacnode . get ( ' code ' )
targets . sort ( )
2008-05-15 20:09:24 +02:00
# filter option
2010-08-04 17:16:59 +02:00
if status_filter or name_filter or not show_excluded :
2008-05-15 20:09:24 +02:00
pacs_to_show = [ ]
2008-05-16 13:15:41 +02:00
targets_to_show = [ ]
2008-05-15 20:09:24 +02:00
2009-10-20 16:30:15 +02:00
#filtering for Package Status
2008-05-15 20:09:24 +02:00
if status_filter :
if status_filter in buildstatus_symbols . values ( ) :
for txt , sym in buildstatus_symbols . items ( ) :
if sym == status_filter :
filt_txt = txt
for pkg in status . keys ( ) :
for repo in status [ pkg ] . keys ( ) :
if status [ pkg ] [ repo ] == filt_txt :
if not name_filter :
pacs_to_show . append ( pkg )
2008-05-16 13:15:41 +02:00
targets_to_show . append ( repo )
2008-05-15 20:09:24 +02:00
elif name_filter in pkg :
pacs_to_show . append ( pkg )
2009-10-20 16:30:15 +02:00
#filtering for Package Name
2008-05-15 20:09:24 +02:00
elif name_filter :
for pkg in pacs :
if name_filter in pkg :
pacs_to_show . append ( pkg )
2010-07-28 15:38:01 +02:00
#filter non building states
2010-08-04 17:16:59 +02:00
elif not show_excluded :
2010-08-04 16:44:51 +02:00
enabled = { }
for pkg in status . keys ( ) :
showpkg = False
for repo in status [ pkg ] . keys ( ) :
2010-08-04 17:16:59 +02:00
if status [ pkg ] [ repo ] != " excluded " :
2010-08-04 16:44:51 +02:00
enabled [ repo ] = 1
showpkg = True
if showpkg :
pacs_to_show . append ( pkg )
2010-07-28 15:38:01 +02:00
2010-08-04 16:44:51 +02:00
targets_to_show = enabled . keys ( )
2010-07-28 15:38:01 +02:00
2008-05-15 20:09:24 +02:00
pacs = [ i for i in pacs if i in pacs_to_show ]
2008-05-20 13:36:16 +02:00
if len ( targets_to_show ) :
2008-05-16 13:15:41 +02:00
targets = [ i for i in targets if i in targets_to_show ]
2008-05-15 20:09:24 +02:00
2008-02-12 13:45:06 +01:00
# csv output
if csv :
# TODO: option to disable the table header
row = [ ' _ ' ] + [ ' / ' . join ( tg ) for tg in targets ]
2008-03-13 12:13:22 +01:00
r . append ( ' ; ' . join ( row ) )
2008-02-12 13:45:06 +01:00
for pac in pacs :
row = [ pac ] + [ status [ pac ] [ tg ] for tg in targets ]
2008-03-13 12:13:22 +01:00
r . append ( ' ; ' . join ( row ) )
2008-02-12 13:45:06 +01:00
return r
2006-09-29 11:55:27 +02:00
2010-01-11 16:36:21 +01:00
if not vertical :
# human readable output
max_pacs = 40
for startpac in range ( 0 , len ( pacs ) , max_pacs ) :
offset = 0
for pac in pacs [ startpac : startpac + max_pacs ] :
r . append ( ' | ' * offset + ' ' + pac )
offset + = 1
for tg in targets :
line = [ ]
line . append ( ' ' )
for pac in pacs [ startpac : startpac + max_pacs ] :
st = ' '
if not status . has_key ( pac ) or not status [ pac ] . has_key ( tg ) :
# for newly added packages, status may be missing
st = ' ? '
else :
try :
st = buildstatus_symbols [ status [ pac ] [ tg ] ]
except :
print ' osc: warn: unknown status \' %s \' ... ' % status [ pac ] [ tg ]
print ' please edit osc/core.py, and extend the buildstatus_symbols dictionary. '
st = ' ? '
buildstatus_symbols [ status [ pac ] [ tg ] ] = ' ? '
line . append ( st )
line . append ( ' ' )
line . append ( ' %s %s ( %s ) ' % tg )
line = ' ' . join ( line )
r . append ( line )
r . append ( ' ' )
else :
2006-09-29 11:55:27 +02:00
offset = 0
2010-01-11 16:36:21 +01:00
for tg in targets :
r . append ( ' | ' * offset + ' %s %s ( %s ) ' % tg )
2006-09-29 11:55:27 +02:00
offset + = 1
2010-01-11 16:36:21 +01:00
for pac in pacs :
2006-09-29 11:55:27 +02:00
line = [ ]
2010-01-11 16:36:21 +01:00
for tg in targets :
2008-02-12 13:45:06 +01:00
st = ' '
if not status . has_key ( pac ) or not status [ pac ] . has_key ( tg ) :
# for newly added packages, status may be missing
st = ' ? '
2008-05-05 14:27:34 +02:00
else :
try :
st = buildstatus_symbols [ status [ pac ] [ tg ] ]
except :
print ' osc: warn: unknown status \' %s \' ... ' % status [ pac ] [ tg ]
print ' please edit osc/core.py, and extend the buildstatus_symbols dictionary. '
st = ' ? '
buildstatus_symbols [ status [ pac ] [ tg ] ] = ' ? '
2008-02-12 13:45:06 +01:00
line . append ( st )
2010-01-11 16:36:21 +01:00
line . append ( ' ' + pac )
r . append ( ' ' . join ( line ) )
line = [ ]
for i in range ( 0 , len ( targets ) ) :
line . append ( str ( i % 10 ) )
r . append ( ' ' . join ( line ) )
2010-02-28 02:30:13 +01:00
2006-09-29 11:55:27 +02:00
r . append ( ' ' )
2006-09-25 17:11:03 +02:00
2008-05-20 13:36:16 +02:00
if not hide_legend and len ( pacs ) :
2007-04-25 01:00:12 +02:00
r . append ( ' Legend: ' )
2010-01-11 16:36:21 +01:00
legend = [ ]
2007-04-25 01:00:12 +02:00
for i , j in buildstatus_symbols . items ( ) :
2010-09-02 16:43:34 +02:00
if i == " expansion error " :
continue
2010-01-11 16:36:21 +01:00
legend . append ( ' %3s %-20s ' % ( j , i ) )
if vertical :
for i in range ( 0 , len ( targets ) ) :
s = ' %1d %s %s ( %s ) ' % ( i % 10 , targets [ i ] [ 0 ] , targets [ i ] [ 1 ] , targets [ i ] [ 2 ] )
if i < len ( legend ) :
legend [ i ] + = s
else :
legend . append ( ' ' * 24 + s )
r + = legend
2006-09-25 17:11:03 +02:00
return r
2010-04-07 03:06:03 +02:00
def streamfile ( url , http_meth = http_GET , bufsize = 8192 , data = None , progress_obj = None , text = None ) :
2009-04-09 17:52:59 +02:00
"""
performs http_meth on url and read bufsize bytes from the response
until EOF is reached . After each read bufsize bytes are yielded to the
caller .
"""
2010-12-01 10:22:53 +01:00
cl = ' '
retries = 0
# Repeat requests until we get reasonable Content-Length header
# Server (or iChain) is corrupting data at some point, see bnc#656281
while cl == ' ' :
if retries > = int ( conf . config [ ' http_retries ' ] ) :
raise oscerr . OscIOError ( None , ' Content-Length is empty for %s , protocol violation ' % url )
retries = retries + 1
if retries > 1 and conf . config [ ' http_debug ' ] :
print >> sys . stderr , ' \n \n Retry %d -- ' % ( retries - 1 ) , url
f = http_meth . __call__ ( url , data = data )
cl = f . info ( ) . get ( ' Content-Length ' )
2010-11-30 16:39:14 +01:00
if cl is not None :
cl = int ( cl )
2010-02-09 20:57:10 +01:00
if progress_obj :
2010-12-01 10:17:12 +01:00
import urlparse
2010-02-09 20:57:10 +01:00
basename = os . path . basename ( urlparse . urlsplit ( url ) [ 2 ] )
2010-09-09 15:04:00 +02:00
progress_obj . start ( basename = basename , text = text , size = cl )
2009-04-09 17:52:59 +02:00
data = f . read ( bufsize )
2010-02-09 20:57:10 +01:00
read = len ( data )
2009-04-09 17:52:59 +02:00
while len ( data ) :
2010-02-09 20:57:10 +01:00
if progress_obj :
progress_obj . update ( read )
2009-04-09 17:52:59 +02:00
yield data
data = f . read ( bufsize )
2010-02-09 20:57:10 +01:00
read + = len ( data )
if progress_obj :
progress_obj . end ( read )
2009-04-09 18:14:29 +02:00
f . close ( )
2009-04-09 17:52:59 +02:00
2010-11-30 19:10:06 +01:00
if not cl is None and read != cl :
raise oscerr . OscIOError ( None , ' Content-Length is not matching file size for %s : %i vs %i file size ' % ( url , cl , read ) )
2010-11-30 16:39:14 +01:00
2009-04-09 17:52:59 +02:00
2009-09-08 10:14:27 +02:00
def print_buildlog ( apiurl , prj , package , repository , arch , offset = 0 ) :
2008-01-03 23:10:16 +01:00
""" prints out the buildlog on stdout """
2009-04-09 17:52:59 +02:00
query = { ' nostream ' : ' 1 ' , ' start ' : ' %s ' % offset }
2009-04-24 20:17:12 +02:00
while True :
query [ ' start ' ] = offset
start_offset = offset
2009-09-08 10:14:27 +02:00
u = makeurl ( apiurl , [ ' build ' , prj , repository , arch , package , ' _log ' ] , query = query )
2009-04-24 20:17:12 +02:00
for data in streamfile ( u ) :
offset + = len ( data )
2009-04-27 20:30:00 +02:00
sys . stdout . write ( data )
2009-04-24 20:17:12 +02:00
if start_offset == offset :
break
2006-05-02 10:17:45 +02:00
2009-12-04 16:20:17 +01:00
def get_dependson ( apiurl , project , repository , arch , packages = None , reverse = None ) :
query = [ ]
if packages :
for i in packages :
query . append ( ' package= %s ' % quote_plus ( i ) )
if reverse :
query . append ( ' view=revpkgnames ' )
else :
query . append ( ' view=pkgnames ' )
u = makeurl ( apiurl , [ ' build ' , project , repository , arch , ' _builddepinfo ' ] , query = query )
f = http_GET ( u )
return f . read ( )
2009-09-08 10:14:27 +02:00
def get_buildinfo ( apiurl , prj , package , repository , arch , specfile = None , addlist = None ) :
2007-05-09 11:36:55 +02:00
query = [ ]
if addlist :
for i in addlist :
query . append ( ' add= %s ' % quote_plus ( i ) )
2009-09-08 10:14:27 +02:00
u = makeurl ( apiurl , [ ' build ' , prj , repository , arch , package , ' _buildinfo ' ] , query = query )
2007-05-09 11:36:55 +02:00
2007-04-25 01:00:12 +02:00
if specfile :
f = http_POST ( u , data = specfile )
else :
f = http_GET ( u )
2006-07-05 12:25:31 +02:00
return f . read ( )
2010-07-27 13:58:52 +02:00
def get_buildconfig ( apiurl , prj , repository ) :
2009-09-08 10:14:27 +02:00
u = makeurl ( apiurl , [ ' build ' , prj , repository , ' _buildconfig ' ] )
2007-04-19 10:47:22 +02:00
f = http_GET ( u )
2006-07-05 12:25:31 +02:00
return f . read ( )
2010-12-26 21:14:40 +01:00
def get_source_rev ( apiurl , project , package , revision = None ) :
# API supports ?deleted=1&meta=1&rev=4
# but not rev=current,rev=latest,rev=top, or anything like this.
# CAUTION: We have to loop through all rev and find the highest one, if none given.
if revision :
url = makeurl ( apiurl , [ ' source ' , project , package , ' _history ' ] , { ' rev ' : revision } )
else :
url = makeurl ( apiurl , [ ' source ' , project , package , ' _history ' ] )
f = http_GET ( url )
xml = ET . parse ( f )
ent = None
for new in xml . findall ( ' revision ' ) :
# remember the newest one.
if not ent :
ent = new
elif ent . find ( ' time ' ) . text < new . find ( ' time ' ) . text :
ent = new
if not ent :
return { ' version ' : None , ' error ' : ' empty revisionlist: no such package? ' }
e = { }
for k in ent . keys ( ) :
e [ k ] = ent . get ( k )
for k in list ( ent ) :
e [ k . tag ] = k . text
return e
2006-07-05 12:25:31 +02:00
2009-09-08 10:14:27 +02:00
def get_buildhistory ( apiurl , prj , package , repository , arch , format = ' text ' ) :
2006-09-25 17:11:03 +02:00
import time
2009-09-08 10:14:27 +02:00
u = makeurl ( apiurl , [ ' build ' , prj , repository , arch , package , ' _history ' ] )
2007-04-19 10:47:22 +02:00
f = http_GET ( u )
2006-09-25 17:11:03 +02:00
root = ET . parse ( f ) . getroot ( )
r = [ ]
for node in root . findall ( ' entry ' ) :
rev = int ( node . get ( ' rev ' ) )
2009-10-20 16:30:15 +02:00
srcmd5 = node . get ( ' srcmd5 ' )
versrel = node . get ( ' versrel ' )
2006-09-25 17:11:03 +02:00
bcnt = int ( node . get ( ' bcnt ' ) )
2006-10-10 16:04:34 +02:00
t = time . localtime ( int ( node . get ( ' time ' ) ) )
2006-09-25 17:11:03 +02:00
t = time . strftime ( ' % Y- % m- %d % H: % M: % S ' , t )
2009-05-13 11:04:27 +02:00
if format == ' csv ' :
r . append ( ' %s | %s | %d | %s . %d ' % ( t , srcmd5 , rev , versrel , bcnt ) )
else :
r . append ( ' %s %s %6d %s . %d ' % ( t , srcmd5 , rev , versrel , bcnt ) )
2006-09-25 17:11:03 +02:00
2009-05-13 11:04:27 +02:00
if format == ' text ' :
r . insert ( 0 , ' time srcmd5 rev vers-rel.bcnt ' )
2006-09-25 17:11:03 +02:00
return r
2006-05-19 22:13:29 +02:00
2009-11-13 14:31:10 +01:00
def print_jobhistory ( apiurl , prj , current_package , repository , arch , format = ' text ' , limit = 20 ) :
2009-02-20 12:04:45 +01:00
import time
2009-11-23 11:13:12 +01:00
query = { }
2009-02-20 12:56:13 +01:00
if current_package :
2010-01-12 17:22:47 +01:00
query [ ' package ' ] = current_package
2009-11-23 11:13:12 +01:00
if limit != None and int ( limit ) > 0 :
2010-01-12 17:22:47 +01:00
query [ ' limit ' ] = int ( limit )
2009-11-23 11:13:12 +01:00
u = makeurl ( apiurl , [ ' build ' , prj , repository , arch , ' _jobhistory ' ] , query )
2009-02-20 12:04:45 +01:00
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
2009-05-13 11:04:27 +02:00
if format == ' text ' :
2009-11-13 14:31:10 +01:00
print " time package reason code build time worker "
2009-02-20 12:04:45 +01:00
for node in root . findall ( ' jobhist ' ) :
package = node . get ( ' package ' )
2009-11-13 14:31:10 +01:00
worker = node . get ( ' workerid ' )
2009-02-20 12:04:45 +01:00
reason = node . get ( ' reason ' )
if not reason :
reason = " unknown "
code = node . get ( ' code ' )
rt = int ( node . get ( ' readytime ' ) )
readyt = time . localtime ( rt )
readyt = time . strftime ( ' % Y- % m- %d % H: % M: % S ' , readyt )
st = int ( node . get ( ' starttime ' ) )
et = int ( node . get ( ' endtime ' ) )
endtime = time . strftime ( ' % Y- % m- %d % H: % M: % S ' , time . localtime ( et ) )
waittm = time . gmtime ( et - st )
if waittm . tm_hour :
waitbuild = " %2d h %2d m %2d s " % ( waittm . tm_hour , waittm . tm_min , waittm . tm_sec )
else :
waitbuild = " %2d m %2d s " % ( waittm . tm_min , waittm . tm_sec )
2009-10-20 16:30:15 +02:00
2009-05-13 11:04:27 +02:00
if format == ' csv ' :
2009-11-13 14:31:10 +01:00
print ' %s | %s | %s | %s | %s | %s ' % ( endtime , package , reason , code , waitbuild , worker )
2009-05-13 11:04:27 +02:00
else :
2009-11-13 14:31:10 +01:00
print ' %s %-50s %-16s %-16s %-16s %-16s ' % ( endtime , package [ 0 : 49 ] , reason [ 0 : 15 ] , code [ 0 : 15 ] , waitbuild , worker )
2009-02-20 12:04:45 +01:00
2006-05-19 22:13:29 +02:00
2010-05-27 02:18:00 +02:00
def get_commitlog ( apiurl , prj , package , revision , format = ' text ' , meta = False ) :
2007-07-13 12:02:35 +02:00
import time , locale
2010-05-25 13:59:46 +02:00
query = { }
if meta :
query [ ' meta ' ] = 1
u = makeurl ( apiurl , [ ' source ' , prj , package , ' _history ' ] , query )
2007-07-12 01:24:26 +02:00
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
r = [ ]
2009-05-13 10:53:32 +02:00
if format == ' xml ' :
r . append ( ' <?xml version= " 1.0 " ?> ' )
r . append ( ' <log> ' )
2007-07-12 01:24:26 +02:00
revisions = root . findall ( ' revision ' )
revisions . reverse ( )
for node in revisions :
2009-05-05 16:01:41 +02:00
srcmd5 = node . find ( ' srcmd5 ' ) . text
2007-07-12 02:48:52 +02:00
try :
rev = int ( node . get ( ' rev ' ) )
#vrev = int(node.get('vrev')) # what is the meaning of vrev?
2009-05-05 16:01:41 +02:00
try :
if revision and rev != int ( revision ) :
continue
except ValueError :
if revision != srcmd5 :
continue
2007-07-12 02:48:52 +02:00
except ValueError :
# this part should _never_ be reached but...
return [ ' an unexpected error occured - please file a bug ' ]
2007-07-12 01:24:26 +02:00
version = node . find ( ' version ' ) . text
user = node . find ( ' user ' ) . text
try :
2007-07-13 12:02:35 +02:00
comment = node . find ( ' comment ' ) . text . encode ( locale . getpreferredencoding ( ) , ' replace ' )
2007-07-12 01:24:26 +02:00
except :
comment = ' <no message> '
2009-09-05 15:46:55 +02:00
try :
requestid = node . find ( ' requestid ' ) . text . encode ( locale . getpreferredencoding ( ) , ' replace ' )
except :
requestid = " "
2007-07-12 01:24:26 +02:00
t = time . localtime ( int ( node . find ( ' time ' ) . text ) )
t = time . strftime ( ' % Y- % m- %d % H: % M: % S ' , t )
2009-05-13 10:53:32 +02:00
if format == ' csv ' :
2009-10-20 16:30:15 +02:00
s = ' %s | %s | %s | %s | %s | %s | %s ' % ( rev , user , t , srcmd5 , version ,
2009-09-05 15:46:55 +02:00
comment . replace ( ' \\ ' , ' \\ \\ ' ) . replace ( ' \n ' , ' \\ n ' ) . replace ( ' | ' , ' \\ | ' ) , requestid )
2009-05-13 10:53:32 +02:00
r . append ( s )
elif format == ' xml ' :
r . append ( ' <logentry ' )
2009-05-13 10:57:24 +02:00
r . append ( ' revision= " %s " srcmd5= " %s " > ' % ( rev , srcmd5 ) )
2009-05-13 10:53:32 +02:00
r . append ( ' <author> %s </author> ' % user )
r . append ( ' <date> %s </date> ' % t )
2009-09-05 15:46:55 +02:00
r . append ( ' <requestid> %s </requestid> ' % requestid )
2009-10-20 16:30:15 +02:00
r . append ( ' <msg> %s </msg> ' %
2009-05-13 10:53:32 +02:00
comment . replace ( ' & ' , ' & ' ) . replace ( ' < ' , ' > ' ) . replace ( ' > ' , ' < ' ) )
r . append ( ' </logentry> ' )
else :
s = ' - ' * 76 + \
2009-09-07 09:28:00 +02:00
' \n r %s | %s | %s | %s | %s | sr %s \n ' % ( rev , user , t , srcmd5 , version , requestid ) + \
2009-05-13 10:53:32 +02:00
' \n ' + comment
r . append ( s )
if format not in [ ' csv ' , ' xml ' ] :
r . append ( ' - ' * 76 )
if format == ' xml ' :
r . append ( ' </log> ' )
2007-07-12 01:24:26 +02:00
return r
2010-09-01 12:44:47 +02:00
def runservice ( apiurl , prj , package ) :
u = makeurl ( apiurl , [ ' source ' , prj , package ] , query = { ' cmd ' : ' runservice ' } )
try :
f = http_POST ( u )
except urllib2 . HTTPError , e :
e . osc_msg = ' could not trigger service run for project \' %s \' package \' %s \' ' % ( prj , package )
raise
root = ET . parse ( f ) . getroot ( )
return root . get ( ' code ' )
2007-06-14 16:30:36 +02:00
def rebuild ( apiurl , prj , package , repo , arch , code = None ) :
2008-04-02 16:07:40 +02:00
query = { ' cmd ' : ' rebuild ' }
2007-04-25 01:00:12 +02:00
if package :
2008-04-02 16:07:40 +02:00
query [ ' package ' ] = package
2006-09-25 17:11:03 +02:00
if repo :
2008-04-02 16:07:40 +02:00
query [ ' repository ' ] = repo
2006-09-25 17:11:03 +02:00
if arch :
2008-04-02 16:07:40 +02:00
query [ ' arch ' ] = arch
2007-04-25 01:00:12 +02:00
if code :
2008-04-02 16:07:40 +02:00
query [ ' code ' ] = code
2007-04-25 01:00:12 +02:00
2007-05-09 11:36:55 +02:00
u = makeurl ( apiurl , [ ' build ' , prj ] , query = query )
2006-06-26 17:11:22 +02:00
try :
2007-04-19 10:47:22 +02:00
f = http_POST ( u )
2006-06-26 17:11:22 +02:00
except urllib2 . HTTPError , e :
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
e . osc_msg = ' could not trigger rebuild for project \' %s \' package \' %s \' ' % ( prj , package )
raise
2006-06-26 17:11:22 +02:00
root = ET . parse ( f ) . getroot ( )
2007-04-25 01:00:12 +02:00
return root . get ( ' code ' )
2006-06-08 12:30:29 +02:00
2006-04-20 16:26:50 +02:00
def store_read_project ( dir ) :
2010-08-31 14:43:43 +02:00
global store
2007-07-12 02:48:52 +02:00
try :
p = open ( os . path . join ( dir , store , ' _project ' ) ) . readlines ( ) [ 0 ] . strip ( )
except IOError :
2009-08-21 22:43:08 +02:00
msg = ' Error: \' %s \' is not an osc project dir or working copy ' % os . path . abspath ( dir )
2009-08-20 21:28:05 +02:00
if os . path . exists ( os . path . join ( dir , ' .svn ' ) ) :
2009-08-21 22:43:08 +02:00
msg + = ' \n Try svn instead of osc. '
raise oscerr . NoWorkingCopy ( msg )
2006-04-20 16:26:50 +02:00
return p
2006-05-02 10:17:45 +02:00
2006-04-20 16:26:50 +02:00
def store_read_package ( dir ) :
2010-08-31 14:43:43 +02:00
global store
2007-07-12 02:48:52 +02:00
try :
p = open ( os . path . join ( dir , store , ' _package ' ) ) . readlines ( ) [ 0 ] . strip ( )
except IOError :
2009-09-28 21:50:57 +02:00
msg = ' Error: \' %s \' is not an osc package working copy ' % os . path . abspath ( dir )
2009-08-20 21:28:05 +02:00
if os . path . exists ( os . path . join ( dir , ' .svn ' ) ) :
2009-08-21 22:43:08 +02:00
msg + = ' \n Try svn instead of osc. '
raise oscerr . NoWorkingCopy ( msg )
2006-04-20 16:26:50 +02:00
return p
2010-09-19 23:00:19 +02:00
def store_read_apiurl ( dir , defaulturl = True ) :
2010-08-31 14:43:43 +02:00
global store
2007-05-04 23:51:54 +02:00
fname = os . path . join ( dir , store , ' _apiurl ' )
try :
2009-07-16 14:07:14 +02:00
url = open ( fname ) . readlines ( ) [ 0 ] . strip ( )
# this is needed to get a proper apiurl
# (former osc versions may stored an apiurl with a trailing slash etc.)
apiurl = conf . urljoin ( * conf . parse_apisrv_url ( None , url ) )
2007-05-04 23:51:54 +02:00
except :
2010-10-10 21:40:31 +02:00
if not defaulturl :
if is_project_dir ( dir ) :
project = store_read_project ( dir )
package = None
elif is_package_dir ( dir ) :
project = store_read_project ( dir )
package = None
else :
msg = ' Error: \' %s \' is not an osc package working copy ' % os . path . abspath ( dir )
raise oscerr . NoWorkingCopy ( msg )
2010-09-28 23:07:33 +02:00
msg = ' Your working copy \' %s \' is in an inconsistent state. \n ' \
' Please run \' osc repairwc %s \' (Note this might _remove_ \n ' \
' files from the .osc/ dir). Please check the state \n ' \
' of the working copy afterwards (via \' osc status %s \' ) ' % ( dir , dir , dir )
2010-10-10 21:40:31 +02:00
raise oscerr . WorkingCopyInconsistent ( project , package , [ ' _apiurl ' ] , msg )
2009-02-24 00:29:32 +01:00
apiurl = conf . config [ ' apiurl ' ]
2007-05-04 23:51:54 +02:00
return apiurl
2010-08-19 18:10:32 +02:00
def store_write_string ( dir , file , string , subdir = ' ' ) :
2010-08-31 14:43:43 +02:00
global store
2010-08-19 18:10:32 +02:00
if subdir and not os . path . isdir ( os . path . join ( dir , store , subdir ) ) :
os . mkdir ( os . path . join ( dir , store , subdir ) )
fname = os . path . join ( dir , store , subdir , file )
2010-03-04 00:31:46 +01:00
try :
f = open ( fname + ' .new ' , ' w ' )
f . write ( string )
f . close ( )
os . rename ( fname + ' .new ' , fname )
except :
if os . path . exists ( fname + ' .new ' ) :
os . unlink ( fname + ' .new ' )
raise
2009-04-21 18:52:26 +02:00
2007-05-04 23:51:54 +02:00
def store_write_project ( dir , project ) :
2010-03-04 00:31:46 +01:00
store_write_string ( dir , ' _project ' , project + ' \n ' )
2007-05-04 23:51:54 +02:00
def store_write_apiurl ( dir , apiurl ) :
2010-03-04 00:31:46 +01:00
store_write_string ( dir , ' _apiurl ' , apiurl + ' \n ' )
2006-08-11 12:37:29 +02:00
2010-02-11 11:25:56 +01:00
def store_unlink_file ( dir , file ) :
2010-08-31 14:43:43 +02:00
global store
2010-02-11 11:25:56 +01:00
try : os . unlink ( os . path . join ( dir , store , file ) )
except : pass
def store_read_file ( dir , file ) :
2010-08-31 14:43:43 +02:00
global store
2010-02-11 11:25:56 +01:00
try :
content = open ( os . path . join ( dir , store , file ) ) . read ( )
return content
except :
return None
2008-03-10 19:04:23 +01:00
def store_write_initial_packages ( dir , project , subelements ) :
2010-08-31 14:43:43 +02:00
global store
2008-03-10 19:04:23 +01:00
fname = os . path . join ( dir , store , ' _packages ' )
root = ET . Element ( ' project ' , name = project )
for elem in subelements :
root . append ( elem )
ET . ElementTree ( root ) . write ( fname )
2006-05-23 10:43:04 +02:00
def get_osc_version ( ) :
return __version__
2006-04-20 16:26:50 +02:00
2007-06-14 16:30:36 +02:00
def abortbuild ( apiurl , project , package = None , arch = None , repo = None ) :
2008-04-02 16:07:40 +02:00
query = { ' cmd ' : ' abortbuild ' }
2007-06-14 16:30:36 +02:00
if package :
2008-04-02 16:07:40 +02:00
query [ ' package ' ] = package
2007-06-14 16:30:36 +02:00
if arch :
2008-04-02 16:07:40 +02:00
query [ ' arch ' ] = arch
2007-06-14 16:30:36 +02:00
if repo :
2008-04-02 16:07:40 +02:00
query [ ' repository ' ] = repo
2007-06-14 16:30:36 +02:00
u = makeurl ( apiurl , [ ' build ' , project ] , query )
try :
f = http_POST ( u )
except urllib2 . HTTPError , e :
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
e . osc_msg = ' abortion failed for project %s ' % project
2007-06-14 16:30:36 +02:00
if package :
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
e . osc_msg + = ' package %s ' % package
2007-06-14 16:30:36 +02:00
if arch :
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
e . osc_msg + = ' arch %s ' % arch
2007-06-14 16:30:36 +02:00
if repo :
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
e . osc_msg + = ' repo %s ' % repo
raise
2007-06-14 16:30:36 +02:00
root = ET . parse ( f ) . getroot ( )
return root . get ( ' code ' )
2007-10-27 21:13:24 +02:00
def wipebinaries ( apiurl , project , package = None , arch = None , repo = None , code = None ) :
2008-04-02 16:07:40 +02:00
query = { ' cmd ' : ' wipe ' }
2007-06-14 16:30:36 +02:00
if package :
2008-04-02 16:07:40 +02:00
query [ ' package ' ] = package
2007-06-14 16:30:36 +02:00
if arch :
2008-04-02 16:07:40 +02:00
query [ ' arch ' ] = arch
2007-06-14 16:30:36 +02:00
if repo :
2008-04-02 16:07:40 +02:00
query [ ' repository ' ] = repo
2007-10-27 21:13:24 +02:00
if code :
2008-04-02 16:07:40 +02:00
query [ ' code ' ] = code
2007-06-14 16:30:36 +02:00
u = makeurl ( apiurl , [ ' build ' , project ] , query )
try :
f = http_POST ( u )
except urllib2 . HTTPError , e :
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
e . osc_msg = ' wipe binary rpms failed for project %s ' % project
2007-06-14 16:30:36 +02:00
if package :
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
e . osc_msg + = ' package %s ' % package
2007-06-14 16:30:36 +02:00
if arch :
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
e . osc_msg + = ' arch %s ' % arch
2007-06-14 16:30:36 +02:00
if repo :
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
e . osc_msg + = ' repository %s ' % repo
2007-10-27 21:13:24 +02:00
if code :
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
e . osc_msg + = ' code= %s ' % code
raise
2007-06-14 16:30:36 +02:00
root = ET . parse ( f ) . getroot ( )
return root . get ( ' code ' )
2007-07-04 14:55:26 +02:00
2007-07-12 01:24:26 +02:00
2007-07-04 14:55:26 +02:00
def parseRevisionOption ( string ) :
"""
2007-07-04 15:48:24 +02:00
returns a tuple which contains the revisions
2007-07-04 14:55:26 +02:00
"""
if string :
if ' : ' in string :
splitted_rev = string . split ( ' : ' )
try :
for i in splitted_rev :
int ( i )
return splitted_rev
except ValueError :
print >> sys . stderr , ' your revision \' %s \' will be ignored ' % string
return None , None
else :
if string . isdigit ( ) :
return string , None
2008-03-22 17:35:22 +01:00
elif string . isalnum ( ) and len ( string ) == 32 :
# could be an md5sum
return string , None
2007-07-04 14:55:26 +02:00
else :
print >> sys . stderr , ' your revision \' %s \' will be ignored ' % string
return None , None
else :
return None , None
2007-07-06 13:54:34 +02:00
2010-05-27 02:18:00 +02:00
def checkRevision ( prj , pac , revision , apiurl = None , meta = False ) :
2007-07-06 13:54:34 +02:00
"""
2009-10-20 16:30:15 +02:00
check if revision is valid revision , i . e . it is not
2008-03-22 17:35:22 +01:00
larger than the upstream revision id
2007-07-06 13:54:34 +02:00
"""
2008-03-22 17:35:22 +01:00
if len ( revision ) == 32 :
# there isn't a way to check this kind of revision for validity
return True
2008-02-18 14:44:20 +01:00
if not apiurl :
apiurl = conf . config [ ' apiurl ' ]
2007-07-06 17:54:10 +02:00
try :
2010-05-27 02:18:00 +02:00
if int ( revision ) > int ( show_upstream_rev ( apiurl , prj , pac , meta ) ) \
2007-07-12 02:48:52 +02:00
or int ( revision ) < = 0 :
2007-07-06 17:54:10 +02:00
return False
else :
return True
2007-07-07 19:13:37 +02:00
except ( ValueError , TypeError ) :
2007-07-06 13:54:34 +02:00
return False
2007-07-15 15:49:13 +02:00
2009-05-15 10:32:48 +02:00
def build_table ( col_num , data = [ ] , headline = [ ] , width = 1 , csv = False ) :
2007-07-15 15:49:13 +02:00
"""
This method builds a simple table .
Example1 : build_table ( 2 , [ ' foo ' , ' bar ' , ' suse ' , ' osc ' ] , [ ' col1 ' , ' col2 ' ] , 2 )
col1 col2
foo bar
suse osc
"""
longest_col = [ ]
for i in range ( col_num ) :
longest_col . append ( 0 )
2009-05-15 10:32:48 +02:00
if headline and not csv :
2007-07-15 15:49:13 +02:00
data [ 0 : 0 ] = headline
# find longest entry in each column
i = 0
for itm in data :
if longest_col [ i ] < len ( itm ) :
longest_col [ i ] = len ( itm )
if i == col_num - 1 :
i = 0
else :
i + = 1
# calculate length for each column
for i , row in enumerate ( longest_col ) :
longest_col [ i ] = row + width
2009-10-20 16:30:15 +02:00
# build rows
2007-07-15 15:49:13 +02:00
row = [ ]
table = [ ]
i = 0
for itm in data :
if i % col_num == 0 :
i = 0
2009-05-15 10:32:48 +02:00
row = [ ]
table . append ( row )
# there is no need to justify the entries of the last column
# or when generating csv
if i == col_num - 1 or csv :
row . append ( itm )
2007-07-15 15:49:13 +02:00
else :
2009-05-15 10:32:48 +02:00
row . append ( itm . ljust ( longest_col [ i ] ) )
2007-07-15 15:49:13 +02:00
i + = 1
2009-05-15 10:32:48 +02:00
if csv :
separator = ' | '
else :
separator = ' '
return [ separator . join ( row ) for row in table ]
2007-07-15 15:49:13 +02:00
2010-03-10 23:36:09 +01:00
def xpath_join ( expr , new_expr , op = ' or ' , inner = False ) :
2007-07-15 15:49:13 +02:00
"""
2010-03-10 23:36:09 +01:00
Join two xpath expressions . If inner is False expr will
be surrounded with parentheses ( unless it ' s not already
surrounded ) .
2007-07-15 15:49:13 +02:00
"""
2010-03-10 23:36:09 +01:00
if not expr :
return new_expr
2010-03-13 13:55:53 +01:00
elif not new_expr :
return expr
2010-03-10 23:36:09 +01:00
# NOTE: this is NO syntax check etc. (e.g. if a literal contains a '(' or ')'
# the check might fail and expr will be surrounded with parentheses or NOT)
parentheses = not inner
if not inner and expr . startswith ( ' ( ' ) and expr . endswith ( ' ) ' ) :
parentheses = False
braces = [ i for i in expr if i == ' ( ' or i == ' ) ' ]
closed = 0
while len ( braces ) :
if braces . pop ( ) == ' ) ' :
closed + = 1
2009-09-03 21:00:09 +02:00
continue
2010-03-10 23:36:09 +01:00
else :
closed + = - 1
while len ( braces ) :
if braces . pop ( ) == ' ( ' :
closed + = - 1
else :
closed + = 1
if closed != 0 :
parentheses = True
break
if parentheses :
expr = ' ( %s ) ' % expr
return ' %s %s %s ' % ( expr , op , new_expr )
2009-08-21 03:26:37 +02:00
2010-03-10 23:36:09 +01:00
def search ( apiurl , * * kwargs ) :
"""
Perform a search request . The requests are constructed as follows :
kwargs = { ' kind1 ' = > xpath1 , ' kind2 ' = > xpath2 , . . . , ' kindN ' = > xpathN }
GET / search / kind1 ? match = xpath1
. . .
GET / search / kindN ? match = xpathN
"""
res = { }
for urlpath , xpath in kwargs . iteritems ( ) :
u = makeurl ( apiurl , [ ' search ' , urlpath ] , [ ' match= %s ' % quote_plus ( xpath ) ] )
f = http_GET ( u )
res [ urlpath ] = ET . parse ( f ) . getroot ( )
return res
2009-04-09 10:21:12 +02:00
2010-09-07 15:03:01 +02:00
def set_link_rev ( apiurl , project , package , revision = None , use_xsrcmd5 = None , use_baserev = None ) :
2009-04-16 10:13:55 +02:00
url = makeurl ( apiurl , [ ' source ' , project , package , ' _link ' ] )
2009-04-09 10:21:12 +02:00
try :
2009-10-20 16:30:15 +02:00
f = http_GET ( url )
root = ET . parse ( f ) . getroot ( )
2009-04-09 10:21:12 +02:00
except urllib2 . HTTPError , e :
2009-10-20 16:30:15 +02:00
e . osc_msg = ' Unable to get _link file in package \' %s \' for project \' %s \' ' % ( package , project )
raise
2009-04-09 10:21:12 +02:00
2009-06-18 11:18:17 +02:00
# set revision element
2010-09-07 12:14:13 +02:00
src_project = root . attrib [ ' project ' ]
src_package = root . attrib [ ' package ' ]
2009-04-09 13:44:32 +02:00
if not revision :
2010-09-07 12:14:13 +02:00
root . attrib [ ' rev ' ] = show_upstream_rev ( apiurl , src_project , src_package )
2009-06-18 11:18:17 +02:00
elif revision == - 1 :
2009-10-20 16:30:15 +02:00
del root . attrib [ ' rev ' ]
2009-06-18 11:18:17 +02:00
else :
2009-10-20 16:30:15 +02:00
root . attrib [ ' rev ' ] = revision
2009-04-09 10:21:12 +02:00
2010-09-07 15:03:01 +02:00
if use_xsrcmd5 :
if use_baserev :
try :
root . attrib [ ' rev ' ] = show_upstream_xsrcmd5 ( apiurl , src_project , src_package , revision = root . attrib [ ' rev ' ] , linkrev = ' base ' )
except oscerr . LinkExpandError , e :
e . osc_msg = ' Unable to merge packages via links from package \' %s \' for project \' %s \' . These revisions have never worked! ' % ( package , project )
raise
else :
try :
root . attrib [ ' rev ' ] = show_upstream_xsrcmd5 ( apiurl , src_project , src_package , revision = root . attrib [ ' rev ' ] )
except oscerr . LinkExpandError , e :
e . osc_msg = ' Unable to merge packages via links from package \' %s \' for project \' %s \' . Please try again using baserev to use source revisions when created the commits. ' % ( package , project )
raise
2010-09-07 12:14:13 +02:00
2009-04-09 10:21:12 +02:00
l = ET . tostring ( root )
# upload _link file again
http_PUT ( url , data = l )
2008-03-10 19:04:23 +01:00
def delete_dir ( dir ) :
2007-07-23 18:03:30 +02:00
# small security checks
2008-03-10 19:04:23 +01:00
if os . path . islink ( dir ) :
2009-10-24 14:47:21 +02:00
raise oscerr . OscIOError ( None , ' cannot remove linked dir ' )
2008-03-10 19:04:23 +01:00
elif os . path . abspath ( dir ) == ' / ' :
2009-10-24 14:47:21 +02:00
raise oscerr . OscIOError ( None , ' cannot remove \' / \' ' )
2007-07-23 18:03:30 +02:00
2008-03-10 19:04:23 +01:00
for dirpath , dirnames , filenames in os . walk ( dir , topdown = False ) :
2010-08-20 14:34:41 +02:00
for filename in filenames :
os . unlink ( os . path . join ( dirpath , filename ) )
2007-07-23 18:03:30 +02:00
for dirname in dirnames :
2009-10-24 14:47:21 +02:00
os . rmdir ( os . path . join ( dirpath , dirname ) )
os . rmdir ( dir )
2007-07-23 18:03:30 +02:00
2008-03-10 19:04:23 +01:00
def delete_storedir ( store_dir ) :
"""
This method deletes a store dir .
"""
head , tail = os . path . split ( store_dir )
if tail == ' .osc ' :
2009-10-24 14:47:21 +02:00
delete_dir ( store_dir )
2008-03-10 19:04:23 +01:00
2007-07-23 18:03:30 +02:00
def unpack_srcrpm ( srpm , dir , * files ) :
"""
This method unpacks the passed srpm into the
passed dir . If arguments are passed to the \' files \' tuple
only this files will be unpacked .
"""
if not is_srcrpm ( srpm ) :
print >> sys . stderr , ' error - \' %s \' is not a source rpm. ' % srpm
sys . exit ( 1 )
curdir = os . getcwd ( )
2010-06-15 17:07:14 +02:00
if os . path . isdir ( dir ) :
2007-07-23 18:03:30 +02:00
os . chdir ( dir )
cmd = ' rpm2cpio %s | cpio -i %s &> /dev/null ' % ( srpm , ' ' . join ( files ) )
2008-10-11 22:26:45 +02:00
ret = subprocess . call ( cmd , shell = True )
2007-07-23 18:03:30 +02:00
if ret != 0 :
print >> sys . stderr , ' error \' %s \' - cannot extract \' %s \' ' % ( ret , srpm )
sys . exit ( 1 )
os . chdir ( curdir )
def is_rpm ( f ) :
""" check if the named file is an RPM package """
2009-10-20 16:30:15 +02:00
try :
2009-05-22 17:00:31 +02:00
h = open ( f , ' rb ' ) . read ( 4 )
2007-07-23 18:03:30 +02:00
except :
return False
if h == ' \xed \xab \xee \xdb ' :
return True
else :
return False
def is_srcrpm ( f ) :
""" check if the named file is a source RPM """
if not is_rpm ( f ) :
return False
try :
2009-05-22 17:00:31 +02:00
h = open ( f , ' rb ' ) . read ( 8 )
2007-07-23 18:03:30 +02:00
except :
return False
if h [ 7 ] == ' \x01 ' :
return True
else :
2009-10-20 16:30:15 +02:00
return False
2007-07-30 13:12:42 +02:00
2007-09-12 20:01:13 +02:00
def addMaintainer ( apiurl , prj , pac , user ) :
2009-06-19 15:57:27 +02:00
# for backward compatibility only
addPerson ( apiurl , prj , pac , user )
def addPerson ( apiurl , prj , pac , user , role = " maintainer " ) :
""" add a new person to a package or project """
2007-09-12 20:01:13 +02:00
path = quote_plus ( prj ) ,
kind = ' prj '
if pac :
path = path + ( quote_plus ( pac ) , )
kind = ' pkg '
data = meta_exists ( metatype = kind ,
path_args = path ,
template_args = None ,
create_new = False )
2009-10-20 16:30:15 +02:00
2007-09-12 20:01:13 +02:00
if data and get_user_meta ( apiurl , user ) != None :
2009-12-26 14:22:34 +01:00
root = ET . fromstring ( ' ' . join ( data ) )
2007-09-12 20:01:13 +02:00
found = False
2009-12-26 14:22:34 +01:00
for person in root . getiterator ( ' person ' ) :
2009-06-19 15:57:27 +02:00
if person . get ( ' userid ' ) == user and person . get ( ' role ' ) == role :
2007-09-12 20:01:13 +02:00
found = True
print " user already exists "
break
if not found :
# the xml has a fixed structure
2009-12-26 14:22:34 +01:00
root . insert ( 2 , ET . Element ( ' person ' , role = role , userid = user ) )
2007-09-12 20:01:13 +02:00
print ' user \' %s \' added to \' %s \' ' % ( user , pac or prj )
edit_meta ( metatype = kind ,
path_args = path ,
2009-12-26 14:22:34 +01:00
data = ET . tostring ( root ) )
2007-09-12 20:01:13 +02:00
else :
print " osc: an error occured "
def delMaintainer ( apiurl , prj , pac , user ) :
2009-08-26 16:22:54 +02:00
# for backward compatibility only
delPerson ( apiurl , prj , pac , user )
def delPerson ( apiurl , prj , pac , user , role = " maintainer " ) :
""" delete a person from a package or project """
2009-10-20 16:30:15 +02:00
path = quote_plus ( prj ) ,
2007-09-12 20:01:13 +02:00
kind = ' prj '
if pac :
path = path + ( quote_plus ( pac ) , )
kind = ' pkg '
data = meta_exists ( metatype = kind ,
path_args = path ,
template_args = None ,
create_new = False )
2010-07-26 16:46:21 +02:00
if data and get_user_meta ( apiurl , user ) != None :
2009-12-26 14:22:34 +01:00
root = ET . fromstring ( ' ' . join ( data ) )
2007-09-12 20:01:13 +02:00
found = False
2009-12-26 14:22:34 +01:00
for person in root . getiterator ( ' person ' ) :
2009-08-26 16:22:54 +02:00
if person . get ( ' userid ' ) == user and person . get ( ' role ' ) == role :
2009-12-26 14:22:34 +01:00
root . remove ( person )
2007-09-12 20:01:13 +02:00
found = True
print " user \' %s \' removed " % user
if found :
edit_meta ( metatype = kind ,
path_args = path ,
2009-12-26 14:22:34 +01:00
data = ET . tostring ( root ) )
2007-09-12 20:01:13 +02:00
else :
print " user \' %s \' not found in \' %s \' " % ( user , pac or prj )
else :
print " an error occured "
2008-03-10 19:04:23 +01:00
2009-06-18 18:20:49 +02:00
def setDevelProject ( apiurl , prj , pac , dprj , dpkg = None ) :
""" set the <devel project= " ... " > element to package metadata """
path = ( quote_plus ( prj ) , ) + ( quote_plus ( pac ) , )
data = meta_exists ( metatype = ' pkg ' ,
2008-05-20 10:29:54 +02:00
path_args = path ,
template_args = None ,
create_new = False )
2009-10-20 16:30:15 +02:00
2008-05-20 10:29:54 +02:00
if data and show_project_meta ( apiurl , dprj ) != None :
2009-12-26 14:22:34 +01:00
root = ET . fromstring ( ' ' . join ( data ) )
if not root . find ( ' devel ' ) != None :
ET . SubElement ( root , ' devel ' )
elem = root . find ( ' devel ' )
2009-06-18 18:20:49 +02:00
if dprj :
2009-10-20 16:30:15 +02:00
elem . attrib [ ' project ' ] = dprj
2009-06-18 18:20:49 +02:00
else :
2009-10-20 16:30:15 +02:00
if elem . attrib . has_key ( ' project ' ) :
del elem . attrib [ ' project ' ]
2009-06-18 18:20:49 +02:00
if dpkg :
2009-10-20 16:30:15 +02:00
elem . attrib [ ' package ' ] = dpkg
2009-06-18 18:20:49 +02:00
else :
2009-10-20 16:30:15 +02:00
if elem . attrib . has_key ( ' package ' ) :
del elem . attrib [ ' package ' ]
2009-06-18 18:20:49 +02:00
edit_meta ( metatype = ' pkg ' ,
2008-05-20 10:29:54 +02:00
path_args = path ,
2009-12-26 14:22:34 +01:00
data = ET . tostring ( root ) )
2008-05-20 10:29:54 +02:00
else :
print " osc: an error occured "
2008-03-15 23:51:37 +01:00
def createPackageDir ( pathname , prj_obj = None ) :
"""
create and initialize a new package dir in the given project .
prj_obj can be a Project ( ) instance .
"""
prj_dir , pac_dir = getPrjPacPaths ( pathname )
if is_project_dir ( prj_dir ) :
if not os . path . exists ( pac_dir ) :
prj = prj_obj or Project ( prj_dir , False )
2009-12-25 00:08:29 +01:00
prj . addPackage ( pac_dir )
2010-08-30 13:46:49 +02:00
Package . init_package ( prj . apiurl , prj . name , pac_dir , pac_dir )
2009-12-25 00:08:29 +01:00
print statfrmt ( ' A ' , os . path . normpath ( pathname ) )
2008-03-18 00:43:32 +01:00
else :
2009-12-25 00:08:29 +01:00
raise oscerr . OscIOError ( None , ' file or directory \' %s \' already exists ' % pathname )
2008-03-15 23:51:37 +01:00
else :
2009-12-25 00:08:29 +01:00
msg = ' \' %s \' is not a working copy ' % prj_dir
2009-08-20 21:28:05 +02:00
if os . path . exists ( os . path . join ( prj_dir , ' .svn ' ) ) :
2009-12-25 00:08:29 +01:00
msg + = ' \n try svn instead of osc. '
raise oscerr . NoWorkingCopy ( msg )
2008-03-15 23:51:37 +01:00
2010-05-14 16:44:42 +02:00
def stripETxml ( node ) :
node . tail = None
if node . text != None :
node . text = node . text . replace ( " " , " " ) . replace ( " \n " , " " )
for child in node . getchildren ( ) :
stripETxml ( child )
2010-09-20 11:09:43 +02:00
def addGitSource ( url ) :
service_file = os . path . join ( os . getcwd ( ) , ' _service ' )
addfile = False
if os . path . exists ( service_file ) :
services = ET . parse ( os . path . join ( os . getcwd ( ) , ' _service ' ) ) . getroot ( )
else :
services = ET . fromstring ( " <services /> " )
addfile = True
stripETxml ( services )
si = Serviceinfo ( )
s = si . addGitUrl ( services , url )
si . read ( s )
# for pretty output
reparsed = minidom . parseString ( ET . tostring ( s ) )
f = open ( service_file , ' wb ' )
f . write ( reparsed . toprettyxml ( indent = " " ) )
f . close ( )
if addfile :
addFiles ( [ ' _service ' ] )
2010-05-14 16:44:42 +02:00
def addDownloadUrlService ( url ) :
service_file = os . path . join ( os . getcwd ( ) , ' _service ' )
2010-05-14 16:51:18 +02:00
addfile = False
2010-05-14 16:44:42 +02:00
if os . path . exists ( service_file ) :
services = ET . parse ( os . path . join ( os . getcwd ( ) , ' _service ' ) ) . getroot ( )
else :
services = ET . fromstring ( " <services /> " )
2010-05-14 16:51:18 +02:00
addfile = True
2010-05-14 16:44:42 +02:00
stripETxml ( services )
si = Serviceinfo ( )
s = si . addDownloadUrl ( services , url )
si . read ( s )
# for pretty output
reparsed = minidom . parseString ( ET . tostring ( s ) )
f = open ( service_file , ' wb ' )
f . write ( reparsed . toprettyxml ( indent = " " ) )
f . close ( )
2010-05-14 16:51:18 +02:00
if addfile :
addFiles ( [ ' _service ' ] )
2010-05-14 16:44:42 +02:00
# download file
2010-05-17 19:24:00 +02:00
path = os . getcwd ( )
files = os . listdir ( path )
si . execute ( path )
newfiles = os . listdir ( path )
# add verify service for new files
2010-08-20 14:34:41 +02:00
for filename in files :
newfiles . remove ( filename )
2010-05-17 19:24:00 +02:00
2010-08-20 14:34:41 +02:00
for filename in newfiles :
if filename . startswith ( ' _service:download_url: ' ) :
s = si . addVerifyFile ( services , filename )
2010-05-17 19:24:00 +02:00
# for pretty output
reparsed = minidom . parseString ( ET . tostring ( s ) )
f = open ( service_file , ' wb ' )
f . write ( reparsed . toprettyxml ( indent = " " ) )
f . close ( )
2010-05-14 16:44:42 +02:00
2008-08-20 21:24:55 +02:00
def addFiles ( filenames , prj_obj = None ) :
2008-03-10 19:04:23 +01:00
for filename in filenames :
if not os . path . exists ( filename ) :
2009-12-25 00:08:29 +01:00
raise oscerr . OscIOError ( None , ' file \' %s \' does not exist ' % filename )
2008-03-10 19:04:23 +01:00
# init a package dir if we have a normal dir in the "filenames"-list
# so that it will be find by findpacs() later
2010-02-17 20:45:09 +01:00
pacs = list ( filenames )
2008-03-10 19:04:23 +01:00
for filename in filenames :
prj_dir , pac_dir = getPrjPacPaths ( filename )
if not is_package_dir ( filename ) and os . path . isdir ( filename ) and is_project_dir ( prj_dir ) \
and conf . config [ ' do_package_tracking ' ] :
prj_name = store_read_project ( prj_dir )
2010-09-19 23:00:19 +02:00
prj_apiurl = store_read_apiurl ( prj_dir , defaulturl = False )
2010-09-06 17:50:56 +02:00
Package . init_package ( prj_apiurl , prj_name , pac_dir , filename )
2008-03-10 19:04:23 +01:00
elif is_package_dir ( filename ) and conf . config [ ' do_package_tracking ' ] :
2009-12-25 00:08:29 +01:00
raise oscerr . PackageExists ( store_read_project ( filename ) , store_read_package ( filename ) ,
' osc: warning: \' %s \' is already under version control ' % filename )
2009-03-16 22:29:42 +01:00
elif os . path . isdir ( filename ) and is_project_dir ( prj_dir ) :
2009-12-25 00:08:29 +01:00
raise oscerr . WrongArgs ( ' osc: cannot add a directory to a project unless ' \
' \' do_package_tracking \' is enabled in the configuration file ' )
2010-02-17 20:45:09 +01:00
elif os . path . isdir ( filename ) :
print ' skipping directory \' %s \' ' % filename
pacs . remove ( filename )
pacs = findpacs ( pacs )
2008-03-10 19:04:23 +01:00
for pac in pacs :
if conf . config [ ' do_package_tracking ' ] and not pac . todo :
2009-12-24 21:30:02 +01:00
prj = prj_obj or Project ( os . path . dirname ( pac . absdir ) , False )
2008-03-10 19:04:23 +01:00
if pac . name in prj . pacs_unvers :
2009-12-25 00:08:29 +01:00
prj . addPackage ( pac . name )
2008-03-10 19:04:23 +01:00
print statfrmt ( ' A ' , getTransActPath ( os . path . join ( pac . dir , os . pardir , pac . name ) ) )
for filename in pac . filenamelist_unvers :
2010-02-17 20:45:09 +01:00
if os . path . isdir ( os . path . join ( pac . dir , filename ) ) :
print ' skipping directory \' %s \' ' % os . path . join ( pac . dir , filename )
else :
pac . todo . append ( filename )
2008-03-10 19:04:23 +01:00
elif pac . name in prj . pacs_have :
print ' osc: warning: \' %s \' is already under version control ' % pac . name
for filename in pac . todo :
2010-04-22 15:27:54 +02:00
if filename in pac . skipped :
continue
2008-03-10 19:04:23 +01:00
if filename in pac . excluded :
2008-06-25 19:37:05 +02:00
print >> sys . stderr , ' osc: warning: \' %s \' is excluded from a working copy ' % filename
2008-03-10 19:04:23 +01:00
continue
pac . addfile ( filename )
def getPrjPacPaths ( path ) :
"""
returns the path for a project and a package
from path . This is needed if you try to add
or delete packages :
Examples :
osc add pac1 / : prj_dir = CWD ;
pac_dir = pac1
osc add / path / to / pac1 :
prj_dir = path / to ;
pac_dir = pac1
osc add / path / to / pac1 / file
= > this would be an invalid path
the caller has to validate the returned
path !
"""
# make sure we hddave a dir: osc add bar vs. osc add bar/; osc add /path/to/prj_dir/new_pack
# filename = os.path.join(tail, '')
prj_dir , pac_dir = os . path . split ( os . path . normpath ( path ) )
if prj_dir == ' ' :
prj_dir = os . getcwd ( )
return ( prj_dir , pac_dir )
def getTransActPath ( pac_dir ) :
"""
returns the path for the commit and update operations / transactions .
Normally the " dir " attribute of a Package ( ) object will be passed to
this method .
"""
if pac_dir != ' . ' :
pathn = os . path . normpath ( pac_dir )
else :
pathn = ' '
return pathn
2008-04-23 23:51:24 +02:00
2009-04-16 15:48:37 +02:00
def get_commit_message_template ( pac ) :
"""
Read the difference in . changes file ( s ) and put them as a template to commit message .
"""
2010-08-31 16:13:16 +02:00
diff = [ ]
2009-04-16 15:48:37 +02:00
template = [ ]
2010-05-09 21:06:00 +02:00
files = [ i for i in pac . todo if i . endswith ( ' .changes ' ) and pac . status ( i ) in ( ' A ' , ' M ' ) ]
2010-08-20 14:34:41 +02:00
for filename in files :
if pac . status ( filename ) == ' M ' :
diff + = get_source_file_diff ( pac . absdir , filename , pac . rev )
elif pac . status ( filename ) == ' A ' :
f = open ( filename , ' r ' )
2010-05-09 21:06:00 +02:00
for line in f :
diff + = ' + ' + line
f . close ( )
2009-10-20 16:30:15 +02:00
2009-04-16 15:48:37 +02:00
if diff :
2010-08-31 16:13:16 +02:00
template = parse_diff_for_commit_message ( ' ' . join ( diff ) )
2009-04-16 15:48:37 +02:00
2010-02-02 14:12:22 +01:00
return template
def parse_diff_for_commit_message ( diff , template = [ ] ) :
date_re = re . compile ( r ' \ +(Mon|Tue|Wed|Thu|Fri|Sat|Sun) ([A-Z][a-z] {2} ) ( ?[0-9]|[0-3][0-9]) .* ' )
diff = diff . split ( ' \n ' )
# The first four lines contains a header of diff
for line in diff [ 3 : ] :
# this condition is magical, but it removes all unwanted lines from commit message
if not ( line ) or ( line and line [ 0 ] != ' + ' ) or \
date_re . match ( line ) or \
line == ' + ' or line [ 0 : 3 ] == ' +++ ' :
continue
if line == ' +------------------------------------------------------------------- ' :
template . append ( ' ' )
else :
template . append ( line [ 1 : ] )
2009-10-20 16:30:15 +02:00
2009-04-16 15:48:37 +02:00
return template
2009-08-03 15:03:24 +02:00
2010-12-26 13:33:14 +01:00
def get_commit_msg ( wc_dir , pacs ) :
template = store_read_file ( wc_dir , ' _commit_msg ' )
# open editor for commit message
# but first, produce status and diff to append to the template
footer = [ ]
lines = [ ]
for p in pacs :
states = sorted ( p . get_status ( False , ' ' , ' ? ' ) , lambda x , y : cmp ( x [ 1 ] , y [ 1 ] ) )
changed = [ statfrmt ( st , os . path . normpath ( os . path . join ( p . dir , filename ) ) ) for st , filename in states ]
if changed :
footer + = changed
footer . append ( ' \n Diff for working copy: %s ' % p . dir )
footer . extend ( [ ' ' . join ( i ) for i in p . get_diff ( ignoreUnversioned = True ) ] )
lines . extend ( get_commit_message_template ( p ) )
if template is None :
template = ' \n ' . join ( lines )
msg = ' '
# if footer is empty, there is nothing to commit, and no edit needed.
if footer :
msg = edit_message ( footer = ' \n ' . join ( footer ) , template = template )
if msg :
store_write_string ( wc_dir , ' _commit_msg ' , msg + ' \n ' )
else :
store_unlink_file ( wc_dir , ' _commit_msg ' )
return msg
2009-08-03 15:03:24 +02:00
def check_filelist_before_commit ( pacs ) :
# warn if any of files has a ? status (usually a patch, or new source was not added to meta)
for p in pacs :
# no files given as argument? Take all files in current dir
if not p . todo :
p . todo = p . filenamelist + p . filenamelist_unvers
p . todo . sort ( )
2010-03-21 23:40:13 +01:00
for f in [ f for f in p . todo if not os . path . isdir ( f ) ] :
2010-02-05 11:49:57 +01:00
if not f . startswith ( ' _service: ' ) and not f . startswith ( ' _service_ ' ) and p . status ( f ) in ( ' ? ' , ' ! ' ) :
2010-05-25 18:31:50 +02:00
print ' File " %s " is listed in package meta but does not exist. ' % f
resp = raw_input ( ' (s)kip/(r)emove/(e)dit file lists/(c)ommit/(A)bort? ' )
2009-08-03 15:03:24 +02:00
if resp in ( ' s ' , ' S ' ) :
continue
elif resp in ( ' r ' , ' R ' ) :
2010-05-25 18:31:50 +02:00
p . process_filelist ( [ ' r ? %s ' % f ] )
2009-08-03 15:03:24 +02:00
elif resp in ( ' e ' , ' E ' ) :
try :
p . edit_filelist ( )
except ValueError :
print >> sys . stderr , " Error during processiong of file list. "
raise oscerr . UserAbort ( )
elif resp in ( ' c ' , ' C ' ) :
break
else :
raise oscerr . UserAbort ( )
2009-09-18 03:10:41 +02:00
def print_request_list ( apiurl , project , package = None , states = ( ' new ' , ) , force = False ) :
"""
prints list of pending requests for the specified project / package if " check_for_request_on_action "
is enabled in the config or if " force " is set to True
"""
if not conf . config [ ' check_for_request_on_action ' ] and not force :
return
requests = get_request_list ( apiurl , project , package , req_state = states )
msg = ' Pending requests for %s : %s ( %s ) '
if package is None and len ( requests ) :
print msg % ( ' project ' , project , len ( requests ) )
elif len ( requests ) :
2009-09-23 01:31:10 +02:00
print msg % ( ' package ' , ' / ' . join ( [ project , package ] ) , len ( requests ) )
2009-09-18 03:10:41 +02:00
for r in requests :
2010-12-30 03:10:27 +01:00
print r . list_view ( ) , ' \n '
2010-02-11 01:47:47 +01:00
def request_interactive_review ( apiurl , request ) :
""" review the request interactively """
2010-07-26 16:46:21 +02:00
import tempfile , re
2010-02-11 01:47:47 +01:00
tmpfile = None
2010-06-29 14:32:22 +02:00
2010-08-31 14:15:04 +02:00
def print_request ( request ) :
try :
# FIXME: print can fail with unicode chars in the string.
# Here we fix the symptoms, not the cause.
# UnicodeEncodeError: 'ascii' codec can't encode character u'\u2002' in position 309: ordinal not in range(128)
print request
except :
print request . __str__ ( ) . encode ( ' ascii ' , ' xmlcharrefreplace ' )
print_request ( request )
2010-02-11 01:47:47 +01:00
try :
2010-10-26 15:47:07 +02:00
msg = ' (a)ccept/(d)ecline/(r)evoke/(b)uildstatus/c(l)one/(s)kip/(c)ancel > '
2010-04-20 15:29:18 +02:00
if request . actions [ 0 ] . type == ' submit ' :
msg = ' d(i)ff/ %s ' % msg
2010-02-11 01:47:47 +01:00
while True :
2010-08-16 13:53:52 +02:00
repl = raw_input ( msg ) . strip ( )
2010-04-20 15:29:18 +02:00
if repl == ' i ' and request . actions [ 0 ] . type == ' submit ' :
2010-02-11 01:47:47 +01:00
if tmpfile is None :
tmpfile = tempfile . NamedTemporaryFile ( )
2010-04-26 17:57:57 +02:00
# backward compatiblity: only a recent api/backend supports the missingok parameter
try :
2010-12-30 03:04:10 +01:00
diff = server_diff ( apiurl , request . actions [ 0 ] . tgt_project , request . actions [ 0 ] . tgt_package , None ,
2010-04-26 17:57:57 +02:00
request . actions [ 0 ] . src_project , request . actions [ 0 ] . src_package , request . actions [ 0 ] . src_rev , True , True )
except urllib2 . HTTPError , e :
2010-08-27 12:44:10 +02:00
if e . code == 400 :
try :
2010-12-30 03:04:10 +01:00
diff = server_diff ( apiurl , request . actions [ 0 ] . tgt_project , request . actions [ 0 ] . tgt_package , None ,
2010-08-27 12:44:10 +02:00
request . actions [ 0 ] . src_project , request . actions [ 0 ] . src_package , request . actions [ 0 ] . src_rev , True , False )
except urllib2 . HTTPError , e :
tmpfile . close ( )
tmpfile = None
if e . code != 404 :
raise e
root = ET . fromstring ( e . read ( ) )
print >> sys . stderr , root . find ( ' summary ' ) . text
continue
elif e . code == 404 :
tmpfile . close ( )
tmpfile = None
root = ET . fromstring ( e . read ( ) )
print >> sys . stderr , root . find ( ' summary ' ) . text
continue
else :
2010-04-26 17:57:57 +02:00
raise e
tmpfile . write ( diff )
2010-02-15 23:56:21 +01:00
tmpfile . flush ( )
2010-06-09 14:28:03 +02:00
run_editor ( tmpfile . name )
2010-08-31 14:15:04 +02:00
print_request ( request )
2010-09-17 23:03:29 +02:00
elif repl == ' s ' :
2010-12-30 13:28:11 +01:00
print >> sys . stderr , ' skipping: # %s ' % request . reqid
2010-09-17 23:03:29 +02:00
break
2010-02-11 01:47:47 +01:00
elif repl == ' c ' :
print >> sys . stderr , ' Aborting '
2010-04-20 15:22:03 +02:00
raise oscerr . UserAbort ( )
2010-09-14 16:02:21 +02:00
elif repl == ' b ' :
print ' \n ' . join ( get_results ( apiurl , request . actions [ 0 ] . src_project , request . actions [ 0 ] . src_package ) )
2010-02-11 01:47:47 +01:00
else :
2010-02-19 13:46:29 +01:00
state_map = { ' a ' : ' accepted ' , ' d ' : ' declined ' , ' r ' : ' revoked ' }
2010-10-26 15:47:07 +02:00
mo = re . search ( ' ^([adrl])(?: \ s+-m \ s+(.*))?$ ' , repl )
2010-02-11 01:47:47 +01:00
if mo is None :
2010-02-25 14:32:24 +01:00
print >> sys . stderr , ' invalid choice: \' %s \' ' % repl
continue
2010-10-26 15:47:07 +02:00
state = state_map . get ( mo . group ( 1 ) )
2010-02-11 01:47:47 +01:00
msg = mo . group ( 2 )
2010-10-26 15:47:07 +02:00
footer = ' '
if not state is None :
footer = ' changing request from state \' %s \' to \' %s \' \n \n ' \
% ( request . state . name , state )
2010-08-19 11:40:49 +02:00
footer + = str ( request )
2010-02-11 01:47:47 +01:00
if tmpfile is not None :
tmpfile . seek ( 0 )
# the read bytes probably have a moderate size so the str won't be too large
footer + = ' \n \n ' + tmpfile . read ( )
if msg is None :
2010-11-14 18:32:02 +01:00
tmpl = ' '
if not state is None :
tmpl = change_request_state_template ( request , state )
msg = edit_message ( footer = footer , template = tmpl )
2010-02-11 01:47:47 +01:00
else :
msg = msg . strip ( ' \' ' ) . strip ( ' " ' )
2010-10-26 15:47:07 +02:00
if state is None :
2010-12-30 13:28:11 +01:00
clone_request ( apiurl , request . reqid , msg )
2010-10-26 15:47:07 +02:00
else :
2010-12-30 13:28:11 +01:00
change_request_state ( apiurl , request . reqid , state , msg )
2010-02-11 02:48:08 +01:00
break
2010-02-11 01:47:47 +01:00
finally :
if tmpfile is not None :
tmpfile . close ( )
2010-02-25 09:52:47 +01:00
2010-09-29 19:57:00 +02:00
def get_user_projpkgs ( apiurl , user , role = None , exclude_projects = [ ] , proj = True , pkg = True , maintained = False , metadata = False ) :
2010-03-13 21:06:18 +01:00
""" Return all project/packages where user is involved. """
xpath = ' person/@userid = \' %s \' ' % user
excl_prj = ' '
excl_pkg = ' '
for i in exclude_projects :
excl_prj = xpath_join ( excl_prj , ' not(@name = \' %s \' ) ' % i , op = ' and ' )
excl_pkg = xpath_join ( excl_pkg , ' not(@project = \' %s \' ) ' % i , op = ' and ' )
role_filter_xpath = xpath
if role :
xpath = xpath_join ( xpath , ' person/@role = \' %s \' ' % role , inner = True , op = ' and ' )
xpath_pkg = xpath_join ( xpath , excl_pkg , op = ' and ' )
xpath_prj = xpath_join ( xpath , excl_prj , op = ' and ' )
2010-07-07 16:25:09 +02:00
if maintained :
xpath_pkg = xpath_join ( xpath_pkg , ' (project/attribute/@name= \' %(attr)s \' or attribute/@name= \' %(attr)s \' ) ' % { ' attr ' : conf . config [ ' maintained_attribute ' ] } , op = ' and ' )
2010-03-13 21:06:18 +01:00
what = { }
if pkg :
2010-09-29 19:57:00 +02:00
if metadata :
what [ ' package ' ] = xpath_pkg
else :
what [ ' package_id ' ] = xpath_pkg
2010-03-13 21:06:18 +01:00
if proj :
2010-09-29 19:57:00 +02:00
if metadata :
what [ ' project ' ] = xpath_prj
else :
what [ ' project_id ' ] = xpath_prj
2010-03-13 21:06:18 +01:00
try :
res = search ( apiurl , * * what )
except urllib2 . HTTPError , e :
2010-05-26 16:46:01 +02:00
if e . code != 400 or not role_filter_xpath :
2010-03-13 21:06:18 +01:00
raise e
# backward compatibility: local role filtering
what = dict ( [ [ kind , role_filter_xpath ] for kind in what . keys ( ) ] )
if what . has_key ( ' package ' ) :
what [ ' package ' ] = xpath_join ( role_filter_xpath , excl_pkg , op = ' and ' )
if what . has_key ( ' project ' ) :
what [ ' project ' ] = xpath_join ( role_filter_xpath , excl_prj , op = ' and ' )
res = search ( apiurl , * * what )
filter_role ( res , user , role )
return res
2010-12-22 00:01:46 +01:00
def raw_input ( * args ) :
import __builtin__
try :
2010-12-22 17:30:06 +01:00
return __builtin__ . raw_input ( * args )
2010-12-22 00:01:46 +01:00
except EOFError :
# interpret ctrl-d as user abort
raise oscerr . UserAbort ( )
2010-03-13 13:55:53 +01:00
# backward compatibility: local role filtering
def filter_role ( meta , user , role ) :
"""
remove all project / package nodes if no person node exists
where @userid = user and @role = role
"""
for kind , root in meta . iteritems ( ) :
delete = [ ]
for node in root . findall ( kind ) :
found = False
for p in node . findall ( ' person ' ) :
if p . get ( ' userid ' ) == user and p . get ( ' role ' ) == role :
found = True
break
if not found :
delete . append ( node )
for node in delete :
root . remove ( node )
2010-02-25 09:52:47 +01:00
# vim: sw=4 et