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
2022-06-08 07:06:45 +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
2022-07-28 12:28:33 +02:00
2022-09-09 11:46:28 +02:00
import codecs
2023-04-28 14:38:43 +02:00
import copy
2022-09-09 11:46:28 +02:00
import datetime
import difflib
2022-07-28 12:28:33 +02:00
import errno
2022-09-09 11:46:28 +02:00
import fnmatch
import glob
2022-07-28 12:28:33 +02:00
import hashlib
2011-10-18 03:03:42 +02:00
import locale
2006-04-20 16:26:50 +02:00
import os
2022-07-28 12:28:33 +02:00
import platform
2013-04-09 14:03:17 +02:00
import re
2013-08-03 17:20:03 +02:00
import shlex
2022-07-28 12:28:33 +02:00
import shutil
import subprocess
import sys
2022-09-09 11:46:28 +02:00
import tempfile
import textwrap
2022-09-05 15:33:00 +02:00
import time
2022-09-12 17:16:52 +02:00
from functools import cmp_to_key , total_ordering
2022-07-28 12:28:33 +02:00
from http . client import IncompleteRead
from io import StringIO
2023-02-08 11:46:16 +01:00
from pathlib import Path
2022-12-07 13:01:23 +01:00
from typing import Optional , Dict , Union , List , Iterable
2022-02-03 11:11:40 +01:00
from urllib . parse import urlsplit , urlunsplit , urlparse , quote_plus , urlencode , unquote
from urllib . error import HTTPError
from urllib . request import pathname2url
2022-07-28 12:28:33 +02:00
from xml . etree import ElementTree as ET
2013-04-09 14:03:17 +02:00
2007-03-13 00:17:34 +01:00
try :
2022-07-28 12:28:33 +02:00
import distro
2007-03-13 00:17:34 +01:00
except ImportError :
2022-07-28 12:28:33 +02:00
distro = None
2007-03-13 00:17:34 +01:00
2022-08-24 09:53:26 +02:00
from . import __version__
2022-11-07 10:36:03 +01:00
from . import _private
2013-04-09 12:36:42 +02:00
from . import conf
2022-09-09 11:46:28 +02:00
from . import meter
2022-07-28 12:28:33 +02:00
from . import oscerr
2022-02-03 11:11:40 +01:00
from . connection import http_request , http_GET , http_POST , http_PUT , http_DELETE
2022-10-24 16:39:45 +02:00
from . store import Store
2022-07-29 22:00:41 +02:00
from . util . helper import decode_list , decode_it , raw_input , _html_escape
2013-04-09 12:36:42 +02:00
2018-12-13 15:14:06 +01:00
2022-07-28 12:28:33 +02:00
ET_ENCODING = " unicode "
2013-04-09 13:27:24 +02:00
2022-09-12 13:43:10 +02:00
2018-12-13 15:14:06 +01:00
def compare ( a , b ) : return cmp ( a [ 1 : ] , b [ 1 : ] )
2022-09-12 13:43:10 +02:00
2018-12-13 15:14:06 +01:00
def cmp ( a , b ) :
return ( a > b ) - ( a < b )
2022-09-12 13:43:10 +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$ " )
2022-09-12 13:43:10 +02:00
BUFSIZE = 1024 * 1024
2006-04-20 16:26:50 +02:00
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 - - >
2011-07-20 19:34:46 +02:00
< description > < / description >
2010-01-22 08:57:47 +01:00
< ! - - This is for a longer description of the purpose of the project - - >
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 >
2015-05-05 22:46:26 +02:00
< enable / >
2007-07-04 14:59:18 +02:00
< / 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 " >
2012-02-20 13:51:33 +01:00
< path project = " openSUSE:Factory " repository = " snapshot " / >
2006-06-23 12:35:20 +02:00
< arch > x86_64 < / arch >
< arch > i586 < / arch >
< / repository >
2015-05-05 22:46:26 +02:00
< repository name = " openSUSE_13.2 " >
< path project = " openSUSE:13.2 " repository = " standard " / >
2009-10-16 17:55:29 +02:00
< arch > x86_64 < / arch >
< arch > i586 < / arch >
< / repository >
2015-05-05 22:46:26 +02:00
< repository name = " openSUSE_13.1 " >
< path project = " openSUSE:13.1 " repository = " standard " / >
2007-07-04 14:59:18 +02:00
< arch > x86_64 < / arch >
< arch > i586 < / arch >
< / repository >
2015-05-05 22:46:26 +02:00
< repository name = " Fedora_21 " >
< path project = " Fedora:21 " repository = " standard " / >
2009-04-09 10:21:12 +02:00
< arch > x86_64 < / arch >
< arch > i586 < / arch >
< / repository >
2015-05-05 22:46:26 +02:00
< repository name = " SLE_12 " >
< path project = " SUSE:SLE-12:GA " 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
2011-07-20 19:34:46 +02:00
< description > < / description > < ! - - for long description - - >
2006-06-23 12:35:20 +02:00
2011-03-29 12:16:56 +02:00
< ! - - following roles are inherited from the parent project
2008-03-07 10:13:30 +01:00
< person role = " maintainer " userid = " %(user)s " / >
< person role = " bugowner " userid = " %(user)s " / >
2011-03-29 12:16:56 +02:00
- - >
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
2017-08-18 14:57:47 +02:00
new_group_template = """ \
< group >
< title > % ( group ) s < / title >
< person >
< person userid = " " / >
< / person >
< / group >
"""
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 = """ \
2012-04-02 10:51:57 +02:00
< ! - - See https : / / github . com / openSUSE / libzypp / tree / master / zypp / parser / yum / schema / patterns . rng - - >
2007-07-19 12:08:42 +02:00
2012-04-02 10:51:57 +02:00
< ! - -
< pattern xmlns = " http://novell.com/package/metadata/suse/pattern "
xmlns : rpm = " http://linux.duke.edu/metadata/rpm " >
< name > < / name >
< summary > < / summary >
< description > < / description >
< uservisible / >
< category lang = " en " > < / category >
2012-04-02 10:55:18 +02:00
< rpm : requires >
< rpm : entry name = " must-have-package " / >
< / rpm : requires >
2012-04-02 10:51:57 +02:00
< rpm : recommends >
< rpm : entry name = " package " / >
< / rpm : recommends >
< rpm : suggests >
< rpm : entry name = " anotherpackage " / >
< / rpm : suggests >
2007-07-19 12:08:42 +02:00
< / pattern >
2012-04-02 10:51:57 +02:00
- - >
2007-07-19 12:08:42 +02:00
"""
2022-09-12 13:43:10 +02:00
buildstatus_symbols = { ' succeeded ' : ' . ' ,
' disabled ' : ' ' ,
2010-05-22 08:22:12 +02:00
' expansion error ' : ' U ' , # obsolete with OBS 2.0
2022-09-12 13:43:10 +02:00
' unresolvable ' : ' U ' ,
' failed ' : ' F ' ,
' broken ' : ' B ' ,
' blocked ' : ' b ' ,
' building ' : ' % ' ,
' finished ' : ' f ' ,
' scheduled ' : ' s ' ,
' locked ' : ' L ' ,
' excluded ' : ' x ' ,
' dispatching ' : ' d ' ,
' signing ' : ' S ' ,
}
2006-09-25 17:11:03 +02:00
2010-05-14 16:44:42 +02:00
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 )
2018-12-17 17:13:38 +01:00
except AttributeError :
2009-10-20 16:30:15 +02:00
return os . path . realpath ( path1 ) == os . path . realpath ( path2 )
2006-09-25 17:11:03 +02:00
2022-09-12 13:43:10 +02:00
2022-10-24 16:30:45 +02:00
@total_ordering
2006-05-19 22:13:29 +02:00
class File :
""" represent a file, including its metadata """
2022-09-12 13:43:10 +02:00
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
2022-09-12 13:43:10 +02:00
2010-08-19 18:10:32 +02:00
def __repr__ ( self ) :
return self . name
2022-09-12 13:43:10 +02:00
2006-05-19 22:13:29 +02:00
def __str__ ( self ) :
return self . name
2022-10-24 16:30:45 +02:00
def __eq__ ( self , other ) :
2022-10-24 17:01:55 +02:00
if isinstance ( other , str ) :
return self . name == other
2022-10-24 16:30:45 +02:00
self_data = ( self . name , self . md5 , self . size , self . mtime , self . skipped )
other_data = ( other . name , other . md5 , other . size , other . mtime , other . skipped )
return self_data == other_data
def __lt__ ( self , other ) :
self_data = ( self . name , self . md5 , self . size , self . mtime , self . skipped )
other_data = ( other . name , other . md5 , other . size , other . mtime , other . skipped )
return self_data < other_data
2022-10-12 14:01:38 +02:00
@classmethod
def from_xml_node ( cls , node ) :
assert node . tag == " entry "
kwargs = {
" name " : node . get ( " name " ) ,
" md5 " : node . get ( " md5 " ) ,
" size " : int ( node . get ( " size " ) ) ,
" mtime " : int ( node . get ( " mtime " ) ) ,
2022-10-24 16:28:30 +02:00
" skipped " : " skipped " in node . attrib ,
2022-10-12 14:01:38 +02:00
}
return cls ( * * kwargs )
2022-10-24 16:29:53 +02:00
def to_xml_node ( self , parent_node ) :
attributes = {
" name " : self . name ,
" md5 " : self . md5 ,
" size " : str ( int ( self . size ) ) ,
" mtime " : str ( int ( self . mtime ) ) ,
}
if self . skipped :
attributes [ " skipped " ] = " true "
new_node = ET . SubElement ( parent_node , " entry " , attributes )
return new_node
2006-05-19 22:13:29 +02:00
2009-09-03 16:56:48 +02:00
class Serviceinfo :
""" Source service content
"""
2022-09-12 13:43:10 +02:00
2009-09-03 16:56:48 +02:00
def __init__ ( self ) :
""" creates an empty serviceinfo instance """
2016-03-04 10:22:21 +01:00
self . services = [ ]
2022-10-21 10:38:57 +02:00
self . apiurl : Optional [ str ] = None
self . project : Optional [ str ] = None
self . package : Optional [ str ] = None
2009-09-03 16:56:48 +02:00
2011-01-26 17:22:03 +01:00
def read ( self , serviceinfo_node , append = False ) :
2022-01-24 08:57:53 +01:00
""" read in the source services ``<services>`` element passed as
2009-09-03 16:56:48 +02:00
elementtree node .
"""
2016-03-04 10:22:21 +01:00
def error ( msg , xml ) :
data = ' invalid service format: \n %s ' % ET . tostring ( xml , encoding = ET_ENCODING )
raise ValueError ( " %s \n \n %s " % ( data , msg ) )
if serviceinfo_node is None :
2009-09-03 16:56:48 +02:00
return
2016-03-04 10:22:21 +01:00
if not append :
2011-01-26 17:22:03 +01:00
self . services = [ ]
2009-09-03 16:56:48 +02:00
services = serviceinfo_node . findall ( ' service ' )
for service in services :
name = service . get ( ' name ' )
2017-12-08 13:20:24 +01:00
if name is None :
error ( " invalid service definition. Attribute name missing. " , service )
2014-10-16 21:47:11 +02:00
if len ( name ) < 3 or ' / ' in name :
2016-03-04 10:22:21 +01:00
error ( " invalid service name: %s " % name , service )
mode = service . get ( ' mode ' , ' ' )
2022-04-20 19:22:35 +02:00
data = { ' name ' : name , ' mode ' : mode }
2022-09-12 13:43:10 +02:00
command = [ name ]
2016-03-04 10:22:21 +01:00
for param in service . findall ( ' param ' ) :
option = param . get ( ' name ' )
if option is None :
error ( " %s : a parameter requires a name " % name , service )
value = ' '
if param . text :
value = param . text
command . append ( ' -- ' + option )
# hmm is this reasonable or do we want to allow real
# options (e.g., "--force" (without an argument)) as well?
command . append ( value )
data [ ' command ' ] = command
self . services . append ( data )
2009-09-03 16:56:48 +02:00
2022-10-21 10:38:57 +02:00
def getProjectGlobalServices ( self , apiurl : str , project : str , package : str ) :
2016-10-01 23:50:33 +02:00
self . apiurl = apiurl
2011-02-15 18:39:06 +01:00
# get all project wide services in one file, we don't store it yet
u = makeurl ( apiurl , [ ' source ' , project , package ] , query = ' cmd=getprojectservices ' )
2011-01-26 17:42:17 +01:00
try :
2011-02-15 18:39:06 +01:00
f = http_POST ( u )
2011-01-26 17:42:17 +01:00
root = ET . parse ( f ) . getroot ( )
2011-01-26 18:07:42 +01:00
self . read ( root , True )
2011-08-23 16:03:58 +02:00
self . project = project
self . package = package
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2017-03-10 11:08:31 +01:00
if e . code == 404 and package != ' _project ' :
self . getProjectGlobalServices ( apiurl , project , ' _project ' )
self . package = package
elif e . code != 403 and e . code != 400 :
2011-01-26 17:42:17 +01:00
raise e
2011-01-26 17:22:03 +01:00
2022-10-21 10:38:57 +02:00
def addVerifyFile ( self , serviceinfo_node , filename : str ) :
2018-12-13 15:14:06 +01:00
f = open ( filename , ' rb ' )
2010-05-17 19:24:00 +02:00
digest = hashlib . sha256 ( f . read ( ) ) . hexdigest ( )
f . close ( )
r = serviceinfo_node
2022-09-12 13:43:10 +02:00
s = ET . Element ( " service " , name = " verify_file " )
2010-05-17 19:24:00 +02:00
ET . SubElement ( s , " param " , name = " file " ) . text = filename
2022-04-20 19:22:35 +02:00
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
2022-09-12 13:43:10 +02:00
r . append ( s )
2010-05-17 19:24:00 +02:00
return r
2022-10-21 10:38:57 +02:00
def addDownloadUrl ( self , serviceinfo_node , url_string : str ) :
2022-09-12 13:43:10 +02:00
url = urlparse ( url_string )
2010-05-14 16:44:42 +02:00
protocol = url . scheme
host = url . netloc
path = url . path
r = serviceinfo_node
2022-09-12 13:43:10 +02:00
s = ET . Element ( " service " , name = " download_url " )
2010-05-14 16:44:42 +02:00
ET . SubElement ( s , " param " , name = " protocol " ) . text = protocol
2022-04-20 19:22:35 +02:00
ET . SubElement ( s , " param " , name = " host " ) . text = host
ET . SubElement ( s , " param " , name = " path " ) . text = path
2010-05-14 16:44:42 +02:00
2022-04-20 19:22:35 +02:00
r . append ( s )
2010-05-14 16:44:42 +02:00
return r
2014-07-22 09:31:54 +02:00
def addSetVersion ( self , serviceinfo_node ) :
r = serviceinfo_node
2022-09-12 13:43:10 +02:00
s = ET . Element ( " service " , name = " set_version " , mode = " buildtime " )
r . append ( s )
2014-07-22 09:31:54 +02:00
return r
2022-10-21 10:38:57 +02:00
def addGitUrl ( self , serviceinfo_node , url_string : Optional [ str ] ) :
2010-09-20 11:09:43 +02:00
r = serviceinfo_node
2022-09-12 13:43:10 +02:00
s = ET . Element ( " service " , name = " obs_scm " )
2010-09-20 11:09:43 +02:00
ET . SubElement ( s , " param " , name = " url " ) . text = url_string
2011-01-26 17:29:43 +01:00
ET . SubElement ( s , " param " , name = " scm " ) . text = " git "
2022-09-12 13:43:10 +02:00
r . append ( s )
2011-01-26 17:29:43 +01:00
return r
2016-04-08 09:07:38 +02:00
def addTarUp ( self , serviceinfo_node ) :
r = serviceinfo_node
2022-09-12 13:43:10 +02:00
s = ET . Element ( " service " , name = " tar " , mode = " buildtime " )
r . append ( s )
2016-04-08 09:07:38 +02:00
return r
2011-01-26 17:29:43 +01:00
def addRecompressTar ( self , serviceinfo_node ) :
r = serviceinfo_node
2022-09-12 13:43:10 +02:00
s = ET . Element ( " service " , name = " recompress " , mode = " buildtime " )
2011-01-26 17:29:43 +01:00
ET . SubElement ( s , " param " , name = " file " ) . text = " *.tar "
2014-07-22 09:30:43 +02:00
ET . SubElement ( s , " param " , name = " compression " ) . text = " xz "
2022-09-12 13:43:10 +02:00
r . append ( s )
2010-09-20 11:09:43 +02:00
return r
2010-05-14 16:44:42 +02:00
2022-10-21 10:38:57 +02:00
def execute ( self , dir , callmode : Optional [ str ] = None , singleservice = None , verbose : Optional [ bool ] = None ) :
Add .old dir support for source services
Some services expect "old" service files (that is, files from a
previous service run) to be present in an ".old" dir. Hence, osc
should support that.
Instead of removing all files from a previous service run, move them
to the ".old" dir, run the services, and, finally, remove the ".old"
dir.
Unfortunately, the location of the ".old" dir is hardcoded in the
specific services. That is, we have to be careful if an ".old" dir
exists (in this case, we error out).
Based on [1].
[1] https://github.com/openSUSE/osc/pull/846
2020-10-01 13:53:19 +02:00
old_dir = os . path . join ( dir , ' .old ' )
2022-09-05 15:33:00 +02:00
# if 2 osc instances are executed at a time one, of them fails on .old file existence
# sleep up to 10 seconds until we can create the directory
for i in reversed ( range ( 10 ) ) :
try :
os . mkdir ( old_dir )
break
except FileExistsError :
time . sleep ( 1 )
if i == 0 :
msg = f ' " { old_dir } " exists, please remove it '
raise oscerr . OscIOError ( None , msg )
2023-04-14 13:51:01 +02:00
try :
result = self . _execute ( dir , old_dir , callmode , singleservice , verbose )
finally :
shutil . rmtree ( old_dir )
2022-09-05 15:33:00 +02:00
return result
Add .old dir support for source services
Some services expect "old" service files (that is, files from a
previous service run) to be present in an ".old" dir. Hence, osc
should support that.
Instead of removing all files from a previous service run, move them
to the ".old" dir, run the services, and, finally, remove the ".old"
dir.
Unfortunately, the location of the ".old" dir is hardcoded in the
specific services. That is, we have to be careful if an ".old" dir
exists (in this case, we error out).
Based on [1].
[1] https://github.com/openSUSE/osc/pull/846
2020-10-01 13:53:19 +02:00
2022-10-21 10:38:57 +02:00
def _execute (
self , dir , old_dir , callmode : Optional [ str ] = None , singleservice = None , verbose : Optional [ bool ] = None
) :
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_ ' ) :
Add .old dir support for source services
Some services expect "old" service files (that is, files from a
previous service run) to be present in an ".old" dir. Hence, osc
should support that.
Instead of removing all files from a previous service run, move them
to the ".old" dir, run the services, and, finally, remove the ".old"
dir.
Unfortunately, the location of the ".old" dir is hardcoded in the
specific services. That is, we have to be careful if an ".old" dir
exists (in this case, we error out).
Based on [1].
[1] https://github.com/openSUSE/osc/pull/846
2020-10-01 13:53:19 +02:00
os . rename ( os . path . join ( dir , filename ) ,
os . path . join ( old_dir , filename ) )
2011-01-06 15:03:18 +01:00
2011-02-15 09:41:03 +01:00
allservices = self . services or [ ]
Fix single service disabled run
Without this patch, running an individual service that has parameters
defined in the _service file fails:
$ osc service run obs_scm
Please specify valid --scm=... options
Aborting: service call failed: /usr/lib/obs/service/obs_scm --outdir [snipped]
This is because although the service is defined in the _service file and
the "scm" parameter is set in it, the service wasn't being found in the
data structure and so the service executable wasn't being called with
the parameters supplied in the _service file. This patch corrects the
issue with the services data structure so that the service data isn't
overridden if it is defined in the _service file.
A side effect of this correction for services defined in the _service
file is that instead of overriding the service mode with '', the mode is
taken from the _service file. When using the "run" command, this would
mean that the call mode of None may not be in agreement with the service
mode defined in the file, e.g. "manual", and so the "run" command would
no longer cause it to run when it would before. We can take this
opportunity to define this as the correct behavior - the "run" command
now only runs services with "trylocal", "localonly", or no mode set -
and also ensure that other call mode commands result in sensible
behavior when called with a service name, for instance "osc service
manualrun download_files" will run only services with mode="manual" and
name="download"files" instead of all services with mode="manual".
Additionally, services that aren't defined in the _service file can be
called with a call mode command and will use that call mode rather than
None.
2020-03-16 22:13:15 +01:00
service_names = [ s [ ' name ' ] for s in allservices ]
if singleservice and singleservice not in service_names :
2011-02-15 09:41:03 +01:00
# set array to the manual specified singleservice, if it is not part of _service file
2022-09-12 13:43:10 +02:00
data = { ' name ' : singleservice , ' command ' : [ singleservice ] , ' mode ' : callmode }
2011-02-15 09:41:03 +01:00
allservices = [ data ]
Fix single service disabled run
Without this patch, running an individual service that has parameters
defined in the _service file fails:
$ osc service run obs_scm
Please specify valid --scm=... options
Aborting: service call failed: /usr/lib/obs/service/obs_scm --outdir [snipped]
This is because although the service is defined in the _service file and
the "scm" parameter is set in it, the service wasn't being found in the
data structure and so the service executable wasn't being called with
the parameters supplied in the _service file. This patch corrects the
issue with the services data structure so that the service data isn't
overridden if it is defined in the _service file.
A side effect of this correction for services defined in the _service
file is that instead of overriding the service mode with '', the mode is
taken from the _service file. When using the "run" command, this would
mean that the call mode of None may not be in agreement with the service
mode defined in the file, e.g. "manual", and so the "run" command would
no longer cause it to run when it would before. We can take this
opportunity to define this as the correct behavior - the "run" command
now only runs services with "trylocal", "localonly", or no mode set -
and also ensure that other call mode commands result in sensible
behavior when called with a service name, for instance "osc service
manualrun download_files" will run only services with mode="manual" and
name="download"files" instead of all services with mode="manual".
Additionally, services that aren't defined in the _service file can be
called with a call mode command and will use that call mode rather than
None.
2020-03-16 22:13:15 +01:00
elif singleservice :
allservices = [ s for s in allservices if s [ ' name ' ] == singleservice ]
2023-01-10 08:41:23 +01:00
# set the right called mode or the service would be skipped below
for s in allservices :
s [ ' mode ' ] = callmode
2011-02-15 09:41:03 +01:00
2019-02-04 12:16:54 +01:00
if not allservices :
# short-circuit to avoid a potential http request in vc_export_env
# (if there are no services to execute this http request is
# useless)
return 0
2016-04-01 12:57:00 +02:00
# services can detect that they run via osc this way
os . putenv ( " OSC_VERSION " , get_osc_version ( ) )
2011-08-23 16:03:58 +02:00
# set environment when using OBS 2.3 or later
2022-08-29 12:56:57 +02:00
if self . project is not None :
2016-10-20 13:12:15 +02:00
# These need to be kept in sync with bs_service
2022-04-20 19:22:35 +02:00
os . putenv ( " OBS_SERVICE_APIURL " , self . apiurl )
2011-08-23 16:03:58 +02:00
os . putenv ( " OBS_SERVICE_PROJECT " , self . project )
os . putenv ( " OBS_SERVICE_PACKAGE " , self . package )
2019-01-29 14:30:52 +01:00
# also export vc env vars (some services (like obs_scm) use them)
vc_export_env ( self . apiurl )
2011-08-18 11:32:19 +02:00
2011-01-06 15:03:18 +01:00
# recreate files
2011-05-24 10:49:08 +02:00
ret = 0
2011-02-15 09:41:03 +01:00
for service in allservices :
2016-06-01 17:01:34 +02:00
if callmode != " all " :
if service [ ' mode ' ] == " buildtime " :
continue
2020-07-24 23:17:12 +02:00
if service [ ' mode ' ] == " serveronly " and callmode != " local " :
continue
if service [ ' mode ' ] == " manual " and callmode != " manual " :
continue
if service [ ' mode ' ] != " manual " and callmode == " manual " :
2016-06-01 17:01:34 +02:00
continue
if service [ ' mode ' ] == " disabled " and callmode != " disabled " :
continue
if service [ ' mode ' ] != " disabled " and callmode == " disabled " :
continue
if service [ ' mode ' ] != " trylocal " and service [ ' mode ' ] != " localonly " and callmode == " trylocal " :
continue
2013-04-26 20:43:53 +02:00
temp_dir = None
try :
2016-03-04 10:20:39 +01:00
temp_dir = tempfile . mkdtemp ( dir = dir , suffix = ' . %s .service ' % service [ ' name ' ] )
2014-10-16 21:47:11 +02:00
cmd = service [ ' command ' ]
2022-04-20 19:22:35 +02:00
if not os . path . exists ( " /usr/lib/obs/service/ " + cmd [ 0 ] ) :
raise oscerr . PackageNotInstalled ( " obs-service- %s " % cmd [ 0 ] )
2022-09-12 13:43:10 +02:00
cmd [ 0 ] = " /usr/lib/obs/service/ " + cmd [ 0 ]
cmd = cmd + [ " --outdir " , temp_dir ]
2022-08-04 10:09:10 +02:00
if conf . config [ ' verbose ' ] or verbose or conf . config [ ' debug ' ] :
2015-03-26 14:37:14 +01:00
print ( " Run source service: " , ' ' . join ( cmd ) )
2014-10-16 21:47:11 +02:00
r = run_external ( * cmd )
2013-04-26 20:43:53 +02:00
if r != 0 :
2015-03-26 14:37:14 +01:00
print ( " Aborting: service call failed: " , ' ' . join ( cmd ) )
2014-08-12 15:01:16 +02:00
# FIXME: addDownloadUrlService calls si.execute after
2013-04-26 20:43:53 +02:00
# updating _services.
return r
2020-07-24 23:17:12 +02:00
if service [ ' mode ' ] == " manual " or service [ ' mode ' ] == " disabled " or service [ ' mode ' ] == " trylocal " or service [ ' mode ' ] == " localonly " or callmode == " local " or callmode == " trylocal " or callmode == " all " :
2013-04-26 20:43:53 +02:00
for filename in os . listdir ( temp_dir ) :
2016-03-04 09:40:58 +01:00
os . rename ( os . path . join ( temp_dir , filename ) , os . path . join ( dir , filename ) )
2013-04-26 20:43:53 +02:00
else :
2015-03-16 08:13:29 +01:00
name = service [ ' name ' ]
2013-04-26 20:43:53 +02:00
for filename in os . listdir ( temp_dir ) :
2022-09-12 13:43:10 +02:00
os . rename ( os . path . join ( temp_dir , filename ) , os . path . join ( dir , " _service: " + name + " : " + filename ) )
2013-04-26 20:43:53 +02:00
finally :
if temp_dir is not None :
shutil . rmtree ( temp_dir )
2009-09-03 16:56:48 +02:00
2011-12-12 10:04:21 +01:00
return 0
2011-05-24 10:49:08 +02:00
2022-09-12 13:43:10 +02:00
2008-03-22 14:37:59 +01:00
class Linkinfo :
2022-01-24 08:57:53 +01:00
""" linkinfo metadata (which is part of the xml representing a directory)
2008-03-22 14:37:59 +01:00
"""
2022-09-12 13:43:10 +02:00
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 ) :
2022-01-24 08:57:53 +01:00
""" read in the linkinfo metadata from the ``<linkinfo>`` element passed as
2008-03-22 14:37:59 +01:00
elementtree node .
2022-01-24 08:57:53 +01:00
If the passed element is ` ` None ` ` , the method does nothing .
2008-03-22 14:37:59 +01:00
"""
2022-08-29 12:56:57 +02:00
if linkinfo_node is None :
2008-03-22 14:37:59 +01:00
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 ' )
2022-04-20 19:22:35 +02:00
self . srcmd5 = linkinfo_node . get ( ' srcmd5 ' )
self . error = linkinfo_node . get ( ' error ' )
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 ) :
2022-01-24 08:57:53 +01:00
""" :return: ``True`` if the linkinfo is not empty, otherwise ``False`` """
2021-09-14 14:09:27 +02:00
if self . xsrcmd5 or self . lsrcmd5 or self . error is not None :
2008-03-22 14:37:59 +01:00
return True
2008-03-22 18:37:17 +01:00
return False
def isexpanded ( self ) :
2022-01-24 08:57:53 +01:00
""" :return: ``True`` if the package is an expanded link """
2008-03-22 18:37:17 +01:00
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 ) :
2022-01-24 08:57:53 +01:00
""" :return: ``True`` if the link is in error state (could not be applied) """
2008-07-16 17:14:57 +02:00
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 ' \
2022-09-12 13:43:10 +02:00
% ( 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 ' \
2022-09-12 13:43:10 +02:00
% ( self . project , self . package , self . srcmd5 , self . lsrcmd5 , self . error )
2008-07-16 17:14:57 +02:00
else :
return ' expanded link to project %s , package %s , srcmd5 %s , lsrcmd5 %s ' \
2022-09-12 13:43:10 +02:00
% ( self . project , self . package , self . srcmd5 , self . lsrcmd5 )
2008-03-22 14:37:59 +01:00
else :
return ' None '
2022-09-12 13:43:10 +02:00
2014-06-22 15:41:14 +02:00
class DirectoryServiceinfo :
def __init__ ( self ) :
self . code = None
self . xsrcmd5 = None
self . lsrcmd5 = None
self . error = ' '
def read ( self , serviceinfo_node ) :
if serviceinfo_node is None :
return
self . code = serviceinfo_node . get ( ' code ' )
self . xsrcmd5 = serviceinfo_node . get ( ' xsrcmd5 ' )
self . lsrcmd5 = serviceinfo_node . get ( ' lsrcmd5 ' )
self . error = serviceinfo_node . find ( ' error ' )
if self . error :
self . error = self . error . text
def isexpanded ( self ) :
"""
Returns true , if the directory contains the " expanded " / generated service files
"""
return self . lsrcmd5 is not None and self . xsrcmd5 is None
def haserror ( self ) :
return self . error is not None
2008-03-22 14:37:59 +01:00
2010-08-04 11:46:30 +02:00
# http://effbot.org/zone/element-lib.htm#prettyprint
2022-09-12 13:43:10 +02:00
2010-08-04 11:46:30 +02:00
def xmlindent ( elem , level = 0 ) :
2022-09-12 13:43:10 +02:00
i = " \n " + level * " "
2023-05-09 08:42:53 +02:00
if isinstance ( elem , ET . ElementTree ) :
elem = elem . getroot ( )
2010-08-04 11:46:30 +02:00
if len ( elem ) :
if not elem . text or not elem . text . strip ( ) :
elem . text = i + " "
for e in elem :
2022-09-12 13:43:10 +02:00
xmlindent ( e , level + 1 )
2010-08-04 11:46:30 +02:00
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
2022-09-12 13:43:10 +02:00
2006-05-22 12:50:37 +02:00
class Project :
2013-01-15 18:57:40 +01:00
"""
Represent a checked out project directory , holding packages .
: Attributes :
` ` dir ` `
The directory path containing the project .
` ` name ` `
The name of the project .
` ` apiurl ` `
The endpoint URL of the API server .
` ` pacs_available ` `
List of names of packages available server - side .
This is only populated if ` ` getPackageList ` ` is set
to ` ` True ` ` in the constructor .
` ` pacs_have ` `
2013-01-16 14:48:15 +01:00
List of names of packages which exist server - side
and exist in the local project working copy ( if
' do_package_tracking ' is disabled ) .
If ' do_package_tracking ' is enabled it represents the
list names of packages which are tracked in the project
working copy ( that is it might contain packages which
exist on the server as well as packages which do not
exist on the server ( for instance if the local package
was added or if the package was removed on the server - side ) ) .
2013-01-15 18:57:40 +01:00
` ` pacs_excluded ` `
List of names of packages in the local project directory
which are excluded by the ` exclude_glob ` configuration
variable . Only set if ` do_package_tracking ` is enabled .
` ` pacs_unvers ` `
List of names of packages in the local project directory
2013-01-16 14:48:15 +01:00
which are not tracked . Only set if ` do_package_tracking `
is enabled .
2013-01-15 18:57:40 +01:00
` ` pacs_broken ` `
2013-01-16 14:48:15 +01:00
List of names of packages which are tracked but do not
exist in the local project working copy . Only set if
` do_package_tracking ` is enabled .
2013-01-15 18:57:40 +01:00
` ` pacs_missing ` `
List of names of packages which exist server - side but
are not expected to exist in the local project directory .
"""
2010-10-10 21:40:31 +02:00
REQ_STOREFILES = ( ' _project ' , ' _apiurl ' )
2013-01-15 18:57:40 +01:00
2010-10-10 21:40:31 +02:00
def __init__ ( self , dir , getPackageList = True , progress_obj = None , wc_check = True ) :
2013-01-15 18:57:40 +01:00
"""
Constructor .
: Parameters :
` dir ` : str
The directory path containing the checked out project .
` getPackageList ` : bool
Set to ` False ` if you want to skip retrieval from the
server of the list of packages in the project .
` wc_check ` : bool
"""
2023-02-08 11:46:16 +01:00
self . dir = Path ( dir )
2006-06-06 12:50:40 +02:00
self . absdir = os . path . abspath ( dir )
2022-10-14 14:25:54 +02:00
self . store = Store ( 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 )
2022-10-14 14:31:42 +02:00
self . scm_url = self . store . scmurl
2022-10-14 14:25:54 +02:00
self . apiurl = self . store . apiurl
2010-10-10 21:40:31 +02:00
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 ( )
2022-09-12 13:43:10 +02:00
self . pacs_have = [ pac . get ( ' name ' ) for pac in self . pac_root . findall ( ' package ' ) ]
self . pacs_excluded = [ i for i in os . listdir ( self . dir )
for j in conf . config [ ' exclude_glob ' ]
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 :
2022-09-12 13:43:10 +02:00
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
2022-09-12 13:43:10 +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 = [ ]
2014-09-26 13:41:53 +02:00
req_storefiles = Project . REQ_STOREFILES
2022-08-29 12:56:57 +02:00
if conf . config [ ' do_package_tracking ' ] and self . scm_url is None :
2014-09-26 13:41:53 +02:00
req_storefiles + = ( ' _packages ' , )
for fname in req_storefiles :
2010-10-10 21:40:31 +02:00
if not os . path . exists ( os . path . join ( self . absdir , store , fname ) ) :
dirty_files . append ( fname )
return dirty_files
2022-10-21 10:38:57 +02:00
def wc_repair ( self , apiurl : Optional [ str ] = None ) :
2022-10-14 08:58:35 +02:00
store = Store ( self . dir )
store . assert_is_project ( )
if not store . exists ( " _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?
2022-08-29 10:00:13 +02:00
raise oscerr . WorkingCopyInconsistent ( self . name , None , [ ] , msg )
2010-12-09 20:36:06 +01:00
# sanity check
conf . parse_apisrv_url ( None , apiurl )
2022-10-14 08:58:35 +02:00
store . apiurl = apiurl
self . apiurl = apiurl
2010-10-10 21:40:31 +02:00
2016-11-18 13:00:55 +01:00
def checkout_missing_pacs ( self , sinfos , expand_link = False , unexpand_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 )
2016-10-06 11:15:30 +02:00
if not ( expand_link or unexpand_link ) :
2016-11-18 13:00:55 +01:00
sinfo = sinfos . get ( pac )
if sinfo is None :
# should never happen...
continue
linked = sinfo . find ( ' linked ' )
if linked is not None and linked . get ( ' project ' ) == self . name :
# hmm what about a linkerror (sinfo.get('lsrcmd5') is None)?
# Should we skip the package as well or should we it out?
# let's skip it for now
print ( ' Skipping %s (link to package %s ) ' % ( pac , linked . get ( ' package ' ) ) )
continue
2016-10-06 11:15:30 +02:00
print ( ' checking out new package %s ' % pac )
2022-09-12 13:43:10 +02:00
checkout_package ( self . apiurl , self . name , pac ,
pathname = getTransActPath ( os . path . join ( self . dir , pac ) ) ,
2016-10-06 11:15:30 +02:00
prj_obj = self , prj_dir = self . dir ,
expand_link = expand_link or not unexpand_link , progress_obj = self . progress_obj )
2008-03-10 19:04:23 +01:00
2022-10-21 10:38:57 +02:00
def status ( self , pac : str ) :
2010-12-22 23:17:11 +01:00
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 )
2022-09-12 14:15:34 +02:00
if st not in exclude_states :
2010-12-22 23:17:11 +01:00
res . append ( ( st , pac ) )
2022-09-12 14:15:34 +02:00
if ' ? ' not in exclude_states :
2010-12-22 23:17:11 +01:00
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 )
2022-08-29 12:56:57 +02:00
if node is None :
2008-03-10 19:04:23 +01:00
self . new_package_entry ( pac , state )
else :
2011-02-22 17:52:12 +01:00
node . set ( ' state ' , state )
2008-03-10 19:04:23 +01:00
2022-10-21 10:38:57 +02:00
def get_package_node ( self , pac : str ) :
2008-03-10 19:04:23 +01:00
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 )
2022-10-21 10:38:57 +02:00
def get_state ( self , pac : str ) :
2008-03-10 19:04:23 +01:00
node = self . get_package_node ( pac )
2022-08-29 12:56:57 +02:00
if node is not None :
2008-03-10 19:04:23 +01:00
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 ) :
2013-01-15 18:57:40 +01:00
"""
2020-06-02 22:22:17 +02:00
Returns an ` ` xml . etree . ElementTree ` ` object representing the
2013-01-15 18:57:40 +01:00
parsed contents of the project ' s ``.osc/_packages`` XML file.
"""
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 ) :
2015-05-24 19:57:03 +02:00
try :
result = ET . parse ( packages_file )
except :
msg = ' Cannot read package file \' %s \' . ' % packages_file
msg + = ' You can try to remove it and then run osc repairwc. '
raise oscerr . OscIOError ( None , msg )
return result
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 )
2013-04-10 11:34:59 +02:00
store_write_string ( self . absdir , ' _packages ' , ET . tostring ( self . pac_root , encoding = ET_ENCODING ) )
2008-03-10 19:04:23 +01:00
def addPackage ( self , pac ) :
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 )
2022-08-29 12:56:57 +02:00
if state is None or state == ' D ' :
2008-03-10 19:04:23 +01:00
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
2022-09-12 13:43:10 +02:00
def delPackage ( self , pac , force = False ) :
2008-03-10 19:04:23 +01:00
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 ) != ' ? ' :
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 )
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' D ' , getTransActPath ( os . path . join ( pac . dir , filename ) ) ) )
print ( statfrmt ( ' D ' , getTransActPath ( os . path . join ( pac . dir , os . pardir , pac . name ) ) ) )
2008-03-10 19:04:23 +01:00
pac . write_deletelist ( )
self . set_state ( pac . name , ' D ' )
self . write_packages ( )
else :
2013-04-09 12:51:28 +02:00
print ( ' package \' %s \' has local modifications (see osc st for details) ' % pac . name )
2008-03-10 19:04:23 +01:00
elif state == ' A ' :
if force :
delete_dir ( pac . absdir )
self . del_package_node ( pac . name )
self . write_packages ( )
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' D ' , pac . name ) )
2008-03-10 19:04:23 +01:00
else :
2013-04-09 12:51:28 +02:00
print ( ' package \' %s \' has local modifications (see osc st for details) ' % pac . name )
2022-08-29 12:56:57 +02:00
elif state is None :
2013-04-09 12:51:28 +02:00
print ( ' package is not under version control ' )
2008-03-10 19:04:23 +01:00
else :
2013-04-09 12:51:28 +02:00
print ( ' unsupported state ' )
2008-03-10 19:04:23 +01:00
2022-09-12 13:43:10 +02:00
def update ( self , pacs = ( ) , expand_link = False , unexpand_link = False , service_files = False ) :
2022-08-29 13:23:29 +02:00
if pacs :
2008-03-10 19:04:23 +01:00
for pac in pacs :
2011-05-16 14:27:55 +02: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
2022-09-12 14:15:34 +02:00
upstream_del = [ pac for pac in self . pacs_have if pac not in self . pacs_available and self . get_state ( pac ) != ' A ' ]
sinfo_pacs = [ pac for pac in self . pacs_have if self . get_state ( pac ) in ( ' ' , ' D ' ) and pac not in self . pacs_broken ]
2016-11-18 13:00:55 +01:00
sinfo_pacs . extend ( self . pacs_missing )
2014-06-23 10:58:20 +02:00
sinfos = get_project_sourceinfo ( self . apiurl , self . name , True , * sinfo_pacs )
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 :
2013-02-13 18:50:01 +01:00
if self . status ( pac ) != ' ! ' :
2011-08-25 13:43:58 +02:00
p = Package ( os . path . join ( self . dir , pac ) )
2022-09-12 13:43:10 +02:00
self . delPackage ( p , force = True )
2011-08-25 13:43:58 +02:00
delete_storedir ( p . storedir )
try :
os . rmdir ( pac )
except :
pass
2013-02-13 18:50:01 +01:00
self . pac_root . remove ( self . get_package_node ( 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 . 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 ,
2014-06-22 15:41:14 +02:00
pathname = getTransActPath ( os . path . join ( self . dir , pac ) ) , prj_obj = self ,
2010-02-09 20:57:10 +01:00
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
2014-06-22 15:41:14 +02:00
needs_update = True
2022-08-29 12:56:57 +02:00
if p . scm_url is not None :
2021-11-30 13:13:11 +01:00
# git managed.
print ( " Skipping git managed package " , pac )
continue
elif 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
2013-04-09 12:51:28 +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
2013-04-09 12:51:28 +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 ( ) :
2014-06-22 15:41:14 +02:00
needs_update = p . update_needed ( sinfos [ p . name ] )
if needs_update :
rev = p . latest_rev ( )
elif p . hasserviceinfo ( ) and p . serviceinfo . isexpanded ( ) and not service_files :
2014-08-12 15:01:16 +02:00
# FIXME: currently, do_update does not propagate the --server-side-source-service-files
2014-06-22 15:41:14 +02:00
# option to this method. Consequence: an expanded service is always unexpanded during
# an update (TODO: discuss if this is a reasonable behavior (at least this the default
# behavior for a while))
needs_update = True
else :
needs_update = p . update_needed ( sinfos [ p . name ] )
2013-04-09 12:51:28 +02:00
print ( ' Updating %s ' % p . name )
2014-06-22 15:41:14 +02:00
if needs_update :
p . update ( rev , service_files )
else :
print ( ' At revision %s . ' % p . rev )
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 ' :
2014-06-22 15:41:14 +02:00
# pac exists (the non-existent pac case was handled in the first if block)
p = Package ( os . path . join ( self . dir , pac ) , progress_obj = self . progress_obj )
2014-10-11 13:29:47 +02:00
if p . update_needed ( sinfos [ p . name ] ) :
2014-06-22 15:41:14 +02:00
p . 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 :
2013-04-09 12:51:28 +02:00
print ( ' unexpected state.. package \' %s \' ' % pac )
2008-03-10 19:04:23 +01:00
2016-11-18 13:00:55 +01:00
self . checkout_missing_pacs ( sinfos , expand_link , 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
2022-08-29 15:32:41 +02:00
def commit ( self , pacs = ( ) , msg = ' ' , files = None , verbose = False , skip_local_service_run = False , can_branch = False , force = False ) :
files = files or { }
2022-08-29 13:23:29 +02:00
if 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 = [ ]
2013-04-09 11:33:25 +02:00
if pac in files :
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
todo = files [ pac ]
state = self . get_state ( pac )
if state == ' A ' :
2011-09-07 13:55:05 +02:00
self . commitNewPackage ( pac , msg , todo , verbose = verbose , skip_local_service_run = skip_local_service_run )
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 ' :
2023-02-15 20:13:39 +01:00
self . commitDelPackage ( pac , force = force )
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 == ' ' :
# 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
2015-04-29 13:43:23 +02:00
p . commit ( msg , verbose = verbose , skip_local_service_run = skip_local_service_run , can_branch = can_branch , force = force )
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 ) ) :
2013-04-09 12:51:28 +02:00
print ( ' osc: \' %s \' is not under version control ' % pac )
2021-06-04 13:06:00 +02:00
elif pac in self . pacs_broken or not os . path . exists ( os . path . join ( self . dir , pac ) ) :
2013-04-09 12:51:28 +02:00
print ( ' osc: \' %s \' package not found ' % pac )
2022-08-29 12:56:57 +02:00
elif state is None :
2012-09-17 13:12:50 +02:00
self . commitExtPackage ( pac , msg , todo , verbose = verbose , skip_local_service_run = skip_local_service_run )
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
2011-09-07 13:55:05 +02:00
Package ( os . path . join ( self . dir , pac ) ) . commit ( msg , verbose = verbose , skip_local_service_run = skip_local_service_run )
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 ' :
2023-02-15 20:13:39 +01:00
self . commitDelPackage ( pac , force = force )
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 ' :
2011-09-07 13:55:05 +02:00
self . commitNewPackage ( pac , msg , verbose = verbose , skip_local_service_run = skip_local_service_run )
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
2022-08-29 15:32:41 +02:00
def commitNewPackage ( self , pac , msg = ' ' , files = None , verbose = False , skip_local_service_run = False ) :
2008-03-10 19:04:23 +01:00
""" creates and commits a new package if it does not exist on the server """
2022-08-29 15:32:41 +02:00
files = files or [ ]
2008-03-10 19:04:23 +01:00
if pac in self . pacs_available :
2013-04-09 12:51:28 +02:00
print ( ' package \' %s \' already exists ' % pac )
2008-03-10 19:04:23 +01:00
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 = ( {
2022-09-12 13:43:10 +02:00
' name ' : pac ,
' user ' : user } ) ,
2009-04-21 18:52:26 +02:00
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
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' Sending ' , os . path . normpath ( p . dir ) ) )
2011-09-07 13:55:05 +02:00
p . commit ( msg = msg , verbose = verbose , skip_local_service_run = skip_local_service_run )
2008-03-10 19:04:23 +01:00
self . set_state ( pac , ' ' )
2006-05-22 12:50:37 +02:00
os . chdir ( olddir )
2023-02-15 20:13:39 +01:00
def commitDelPackage ( self , pac , force = False ) :
2008-03-10 19:04:23 +01:00
""" 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 ) )
2022-09-12 13:43:10 +02:00
# print statfrmt('Deleting', os.path.normpath(os.path.join(p.dir, os.pardir, pac)))
2008-03-10 19:04:23 +01:00
delete_storedir ( p . storedir )
try :
os . rmdir ( p . dir )
except :
pass
except OSError :
pac_dir = os . path . join ( self . dir , pac )
2017-08-04 13:52:56 +02:00
except ( oscerr . NoWorkingCopy , oscerr . WorkingCopyOutdated , oscerr . PackageError ) :
pass
2022-09-12 13:43:10 +02:00
# print statfrmt('Deleting', getTransActPath(os.path.join(self.dir, pac)))
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' Deleting ' , getTransActPath ( pac_dir ) ) )
2023-02-15 20:13:39 +01:00
delete_package ( self . apiurl , self . name , pac , force = force )
2008-03-10 19:04:23 +01:00
self . del_package_node ( pac )
2022-08-29 15:32:41 +02:00
def commitExtPackage ( self , pac , msg , files = None , verbose = False , skip_local_service_run = False ) :
2008-03-10 19:04:23 +01:00
""" commits a package from an external project """
2022-08-29 15:32:41 +02:00
files = files or [ ]
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
2022-10-14 14:25:54 +02:00
store = Store ( pac_path )
2008-03-10 19:04:23 +01:00
project = store_read_project ( pac_path )
package = store_read_package ( pac_path )
2022-10-14 14:25:54 +02:00
apiurl = store . apiurl
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
2012-09-17 13:12:50 +02:00
p . commit ( msg = msg , verbose = verbose , skip_local_service_run = skip_local_service_run )
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
2022-10-21 10:38:57 +02:00
def init_project (
apiurl : str ,
2023-02-08 11:46:16 +01:00
dir : Path ,
2022-10-21 10:38:57 +02:00
project ,
package_tracking = True ,
getPackageList = True ,
progress_obj = None ,
wc_check = True ,
scm_url = None ,
) :
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 )
2022-10-14 15:37:24 +02:00
Store ( dir ) . apiurl = apiurl
2021-11-30 13:13:11 +01:00
if scm_url :
2022-10-14 15:39:40 +02:00
Store ( dir ) . scmurl = scm_url
2021-11-30 13:13:11 +01:00
package_tracking = None
2010-10-09 16:26:55 +02:00
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
2022-09-12 17:16:52 +02:00
@total_ordering
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 ' ,
2022-09-12 13:43:10 +02:00
' _in_commit ' , ' _meta ' , ' _meta_mode ' , ' _frozenlink ' , ' _pulled ' , ' _linkrepair ' ,
' _size_limit ' , ' _commit_msg ' , ' _last_buildroot ' )
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
2023-01-26 10:11:54 +01:00
self . todo = [ ]
if os . path . isfile ( workingdir ) or not os . path . exists ( workingdir ) :
# workingdir is a file
# workingdir doesn't exist -> it points to a non-existing file in a working dir (e.g. during mv)
workingdir , todo_entry = os . path . split ( workingdir )
self . todo . append ( todo_entry )
self . dir = workingdir or " . "
2006-06-06 12:50:40 +02:00
self . absdir = os . path . abspath ( self . dir )
2022-10-14 14:25:54 +02:00
self . store = Store ( 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
2022-10-14 14:31:42 +02:00
self . scm_url = self . store . scmurl
2010-09-03 14:51:20 +02:00
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 )
2022-10-14 14:25:54 +02:00
self . apiurl = self . store . apiurl
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
2022-09-12 17:16:52 +02:00
def __repr__ ( self ) :
return super ( ) . __repr__ ( ) + f " ( { self . prjname } / { self . name } ) "
def __hash__ ( self ) :
return hash ( ( self . name , self . prjname , self . apiurl ) )
def __eq__ ( self , other ) :
return ( self . name , self . prjname , self . apiurl ) == ( other . name , other . prjname , other . apiurl )
def __lt__ ( self , other ) :
return ( self . name , self . prjname , self . apiurl ) < ( other . name , other . prjname , other . apiurl )
2022-09-13 16:34:54 +02:00
@classmethod
def from_paths ( cls , paths , progress_obj = None ) :
"""
Return a list of Package objects from working copies in given paths .
"""
packages = [ ]
for path in paths :
package = cls ( path , progress_obj )
2023-01-26 10:11:54 +01:00
seen_package = None
2023-01-20 16:52:11 +01:00
try :
# re-use an existing package
seen_package_index = packages . index ( package )
2023-01-26 10:11:54 +01:00
seen_package = packages [ seen_package_index ]
2023-01-20 16:52:11 +01:00
except ValueError :
2023-01-26 10:11:54 +01:00
pass
2023-01-20 16:52:11 +01:00
2023-01-26 10:11:54 +01:00
if seen_package :
# merge package into seen_package
if seen_package . absdir != package . absdir :
raise oscerr . PackageExists ( package . prjname , package . name , " Duplicate package " )
seen_package . merge ( package )
else :
# use the new package instance
packages . append ( package )
2023-01-20 16:52:11 +01:00
2022-09-13 16:34:54 +02:00
return packages
@classmethod
def from_paths_nofail ( cls , paths , progress_obj = None ) :
"""
Return a list of Package objects from working copies in given paths
and a list of strings with paths that do not contain Package working copies .
"""
packages = [ ]
failed_to_load = [ ]
for path in paths :
try :
package = cls ( path , progress_obj )
2023-01-26 10:11:54 +01:00
except oscerr . NoWorkingCopy :
failed_to_load . append ( path )
continue
# the following code is identical to from_paths()
seen_package = None
try :
# re-use an existing package
seen_package_index = packages . index ( package )
seen_package = packages [ seen_package_index ]
except ValueError :
pass
if seen_package :
# merge package into seen_package
if seen_package . absdir != package . absdir :
2022-09-13 16:34:54 +02:00
raise oscerr . PackageExists ( package . prjname , package . name , " Duplicate package " )
2023-01-26 10:11:54 +01:00
seen_package . merge ( package )
else :
# use the new package instance
2022-09-13 16:34:54 +02:00
packages . append ( package )
2023-01-26 10:11:54 +01:00
2022-09-13 16:34:54 +02:00
return packages , failed_to_load
2010-09-08 18:56:15 +02:00
def wc_check ( self ) :
2010-09-28 23:07:33 +02:00
dirty_files = [ ]
2021-11-30 13:13:11 +01:00
if self . scm_url :
return dirty_files
2010-09-08 18:56:15 +02:00
for fname in self . filenamelist :
2022-09-12 14:15:34 +02:00
if not os . path . exists ( os . path . join ( self . storedir , fname ) ) and fname not 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 \
2022-09-12 13:43:10 +02:00
fname . startswith ( ' _build ' ) :
2010-09-08 18:56:15 +02:00
continue
elif fname in self . filenamelist and fname in self . skipped :
2010-09-28 23:07:33 +02:00
dirty_files . append ( fname )
2022-09-12 14:15:34 +02:00
elif fname not 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 [ : ] :
2022-09-12 14:15:34 +02:00
if fname not 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 [ : ] :
2022-09-12 14:15:34 +02:00
if fname not in self . filenamelist :
2010-09-28 23:07:33 +02:00
dirty_files . append ( fname )
return dirty_files
2022-10-21 10:38:57 +02:00
def wc_repair ( self , apiurl : Optional [ str ] = None ) :
2022-10-14 09:14:37 +02:00
store = Store ( self . dir )
store . assert_is_package ( )
if not store . exists ( " _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 )
2022-10-14 09:14:37 +02:00
store . apiurl = apiurl
self . apiurl = apiurl
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?
2022-09-12 14:15:34 +02:00
if not os . path . exists ( os . path . join ( self . storedir , f . name ) ) and f . name not in self . skipped :
2010-09-08 18:56:15 +02:00
# if get_source_file fails we're screwed up...
get_source_file ( self . apiurl , self . prjname , self . name , f . name ,
2022-09-12 13:43:10 +02:00
targetfilename = os . path . join ( self . storedir , f . name ) , revision = self . rev ,
mtime = f . mtime )
2022-10-14 09:14:37 +02:00
for fname in store :
2010-09-08 18:56:15 +02:00
if fname in Package . REQ_STOREFILES or fname in Package . OPT_STOREFILES or \
2022-09-12 13:43:10 +02:00
fname . startswith ( ' _build ' ) :
2010-09-08 18:56:15 +02:00
continue
2022-09-12 14:15:34 +02:00
elif fname not in self . filenamelist or fname in self . skipped :
2010-09-08 18:56:15 +02:00
# this file does not belong to the storedir so remove it
2022-10-14 09:14:37 +02:00
store . unlink ( fname )
2010-09-08 18:56:15 +02:00
for fname in self . to_be_deleted [ : ] :
2022-09-12 14:15:34 +02:00
if fname not in self . filenamelist :
2010-09-08 18:56:15 +02:00
self . to_be_deleted . remove ( fname )
self . write_deletelist ( )
2022-10-14 09:14:37 +02:00
2010-09-08 18:56:15 +02:00
for fname in self . in_conflict [ : ] :
2022-09-12 14:15:34 +02:00
if fname not in self . filenamelist :
2010-09-08 18:56:15 +02:00
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 ( )
2013-04-09 12:51:28 +02:00
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 )
2022-07-28 19:11:29 +02:00
except OSError as ioe :
2010-03-22 11:07:10 +01:00
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 )
2011-01-17 15:00:21 +01:00
# special handling for skipped files: if file exists, simply delete it
if state == ' S ' :
exists = os . path . exists ( os . path . join ( self . dir , n ) )
self . delete_localfile ( n )
return ( exists , ' S ' )
2009-07-15 23:10:38 +02:00
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 ' :
2021-07-20 14:56:49 +02:00
# don't remove "merge files" (*.mine, *.new...)
2010-08-24 18:06:47 +02:00
# that's why we don't use clear_from_conflictlist
self . in_conflict . remove ( n )
self . write_conflictlist ( )
2022-09-12 14:15:34 +02:00
if state not 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 ) :
2022-09-12 13:43:10 +02:00
try :
os . unlink ( os . path . join ( self . storedir , n ) )
except :
pass
2007-03-19 14:30:59 +01:00
2006-05-30 12:07:16 +02:00
def delete_localfile ( self , n ) :
2022-09-12 13:43:10 +02:00
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 ' )
2021-07-20 14:56:49 +02:00
upfilename = os . path . join ( self . dir , n + ' .new ' )
2006-05-22 16:12:06 +02:00
2006-06-08 12:30:29 +02:00
try :
os . unlink ( myfilename )
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
2014-01-09 13:56:34 +01:00
def put_source_file ( self , n , tdir , copy_only = False ) :
query = ' rev=repository '
tfilename = os . path . join ( tdir , n )
shutil . copyfile ( os . path . join ( self . dir , n ) , tfilename )
# 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 )
2022-09-12 13:43:10 +02:00
http_PUT ( u , file = tfilename )
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
2014-01-09 13:56:34 +01:00
def __commit_update_store ( self , tdir ) :
""" move files from transaction directory into the store """
for filename in os . listdir ( tdir ) :
os . rename ( os . path . join ( tdir , filename ) , os . path . join ( self . storedir , filename ) )
2010-09-03 17:46:01 +02:00
def __generate_commitlist ( self , todo_send ) :
root = ET . Element ( ' directory ' )
2013-04-09 11:25:19 +02:00
for i in sorted ( todo_send . keys ( ) ) :
2010-09-03 17:46:01 +02:00
ET . SubElement ( root , ' entry ' , name = i , md5 = todo_send [ i ] )
return root
2016-02-05 17:16:42 +01:00
@staticmethod
2022-10-21 10:38:57 +02:00
def commit_filelist ( apiurl : str , project : str , package : str , filelist , msg = " " , user = None , * * query ) :
2010-09-03 17:46:01 +02:00
""" send the commitlog and the local filelist to the server """
2016-02-05 17:16:42 +01:00
if user is None :
user = conf . get_apiurl_usr ( apiurl )
query . update ( { ' cmd ' : ' commitfilelist ' , ' user ' : user , ' comment ' : msg } )
u = makeurl ( apiurl , [ ' source ' , project , package ] , query = query )
f = http_POST ( u , data = ET . tostring ( filelist , encoding = ET_ENCODING ) )
2010-09-03 17:46:01 +02:00
root = ET . parse ( f ) . getroot ( )
return root
2016-02-05 17:16:42 +01:00
@staticmethod
def commit_get_missing ( filelist ) :
""" returns list of missing files (filelist is the result of commit_filelist) """
error = filelist . get ( ' error ' )
2010-09-03 17:46:01 +02:00
if error is None :
return [ ]
elif error != ' missing ' :
2016-02-05 17:16:42 +01:00
raise oscerr . APIError ( ' commit_get_missing_files: '
2022-09-12 13:43:10 +02:00
' unexpected \' error \' attr: \' %s \' ' % error )
2010-09-03 17:46:01 +02:00
todo = [ ]
2016-02-05 17:16:42 +01:00
for n in filelist . findall ( ' entry ' ) :
2010-09-03 17:46:01 +02:00
name = n . get ( ' name ' )
if name is None :
2016-02-05 17:16:42 +01:00
raise oscerr . APIError ( ' missing \' name \' attribute: \n %s \n '
2022-09-12 13:43:10 +02:00
% ET . tostring ( filelist , encoding = ET_ENCODING ) )
2010-09-03 17:46:01 +02:00
todo . append ( n . get ( ' name ' ) )
return todo
2017-11-27 16:11:32 +01:00
def __send_commitlog ( self , msg , local_filelist , validate = False ) :
2016-02-05 17:16:42 +01:00
""" send the commitlog and the local filelist to the server """
query = { }
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 '
2017-11-27 16:11:32 +01:00
if validate :
query [ ' withvalidate ' ] = ' 1 '
2016-02-05 17:16:42 +01:00
return self . commit_filelist ( self . apiurl , self . prjname , self . name ,
local_filelist , msg , * * query )
2015-04-29 13:43:23 +02:00
def commit ( self , msg = ' ' , verbose = False , skip_local_service_run = False , can_branch = False , force = 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
2011-05-25 13:34:32 +02:00
if not skip_local_service_run :
r = self . run_source_services ( mode = " trylocal " , verbose = verbose )
Use html.escape instead removed cgi.escape
Fixes:
`Traceback (most recent call last):
File "/usr/bin/osc", line 41, in <module>
r = babysitter.run(osccli)
File "/usr/lib/python3.8/site-packages/osc/babysitter.py", line 64, in run
return prg.main(argv)
File "/usr/lib/python3.8/site-packages/osc/cmdln.py", line 344, in main
return self.cmd(args)
File "/usr/lib/python3.8/site-packages/osc/cmdln.py", line 367, in cmd
retval = self.onecmd(argv)
File "/usr/lib/python3.8/site-packages/osc/cmdln.py", line 501, in onecmd
return self._dispatch_cmd(handler, argv)
File "/usr/lib/python3.8/site-packages/osc/cmdln.py", line 1232, in _dispatch_cmd
return handler(argv[0], opts, *args)
File "/usr/lib/python3.8/site-packages/osc/commandline.py", line 1458, in do_submitrequest
result = create_submit_request(apiurl,
File "/usr/lib/python3.8/site-packages/osc/core.py", line 4244, in create_submit_request
cgi.escape(message))
AttributeError: module 'cgi' has no attribute 'escape'
`
`cgi.escape` was deprecated in python 3.2
2020-03-11 16:33:20 +01:00
if r != 0 :
2013-08-29 15:22:25 +02:00
# FIXME: it is better to raise this in Serviceinfo.execute with more
# information (like which service/command failed)
raise oscerr . ServiceRuntimeError ( ' A service failed with error: %d ' % r )
2011-05-25 13:34:32 +02:00
2014-02-24 16:02:47 +01:00
# check if it is a link, if so, branch the package
2014-02-25 16:51:39 +01:00
if self . is_link_to_different_project ( ) :
if can_branch :
orgprj = self . get_local_origin_project ( )
2022-07-28 19:11:29 +02:00
print ( f " Branching { self . name } from { orgprj } to { self . prjname } " )
2014-02-25 16:51:39 +01:00
exists , targetprj , targetpkg , srcprj , srcpkg = branch_pkg (
self . apiurl , orgprj , self . name , target_project = self . prjname )
2014-02-24 16:02:47 +01:00
# update _meta and _files to sychronize the local package
# to the new branched one in OBS
self . update_local_pacmeta ( )
self . update_local_filesmeta ( )
else :
2022-07-28 19:11:29 +02:00
print ( f " { self . name } Not commited because is link to a different project " )
2014-02-24 16:02:47 +01:00
return 1
2007-07-30 13:12:42 +02:00
if not self . todo :
2022-09-12 14:15:34 +02:00
self . todo = [ i for i in self . to_be_added if i not 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 = [ ]
2017-11-27 16:11:32 +01:00
sha256sums = { }
2022-09-12 14:15:34 +02:00
for filename in self . filenamelist + [ i for i in self . to_be_added if i not in self . filenamelist ] :
2010-09-03 17:46:01 +02:00
if filename . startswith ( ' _service: ' ) or filename . startswith ( ' _service_ ' ) :
continue
st = self . status ( filename )
if st == ' C ' :
2013-04-09 12:51:28 +02:00
print ( ' Please resolve all conflicts before committing using " osc resolved FILE " ! ' )
2010-09-03 17:46:01 +02:00
return 1
elif filename in self . todo :
if st in ( ' A ' , ' R ' , ' M ' ) :
todo_send [ filename ] = dgst ( os . path . join ( self . absdir , filename ) )
2017-11-27 16:11:32 +01:00
sha256sums [ filename ] = sha256_dgst ( os . path . join ( self . absdir , filename ) )
2010-09-03 17:46:01 +02:00
real_send . append ( filename )
2013-04-09 12:51:28 +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 :
2013-04-09 12:51:28 +02:00
print ( ' file \' %s \' is marked as \' A \' but does not exist ' % filename )
2010-12-17 23:25:50 +01:00
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 ,
2022-09-12 13:43:10 +02:00
' error: file \' %s \' with state \' %s \' is not known by meta '
% ( filename , st ) )
2010-09-03 17:46:01 +02:00
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 )
2013-04-09 12:51:28 +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 ,
2022-09-12 13:43:10 +02:00
' error: file \' %s \' with state \' %s \' is not known by meta '
% ( filename , st ) )
2010-09-03 17:46:01 +02:00
todo_send [ filename ] = f . md5
2021-07-02 23:20:16 +02:00
if ( ( self . ispulled ( ) or self . islinkrepair ( ) or self . isfrozen ( ) )
2022-09-12 13:43:10 +02:00
and st != ' A ' and filename not in sha256sums ) :
2017-12-03 14:44:01 +01:00
# Ignore files with state 'A': if we should consider it,
# it would have been in pac.todo, which implies that it is
# in sha256sums.
# The storefile is guaranteed to exist (since we have a
# pulled/linkrepair wc, the file cannot have state 'S')
storefile = os . path . join ( self . storedir , filename )
sha256sums [ filename ] = sha256_dgst ( storefile )
2010-09-03 17:46:01 +02:00
2015-04-29 13:43:23 +02:00
if not force and not real_send and not todo_delete and not self . islinkrepair ( ) and not self . ispulled ( ) :
2013-04-09 12:51:28 +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
2013-04-09 12:51:28 +02:00
print ( ' Transmitting file data ' , end = ' ' )
2010-09-03 17:46:01 +02:00
filelist = self . __generate_commitlist ( todo_send )
2017-11-27 16:11:32 +01:00
sfilelist = self . __send_commitlog ( msg , filelist , validate = True )
2022-05-20 12:00:44 +02:00
hash_entries = [ e for e in sfilelist . findall ( ' entry ' ) if e . get ( ' hash ' ) is not None ]
2018-02-23 11:55:14 +01:00
if sfilelist . get ( ' error ' ) and hash_entries :
2022-07-28 19:11:29 +02:00
name2elem = { e . get ( ' name ' ) : e for e in filelist . findall ( ' entry ' ) }
2018-02-23 11:55:14 +01:00
for entry in hash_entries :
2017-11-27 16:11:32 +01:00
filename = entry . get ( ' name ' )
fileelem = name2elem . get ( filename )
if filename not in sha256sums :
msg = ' There is no sha256 sum for file %s . \n ' \
' This could be due to an outdated working copy. \n ' \
' Please update your working copy with osc update and \n ' \
' commit again afterwards. '
print ( msg % filename )
return 1
fileelem . set ( ' hash ' , ' sha256: %s ' % sha256sums [ filename ] )
sfilelist = self . __send_commitlog ( msg , filelist )
2016-02-05 17:16:42 +01:00
send = self . commit_get_missing ( sfilelist )
2022-09-12 14:15:34 +02:00
real_send = [ i for i in real_send if i not in send ]
2010-09-03 17:46:01 +02:00
# abort after 3 tries
tries = 3
2014-01-09 13:56:34 +01:00
tdir = None
try :
tdir = os . path . join ( self . storedir , ' _in_commit ' )
if os . path . isdir ( tdir ) :
shutil . rmtree ( tdir )
os . mkdir ( tdir )
2022-08-29 13:23:29 +02:00
while send and tries :
2014-01-09 13:56:34 +01:00
for filename in send [ : ] :
sys . stdout . write ( ' . ' )
sys . stdout . flush ( )
self . put_source_file ( filename , tdir )
send . remove ( filename )
tries - = 1
sfilelist = self . __send_commitlog ( msg , filelist )
2016-02-05 17:16:42 +01:00
send = self . commit_get_missing ( sfilelist )
2022-08-29 13:23:29 +02:00
if send :
2014-01-09 13:56:34 +01:00
raise oscerr . PackageInternalError ( self . prjname , self . name ,
2022-09-12 13:43:10 +02:00
' server does not accept filelist: \n %s \n missing: \n %s \n '
% ( ET . tostring ( filelist , encoding = ET_ENCODING ) , ET . tostring ( sfilelist , encoding = ET_ENCODING ) ) )
2014-01-09 13:56:34 +01:00
# these files already exist on the server
for filename in real_send :
self . put_source_file ( filename , tdir , copy_only = True )
# update store with the committed files
self . __commit_update_store ( tdir )
finally :
if tdir is not None and os . path . isdir ( tdir ) :
shutil . rmtree ( tdir )
2010-09-03 17:46:01 +02:00
self . rev = sfilelist . get ( ' rev ' )
2013-04-09 12:51:28 +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?
2013-04-09 12:51:28 +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 :
2013-04-10 11:34:59 +02:00
raise oscerr . APIError ( ' linkinfo has no xsrcmd5 attr: \n %s \n ' % ET . tostring ( sfilelist , encoding = ET_ENCODING ) )
2010-09-03 17:46:01 +02:00
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 ' )
2013-04-10 11:34:59 +02:00
store_write_string ( self . absdir , ' _files ' , ET . tostring ( sfilelist , encoding = ET_ENCODING ) + ' \n ' )
2010-09-03 17:46:01 +02:00
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
2011-10-07 14:13:14 +02:00
# FIXME: add testcases for this codepath
sinfo = sfilelist . find ( ' serviceinfo ' )
if sinfo is not None :
2013-04-09 12:51:28 +02:00
print ( ' Waiting for server side source service run ' )
2011-10-07 14:13:14 +02:00
u = makeurl ( self . apiurl , [ ' source ' , self . prjname , self . name ] )
while sinfo is not None and sinfo . get ( ' code ' ) == ' running ' :
sys . stdout . write ( ' . ' )
sys . stdout . flush ( )
# does it make sense to add some delay?
sfilelist = ET . fromstring ( http_GET ( u ) . read ( ) )
# if sinfo is None another commit might have occured in the "meantime"
sinfo = sfilelist . find ( ' serviceinfo ' )
2013-04-09 12:51:28 +02:00
print ( ' ' )
2013-05-27 14:56:24 +02:00
rev = self . latest_rev ( )
2011-10-07 14:13:14 +02:00
self . update ( rev = rev )
2014-03-06 10:24:49 +01:00
elif self . get_local_meta ( ) is None :
# if this was a newly added package there is no _meta
# file
self . update_local_pacmeta ( )
2011-05-03 16:44:20 +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 ,
2022-09-12 13:43:10 +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 )
2013-09-23 17:11:52 +02:00
if mtime :
2014-01-09 14:15:30 +01:00
utime ( filename , ( - 1 , mtime ) )
2022-09-12 14:23:47 +02:00
if origfile is not None :
2010-08-19 18:10:32 +02:00
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 ' )
2021-07-20 14:56:49 +02:00
upfilename = os . path . join ( self . dir , n + ' .new ' )
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
2017-09-28 11:58:51 +02:00
ret = - 1
with open ( filename , ' w ' ) as f :
2019-09-20 21:53:23 +02:00
args = ( ' -m ' , ' -E ' , myfilename , storefilename , upfilename )
ret = run_external ( ' diff3 ' , * args , stdout = f )
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 :
2019-09-20 21:53:23 +02:00
merge_cmd = ' diff3 ' + ' ' . join ( args )
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 \
2022-09-12 13:43:10 +02:00
or skip_service and ( e . get ( ' name ' ) . startswith ( ' _service: ' ) or e . get ( ' name ' ) . startswith ( ' _service_ ' ) ) :
2010-09-03 14:51:20 +02:00
e . set ( ' skipped ' , ' true ' )
2013-04-10 11:34:59 +02:00
return ET . tostring ( root , encoding = ET_ENCODING )
2010-09-03 14:51:20 +02:00
2014-02-24 16:02:47 +01:00
def get_local_meta ( self ) :
""" Get the local _meta file for the package. """
meta = store_read_file ( self . absdir , ' _meta ' )
return meta
def get_local_origin_project ( self ) :
""" Get the originproject from the _meta file. """
2014-03-06 09:56:13 +01:00
# if the wc was checked out via some old osc version
# there might be no meta file: in this case we assume
# that the origin project is equal to the wc's project
meta = self . get_local_meta ( )
if meta is None :
2014-03-06 10:24:49 +01:00
return self . prjname
2014-03-06 09:56:13 +01:00
root = ET . fromstring ( meta )
2014-02-24 16:02:47 +01:00
return root . get ( ' project ' )
2014-02-25 16:51:39 +01:00
def is_link_to_different_project ( self ) :
""" Check if the package is a link to a different project. """
2016-05-31 09:26:28 +02:00
if self . name == " _project " :
return False
2014-02-25 16:51:39 +01:00
orgprj = self . get_local_origin_project ( )
return self . prjname != orgprj
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 ) .
"""
2021-11-30 13:13:11 +01:00
if self . scm_url :
self . filenamelist = [ ]
self . filelist = [ ]
self . skipped = [ ]
self . to_be_added = [ ]
self . to_be_deleted = [ ]
self . in_conflict = [ ]
self . linkrepair = None
self . rev = None
self . srcmd5 = None
self . linkinfo = None
self . serviceinfo = None
2022-07-26 13:13:37 +02:00
self . size_limit = None
self . meta = None
self . excluded = [ ]
self . filenamelist_unvers = [ ]
2021-11-30 13:13:11 +01:00
return
2007-07-30 13:12:42 +02:00
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 ' ) )
2014-06-22 15:41:14 +02:00
self . serviceinfo = DirectoryServiceinfo ( )
self . serviceinfo . read ( files_tree_root . find ( ' serviceinfo ' ) )
2007-07-30 13:12:42 +02:00
self . filenamelist = [ ]
self . filelist = [ ]
2010-04-22 15:27:54 +02:00
self . skipped = [ ]
2021-11-30 13:13:11 +01:00
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
2022-09-12 13:43:10 +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 ]
2007-07-30 13:12:42 +02:00
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 .
2022-01-24 08:57:53 +01:00
Returns ` ` True ` ` if the package is a link , otherwise ` ` False ` ` . """
2008-03-22 14:37:59 +01:00
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.
2022-01-24 08:57:53 +01:00
Returns ` ` True ` ` if the package is expanded , otherwise ` ` False ` ` . """
2008-03-22 18:37:17 +01:00
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
2022-07-28 19:11:29 +02:00
for line in open ( os . path . join ( self . storedir , ' _pulled ' ) ) :
2010-01-12 17:22:47 +01:00
pulledrev = line . strip ( )
return pulledrev
2009-04-06 22:08:14 +02:00
def haslinkerror ( self ) :
"""
2022-01-24 08:57:53 +01:00
Returns ` ` True ` ` if the link is broken otherwise ` ` False ` ` .
If the package is not a link it returns ` ` False ` ` .
2009-04-06 22:08:14 +02:00
"""
return self . linkinfo . haserror ( )
def linkerror ( self ) :
"""
2022-01-24 08:57:53 +01:00
Returns an error message if the link is broken otherwise ` ` None ` ` .
If the package is not a link it returns ` ` None ` ` .
2009-04-06 22:08:14 +02:00
"""
return self . linkinfo . error
2014-06-22 15:41:14 +02:00
def hasserviceinfo ( self ) :
"""
2022-01-24 08:57:53 +01:00
Returns ` ` True ` ` , if this package contains services .
2014-06-22 15:41:14 +02:00
"""
return self . serviceinfo . lsrcmd5 is not None or self . serviceinfo . xsrcmd5 is not None
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 .
"""
2014-04-16 15:47:58 +02:00
meta = show_package_meta ( self . apiurl , self . prjname , self . name )
if meta != " " :
2014-04-16 15:56:59 +02:00
# is empty for _project for example
2018-12-13 15:14:06 +01:00
meta = b ' ' . join ( meta )
store_write_string ( self . absdir , ' _meta ' , meta + b ' \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 )
2022-09-12 14:15:34 +02:00
if st not in exclude_states :
2010-12-22 23:17:11 +01:00
res . append ( ( st , fname ) )
return res
2006-05-19 22:13:29 +02:00
def status ( self , n ) :
"""
2022-01-24 08:57:53 +01:00
status can be : :
file storefile file present STATUS
exists exists in _files
x - - ' A ' and listed in _to_be_added
x x - ' R ' and listed in _to_be_added
x x x ' ' if digest differs : ' M '
and if in conflicts file : ' C '
x - - ' ? '
- 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
x - x ' S ' and listed in self . skipped
- - x ' S ' and listed in self . skipped
- x x ' ! '
- - - NOT DEFINED
2006-05-19 22:13:29 +02:00
"""
known_by_meta = False
exists = False
exists_in_store = False
2017-07-24 21:53:10 +02:00
localfile = os . path . join ( self . absdir , n )
2006-05-19 22:13:29 +02:00
if n in self . filenamelist :
known_by_meta = True
2017-07-24 21:53:10 +02:00
if os . path . exists ( localfile ) :
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 :
2017-07-24 22:03:21 +02:00
filemeta = self . findfilebyname ( n )
2017-08-15 13:31:10 +02:00
state = ' '
if conf . config [ ' status_mtime_heuristic ' ] :
2017-08-17 06:29:20 +02:00
if os . path . getmtime ( localfile ) != filemeta . mtime and dgst ( localfile ) != filemeta . md5 :
2017-08-15 13:31:10 +02:00
state = ' M '
elif dgst ( localfile ) != filemeta . md5 :
2006-05-19 22:13:29 +02:00
state = ' M '
2010-08-26 13:46:10 +02:00
elif n in self . to_be_added and not exists :
state = ' ! '
2022-09-12 14:15:34 +02:00
elif not exists and exists_in_store and known_by_meta and n not in self . to_be_deleted :
2010-08-19 18:10:32 +02:00
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 ,
2022-09-12 13:43:10 +02:00
' 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 '
' .osc/ dir) into the new package wc. ' % n )
2017-07-24 21:53:10 +02:00
elif os . path . islink ( localfile ) :
2016-02-07 22:58:23 +01:00
# dangling symlink, whose name is _not_ tracked: treat it
# as unversioned
state = ' ? '
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 ) :
2019-07-17 10:34:20 +02:00
diff_hdr = b ' Index: %s \n '
diff_hdr + = b ' =================================================================== \n '
2010-08-27 16:24:12 +02:00
kept = [ ]
added = [ ]
deleted = [ ]
2022-09-12 13:43:10 +02:00
2010-08-27 16:24:12 +02:00
def diff_add_delete ( fname , add , revision ) :
diff = [ ]
2019-07-17 10:34:20 +02:00
diff . append ( diff_hdr % fname . encode ( ) )
2010-08-31 11:20:34 +02:00
origname = fname
2010-08-27 16:24:12 +02:00
if add :
2019-07-17 10:34:20 +02:00
diff . append ( b ' --- %s \t (revision 0) \n ' % fname . encode ( ) )
2010-08-27 16:24:12 +02:00
rev = ' revision 0 '
2022-09-12 14:15:34 +02:00
if revision and fname not in self . to_be_added :
2010-08-27 16:24:12 +02:00
rev = ' working copy '
2019-07-17 10:34:20 +02:00
diff . append ( b ' +++ %s \t ( %s ) \n ' % ( fname . encode ( ) , rev . encode ( ) ) )
2010-08-27 16:24:12 +02:00
fname = os . path . join ( self . absdir , fname )
2022-04-27 13:38:45 +02:00
if not os . path . isfile ( 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
else :
2019-07-17 10:34:20 +02:00
if revision :
b_revision = str ( revision ) . encode ( )
else :
b_revision = self . rev . encode ( )
diff . append ( b ' --- %s \t (revision %s ) \n ' % ( fname . encode ( ) , b_revision ) )
diff . append ( b ' +++ %s \t (working copy) \n ' % fname . encode ( ) )
2010-08-27 16:24:12 +02:00
fname = os . path . join ( self . storedir , fname )
2022-08-29 15:39:02 +02:00
2023-01-20 13:43:14 +01:00
fd = None
tmpfile = None
2010-08-27 16:24:12 +02:00
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 ) :
2019-07-17 10:34:20 +02:00
what = b ' added '
2010-08-31 11:20:34 +02:00
if not add :
2019-07-17 10:34:20 +02:00
what = b ' deleted '
2010-08-31 11:20:34 +02:00
diff = diff [ : 1 ]
2019-07-17 10:34:20 +02:00
diff . append ( b ' Binary file \' %s \' %s . \n ' % ( origname . encode ( ) , what ) )
2010-08-31 11:20:34 +02:00
return diff
2019-07-17 10:34:20 +02:00
tmpl = b ' + %s '
ltmpl = b ' @@ -0,0 +1, %d @@ \n '
2010-08-27 16:24:12 +02:00
if not add :
2019-07-17 10:34:20 +02:00
tmpl = b ' - %s '
ltmpl = b ' @@ -1, %d +0,0 @@ \n '
2022-08-24 08:43:09 +02:00
with open ( fname , ' rb ' ) as f :
lines = [ tmpl % i for i in f . readlines ( ) ]
2010-08-27 16:24:12 +02:00
if len ( lines ) :
diff . append ( ltmpl % len ( lines ) )
2019-07-17 10:34:20 +02:00
if not lines [ - 1 ] . endswith ( b ' \n ' ) :
lines . append ( b ' \n \\ No newline at end of file \n ' )
2010-08-27 16:24:12 +02:00
diff . extend ( lines )
finally :
2023-01-20 13:43:14 +01:00
if fd is not None :
2010-08-27 16:24:12 +02:00
os . close ( fd )
2023-01-20 13:43:14 +01:00
if tmpfile is not None and os . path . exists ( tmpfile ) :
2010-08-27 16:24:12 +02:00
os . unlink ( tmpfile )
return diff
if revision is None :
2022-09-12 14:15:34 +02:00
todo = self . todo or [ i for i in self . filenamelist if i not 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 ) == ' ! ' :
2022-09-12 13:43:10 +02:00
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 ]
2022-09-12 14:15:34 +02:00
added . extend ( [ f for f in self . to_be_added if f not in kept ] )
2010-08-27 16:24:12 +02:00
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
2019-07-17 10:34:20 +02:00
yield [ diff_hdr % f . name . encode ( ) ]
2010-08-27 16:24:12 +02:00
if revision is None :
yield get_source_file_diff ( self . absdir , f . name , self . rev )
else :
2023-01-20 13:43:14 +01:00
fd = None
2010-08-27 16:24:12 +02:00
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 ,
2022-09-12 13:43:10 +02:00
os . path . basename ( tmpfile ) , os . path . dirname ( tmpfile ) , f . name )
2010-08-27 16:24:12 +02:00
finally :
2023-01-20 13:43:14 +01:00
if fd is not None :
2010-08-27 16:24:12 +02:00
os . close ( fd )
2023-01-20 13:43:14 +01:00
if tmpfile is not None and os . path . exists ( tmpfile ) :
2010-08-27 16:24:12 +02:00
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 ) :
2023-01-26 10:11:54 +01:00
for todo_entry in otherpac . todo :
if todo_entry not in self . todo :
self . todo . append ( todo_entry )
2006-05-19 22:13:29 +02:00
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,
2022-09-12 13:43:10 +02:00
self . prjname ,
self . dir ,
' \n ' . join ( self . filenamelist ) ,
self . linkinfo ,
self . rev ,
self . todo )
2006-05-19 22:13:29 +02:00
return r
2022-09-12 13:43:10 +02:00
def read_meta_from_spec ( self , spec = None ) :
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 :
2013-04-09 12:51:28 +02:00
print ( ' the following specfiles were found: ' )
2010-08-20 14:34:41 +02:00
for filename in speclist :
2013-04-09 12:51:28 +02:00
print ( filename )
print ( ' please specify one with --specfile ' )
2007-07-04 15:48:24 +02:00
sys . exit ( 1 )
else :
2022-09-12 13:43:10 +02:00
print ( ' no specfile was found - please specify one '
2013-04-09 12:51:28 +02:00
' 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
2018-12-13 15:14:06 +01:00
m = b ' ' . 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 ' )
2022-08-29 12:56:57 +02:00
if url is 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
2022-09-12 13:43:10 +02:00
def delegate ( force = False ) : return make_meta_url ( ' pkg ' ,
( self . prjname , self . name ) ,
self . apiurl , force = force )
2021-08-25 13:55:21 +02:00
url_factory = metafile . _URLFactory ( delegate )
mf = metafile ( url_factory , ET . tostring ( root , encoding = ET_ENCODING ) )
2006-05-31 14:13:26 +02:00
2009-07-10 16:20:02 +02:00
if not force :
2013-04-09 12:51:28 +02:00
print ( ' * ' * 36 , ' old ' , ' * ' * 36 )
2018-12-13 15:14:06 +01:00
print ( decode_it ( m ) )
2013-04-09 12:51:28 +02:00
print ( ' * ' * 36 , ' new ' , ' * ' * 36 )
2013-04-10 11:34:59 +02:00
print ( ET . tostring ( root , encoding = ET_ENCODING ) )
2013-04-09 12:51:28 +02:00
print ( ' * ' * 72 )
2009-07-10 16:20:02 +02:00
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 ' , ' ' )
2013-04-09 12:51:28 +02:00
print ( )
2014-11-21 16:00:07 +01:00
print ( " The link in this package ( \" %s \" ) is currently broken. Checking " % self . name )
2013-04-09 12:51:28 +02:00
print ( " out the last working version instead; please use ' osc pull ' " )
print ( " to merge the conflicts. " )
print ( )
2010-01-20 17:55:44 +01:00
def unmark_frozen ( self ) :
if os . path . exists ( os . path . join ( self . storedir , ' _frozenlink ' ) ) :
os . unlink ( os . path . join ( self . storedir , ' _frozenlink ' ) )
2012-03-28 23:14:28 +02:00
def latest_rev ( self , include_service_files = False , expand = False ) :
# if expand is True the xsrcmd5 will be returned (even if the wc is unexpanded)
2009-04-21 18:52:26 +02:00
if self . islinkrepair ( ) :
2011-05-23 15:26:13 +02:00
upstream_rev = show_upstream_xsrcmd5 ( self . apiurl , self . prjname , self . name , linkrepair = 1 , meta = self . meta , include_service_files = include_service_files )
2012-03-28 23:14:28 +02:00
elif self . islink ( ) and ( self . isexpanded ( ) or expand ) :
2010-01-12 17:22:47 +01:00
if self . isfrozen ( ) or self . ispulled ( ) :
2011-05-23 15:26:13 +02:00
upstream_rev = show_upstream_xsrcmd5 ( self . apiurl , self . prjname , self . name , linkrev = self . linkinfo . srcmd5 , meta = self . meta , include_service_files = include_service_files )
2009-12-17 20:20:35 +01:00
else :
2010-01-12 17:22:47 +01:00
try :
2011-05-23 15:26:13 +02:00
upstream_rev = show_upstream_xsrcmd5 ( self . apiurl , self . prjname , self . name , meta = self . meta , include_service_files = include_service_files )
2010-01-12 17:22:47 +01:00
except :
2010-01-20 17:55:44 +01:00
try :
2011-05-23 15:26:13 +02:00
upstream_rev = show_upstream_xsrcmd5 ( self . apiurl , self . prjname , self . name , linkrev = self . linkinfo . srcmd5 , meta = self . meta , include_service_files = include_service_files )
2010-01-20 17:55:44 +01:00
except :
2011-05-23 15:26:13 +02:00
upstream_rev = show_upstream_xsrcmd5 ( self . apiurl , self . prjname , self . name , linkrev = " base " , meta = self . meta , include_service_files = include_service_files )
2010-07-23 16:17:39 +02:00
self . mark_frozen ( )
2016-02-08 17:24:35 +01:00
elif not self . islink ( ) and expand :
upstream_rev = show_upstream_xsrcmd5 ( self . apiurl , self . prjname , self . name , meta = self . meta , include_service_files = include_service_files )
2009-04-21 18:52:26 +02:00
else :
2011-05-23 15:26:13 +02:00
upstream_rev = show_upstream_rev ( self . apiurl , self . prjname , self . name , meta = self . meta , include_service_files = include_service_files )
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 :
2013-04-10 11:34:59 +02:00
raise oscerr . APIError ( ' missing rev attribute in _files: \n %s ' % ' ' . join ( ET . tostring ( fmeta_root , encoding = ET_ENCODING ) ) )
2010-08-23 11:48:33 +02:00
for i in fmeta_root . findall ( ' entry ' ) :
2015-09-07 19:28:56 +02:00
error = i . get ( ' error ' )
if error is not None :
raise oscerr . APIError ( ' broken files meta: %s ' % error )
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)
2022-09-12 14:15:34 +02:00
if f . name in self . filenamelist and f . name not in self . skipped :
2010-08-19 18:10:32 +02:00
kept . append ( f )
else :
added . append ( f )
for f in self . filelist :
2022-09-12 14:15:34 +02:00
if f . name not in revfilenames :
2010-08-19 18:10:32 +02:00
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
2014-06-22 15:41:14 +02:00
def update_needed ( self , sinfo ) :
# this method might return a false-positive (that is a True is returned,
# even though no update is needed) (for details, see comments below)
if self . islink ( ) :
if self . isexpanded ( ) :
# check if both revs point to the same expanded sources
# Note: if the package contains a _service file, sinfo.srcmd5's lsrcmd5
# points to the "expanded" services (xservicemd5) => chances
# for a false-positive are high, because osc usually works on the
# "unexpanded" services.
# Once the srcserver supports something like noservice=1, we can get rid of
# this false-positives (patch was already sent to the ml) (but this also
# requires some slight changes in osc)
return sinfo . get ( ' srcmd5 ' ) != self . srcmd5
2014-08-12 15:01:16 +02:00
elif self . hasserviceinfo ( ) :
2014-06-22 15:41:14 +02:00
# check if we have expanded or unexpanded services
if self . serviceinfo . isexpanded ( ) :
return sinfo . get ( ' lsrcmd5 ' ) != self . srcmd5
else :
# again, we might have a false-positive here, because
# a mismatch of the "xservicemd5"s does not neccessarily
# imply a change in the "unexpanded" services.
return sinfo . get ( ' lsrcmd5 ' ) != self . serviceinfo . xsrcmd5
# simple case: unexpanded sources and no services
# self.srcmd5 should also work
return sinfo . get ( ' lsrcmd5 ' ) != self . linkinfo . lsrcmd5
elif self . hasserviceinfo ( ) :
if self . serviceinfo . isexpanded ( ) :
return sinfo . get ( ' srcmd5 ' ) != self . srcmd5
else :
# cannot handle this case, because the sourceinfo does not contain
# information about the lservicemd5. Once the srcserver supports
# a noservice=1 query parameter, we can handle this case.
return True
return sinfo . get ( ' srcmd5 ' ) != self . srcmd5
2022-09-12 13:43:10 +02:00
def update ( self , rev = None , service_files = False , size_limit = None ) :
2010-08-19 18:10:32 +02:00
rfiles = [ ]
2010-09-03 14:51:20 +02:00
# size_limit is only temporary for this update
old_size_limit = self . size_limit
2022-09-12 14:23:47 +02:00
if size_limit is not 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 ' ) ) :
2013-04-09 12:51:28 +02:00
print ( ' resuming broken update... ' )
2010-08-19 18:10:32 +02:00
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 ,
2022-09-12 13:43:10 +02:00
' \' %s \' is not known by meta but exists in \' _in_update \' dir ' )
2010-08-19 18:10:32 +02:00
elif os . path . isfile ( wcfile ) and dgst ( wcfile ) != origfile_md5 :
2022-09-12 13:43:10 +02:00
( fd , tmpfile ) = tempfile . mkstemp ( dir = self . absdir , prefix = broken_file [ 0 ] + ' . ' )
2010-08-19 18:10:32 +02:00
os . close ( fd )
os . rename ( wcfile , tmpfile )
os . rename ( origfile , wcfile )
2022-09-12 13:43:10 +02:00
print ( ' warning: it seems you modified \' %s \' after the broken '
' update. Restored original file and saved modified version '
2013-04-09 12:51:28 +02:00
' to \' %s \' . ' % ( wcfile , tmpfile ) )
2010-08-19 18:10:32 +02:00
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 = [ ]
2013-04-10 11:34:59 +02:00
self . __update ( kept , added , deleted , services , ET . tostring ( root , encoding = ET_ENCODING ) , 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 ,
2022-09-12 13:43:10 +02:00
' failed to add file \' %s \' file/dir with the same name already exists ' % f . name )
2010-08-19 18:10:32 +02:00
# ok, the update can't fail due to existing files
for f in added :
self . updatefile ( f . name , rev , f . mtime )
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' A ' , os . path . join ( pathn , f . name ) ) )
2010-08-19 18:10:32 +02:00
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)
2017-03-20 19:20:59 +01:00
if os . path . isfile ( os . path . join ( self . storedir , f . name ) ) and self . status ( f . name ) not in ( ' M ' , ' C ' ) :
2022-04-20 19:22:35 +02:00
# if self.status(f.name) != 'M':
2010-08-19 18:10:32 +02:00
self . delete_localfile ( f . name )
self . delete_storefile ( f . name )
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' D ' , os . path . join ( pathn , f . name ) ) )
2010-08-19 18:10:32 +02:00
if f . name in self . to_be_deleted :
self . to_be_deleted . remove ( f . name )
self . write_deletelist ( )
2017-03-20 19:20:59 +01:00
elif f . name in self . in_conflict :
self . in_conflict . remove ( f . name )
self . write_conflictlist ( )
2010-08-19 18:10:32 +02:00
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 )
2013-04-09 12:51:28 +02:00
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 )
2013-04-09 12:51:28 +02:00
print ( ' Restored \' %s \' ' % os . path . join ( pathn , f . name ) )
2010-08-19 18:10:32 +02:00
elif state == ' C ' :
get_source_file ( self . apiurl , self . prjname , self . name , f . name ,
2022-09-12 13:43:10 +02:00
targetfilename = os . path . join ( self . storedir , f . name ) , revision = rev ,
progress_obj = self . progress_obj , mtime = f . mtime , meta = self . meta )
2013-04-09 12:51:28 +02:00
print ( ' skipping \' %s \' (this is due to conflicts) ' % f . name )
2010-08-19 18:10:32 +02:00
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 )
2013-04-09 12:51:28 +02:00
print ( statfrmt ( merge_status , os . path . join ( pathn , f . name ) ) )
2010-08-19 18:10:32 +02:00
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 )
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' U ' , os . path . join ( pathn , f . name ) ) )
2010-08-19 18:10:32 +02:00
elif state == ' ' and self . findfilebyname ( f . name ) . md5 != f . md5 :
self . updatefile ( f . name , rev , f . mtime )
2013-04-09 12:51:28 +02:00
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 ,
2022-09-12 13:43:10 +02:00
targetfilename = os . path . join ( self . absdir , f . name ) , revision = rev ,
progress_obj = self . progress_obj , mtime = f . mtime , meta = self . meta )
2013-04-09 12:51:28 +02:00
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
2013-04-09 12:51:28 +02:00
print ( ' At revision %s . ' % self . rev )
2009-08-03 15:03:24 +02:00
2011-05-25 13:34:32 +02:00
def run_source_services ( self , mode = None , singleservice = None , verbose = None ) :
2011-05-26 15:54:30 +02:00
if self . name . startswith ( " _ " ) :
return 0
2011-02-02 17:11:14 +01:00
curdir = os . getcwd ( )
2022-09-12 13:43:10 +02:00
os . chdir ( self . absdir ) # e.g. /usr/lib/obs/service/verify_file fails if not inside the project dir.
2011-02-15 09:41:03 +01:00
si = Serviceinfo ( )
2011-08-24 12:06:07 +02:00
if os . path . exists ( ' _service ' ) :
if self . filenamelist . count ( ' _service ' ) or self . filenamelist_unvers . count ( ' _service ' ) :
2015-05-13 14:35:17 +02:00
try :
service = ET . parse ( os . path . join ( self . absdir , ' _service ' ) ) . getroot ( )
except ET . ParseError as v :
line , column = v . position
print ( ' XML error in _service file on line %s , column %s ' % ( line , column ) )
sys . exit ( 1 )
2011-08-24 12:06:07 +02:00
si . read ( service )
2011-02-15 18:39:06 +01:00
si . getProjectGlobalServices ( self . apiurl , self . prjname , self . name )
2011-05-25 13:34:32 +02:00
r = si . execute ( self . absdir , mode , singleservice , verbose )
2011-02-02 17:11:14 +01:00
os . chdir ( curdir )
2011-05-24 10:49:08 +02:00
return r
2009-09-03 16:56:48 +02:00
2010-08-23 16:15:05 +02:00
def revert ( self , filename ) :
2022-09-12 14:15:34 +02:00
if filename not in self . filenamelist and filename not 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 :
2011-01-17 15:00:21 +01:00
raise oscerr . OscIOError ( None , ' file \' %s \' is marked as skipped and cannot be reverted ' % filename )
2010-08-24 18:06:47 +02:00
if filename in self . filenamelist and not os . path . exists ( os . path . join ( self . storedir , filename ) ) :
2023-01-20 16:02:19 +01:00
msg = f " file ' { filename } ' is listed in filenamelist but no storefile exists "
raise oscerr . PackageInternalError ( self . prjname , self . name , msg )
2010-08-23 16:15:05 +02:00
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
2022-10-21 10:38:57 +02:00
def init_package ( apiurl : str , project , package , dir , size_limit = None , meta = False , progress_obj = None , scm_url = 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 ' )
2022-10-14 15:37:24 +02:00
Store ( dir ) . apiurl = apiurl
2010-08-30 13:46:49 +02:00
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 ' )
2021-11-30 13:13:11 +01:00
if scm_url :
2022-10-14 15:39:40 +02:00
Store ( dir ) . scmurl = scm_url
2021-11-30 13:13:11 +01:00
else :
store_write_string ( dir , ' _files ' , ' <directory /> ' + ' \n ' )
2010-08-30 13:46:49 +02:00
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 :
"""
2022-01-24 08:57:53 +01:00
Base class which represents state - like objects ( ` ` < review / > ` ` , ` ` < state / > ` ` ) .
2010-12-30 02:30:37 +01:00
"""
2022-09-12 13:43:10 +02:00
2010-12-30 02:30:37 +01:00
def __init__ ( self , tag ) :
self . __tag = tag
def get_node_attrs ( self ) :
2022-01-24 08:57:53 +01:00
""" :return: attributes for the tag/element """
2010-12-30 02:30:37 +01:00
raise NotImplementedError ( )
def get_node_name ( self ) :
2022-01-24 08:57:53 +01:00
""" :return: tag/element name """
2010-12-30 02:30:37 +01:00
return self . __tag
def get_comment ( self ) :
2022-01-24 08:57:53 +01:00
""" :return: data from ``<comment />`` tag """
2010-12-30 02:30:37 +01:00
raise NotImplementedError ( )
2014-09-11 14:34:22 +02:00
def get_description ( self ) :
2022-01-24 08:57:53 +01:00
""" :return: data from ``<description />`` tag """
2014-09-11 14:34:22 +02:00
raise NotImplementedError ( )
2010-12-30 02:30:37 +01:00
def to_xml ( self ) :
2022-01-24 08:57:53 +01:00
""" :return: object serialized to XML """
2010-12-30 02:30:37 +01:00
root = ET . Element ( self . get_node_name ( ) )
for attr in self . get_node_attrs ( ) :
val = getattr ( self , attr )
2022-09-12 14:23:47 +02:00
if val is not None :
2010-12-30 02:30:37 +01:00
root . set ( attr , val )
2014-09-11 14:34:22 +02:00
if self . get_description ( ) :
ET . SubElement ( root , ' description ' ) . text = self . get_description ( )
2010-12-30 02:30:37 +01:00
if self . get_comment ( ) :
ET . SubElement ( root , ' comment ' ) . text = self . get_comment ( )
return root
def to_str ( self ) :
2022-01-24 08:57:53 +01:00
""" :return: object serialized to pretty-printed XML """
2010-12-30 02:30:37 +01:00
root = self . to_xml ( )
xmlindent ( root )
2013-04-10 11:34:59 +02:00
return ET . tostring ( root , encoding = ET_ENCODING )
2010-12-30 02:30:37 +01:00
class ReviewState ( AbstractState ) :
""" Represents the review state in a request """
2022-09-12 13:43:10 +02:00
2010-12-30 02:30:37 +01:00
def __init__ ( self , review_node ) :
if not review_node . get ( ' state ' ) :
2022-09-12 13:43:10 +02:00
raise oscerr . APIError ( ' invalid review node (state attr expected): %s ' %
ET . tostring ( review_node , encoding = ET_ENCODING ) )
2022-08-31 11:46:12 +02:00
super ( ) . __init__ ( review_node . tag )
2010-12-30 02:30:37 +01:00
self . state = review_node . get ( ' state ' )
self . by_user = review_node . get ( ' by_user ' )
self . by_group = review_node . get ( ' by_group ' )
2011-01-23 21:21:32 +01:00
self . by_project = review_node . get ( ' by_project ' )
self . by_package = review_node . get ( ' by_package ' )
2010-12-30 02:30:37 +01:00
self . who = review_node . get ( ' who ' )
self . when = review_node . get ( ' when ' )
self . comment = ' '
if not review_node . find ( ' comment ' ) is None and \
2022-09-12 13:43:10 +02:00
review_node . find ( ' comment ' ) . text :
2010-12-30 02:30:37 +01:00
self . comment = review_node . find ( ' comment ' ) . text . strip ( )
2023-02-13 14:15:15 +01:00
def __repr__ ( self ) :
result = super ( ) . __repr__ ( )
result + = " ( "
result + = f " { self . state } "
if self . who :
result + = f " by { self . who } "
for by in ( " user " , " group " , " project " , " package " ) :
by_value = getattr ( self , f " by_ { by } " , None )
if by_value :
result + = f " [ { by } { by_value } ]) "
break
result + = " ) "
return result
2010-12-30 02:30:37 +01:00
def get_node_attrs ( self ) :
2011-01-23 21:21:32 +01:00
return ( ' state ' , ' by_user ' , ' by_group ' , ' by_project ' , ' by_package ' , ' who ' , ' when ' )
2010-12-30 02:30:37 +01:00
def get_comment ( self ) :
return self . comment
2014-09-11 14:34:22 +02:00
def get_description ( self ) :
return None
2010-12-30 02:30:37 +01:00
2014-09-11 11:08:13 +02:00
class RequestHistory ( AbstractState ) :
""" Represents a history element of a request """
2015-03-09 20:20:39 +01:00
re_name = re . compile ( r ' ^Request (?:got )?([^ \ s]+)$ ' )
2014-09-11 11:08:13 +02:00
def __init__ ( self , history_node ) :
2022-08-31 11:46:12 +02:00
super ( ) . __init__ ( history_node . tag )
2014-09-11 11:08:13 +02:00
self . who = history_node . get ( ' who ' )
self . when = history_node . get ( ' when ' )
if not history_node . find ( ' description ' ) is None and \
2022-09-12 13:43:10 +02:00
history_node . find ( ' description ' ) . text :
2014-09-11 11:08:13 +02:00
# OBS 2.6
self . description = history_node . find ( ' description ' ) . text . strip ( )
else :
# OBS 2.5 and before
self . description = history_node . get ( ' name ' )
self . comment = ' '
if not history_node . find ( ' comment ' ) is None and \
2022-09-12 13:43:10 +02:00
history_node . find ( ' comment ' ) . text :
2014-09-11 11:08:13 +02:00
self . comment = history_node . find ( ' comment ' ) . text . strip ( )
2015-03-09 20:20:39 +01:00
self . name = self . _parse_name ( history_node )
def _parse_name ( self , history_node ) :
name = history_node . get ( ' name ' , None )
if name is not None :
# OBS 2.5 and before
return name
mo = self . re_name . search ( self . description )
if mo is not None :
return mo . group ( 1 )
return self . description
2014-09-11 11:08:13 +02:00
def get_node_attrs ( self ) :
2014-09-11 14:34:22 +02:00
return ( ' who ' , ' when ' )
def get_description ( self ) :
return self . description
2014-09-11 11:08:13 +02:00
def get_comment ( self ) :
return self . comment
2010-12-30 02:30:37 +01:00
class RequestState ( AbstractState ) :
""" Represents the state of a request """
2022-09-12 13:43:10 +02:00
2010-12-30 02:30:37 +01:00
def __init__ ( self , state_node ) :
if not state_node . get ( ' name ' ) :
2022-09-12 13:43:10 +02:00
raise oscerr . APIError ( ' invalid request state node (name attr expected): %s ' %
ET . tostring ( state_node , encoding = ET_ENCODING ) )
2022-08-31 11:46:12 +02:00
super ( ) . __init__ ( state_node . tag )
2010-12-30 02:30:37 +01:00
self . name = state_node . get ( ' name ' )
self . who = state_node . get ( ' who ' )
self . when = state_node . get ( ' when ' )
2018-10-17 15:31:23 +02:00
self . approver = state_node . get ( ' approver ' )
2014-09-11 11:08:13 +02:00
if state_node . find ( ' description ' ) is None :
# OBS 2.6 has it always, before it did not exist
self . description = state_node . get ( ' description ' )
2010-12-30 02:30:37 +01:00
self . comment = ' '
if not state_node . find ( ' comment ' ) is None and \
2022-09-12 13:43:10 +02:00
state_node . find ( ' comment ' ) . text :
2010-12-30 02:30:37 +01:00
self . comment = state_node . find ( ' comment ' ) . text . strip ( )
def get_node_attrs ( self ) :
2018-10-17 15:31:23 +02:00
return ( ' name ' , ' who ' , ' when ' , ' approver ' )
2010-12-30 02:30:37 +01:00
def get_comment ( self ) :
return self . comment
2014-09-11 14:34:22 +02:00
def get_description ( self ) :
return None
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
"""
2022-01-24 08:57:53 +01:00
Represents an ` ` < action / > ` ` element of a Request .
2010-12-30 02:30:37 +01:00
This class is quite common so that it can be used for all different
2022-01-24 08:57:53 +01:00
action types .
. . note : :
Instances only provide attributes for their specific type .
Examples : :
2010-12-30 02:30:37 +01:00
r = Action ( ' set_bugowner ' , tgt_project = ' foo ' , person_name = ' buguser ' )
2022-08-29 12:56:57 +02:00
# available attributes: r.type (== 'set_bugowner'), r.tgt_project (== 'foo'), r.tgt_package (is None)
2010-12-30 02:30:37 +01:00
r . to_str ( ) - >
< action type = " set_bugowner " >
< target project = " foo " / >
< person name = " buguser " / >
< / action >
2022-01-24 08:57:53 +01:00
2010-12-30 02:30:37 +01:00
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
2011-01-12 22:21:32 +01:00
type_args = { ' submit ' : ( ' src_project ' , ' src_package ' , ' src_rev ' , ' tgt_project ' , ' tgt_package ' , ' opt_sourceupdate ' ,
' acceptinfo_rev ' , ' acceptinfo_srcmd5 ' , ' acceptinfo_xsrcmd5 ' , ' acceptinfo_osrcmd5 ' ,
2015-01-09 15:19:05 +01:00
' acceptinfo_oxsrcmd5 ' , ' opt_updatelink ' , ' opt_makeoriginolder ' ) ,
2022-09-12 13:43:10 +02:00
' add_role ' : ( ' tgt_project ' , ' tgt_package ' , ' person_name ' , ' person_role ' , ' group_name ' , ' group_role ' ) ,
' set_bugowner ' : ( ' tgt_project ' , ' tgt_package ' , ' person_name ' , ' group_name ' ) ,
' maintenance_release ' : ( ' src_project ' , ' src_package ' , ' src_rev ' , ' tgt_project ' , ' tgt_package ' , ' person_name ' ,
' acceptinfo_rev ' , ' acceptinfo_srcmd5 ' , ' acceptinfo_xsrcmd5 ' , ' acceptinfo_osrcmd5 ' ,
' acceptinfo_oxsrcmd5 ' , ' acceptinfo_oproject ' , ' acceptinfo_opackage ' ) ,
' release ' : ( ' src_project ' , ' src_package ' , ' src_rev ' , ' tgt_project ' , ' tgt_package ' , ' person_name ' ,
' acceptinfo_rev ' , ' acceptinfo_srcmd5 ' , ' acceptinfo_xsrcmd5 ' , ' acceptinfo_osrcmd5 ' ,
' acceptinfo_oxsrcmd5 ' , ' acceptinfo_oproject ' , ' acceptinfo_opackage ' , ' tgt_repository ' ) ,
' maintenance_incident ' : ( ' src_project ' , ' src_package ' , ' src_rev ' , ' tgt_project ' , ' tgt_package ' , ' tgt_releaseproject ' , ' person_name ' , ' opt_sourceupdate ' , ' opt_makeoriginolder ' ,
' acceptinfo_rev ' , ' acceptinfo_srcmd5 ' , ' acceptinfo_xsrcmd5 ' , ' acceptinfo_osrcmd5 ' ,
' acceptinfo_oxsrcmd5 ' ) ,
' delete ' : ( ' tgt_project ' , ' tgt_package ' , ' tgt_repository ' ) ,
' change_devel ' : ( ' src_project ' , ' src_package ' , ' tgt_project ' , ' tgt_package ' ) ,
' group ' : ( ' grouped_id ' , ) }
2010-12-30 02:30:37 +01:00
# 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 ) :
2023-02-10 15:27:46 +01:00
self . apiurl = kwargs . pop ( " apiurl " , None )
2023-02-13 13:52:00 +01:00
self . _src_pkg_object = None
self . _tgt_pkg_object = None
2022-09-12 14:15:34 +02:00
if type not in Action . type_args . keys ( ) :
2010-12-30 02:30:37 +01:00
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 ( ) :
2022-09-12 14:15:34 +02:00
if i not in Action . type_args [ type ] :
2010-12-30 02:30:37 +01:00
raise oscerr . WrongArgs ( ' invalid argument: \' %s \' ' % i )
# set all type specific attributes
for i in Action . type_args [ type ] :
2013-04-09 11:25:19 +02:00
setattr ( self , i , kwargs . get ( i ) )
2009-06-02 15:14:46 +02:00
2023-02-13 13:59:32 +01:00
def __repr__ ( self ) :
result = super ( ) . __repr__ ( )
result + = " ( "
result + = f " type= { self . type } "
src_pkg = self . src_pkg_object
if src_pkg :
result + = f " source= { src_pkg . project } / { src_pkg . name } "
elif getattr ( self , " src_project " , None ) :
result + = f " source= { self . src_project } "
tgt_pkg = self . tgt_pkg_object
if tgt_pkg :
result + = f " target= { tgt_pkg . project } / { tgt_pkg . name } "
elif getattr ( self , " tgt_project " , None ) :
result + = f " target= { self . tgt_project } "
result + = " ) "
return result
2023-02-13 13:52:00 +01:00
@property
def src_pkg_object ( self ) :
if not getattr ( self , " src_project " , None ) or not getattr ( self , " src_package " , None ) :
return None
if not self . _src_pkg_object :
src_rev = getattr ( self , " src_rev " , None )
self . _src_pkg_object = _private . ApiPackage ( self . apiurl , self . src_project , self . src_package , src_rev )
return self . _src_pkg_object
@property
def tgt_pkg_object ( self ) :
if not self . _tgt_pkg_object :
if self . type == " maintenance_incident " :
# the target project for maintenance incidents is virtual and cannot be queried
# the actual target project is in the "releaseproject" attribute
#
# tgt_releaseproject is always set for a maintenance_incident
# pylint: disable=no-member
tgt_project = self . tgt_releaseproject
# the target package is not specified
# we need to extract it from source package's _meta
src_package_meta_releasename = self . src_pkg_object . get_meta_value ( " releasename " )
tgt_package = src_package_meta_releasename . split ( " . " ) [ 0 ]
else :
if not getattr ( self , " tgt_project " , None ) or not getattr ( self , " tgt_package " , None ) :
return None
# tgt_project and tgt_package are checked above
# pylint: disable=no-member
tgt_project = self . tgt_project
tgt_package = self . tgt_package
self . _tgt_pkg_object = _private . ApiPackage ( self . apiurl , tgt_project , tgt_package )
return self . _tgt_pkg_object
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.
2022-01-24 08:57:53 +01:00
: return : object serialized to XML
Example : :
2010-12-30 02:30:37 +01:00
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 "
2022-01-24 08:57:53 +01:00
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 .
2010-12-30 02:30:37 +01:00
"""
root = ET . Element ( ' action ' , type = self . type )
for i in Action . type_args [ self . type ] :
prefix , attr = i . split ( ' _ ' , 1 )
2013-08-28 23:00:35 +02:00
vals = getattr ( self , i )
# single, plain elements are _not_ stored in a list
plain = False
if vals is None :
2010-12-30 02:30:37 +01:00
continue
2013-08-28 23:00:35 +02:00
elif not hasattr ( vals , ' append ' ) :
vals = [ vals ]
plain = True
for val in vals :
elm = root . find ( Action . prefix_to_elm . get ( prefix , prefix ) )
if elm is None or not plain :
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 )
2010-12-30 02:30:37 +01:00
return root
2008-03-05 00:41:00 +01:00
2010-12-30 02:30:37 +01:00
def to_str ( self ) :
2022-01-24 08:57:53 +01:00
""" :return: object serialized to pretty-printed XML """
2010-12-30 02:30:37 +01:00
root = self . to_xml ( )
xmlindent ( root )
2013-04-10 11:34:59 +02:00
return ET . tostring ( root , encoding = ET_ENCODING )
2008-03-05 00:41:00 +01:00
2010-12-30 02:30:37 +01:00
@staticmethod
2023-02-10 15:27:46 +01:00
def from_xml ( action_node , apiurl = None ) :
2010-12-30 02:30:37 +01:00
""" create action from XML """
if action_node is None or \
2022-09-12 14:15:34 +02:00
action_node . get ( ' type ' ) not in Action . type_args . keys ( ) or \
action_node . tag not in ( ' action ' , ' submit ' ) :
2010-12-30 02:30:37 +01:00
raise oscerr . WrongArgs ( ' invalid argument ' )
2022-07-28 19:11:29 +02:00
elm_to_prefix = { i [ 1 ] : i [ 0 ] for i in Action . prefix_to_elm . items ( ) }
2010-12-30 02:30:37 +01:00
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 ( ) ]
2013-08-28 23:00:35 +02:00
# it would be easier to store everything in a list but in
# this case we would lose some "structure" (see to_xml)
for k , v in data :
if k in kwargs :
l = kwargs [ k ]
if not hasattr ( l , ' append ' ) :
l = [ l ]
kwargs [ k ] = l
l . append ( v )
else :
kwargs [ k ] = v
2023-02-10 15:27:46 +01:00
kwargs [ " apiurl " ] = apiurl
2010-12-30 02:30:37 +01:00
return Action ( action_node . get ( ' type ' ) , * * kwargs )
2008-03-05 00:41:00 +01:00
2008-03-06 11:25:45 +01:00
2022-09-15 21:17:46 +02:00
@total_ordering
2010-12-30 02:30:37 +01:00
class Request :
2022-01-24 08:57:53 +01:00
""" Represents a request (``<request />``) """
2008-03-05 00:41:00 +01:00
2023-02-10 11:04:34 +01:00
@classmethod
def from_api ( cls , apiurl : str , req_id : int ) :
# TODO: deprecate get_request() or move its content here
req_id = str ( req_id )
return get_request ( apiurl , req_id )
2010-12-30 02:30:37 +01:00
def __init__ ( self ) :
2011-01-18 19:34:25 +01:00
self . _init_attributes ( )
def _init_attributes ( self ) :
""" initialize attributes with default values """
2010-12-30 02:30:37 +01:00
self . reqid = None
2017-05-04 20:49:35 +02:00
self . creator = ' '
2010-12-30 02:30:37 +01:00
self . title = ' '
self . description = ' '
2014-09-11 11:25:24 +02:00
self . priority = None
2010-12-30 02:30:37 +01:00
self . state = None
2013-08-14 18:27:38 +02:00
self . accept_at = None
2010-12-30 02:30:37 +01:00
self . actions = [ ]
self . statehistory = [ ]
self . reviews = [ ]
2023-02-10 11:09:19 +01:00
self . _issues = None
2010-12-30 02:30:37 +01:00
2022-09-15 21:17:46 +02:00
def __eq__ ( self , other ) :
return int ( self . reqid ) == int ( other . reqid )
def __lt__ ( self , other ) :
return int ( self . reqid ) < int ( other . reqid )
2023-02-10 11:05:40 +01:00
@property
def id ( self ) :
return self . reqid
2023-02-10 11:09:19 +01:00
@property
def issues ( self ) :
if self . _issues is None :
self . _issues = get_request_issues ( self . apiurl , self . id )
return self . _issues
2023-02-10 15:27:46 +01:00
def read ( self , root , apiurl = None ) :
2010-12-30 02:30:37 +01:00
""" read in a request """
2011-01-18 19:34:25 +01:00
self . _init_attributes ( )
2023-02-10 15:27:46 +01:00
self . apiurl = apiurl
2017-04-18 09:39:59 +02:00
if not root . get ( ' id ' ) :
2013-04-10 11:34:59 +02:00
raise oscerr . APIError ( ' invalid request: %s \n ' % ET . tostring ( root , encoding = ET_ENCODING ) )
2010-12-30 02:30:37 +01:00
self . reqid = root . get ( ' id ' )
2017-04-18 09:39:59 +02:00
if root . get ( ' creator ' ) :
# OBS 2.8 and later is delivering creator informations
self . creator = root . get ( ' creator ' )
2010-12-30 02:30:37 +01:00
if root . find ( ' state ' ) is None :
2013-04-10 11:34:59 +02:00
raise oscerr . APIError ( ' invalid request (state expected): %s \n ' % ET . tostring ( root , encoding = ET_ENCODING ) )
2010-12-30 02:30:37 +01:00
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 :
2023-02-10 15:27:46 +01:00
self . actions . append ( Action . from_xml ( action , self . apiurl ) )
2010-12-30 02:30:37 +01:00
for review in root . findall ( ' review ' ) :
self . reviews . append ( ReviewState ( review ) )
2014-09-11 11:08:13 +02:00
for history_element in root . findall ( ' history ' ) :
self . statehistory . append ( RequestHistory ( history_element ) )
2014-09-12 08:57:02 +02:00
if not root . find ( ' priority ' ) is None and root . find ( ' priority ' ) . text :
2014-09-11 11:25:24 +02:00
self . priority = root . find ( ' priority ' ) . text . strip ( )
2013-08-14 18:27:38 +02:00
if not root . find ( ' accept_at ' ) is None and root . find ( ' accept_at ' ) . text :
self . accept_at = root . find ( ' accept_at ' ) . text . strip ( )
2010-12-30 02:30:37 +01:00
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
2022-12-07 13:01:23 +01:00
def get_actions ( self , * types ) - > List [ Action ] :
2011-01-29 17:44:03 +01:00
"""
get all actions with a specific type
( if types is empty return all actions )
"""
if not types :
return self . actions
return [ i for i in self . actions if i . type in types ]
2010-12-30 02:30:37 +01:00
def to_xml ( self ) :
2022-01-24 08:57:53 +01:00
""" :return: object serialized to XML """
2010-12-30 02:30:37 +01:00
root = ET . Element ( ' request ' )
2017-04-12 13:03:16 +02:00
if self . reqid is not None :
2010-12-30 02:30:37 +01:00
root . set ( ' id ' , self . reqid )
2017-05-08 21:41:29 +02:00
if self . creator :
2017-04-12 12:58:23 +02:00
root . set ( ' creator ' , self . creator )
2010-12-30 02:30:37 +01:00
for action in self . actions :
root . append ( action . to_xml ( ) )
2022-09-12 14:23:47 +02:00
if self . state is not None :
2010-12-30 02:30:37 +01:00
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
2013-12-05 10:23:53 +01:00
if self . accept_at :
ET . SubElement ( root , ' accept_at ' ) . text = self . accept_at
2014-09-11 11:25:24 +02:00
if self . priority :
ET . SubElement ( root , ' priority ' ) . text = self . priority
2010-12-30 02:30:37 +01:00
return root
2008-06-27 18:36:16 +02:00
2010-12-30 02:30:37 +01:00
def to_str ( self ) :
2022-01-24 08:57:53 +01:00
""" :return: object serialized to pretty-printed XML """
2010-12-30 02:30:37 +01:00
root = self . to_xml ( )
xmlindent ( root )
2013-04-10 11:34:59 +02:00
return ET . tostring ( root , encoding = ET_ENCODING )
2008-06-27 18:36:16 +02:00
2013-12-05 10:23:53 +01:00
def accept_at_in_hours ( self , hours ) :
""" set auto accept_at time """
now = datetime . datetime . utcnow ( )
now = now + datetime . timedelta ( hours = hours )
2019-08-14 13:33:11 +02:00
self . accept_at = now . isoformat ( ) + ' +00:00 '
2013-12-05 10:23:53 +01:00
2011-01-30 21:23:40 +01:00
@staticmethod
def format_review ( review , show_srcupdate = False ) :
2011-01-23 21:21:32 +01:00
"""
format a review depending on the reviewer ' s type.
2011-01-30 21:23:40 +01:00
A dict which contains the formatted str ' s is returned.
2011-01-23 21:21:32 +01:00
"""
d = { ' state ' : ' %s : ' % review . state }
if review . by_package :
2013-05-27 14:26:58 +02:00
d [ ' by ' ] = ' %s / %s ' % ( review . by_project , review . by_package )
d [ ' type ' ] = ' Package '
2011-01-23 21:21:32 +01:00
elif review . by_project :
2013-05-27 14:26:58 +02:00
d [ ' by ' ] = ' %s ' % review . by_project
d [ ' type ' ] = ' Project '
2011-01-23 21:21:32 +01:00
elif review . by_group :
2013-05-27 14:26:58 +02:00
d [ ' by ' ] = ' %s ' % review . by_group
d [ ' type ' ] = ' Group '
2011-01-23 21:21:32 +01:00
else :
2013-05-27 14:26:58 +02:00
d [ ' by ' ] = ' %s ' % review . by_user
d [ ' type ' ] = ' User '
2011-01-23 21:21:32 +01:00
if review . who :
2013-05-27 14:26:58 +02:00
d [ ' by ' ] + = ' ( %s ) ' % review . who
2011-01-23 21:21:32 +01:00
return d
2022-12-07 13:01:23 +01:00
def format_action ( self , action : Action , show_srcupdate = False ) :
2010-12-30 02:30:37 +01:00
"""
format an action depending on the action ' s type.
2011-01-30 21:23:40 +01:00
A dict which contains the formatted str ' s is returned.
2010-12-30 02:30:37 +01:00
"""
2012-11-20 15:29:30 +01:00
def prj_pkg_join ( prj , pkg , repository = None ) :
2010-12-30 02:30:37 +01:00
if not pkg :
2012-11-13 13:20:09 +01:00
if not repository :
2013-05-27 14:26:58 +02:00
return prj or ' '
2012-11-13 13:20:09 +01:00
return ' %s ( %s ) ' % ( prj , repository )
2010-12-30 02:30:37 +01:00
return ' %s / %s ' % ( prj , pkg )
d = { ' type ' : ' %s : ' % action . type }
if action . type == ' set_bugowner ' :
2014-05-09 10:30:55 +02:00
if action . person_name :
d [ ' source ' ] = action . person_name
if action . group_name :
d [ ' source ' ] = ' group: %s ' % action . group_name
2010-12-30 02:30:37 +01:00
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 )
2011-03-04 15:50:06 +01:00
elif action . type == ' maintenance_incident ' :
d [ ' source ' ] = ' %s -> ' % action . src_project
2012-02-20 11:21:30 +01:00
if action . src_package :
2014-02-27 11:13:10 +01:00
d [ ' source ' ] = ' %s ' % prj_pkg_join ( action . src_project , action . src_package )
if action . src_rev :
d [ ' source ' ] = d [ ' source ' ] + ' @ %s ' % action . src_rev
d [ ' source ' ] = d [ ' source ' ] + ' -> '
2011-03-04 15:50:06 +01:00
d [ ' target ' ] = action . tgt_project
2012-02-29 12:22:35 +01:00
if action . tgt_releaseproject :
d [ ' target ' ] + = " (release in " + action . tgt_releaseproject + " ) "
2011-10-31 11:30:26 +01:00
srcupdate = ' '
if action . opt_sourceupdate and show_srcupdate :
srcupdate = ' ( %s ) ' % action . opt_sourceupdate
2020-08-05 21:17:30 +02:00
elif action . type in ( ' maintenance_release ' , ' release ' ) :
2014-02-27 11:13:10 +01:00
d [ ' source ' ] = ' %s ' % prj_pkg_join ( action . src_project , action . src_package )
if action . src_rev :
d [ ' source ' ] = d [ ' source ' ] + ' @ %s ' % action . src_rev
d [ ' source ' ] = d [ ' source ' ] + ' -> '
2011-03-04 15:50:06 +01:00
d [ ' target ' ] = prj_pkg_join ( action . tgt_project , action . tgt_package )
2010-12-30 02:30:37 +01:00
elif action . type == ' submit ' :
2014-02-27 11:13:10 +01:00
d [ ' source ' ] = ' %s ' % prj_pkg_join ( action . src_project , action . src_package )
if action . src_rev :
d [ ' source ' ] = d [ ' source ' ] + ' @ %s ' % action . src_rev
2010-12-30 02:30:37 +01:00
if action . opt_sourceupdate and show_srcupdate :
2014-02-27 11:13:10 +01:00
d [ ' source ' ] = d [ ' source ' ] + ' ( %s ) ' % action . opt_sourceupdate
d [ ' source ' ] = d [ ' source ' ] + ' -> '
2010-12-30 02:30:37 +01:00
tgt_package = action . tgt_package
if action . src_package == action . tgt_package :
tgt_package = ' '
d [ ' target ' ] = prj_pkg_join ( action . tgt_project , tgt_package )
2015-01-09 15:19:05 +01:00
if action . opt_makeoriginolder :
2015-03-09 09:01:00 +01:00
d [ ' target ' ] = d [ ' target ' ] + ' ***make origin older*** '
if action . opt_updatelink :
d [ ' target ' ] = d [ ' target ' ] + ' ***update link*** '
2010-12-30 02:30:37 +01:00
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 ' ] = ' '
2012-11-13 13:20:09 +01:00
d [ ' target ' ] = prj_pkg_join ( action . tgt_project , action . tgt_package , action . tgt_repository )
2013-08-16 11:53:21 +02:00
elif action . type == ' group ' :
2013-08-28 23:00:35 +02:00
l = action . grouped_id
if l is None :
# there may be no requests in a group action
l = ' '
if not hasattr ( l , ' append ' ) :
l = [ l ]
d [ ' source ' ] = ' , ' . join ( l ) + ' -> '
d [ ' target ' ] = self . reqid
2013-08-16 11:53:21 +02:00
else :
raise oscerr . APIError ( ' Unknown action type %s \n ' % action . type )
2010-12-30 02:30:37 +01:00
return d
def list_view ( self ) :
""" return " list view " format """
2018-10-17 15:31:23 +02:00
status = self . state . name
if self . state . name == ' review ' and self . state . approver :
status + = " (approved) "
lines = [ ' %6s State: %-10s By: %-12s When: %-19s ' % ( self . reqid , status , self . state . who , self . state . when ) ]
2022-09-15 20:45:46 +02:00
lines + = [ f " Created by: { self . creator } " ]
2010-12-30 02:30:37 +01:00
tmpl = ' %(type)-16s %(source)-50s %(target)s '
for action in self . actions :
2013-08-28 23:00:35 +02:00
lines . append ( tmpl % self . format_action ( action ) )
2011-01-23 21:21:32 +01:00
tmpl = ' Review by %(type)-10s is %(state)-10s %(by)-50s '
for review in self . reviews :
2011-01-30 21:23:40 +01:00
lines . append ( tmpl % Request . format_review ( review ) )
2014-09-11 11:25:24 +02:00
history = [ ' %s : %s ' % ( hist . description , hist . who ) for hist in self . statehistory ]
2010-12-30 02:30:37 +01:00
if history :
lines . append ( ' From: %s ' % ' -> ' . join ( history ) )
if self . description :
2011-02-11 02:43:10 +01:00
lines . append ( textwrap . fill ( self . description , width = 80 , initial_indent = ' Descr: ' ,
2022-09-12 13:43:10 +02:00
subsequent_indent = ' ' ) )
2011-07-13 15:47:38 +02:00
lines . append ( textwrap . fill ( self . state . comment , width = 80 , initial_indent = ' Comment: ' ,
2022-09-12 13:43:10 +02:00
subsequent_indent = ' ' ) )
2010-12-30 02:30:37 +01:00
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 """
2022-09-15 20:45:46 +02:00
lines = [
f " Request: { self . reqid } " ,
f " Created by: { self . creator } " ,
]
2022-09-12 13:43:10 +02:00
if self . accept_at and self . state . name in [ ' new ' , ' review ' ] :
lines . append ( ' *** This request will get automatically accepted after ' + self . accept_at + ' ! *** \n ' )
2022-09-15 20:45:46 +02:00
2022-09-12 13:43:10 +02:00
if self . priority in [ ' critical ' , ' important ' ] and self . state . name in [ ' new ' , ' review ' ] :
lines . append ( ' *** This request has classified as ' + self . priority + ' ! *** \n ' )
2022-09-15 20:45:46 +02:00
2018-12-13 13:14:19 +01:00
if self . state and self . state . approver and self . state . name == ' review ' :
2022-09-12 13:43:10 +02:00
lines . append ( ' *** This request got approved by ' + self . state . approver + ' . It will get automatically accepted after last review got accepted! *** \n ' )
2022-08-29 15:39:02 +02:00
2022-09-15 20:45:46 +02:00
lines + = [ " " , " Actions: " ]
2009-06-23 16:14:07 +02:00
for action in self . actions :
2022-09-15 20:45:46 +02:00
fmt_action = self . format_action ( action , show_srcupdate = True )
2010-12-30 02:30:37 +01:00
if action . type == ' delete ' :
2022-09-15 20:45:46 +02:00
lines + = [ f " { fmt_action [ ' type ' ] : 13 } { fmt_action [ ' target ' ] } " ]
else :
lines + = [ f " { fmt_action [ ' type ' ] : 13 } { fmt_action [ ' source ' ] } { fmt_action [ ' target ' ] } " ]
lines + = [ " " , " Message: " , textwrap . indent ( self . description or " <no message> " , prefix = " " ) ]
2011-01-29 23:30:54 +01:00
if self . state :
2022-09-15 20:45:46 +02:00
lines + = [ " " , " State: " , f " { self . state . name : 61 } { self . state . when : 12 } { self . state . who } " ]
if self . state . comment :
lines + = [ textwrap . indent ( self . state . comment , prefix = " | " , predicate = lambda line : True ) ]
if self . reviews :
lines + = [ " " ]
lines + = [ " Review: " ]
for review in reversed ( self . reviews ) :
d = { ' state ' : review . state }
if review . by_user :
d [ ' by ' ] = " User: " + review . by_user
if review . by_group :
d [ ' by ' ] = " Group: " + review . by_group
if review . by_package :
d [ ' by ' ] = " Package: " + review . by_project + " / " + review . by_package
elif review . by_project :
d [ ' by ' ] = " Project: " + review . by_project
d [ ' when ' ] = review . when or ' '
d [ ' who ' ] = review . who or ' '
lines + = [ f " { d [ ' state ' ] : 10 } { d [ ' by ' ] : 50 } { d [ ' when ' ] : 12 } { d [ ' who ' ] } " ]
if review . comment :
lines + = [ textwrap . indent ( review . comment , prefix = " | " , predicate = lambda line : True ) ]
if self . statehistory :
lines + = [ " " , " History: " ]
for hist in reversed ( self . statehistory ) :
lines + = [ f " { hist . when : 10 } { hist . who : 30 } { hist . description } " ]
2010-12-30 02:30:37 +01:00
return ' \n ' . join ( lines )
2008-03-06 11:25:45 +01:00
2022-10-21 10:38:57 +02:00
def create ( self , apiurl : str , addrevision = False , enforce_branching = False ) :
2011-01-18 19:34:25 +01:00
""" create a new request """
2022-09-12 13:43:10 +02:00
query = { ' cmd ' : ' create ' }
2012-03-15 12:44:38 +01:00
if addrevision :
query [ ' addrevision ' ] = " 1 "
2019-07-22 15:32:19 +02:00
if enforce_branching :
query [ ' enforce_branching ' ] = " 1 "
2012-03-15 12:44:38 +01:00
u = makeurl ( apiurl , [ ' request ' ] , query = query )
2011-01-18 19:34:25 +01:00
f = http_POST ( u , data = self . to_str ( ) )
root = ET . fromstring ( f . read ( ) )
self . read ( root )
2008-03-05 00:41:00 +01:00
2022-09-12 13:43:10 +02: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
"""
2015-02-17 10:26:04 +01:00
if time . gmtime ( ) [ 0 ] == time . gmtime ( t ) [ 0 ] :
2007-06-26 15:17:38 +02:00
# same year
2015-07-21 11:20:54 +02:00
return time . strftime ( ' % b %d % H: % M ' , time . gmtime ( t ) )
2007-06-26 15:17:38 +02:00
else :
2015-02-17 10:26:04 +01:00
return time . strftime ( ' % b %d % Y ' , time . gmtime ( 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 \
2022-09-12 13:43:10 +02:00
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 \
2022-09-12 13:43:10 +02:00
os . path . exists ( os . path . join ( d , store , ' _package ' ) )
2006-09-29 15:15:41 +02:00
2022-12-07 13:01:23 +01:00
def parse_disturl ( disturl : str ) :
2009-08-26 16:58:53 +02:00
""" 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 ' ) )
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def parse_buildlogurl ( buildlogurl : str ) :
2010-01-28 13:20:11 +01:00
""" 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
2022-09-12 13:43:10 +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
2022-09-12 13:43:10 +02:00
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
2015-09-10 11:25:14 +02:00
using the current directory , or none of them if not possible .
2009-09-28 21:50:57 +02:00
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 .
2015-09-10 11:25:14 +02:00
If args [ idx ] does not exist , an implicit ' . ' is assumed .
If not enough elements up to idx exist , an error is raised .
2009-10-08 16:40:06 +02:00
2022-09-13 16:34:54 +02:00
See also parseargs ( args ) , slash_split ( args ) , Package . from_paths ( args )
2009-10-08 16:40:06 +02:00
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 + = ' . '
2022-09-12 13:43:10 +02:00
if args [ idx + 0 ] == ' . ' :
if howmany == 0 and len ( args ) > idx + 1 :
if args [ idx + 1 ] == ' . ' :
2009-09-28 21:50:57 +02:00
# we have two dots.
# remove one dot and make sure to expand both proj and pack
2022-09-12 13:43:10 +02:00
args . pop ( idx + 1 )
2009-09-28 21:50:57 +02:00
howmany = 2
else :
howmany = 1
# print args,idx,howmany
2022-09-12 13:43:10 +02:00
args [ idx + 0 ] = store_read_project ( ' . ' )
2009-09-28 21:50:57 +02:00
if howmany == 0 :
try :
package = store_read_package ( ' . ' )
2022-09-12 13:43:10 +02:00
args . insert ( idx + 1 , package )
2009-09-28 21:50:57 +02:00
except :
pass
elif howmany == 2 :
package = store_read_package ( ' . ' )
2022-09-12 13:43:10 +02:00
args . insert ( idx + 1 , package )
2009-09-28 21:50:57 +02:00
return args
2007-06-26 15:17:38 +02:00
2016-08-26 16:20:53 +02:00
def findpacs ( files , progress_obj = None , fatal = True ) :
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 """
2022-09-13 16:34:54 +02:00
import warnings
warnings . warn (
" osc.core.findpacs() is deprecated. "
" Use osc.core.Package.from_paths() or osc.core.Package.from_paths_nofail() instead. " ,
DeprecationWarning
)
if fatal :
return Package . from_paths ( files , progress_obj )
return Package . from_paths_nofail ( files , progress_obj )
2010-04-09 15:47:07 +02:00
2006-05-19 22:13:29 +02:00
def read_filemeta ( dir ) :
2010-08-31 14:43:43 +02:00
global store
2011-05-17 16:09:09 +02:00
msg = ' \' %s \' is not a valid working copy. ' % dir
filesmeta = os . path . join ( dir , store , ' _files ' )
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 )
2021-11-30 13:13:11 +01:00
if os . path . isfile ( os . path . join ( dir , store , ' _scm ' ) ) :
raise oscerr . NoWorkingCopy ( " Is managed via scm " )
2010-08-31 14:52:46 +02:00
if not os . path . isfile ( filesmeta ) :
2011-05-17 16:09:09 +02:00
raise oscerr . NoWorkingCopy ( ' %s ( %s does not exist) ' % ( msg , filesmeta ) )
2010-08-31 14:52:46 +02:00
2008-06-10 12:15:49 +02:00
try :
2010-08-31 14:52:46 +02:00
r = ET . parse ( filesmeta )
2013-04-09 11:27:02 +02:00
except SyntaxError as e :
2011-05-17 16:09:09 +02:00
raise oscerr . NoWorkingCopy ( ' %s \n When parsing .osc/_files, the following error was encountered: \n %s ' % ( msg , e ) )
2008-06-10 12:15:49 +02:00
return r
2006-05-19 22:13:29 +02:00
2022-09-12 13:43:10 +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 ) ) :
2022-08-24 08:43:09 +02:00
with open ( os . path . join ( dir , store , name ) ) as f :
r = [ line . rstrip ( ' \n ' ) for line in f ]
2006-05-19 22:13:29 +02:00
return r
2022-09-12 13:43:10 +02:00
2010-08-24 18:06:47 +02:00
def read_tobeadded ( dir ) :
return store_readlist ( dir , ' _to_be_added ' )
2022-09-12 13:43:10 +02:00
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
2022-09-12 13:43:10 +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 ) :
2022-08-24 08:43:09 +02:00
with open ( fname ) as f :
r = f . 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 )
2022-09-12 13:43:10 +02:00
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
2022-09-12 13:43:10 +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
2023-04-28 14:38:43 +02:00
def osc_urlencode ( data ) :
"""
An urlencode wrapper that encodes dictionaries in OBS compatible way :
{ " file " : [ " foo " , " bar " ] } - > & file [ ] = foo & file [ ] = bar
"""
data = copy . deepcopy ( data )
if isinstance ( data , dict ) :
for key , value in list ( data . items ( ) ) :
if isinstance ( value , list ) :
del data [ key ]
data [ f " { key } [] " ] = value
return urlencode ( data , doseq = True )
2022-10-21 10:38:57 +02:00
def makeurl ( baseurl : str , l , query = None ) :
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 .
"""
2022-08-29 15:32:41 +02:00
query = query or [ ]
2022-08-30 12:38:04 +02:00
if conf . config [ ' debug ' ] :
2013-04-09 12:51:28 +02:00
print ( ' makeurl: ' , baseurl , l , query )
2009-11-10 01:56:52 +01:00
2022-08-29 13:55:09 +02:00
if isinstance ( query , list ) :
2008-03-17 22:10:34 +01:00
query = ' & ' . join ( query )
2022-08-29 13:55:09 +02:00
elif isinstance ( query , dict ) :
2023-04-28 14:38:43 +02:00
query = osc_urlencode ( query )
2008-03-17 22:10:34 +01:00
2013-10-26 01:15:18 +02:00
scheme , netloc , path = urlsplit ( baseurl ) [ 0 : 3 ]
2022-04-01 09:32:15 +02:00
return urlunsplit ( ( scheme , netloc , ' / ' . join ( [ path ] + list ( l ) ) , query , ' ' ) )
2006-04-20 16:26:50 +02:00
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 :
2022-08-24 08:43:09 +02:00
with open ( versionfile ) as f :
v = f . 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. '
2013-04-09 12:54:54 +02:00
raise oscerr . WorkingCopyWrongVersion ( msg )
2009-10-20 16:30:15 +02:00
2006-04-28 17:37:25 +02:00
2022-10-21 10:38:57 +02:00
def meta_get_packagelist ( apiurl : str , prj , deleted = None , expand = False ) :
2010-05-22 08:22:12 +02:00
query = { }
if deleted :
2013-05-27 14:26:58 +02:00
query [ ' deleted ' ] = 1
2022-02-23 14:53:59 +01:00
elif deleted in ( False , 0 ) :
# HACK: Omitted 'deleted' and 'deleted=0' produce different results.
# By explicit 'deleted=0', we also get multibuild packages listed.
# See: https://github.com/openSUSE/open-build-service/issues/9715
query [ ' deleted ' ] = 0
2014-08-11 16:59:40 +02:00
if expand :
query [ ' expand ' ] = 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 ( )
2022-09-12 13:43:10 +02:00
return [ node . get ( ' name ' ) for node in root . findall ( ' entry ' ) ]
2006-04-20 16:26:50 +02:00
2022-12-07 13:01:23 +01:00
def meta_get_filelist (
apiurl : str , prj : str , package : str , verbose = False , expand = False , revision = None , meta = False , deleted = False
) :
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
2022-10-21 10:38:57 +02:00
query : Dict [ str , Union [ str , int ] ] = { }
2013-05-17 10:37:51 +02:00
if deleted :
query [ ' deleted ' ] = 1
2009-03-31 00:17:18 +02:00
if expand :
2009-04-09 13:44:32 +02:00
query [ ' expand ' ] = 1
2011-06-08 10:25:15 +02:00
if meta :
query [ ' meta ' ] = 1
2009-04-09 13:44:32 +02:00
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 :
2022-09-12 13:43:10 +02: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
2022-10-21 10:38:57 +02:00
def meta_get_project_list ( apiurl : str , deleted = False ) :
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 ( )
2022-09-12 13:43:10 +02: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
2022-10-21 10:38:57 +02:00
def show_project_meta ( apiurl : str , prj : str , rev = None , blame = None ) :
2017-03-21 14:44:19 +01:00
query = { }
if blame :
query [ ' view ' ] = " blame "
2016-06-01 14:00:37 +02:00
if rev :
query [ ' rev ' ] = rev
url = makeurl ( apiurl , [ ' source ' , prj , ' _project ' , ' _meta ' ] , query )
try :
f = http_GET ( url )
except HTTPError as e :
error_help = " %d " % e . code
os_err = e . hdrs . get ( ' X-Opensuse-Errorcode ' )
if os_err :
error_help = " %s ( %d ) project: %s " % ( os_err , e . code , prj )
if e . code == 404 and os_err == ' unknown_package ' :
error_help = ' option -r|--revision is not supported by this OBS version '
e . osc_msg = ' BuildService API error: %s ' % error_help
raise
else :
2017-03-21 14:44:19 +01:00
if blame :
url = makeurl ( apiurl , [ ' source ' , prj , ' _project ' , ' _meta ' ] , query )
else :
url = makeurl ( apiurl , [ ' source ' , prj , ' _meta ' ] )
2016-06-01 14:00:37 +02:00
f = http_GET ( url )
2006-04-20 16:26:50 +02:00
return f . readlines ( )
2022-09-12 13:43:10 +02:00
2022-10-21 10:38:57 +02:00
def show_project_conf ( apiurl : str , prj : str , rev = None , blame = None ) :
2016-06-01 14:00:37 +02:00
query = { }
2017-03-21 14:44:19 +01:00
url = None
2016-06-01 14:00:37 +02:00
if rev :
query [ ' rev ' ] = rev
2017-03-21 14:44:19 +01:00
if blame :
query [ ' view ' ] = " blame "
url = makeurl ( apiurl , [ ' source ' , prj , ' _project ' , ' _config ' ] , query = query )
else :
url = makeurl ( apiurl , [ ' source ' , prj , ' _config ' ] , query = query )
2007-06-26 15:17:38 +02:00
f = http_GET ( url )
return f . readlines ( )
2022-10-21 10:38:57 +02:00
def show_package_trigger_reason ( apiurl : str , prj : str , pac : str , repo : str , arch : str ) :
2009-12-09 07:53:33 +01:00
url = makeurl ( apiurl , [ ' build ' , prj , repo , arch , pac , ' _reason ' ] )
try :
f = http_GET ( url )
return f . read ( )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2009-12-09 07:53:33 +01:00
e . osc_msg = ' Error getting trigger reason for project \' %s \' package \' %s \' ' % ( prj , pac )
raise
2022-10-21 10:38:57 +02:00
def show_package_meta ( apiurl : str , prj : str , pac : str , meta = False , blame = None ) :
query : Dict [ str , Union [ str , int ] ] = { }
2010-05-25 14:53:20 +02:00
if meta :
query [ ' meta ' ] = 1
2017-03-21 14:44:19 +01:00
if blame :
query [ ' view ' ] = " blame "
query [ ' meta ' ] = 1
2010-05-25 14:53:20 +02:00
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 ( )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2019-09-20 09:28:19 +02:00
e . osc_msg = ' Error getting meta for project \' %s \' package \' %s \' ' % ( unquote ( 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
2022-10-21 10:38:57 +02:00
def show_attribute_meta ( apiurl : str , prj : str , pac , subpac , attribute , with_defaults , with_project ) :
2013-05-27 14:56:24 +02:00
path = [ ]
2009-10-30 10:40:46 +01:00
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 )
2013-05-27 14:56:24 +02:00
query = [ ]
2009-10-30 11:18:44 +01:00
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 ( )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2009-10-30 10:40:46 +01:00
e . osc_msg = ' Error getting meta for project \' %s \' package \' %s \' ' % ( prj , pac )
raise
2021-11-30 13:13:11 +01:00
def clean_assets ( directory ) :
return run_external ( conf . config [ ' download-assets-cmd ' ] , ' --clean ' , directory )
2022-09-12 13:43:10 +02:00
2021-11-30 13:13:11 +01:00
def download_assets ( directory ) :
return run_external ( conf . config [ ' download-assets-cmd ' ] , ' --unpack ' , ' --noassetdir ' , directory )
2022-09-12 13:43:10 +02:00
2021-11-30 13:13:11 +01:00
def show_scmsync ( apiurl , prj , pac = None ) :
if pac :
m = show_package_meta ( apiurl , prj , pac )
else :
m = show_project_meta ( apiurl , prj )
node = ET . fromstring ( b ' ' . join ( m ) ) . find ( ' scmsync ' )
if node is None :
return None
else :
return node . text
2022-09-12 13:43:10 +02:00
2013-10-07 13:12:58 +02:00
def show_devel_project ( apiurl , prj , pac ) :
2008-06-03 17:01:01 +02:00
m = show_package_meta ( apiurl , prj , pac )
2018-12-13 15:14:06 +01:00
node = ET . fromstring ( b ' ' . join ( m ) ) . find ( ' devel ' )
2013-10-07 13:12:58 +02:00
if node is None :
return None , None
else :
return node . get ( ' project ' ) , node . get ( ' package ' , None )
2022-11-07 10:36:03 +01:00
def set_devel_project ( apiurl , prj , pac , devprj = None , devpac = None , print_to = " debug " ) :
if devprj :
msg = " Setting devel project of "
else :
msg = " Unsetting devel project from "
msg = _private . format_msg_project_package_options (
msg ,
prj ,
pac ,
devprj ,
devpac ,
)
_private . print_msg ( msg , print_to = print_to )
2013-10-07 13:12:58 +02:00
meta = show_package_meta ( apiurl , prj , pac )
2018-12-13 15:14:06 +01:00
root = ET . fromstring ( b ' ' . join ( meta ) )
2013-10-07 13:12:58 +02:00
node = root . find ( ' devel ' )
if node is None :
2013-10-18 11:50:07 +02:00
if devprj is None :
return
2013-10-07 13:12:58 +02:00
node = ET . Element ( ' devel ' )
root . append ( node )
else :
2013-10-18 11:50:07 +02:00
if devprj is None :
root . remove ( node )
else :
node . clear ( )
if devprj :
node . set ( ' project ' , devprj )
if devpac :
node . set ( ' package ' , devpac )
2013-10-07 13:12:58 +02:00
url = makeurl ( apiurl , [ ' source ' , prj , pac , ' _meta ' ] )
mf = metafile ( url , ET . tostring ( root , encoding = ET_ENCODING ) )
mf . sync ( )
2008-06-03 17:01:01 +02:00
2022-12-07 13:01:23 +01:00
def show_package_disabled_repos ( apiurl : str , prj : str , pac : str ) :
2010-07-12 14:56:08 +02:00
m = show_package_meta ( apiurl , prj , pac )
2022-09-12 13:43:10 +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 ' )
2017-11-08 10:39:42 +01:00
r = [ ]
for node in elm . findall ( ' disable ' ) :
repo = node . get ( ' repository ' )
arch = node . get ( ' arch ' )
dis_r = { ' repo ' : repo , ' arch ' : arch }
r . append ( dis_r )
2010-07-12 14:56:08 +02:00
return r
except :
return None
2022-12-07 13:01:23 +01:00
def show_pattern_metalist ( apiurl : str , prj : str ) :
2007-07-19 12:08:42 +02:00
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 )
2013-04-09 14:03:17 +02:00
except HTTPError as 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_metalist: Error getting pattern list for project \' %s \' ' % prj
raise
2022-09-12 13:43:10 +02:00
r = sorted ( node . get ( ' name ' ) for node in tree . getroot ( ) )
2007-07-19 12:08:42 +02:00
return r
2022-12-07 13:01:23 +01:00
def show_pattern_meta ( apiurl : str , prj : str , pattern : str ) :
2007-07-19 12:08:42 +02:00
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 ( )
2013-04-09 14:03:17 +02:00
except HTTPError as 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
2022-09-12 13:43:10 +02:00
2015-06-29 23:59:59 +02:00
def show_configuration ( apiurl ) :
u = makeurl ( apiurl , [ ' public ' , ' configuration ' ] )
f = http_GET ( u )
return f . readlines ( )
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. """
2021-08-25 13:55:21 +02:00
class _URLFactory :
# private class which might go away again...
def __init__ ( self , delegate , force_supported = True ) :
2022-05-20 12:00:44 +02:00
self . _delegate = delegate
2021-08-25 13:55:21 +02:00
self . _force_supported = force_supported
def is_force_supported ( self ) :
return self . _force_supported
def __call__ ( self , * * kwargs ) :
return self . _delegate ( * * kwargs )
2008-05-20 11:23:57 +02:00
def __init__ ( self , url , input , change_is_required = False , file_ext = ' .xml ' ) :
2021-08-25 13:55:21 +02:00
if isinstance ( url , self . _URLFactory ) :
self . _url_factory = url
else :
delegate = lambda * * kwargs : url
# force is not supported for a raw url
self . _url_factory = self . _URLFactory ( delegate , False )
self . url = self . _url_factory ( )
2007-01-12 04:52:13 +01:00
self . change_is_required = change_is_required
2022-09-12 13:43:10 +02:00
( fd , self . filename ) = tempfile . mkstemp ( prefix = ' osc_metafile. ' , suffix = file_ext )
2019-06-11 15:08:52 +02:00
open_mode = ' w '
input_as_str = None
if not isinstance ( input , list ) :
input = [ input ]
2019-07-02 09:36:05 +02:00
if input and isinstance ( input [ 0 ] , str ) :
2019-06-11 15:08:52 +02:00
input_as_str = ' ' . join ( input )
2018-12-13 15:14:06 +01:00
else :
2019-06-11 15:08:52 +02:00
open_mode = ' wb '
input_as_str = b ' ' . join ( input )
f = os . fdopen ( fd , open_mode )
f . write ( input_as_str )
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 ) :
2013-04-09 12:51:28 +02:00
print ( ' File unchanged. Not saving. ' )
2007-01-12 04:52:13 +01:00
os . unlink ( self . filename )
2010-02-22 15:43:02 +01:00
return
2006-05-23 17:27:43 +02:00
2013-04-09 12:51:28 +02:00
print ( ' Sending meta data... ' )
2008-05-20 18:03:08 +02:00
# 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 )
2013-04-09 12:51:28 +02:00
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 :
2021-08-25 13:55:21 +02:00
try_force = False
2013-04-09 11:34:46 +02:00
while True :
2021-08-25 13:55:21 +02:00
if not try_force :
run_editor ( self . filename )
try_force = False
2009-06-19 10:56:33 +02:00
try :
self . sync ( )
2010-02-11 21:22:07 +01:00
break
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2009-06-19 10:56:33 +02:00
error_help = " %d " % e . code
2014-06-08 21:33:06 +02:00
if e . hdrs . get ( ' X-Opensuse-Errorcode ' ) :
error_help = " %s ( %d ) " % ( e . hdrs . get ( ' X-Opensuse-Errorcode ' ) , e . code )
2009-06-19 10:56:33 +02:00
2013-04-09 12:51:28 +02:00
print ( ' BuildService API error: ' , error_help , file = sys . stderr )
2009-06-19 10:56:33 +02:00
# examine the error - we can't raise an exception because we might want
# to try again
2019-05-29 12:19:47 +02:00
root = ET . fromstring ( e . read ( ) )
summary = root . find ( ' summary ' )
if summary is not None :
print ( summary . text , file = sys . stderr )
2021-08-25 13:55:21 +02:00
if self . _url_factory . is_force_supported ( ) :
prompt = ' Try again? ([y/N/f]): '
else :
prompt = ' Try again? ([y/N): '
ri = raw_input ( prompt )
if ri in ( ' y ' , ' Y ' ) :
self . url = self . _url_factory ( )
elif ri in ( ' f ' , ' F ' ) and self . _url_factory . is_force_supported ( ) :
self . url = self . _url_factory ( force = ' 1 ' )
try_force = True
else :
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 ) :
2013-04-09 12:51:28 +02: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
2022-09-12 13:43:10 +02:00
2007-07-13 18:01:02 +02:00
# different types of metadata
2022-09-12 13:43:10 +02:00
metatypes = { ' prj ' : { ' path ' : ' source/ %s /_meta ' ,
' template ' : new_project_templ ,
' file_ext ' : ' .xml '
} ,
' pkg ' : { ' path ' : ' source/ %s / %s /_meta ' ,
' template ' : new_package_templ ,
' file_ext ' : ' .xml '
} ,
' attribute ' : { ' path ' : ' source/ %s / %s /_meta ' ,
2009-10-30 10:40:46 +01:00
' template ' : new_attribute_templ ,
' file_ext ' : ' .xml '
2022-09-12 13:43:10 +02:00
} ,
' prjconf ' : { ' path ' : ' source/ %s /_config ' ,
' template ' : ' ' ,
' file_ext ' : ' .txt '
2009-10-30 10:40:46 +01:00
} ,
2022-09-12 13:43:10 +02:00
' user ' : { ' path ' : ' person/ %s ' ,
' template ' : new_user_template ,
' file_ext ' : ' .xml '
} ,
' group ' : { ' path ' : ' group/ %s ' ,
' template ' : new_group_template ,
' file_ext ' : ' .xml '
} ,
' pattern ' : { ' path ' : ' source/ %s /_pattern/ %s ' ,
' template ' : new_pattern_template ,
' file_ext ' : ' .xml '
2007-07-19 12:08:42 +02:00
} ,
2022-09-12 13:43:10 +02:00
}
2007-07-13 18:01:02 +02:00
2022-12-07 13:01:23 +01:00
def meta_exists ( metatype : str , path_args = None , template_args = None , 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 ( )
2013-04-09 14:03:17 +02:00
except HTTPError as 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
2011-03-30 14:12:59 +02:00
2007-08-04 23:11:31 +02:00
return data
2007-07-16 18:20:09 +02:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def make_meta_url (
metatype : str ,
path_args = None ,
apiurl : Optional [ str ] = None ,
force = False ,
remove_linking_repositories = False ,
msg = 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
2011-03-16 10:20:38 +01:00
query = { }
if force :
2022-09-12 13:43:10 +02:00
query = { ' force ' : ' 1 ' }
2012-12-06 14:07:02 +01:00
if remove_linking_repositories :
query [ ' remove_linking_repositories ' ] = ' 1 '
2016-06-01 14:00:37 +02:00
if msg :
query [ ' comment ' ] = msg
2011-03-16 10:20:38 +01:00
return makeurl ( apiurl , [ path ] , query )
2007-07-23 18:03:30 +02:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def parse_meta_to_string ( data : Union [ bytes , list , Iterable ] ) - > str :
2019-11-18 09:36:09 +01:00
"""
Converts the output of meta_exists into a string value
"""
# data can be a bytes object, a list with strings, a list with bytes, just a string.
# So we need the following even if it is ugly.
2022-07-28 19:11:29 +02:00
if isinstance ( data , bytes ) :
data = decode_it ( data )
elif isinstance ( data , list ) :
data = decode_list ( data )
2019-11-18 09:36:09 +01:00
return ' ' . join ( data )
2007-07-23 18:03:30 +02:00
2022-12-07 13:01:23 +01:00
def edit_meta (
metatype ,
path_args = None ,
data : Optional [ List [ str ] ] = None ,
template_args = None ,
edit = False ,
force = False ,
remove_linking_repositories = False ,
change_is_required = False ,
apiurl : Optional [ str ] = None ,
msg = 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 ,
2022-09-12 13:43:10 +02: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
2014-02-24 16:02:47 +01:00
if metatype == ' pkg ' :
# check if the package is a link to a different project
project , package = path_args
2019-11-18 09:36:09 +01:00
orgprj = ET . fromstring ( parse_meta_to_string ( data ) ) . get ( ' project ' )
2018-12-13 15:14:06 +01:00
2014-02-28 00:42:47 +01:00
if orgprj is not None and unquote ( project ) != orgprj :
2014-02-24 16:02:47 +01:00
print ( ' The package is linked from a different project. ' )
print ( ' If you want to edit the meta of the package create first a branch. ' )
print ( ' osc branch %s %s %s ' % ( orgprj , package , unquote ( project ) ) )
print ( ' osc meta pkg %s %s -e ' % ( unquote ( project ) , package ) )
return
2022-09-12 13:43:10 +02:00
def delegate ( force = force ) :
return make_meta_url ( metatype , path_args , apiurl , force , remove_linking_repositories , msg )
2021-08-25 13:55:21 +02:00
url_factory = metafile . _URLFactory ( delegate )
f = metafile ( url_factory , 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
2022-12-07 13:01:23 +01:00
def show_files_meta (
apiurl : str ,
prj : str ,
pac : str ,
revision = None ,
expand = False ,
linkrev = None ,
linkrepair = False ,
meta = False ,
deleted = 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
2017-06-24 14:25:05 +02:00
if deleted :
query [ ' deleted ' ] = 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
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def show_upstream_srcmd5 (
apiurl : str , prj : str , pac : str , expand = False , revision = None , meta = False , include_service_files = False , deleted = False
) :
2017-06-24 14:25:05 +02:00
m = show_files_meta ( apiurl , prj , pac , expand = expand , revision = revision , meta = meta , deleted = deleted )
2018-12-13 15:14:06 +01:00
et = ET . fromstring ( m )
2011-05-23 15:26:13 +02:00
if include_service_files :
try :
2013-10-18 14:58:18 +02:00
sinfo = et . find ( ' serviceinfo ' )
2022-08-29 12:56:57 +02:00
if sinfo is not None and sinfo . get ( ' xsrcmd5 ' ) and not sinfo . get ( ' error ' ) :
2013-10-18 14:58:18 +02:00
return sinfo . get ( ' xsrcmd5 ' )
2011-05-23 15:26:13 +02:00
except :
pass
return et . get ( ' srcmd5 ' )
2008-03-13 00:37:35 +01:00
2022-12-07 13:01:23 +01:00
def show_upstream_xsrcmd5 (
apiurl : str , prj , pac , revision = None , linkrev = None , linkrepair = False , meta = False , include_service_files = False
) :
m = show_files_meta (
apiurl ,
prj ,
pac ,
revision = revision ,
linkrev = linkrev ,
linkrepair = linkrepair ,
meta = meta ,
expand = include_service_files ,
)
2018-12-13 15:14:06 +01:00
et = ET . fromstring ( m )
2011-05-23 15:26:13 +02:00
if include_service_files :
return et . get ( ' srcmd5 ' )
2016-02-09 14:42:50 +01:00
li_node = et . find ( ' linkinfo ' )
if li_node is None :
2008-03-24 21:24:49 +01:00
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
2022-12-07 13:01:23 +01:00
def show_project_sourceinfo ( apiurl : str , project : str , nofilename : bool , * packages ) :
2014-06-22 15:41:14 +02:00
query = [ ' view=info ' ]
if packages :
2014-06-24 23:05:38 +02:00
query . extend ( [ ' package= %s ' % quote_plus ( p ) for p in packages ] )
2014-06-22 15:41:14 +02:00
if nofilename :
query . append ( ' nofilename=1 ' )
f = http_GET ( makeurl ( apiurl , [ ' source ' , project ] , query = query ) )
return f . read ( )
2022-12-07 13:01:23 +01:00
def get_project_sourceinfo ( apiurl : str , project : str , nofilename : bool , * packages ) :
2014-06-23 09:51:49 +02:00
try :
2014-06-23 10:58:20 +02:00
si = show_project_sourceinfo ( apiurl , project , nofilename , * packages )
2015-08-13 13:40:16 +02:00
except HTTPError as e :
2015-08-06 14:23:45 +02:00
# old API servers (e.g. 2.3.5) do not know the 'nofilename' parameter, so retry without
2015-07-29 14:18:23 +02:00
if e . code == 400 and nofilename :
return get_project_sourceinfo ( apiurl , project , False , * packages )
2016-09-09 13:34:21 +02:00
# an uri too long error is sometimes handled as status 500
# (depending, e.g., on the apache2 configuration)
if e . code not in ( 414 , 500 ) :
2014-06-23 09:51:49 +02:00
raise
if len ( packages ) == 1 :
raise oscerr . APIError ( ' package name too long: %s ' % packages [ 0 ] )
2018-12-13 15:14:06 +01:00
n = int ( len ( packages ) / 2 )
2014-06-23 09:51:49 +02:00
pkgs = packages [ : n ]
2014-06-23 10:58:20 +02:00
res = get_project_sourceinfo ( apiurl , project , nofilename , * pkgs )
2014-06-23 09:51:49 +02:00
pkgs = packages [ n : ]
2014-06-23 10:58:20 +02:00
res . update ( get_project_sourceinfo ( apiurl , project , nofilename , * pkgs ) )
2014-06-23 09:51:49 +02:00
return res
2014-06-22 15:41:14 +02:00
root = ET . fromstring ( si )
res = { }
for sinfo in root . findall ( ' sourceinfo ' ) :
res [ sinfo . get ( ' package ' ) ] = sinfo
return res
2022-12-07 13:01:23 +01:00
def show_upstream_rev_vrev ( apiurl : str , prj , pac , revision = None , expand = False , meta = False ) :
2014-03-03 22:44:30 +01:00
m = show_files_meta ( apiurl , prj , pac , revision = revision , expand = expand , meta = meta )
2018-12-13 15:14:06 +01:00
et = ET . fromstring ( m )
2012-03-02 15:44:15 +01:00
return et . get ( ' rev ' ) , et . get ( ' vrev ' )
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def show_upstream_rev (
apiurl : str , prj , pac , revision = None , expand = False , linkrev = None , meta = False , include_service_files = False
) :
2011-03-17 18:18:01 +01:00
m = show_files_meta ( apiurl , prj , pac , revision = revision , expand = expand , linkrev = linkrev , meta = meta )
2018-12-13 15:14:06 +01:00
et = ET . fromstring ( m )
2011-05-23 15:26:13 +02:00
if include_service_files :
try :
2013-10-18 14:58:18 +02:00
sinfo = et . find ( ' serviceinfo ' )
2022-08-29 12:56:57 +02:00
if sinfo is not None and sinfo . get ( ' xsrcmd5 ' ) and not sinfo . get ( ' error ' ) :
2013-10-18 14:58:18 +02:00
return sinfo . get ( ' xsrcmd5 ' )
2011-05-23 15:26:13 +02:00
except :
pass
return et . 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 ) :
"""
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
2022-07-28 19:11:29 +02:00
tag_pat = r ' (?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
2022-07-28 19:11:29 +02:00
section_pat = r ' ^ %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 :
2022-09-12 13:43:10 +02: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
2022-09-12 13:43:10 +02:00
2019-12-04 17:11:35 +01:00
def _get_linux_distro ( ) :
if distro is not None :
return distro . id ( )
2023-01-20 13:24:50 +01:00
return None
2019-12-04 17:11:35 +01:00
2022-09-12 13:43:10 +02:00
2010-06-09 14:20:48 +02:00
def get_default_editor ( ) :
system = platform . system ( )
if system == ' Linux ' :
2019-12-04 17:11:35 +01:00
dist = _get_linux_distro ( )
2010-06-09 14:20:48 +02:00
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 '
2022-09-12 13:43:10 +02:00
2010-06-09 14:20:48 +02:00
def get_default_pager ( ) :
system = platform . system ( )
if system == ' Linux ' :
2019-12-04 17:11:35 +01:00
dist = _get_linux_distro ( )
2010-06-09 14:20:48 +02:00
if dist == ' debian ' :
return ' pager '
return ' less '
return ' more '
2022-09-12 13:43:10 +02:00
2011-04-24 00:27:47 +02:00
def run_pager ( message , tmp_suffix = ' ' ) :
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 ( ) :
2018-12-13 15:14:06 +01:00
if isinstance ( message , str ) :
print ( message )
else :
2019-07-17 10:34:20 +02:00
sys . stdout . buffer . write ( message )
2010-05-09 21:47:21 +02:00
else :
2011-04-24 00:27:47 +02:00
tmpfile = tempfile . NamedTemporaryFile ( suffix = tmp_suffix )
2018-12-13 15:14:06 +01:00
if isinstance ( message , str ) :
tmpfile . write ( bytes ( message , ' utf-8 ' ) )
else :
tmpfile . write ( message )
2010-05-09 21:47:21 +02:00
tmpfile . flush ( )
2022-12-07 15:57:16 +01:00
pager = os . getenv ( " PAGER " , default = " " ) . strip ( )
pager = pager or get_default_pager ( )
2017-02-11 20:21:02 +01:00
cmd = shlex . split ( pager ) + [ tmpfile . name ]
2010-07-08 21:43:39 +02:00
try :
2017-02-11 20:21:02 +01:00
run_external ( * cmd )
2010-07-08 21:43:39 +02:00
finally :
tmpfile . close ( )
2010-05-03 10:05:36 +02:00
2022-09-12 13:43:10 +02:00
2010-04-28 11:49:31 +02:00
def run_editor ( filename ) :
2013-08-03 19:34:47 +02:00
cmd = _editor_command ( )
cmd . append ( filename )
return run_external ( cmd [ 0 ] , * cmd [ 1 : ] )
2022-09-12 13:43:10 +02:00
2013-08-03 19:34:47 +02:00
def _editor_command ( ) :
2022-12-07 15:57:16 +01:00
editor = os . getenv ( " EDITOR " , default = " " ) . strip ( )
editor = editor or get_default_editor ( )
2013-08-03 19:23:25 +02:00
try :
cmd = shlex . split ( editor )
except SyntaxError :
cmd = editor . split ( )
2013-08-03 19:34:47 +02:00
return cmd
2006-05-19 22:13:29 +02:00
2022-09-12 13:43:10 +02:00
2023-05-04 10:58:21 +02:00
# list of files with message backups
# we'll show this list when osc errors out
MESSAGE_BACKUPS = [ ]
2013-03-08 17:17:45 +01:00
def _edit_message_open_editor ( filename , data , orig_mtime ) :
2013-08-03 19:34:47 +02:00
editor = _editor_command ( )
2013-03-08 17:17:45 +01:00
mtime = os . stat ( filename ) . st_mtime
2018-12-13 15:14:06 +01:00
if isinstance ( data , str ) :
data = bytes ( data , ' utf-8 ' )
2013-03-08 17:17:45 +01:00
if mtime == orig_mtime :
# prepare file for editors
if editor [ 0 ] in ( ' vi ' , ' vim ' ) :
with tempfile . NamedTemporaryFile ( ) as f :
f . write ( data )
f . flush ( )
editor . extend ( [ ' -c ' , ' :r %s ' % f . name , filename ] )
run_external ( editor [ 0 ] , * editor [ 1 : ] )
else :
2018-12-13 15:14:06 +01:00
with open ( filename , ' wb ' ) as f :
2013-03-08 17:17:45 +01:00
f . write ( data )
orig_mtime = os . stat ( filename ) . st_mtime
run_editor ( filename )
else :
run_editor ( filename )
2023-05-04 10:58:21 +02:00
if os . stat ( filename ) . st_mtime != orig_mtime :
# file has changed
cache_dir = os . path . expanduser ( " ~/.cache/osc/edited-messages " )
try :
os . makedirs ( cache_dir , mode = 0o700 )
except FileExistsError :
pass
# remove any stored messages older than 1 day
now = datetime . datetime . now ( )
epoch = datetime . datetime . timestamp ( now - datetime . timedelta ( days = 1 ) )
for fn in os . listdir ( cache_dir ) :
path = os . path . join ( cache_dir , fn )
if not os . path . isfile ( path ) :
continue
mtime = os . path . getmtime ( path )
if mtime < epoch :
os . unlink ( path )
# store the current message's backup to the cache dir
message_backup_path = os . path . join ( cache_dir , str ( now ) . replace ( " " , " _ " ) )
shutil . copyfile ( filename , message_backup_path )
MESSAGE_BACKUPS . append ( message_backup_path )
return True
return False
2013-03-08 17:17:45 +01:00
2022-09-12 13:43:10 +02:00
2010-05-09 21:36:51 +02:00
def edit_message ( footer = ' ' , template = ' ' , templatelen = 30 ) :
2013-03-08 17:17:45 +01:00
delim = ' --This line, and those below, will be ignored-- \n '
data = ' '
2009-04-28 09:15:57 +02:00
if template != ' ' :
2022-09-12 14:23:47 +02:00
if templatelen is not None :
2010-05-09 21:36:51 +02:00
lines = template . splitlines ( )
2013-03-08 17:17:45 +01:00
data = ' \n ' . join ( lines [ : templatelen ] )
2010-05-09 21:36:51 +02:00
if lines [ templatelen : ] :
footer = ' %s \n \n %s ' % ( ' \n ' . join ( lines [ templatelen : ] ) , footer )
2013-03-08 17:17:45 +01:00
data + = ' \n ' + delim + ' \n ' + footer
2014-12-08 22:19:28 +01:00
return edit_text ( data , delim , suffix = ' .diff ' , template = template )
2014-10-31 09:22:25 +01:00
2022-09-12 13:43:10 +02:00
2014-11-12 14:40:24 +01:00
def edit_text ( data = ' ' , delim = None , suffix = ' .txt ' , template = ' ' ) :
2010-02-11 21:22:07 +01:00
try :
2014-11-02 20:12:16 +01:00
( fd , filename ) = tempfile . mkstemp ( prefix = ' osc-editor ' , suffix = suffix )
2013-03-08 17:17:45 +01:00
os . close ( fd )
mtime = os . stat ( filename ) . st_mtime
2017-04-19 11:35:14 +02:00
ri_err = False
2013-04-09 11:34:46 +02:00
while True :
2017-04-19 11:35:14 +02:00
if not ri_err :
file_changed = _edit_message_open_editor ( filename , data , mtime )
msg = open ( filename ) . read ( )
2014-10-31 09:22:25 +01:00
if delim :
msg = msg . split ( delim ) [ 0 ] . rstrip ( )
2013-03-08 17:17:45 +01:00
if msg and file_changed :
2010-02-11 12:46:20 +01:00
break
2010-02-11 21:22:07 +01:00
else :
2013-02-13 11:42:34 +01:00
reason = ' Log message not specified '
2014-11-12 14:40:24 +01:00
if template == msg :
2013-03-06 17:33:32 +01:00
reason = ' Default log message was not changed. Press \' c \' to continue. '
2013-02-13 11:42:34 +01:00
ri = raw_input ( ' %s \n a)bort, c)ontinue, e)dit: ' % reason )
2010-08-20 14:34:41 +02:00
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 ' :
2017-04-19 11:35:14 +02:00
ri_err = False
else :
print ( " %s is not a valid option. " % ri )
ri_err = True
2010-02-11 21:22:07 +01:00
finally :
os . unlink ( filename )
2010-02-11 12:46:20 +01:00
return msg
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def clone_request ( apiurl : str , reqid , msg = None ) :
2010-10-26 15:34:32 +02:00
query = { ' cmd ' : ' branch ' , ' request ' : reqid }
url = makeurl ( apiurl , [ ' source ' ] , query )
r = http_POST ( url , data = msg )
2011-01-29 23:14:19 +01:00
root = ET . fromstring ( r . read ( ) )
project = None
for i in root . findall ( ' data ' ) :
if i . get ( ' name ' ) == ' targetproject ' :
project = i . text . strip ( )
if not project :
2013-04-10 11:34:59 +02:00
raise oscerr . APIError ( ' invalid data from clone request: \n %s \n ' % ET . tostring ( root , encoding = ET_ENCODING ) )
2011-01-29 23:14:19 +01:00
return project
2009-06-02 15:14:46 +02:00
2011-03-07 19:45:44 +01:00
# create a maintenance release request
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def create_release_request ( apiurl : str , src_project , message = " " ) :
2011-03-07 19:45:44 +01:00
r = Request ( )
# api will complete the request
r . add_action ( ' maintenance_release ' , src_project = src_project )
2022-07-28 12:28:33 +02:00
r . description = message
2011-03-07 19:45:44 +01:00
r . create ( apiurl )
return r
2011-03-07 11:46:51 +01:00
# create a maintenance incident per request
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def create_maintenance_request (
apiurl : str ,
src_project ,
src_packages ,
tgt_project ,
tgt_releaseproject ,
opt_sourceupdate ,
message = " " ,
enforce_branching = False ,
rev = None ,
) :
2011-03-07 13:03:34 +01:00
r = Request ( )
2012-01-19 11:36:57 +01:00
if src_packages :
for p in src_packages :
2022-09-12 13:43:10 +02:00
r . add_action ( ' maintenance_incident ' , src_project = src_project , src_package = p , src_rev = rev , tgt_project = tgt_project , tgt_releaseproject = tgt_releaseproject , opt_sourceupdate = opt_sourceupdate )
2012-01-19 11:36:57 +01:00
else :
2022-09-12 13:43:10 +02:00
r . add_action ( ' maintenance_incident ' , src_project = src_project , tgt_project = tgt_project , tgt_releaseproject = tgt_releaseproject , opt_sourceupdate = opt_sourceupdate )
2022-07-28 12:28:33 +02:00
r . description = message
2019-07-22 15:32:19 +02:00
r . create ( apiurl , addrevision = True , enforce_branching = enforce_branching )
2011-03-07 13:03:34 +01:00
return r
2011-03-07 11:46:51 +01:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def create_submit_request (
apiurl : str ,
src_project : str ,
src_package : Optional [ str ] = None ,
dst_project : Optional [ str ] = None ,
dst_package : Optional [ str ] = None ,
message = " " ,
orev = None ,
src_update = None ,
dst_updatelink = None ,
) :
2013-05-27 14:56:24 +02:00
options_block = " "
package = " "
2012-01-24 12:03:34 +01:00
if src_package :
2013-05-27 14:56:24 +02:00
package = """ package= " %s " """ % ( src_package )
2015-03-09 08:44:12 +01:00
options_block = " <options> "
2009-09-10 10:48:44 +02:00
if src_update :
2015-03-09 08:44:12 +01:00
options_block + = """ <sourceupdate> %s </sourceupdate> """ % ( src_update )
if dst_updatelink :
2015-03-09 09:01:00 +01:00
options_block + = """ <updatelink>true</updatelink> """
2015-03-09 08:44:12 +01:00
options_block + = " </options> "
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 :
2022-09-12 13:43:10 +02:00
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 = """ \
2015-03-09 08:44:12 +01:00
< request >
< action type = " submit " >
2012-01-23 14:12:17 +01:00
< source project = " %s " % s rev = " %s " / >
2009-11-13 09:58:37 +01:00
% s
2009-09-10 10:48:44 +02:00
% s
2015-03-09 08:44:12 +01:00
< / action >
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,
2012-01-23 14:12:17 +01:00
package ,
2009-06-02 15:14:46 +02:00
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 ,
2020-03-12 23:00:47 +01:00
_html_escape ( message ) )
2011-03-07 18:16:10 +01:00
2008-04-02 16:07:40 +02:00
u = makeurl ( apiurl , [ ' request ' ] , query = ' cmd=create ' )
2012-02-08 15:56:03 +01:00
r = None
2012-01-23 14:12:17 +01:00
try :
f = http_POST ( u , data = xml )
root = ET . parse ( f ) . getroot ( )
r = root . get ( ' id ' )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2014-06-08 21:33:06 +02:00
if e . hdrs . get ( ' X-Opensuse-Errorcode ' ) == " submit_request_rejected " :
2022-03-23 09:30:21 +01:00
print ( ' WARNING: As the project is in maintenance, a maintenance incident request is ' )
print ( ' WARNING: being created (instead of a regular submit request). If this is not your ' )
print ( ' WARNING: intention please revoke it to avoid unnecessary work for all involved parties. ' )
2015-01-13 16:50:47 +01:00
xpath = ' maintenance/maintains/@project = \' %s \' and attribute/@name = \' %s \' ' % ( dst_project , conf . config [ ' maintenance_attribute ' ] )
2012-02-21 10:51:34 +01:00
res = search ( apiurl , project_id = xpath )
root = res [ ' project_id ' ]
project = root . find ( ' project ' )
2015-01-09 11:20:51 +01:00
if project is None :
2022-04-20 19:22:35 +02:00
print ( " WARNING: This project is not maintained in the maintenance project specified by ' %s ' , looking elsewhere " % conf . config [ ' maintenance_attribute ' ] )
xpath = ' maintenance/maintains/@project = \' %s \' ' % dst_project
res = search ( apiurl , project_id = xpath )
root = res [ ' project_id ' ]
project = root . find ( ' project ' )
2012-02-21 10:51:34 +01:00
if project is None :
2012-03-12 14:49:53 +01:00
raise oscerr . APIError ( " Server did not define a default maintenance project, can ' t submit. " )
2012-02-21 10:51:34 +01:00
tproject = project . get ( ' name ' )
2020-01-08 15:26:50 +01:00
r = create_maintenance_request ( apiurl , src_project , [ src_package ] , tproject , dst_project , src_update , message , rev = orev )
2015-02-09 16:44:09 +01:00
r = r . reqid
2012-01-24 11:51:22 +01:00
else :
2012-02-21 10:51:34 +01:00
raise
2008-03-05 00:41:00 +01:00
2012-01-23 14:12:17 +01:00
return r
2008-03-05 00:41:00 +01:00
2022-12-07 13:01:23 +01:00
def get_request ( apiurl : str , reqid ) :
2014-09-11 11:08:13 +02:00
u = makeurl ( apiurl , [ ' request ' , reqid ] , { ' withfullhistory ' : ' 1 ' } )
2008-03-05 00:41:00 +01:00
f = http_GET ( u )
root = ET . parse ( f ) . getroot ( )
2009-06-02 15:14:46 +02:00
r = Request ( )
2023-02-10 15:27:46 +01:00
r . read ( root , apiurl = apiurl )
2008-03-05 00:41:00 +01:00
return r
2022-12-07 13:01:23 +01:00
def change_review_state (
apiurl : str , reqid , newstate , by_user = " " , by_group = " " , by_project = " " , by_package = " " , message = " " , supersed = None
) :
query = { " cmd " : " changereviewstate " , " newstate " : newstate }
2011-04-26 17:18:49 +02:00
if by_user :
query [ ' by_user ' ] = by_user
2010-12-15 14:31:18 +01:00
if by_group :
query [ ' by_group ' ] = by_group
2011-01-23 21:21:32 +01:00
if by_project :
query [ ' by_project ' ] = by_project
if by_package :
query [ ' by_package ' ] = by_package
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 ( )
2011-02-22 17:52:12 +01:00
return root . get ( ' code ' )
2009-11-17 17:59:17 +01:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def change_request_state ( apiurl : str , reqid , newstate , message = " " , supersed = None , force = False ) :
query = { " cmd " : " changestate " , " newstate " : newstate }
2010-12-21 14:17:12 +01:00
if supersed :
query [ ' superseded_by ' ] = supersed
2011-02-08 16:16:18 +01:00
if force :
query [ ' force ' ] = " 1 "
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 )
2015-04-07 15:27:40 +02:00
root = ET . parse ( f ) . getroot ( )
return root . get ( ' code ' , ' unknown ' )
2008-03-06 11:25:45 +01:00
2022-09-12 13:43:10 +02:00
2010-11-14 18:32:02 +01:00
def change_request_state_template ( req , newstate ) :
2022-08-29 13:23:29 +02:00
if not req . actions :
2010-11-14 18:32:02 +01:00
return ' '
action = req . actions [ 0 ]
tmpl_name = ' %s request_ %s _template ' % ( action . type , newstate )
tmpl = conf . config . get ( tmpl_name , ' ' )
2014-08-12 15:01:16 +02:00
tmpl = tmpl . replace ( ' \\ t ' , ' \t ' ) . replace ( ' \\ n ' , ' \n ' )
2017-04-12 12:58:23 +02:00
data = { ' reqid ' : req . reqid , ' type ' : action . type , ' who ' : req . creator }
2010-11-14 18:32:02 +01:00
if req . actions [ 0 ] . type == ' submit ' :
data . update ( { ' src_project ' : action . src_project ,
2022-09-12 13:43:10 +02:00
' src_package ' : action . src_package , ' src_rev ' : action . src_rev ,
' dst_project ' : action . tgt_project , ' dst_package ' : action . tgt_package ,
' tgt_project ' : action . tgt_project , ' tgt_package ' : action . tgt_package } )
2010-11-14 18:32:02 +01:00
try :
return tmpl % data
2013-04-09 11:27:02 +02:00
except KeyError as e :
2013-04-09 12:51:28 +02:00
print ( ' error: cannot interpolate \' %s \' in \' %s \' ' % ( e . args [ 0 ] , tmpl_name ) , file = sys . stderr )
2010-11-14 18:32:02 +01:00
return ' '
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def get_review_list (
apiurl : str , project = " " , package = " " , byuser = " " , bygroup = " " , byproject = " " , bypackage = " " , states = ( ) , req_type = " "
) :
2012-04-03 19:19:54 +02:00
# this is so ugly...
def build_by ( xpath , val ) :
if ' all ' in states :
return xpath_join ( xpath , ' review/ %s ' % val , op = ' and ' )
elif states :
s_xp = ' '
for state in states :
s_xp = xpath_join ( s_xp , ' @state= \' %s \' ' % state , inner = True )
val = val . strip ( ' [ ' ) . strip ( ' ] ' )
return xpath_join ( xpath , ' review[ %s and ( %s )] ' % ( val , s_xp ) , op = ' and ' )
2014-08-25 17:02:56 +02:00
else :
# default case
return xpath_join ( xpath , ' review[ %s and @state= \' new \' ] ' % val , op = ' and ' )
2012-04-03 19:19:54 +02:00
return ' '
2010-07-29 13:45:44 +02:00
xpath = ' '
2023-05-09 16:12:21 +02:00
# we're interested only in reviews of requests that are still open
xpath = xpath_join ( xpath , " (state/@name= ' new ' or state/@name= ' review ' or state/@name= ' declined ' ) " , op = " and " )
2014-08-25 17:02:56 +02:00
if states == ( ) :
xpath = xpath_join ( xpath , ' review/@state= \' new \' ' , op = ' and ' )
2011-01-23 21:21:32 +01:00
if byuser :
2012-04-03 19:19:54 +02:00
xpath = build_by ( xpath , ' @by_user= \' %s \' ' % byuser )
2011-01-23 21:21:32 +01:00
if bygroup :
2012-04-03 19:19:54 +02:00
xpath = build_by ( xpath , ' @by_group= \' %s \' ' % bygroup )
2011-01-23 21:21:32 +01:00
if bypackage :
2012-04-03 19:19:54 +02:00
xpath = build_by ( xpath , ' @by_project= \' %s \' and @by_package= \' %s \' ' % ( byproject , bypackage ) )
2011-01-23 21:21:32 +01:00
elif byproject :
2012-04-03 19:19:54 +02:00
xpath = build_by ( xpath , ' @by_project= \' %s \' ' % byproject )
2010-07-29 13:45:44 +02:00
2017-08-24 12:01:19 +02:00
if req_type :
xpath = xpath_join ( xpath , ' action/@type= \' %s \' ' % req_type , 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
2013-04-09 11:25:19 +02:00
for kind , val in todo . items ( ) :
2018-08-07 11:21:22 +02:00
xpath_base = ' action/target/@ %(kind)s = \' %(val)s \' '
2011-05-12 23:27:19 +02:00
if conf . config [ ' include_request_from_project ' ] :
2018-08-07 11:21:22 +02:00
xpath_base = xpath_join ( xpath_base , ' action/source/@ %(kind)s = \' %(val)s \' ' , op = ' or ' , inner = True )
2011-05-12 23:27:19 +02:00
xpath = xpath_join ( xpath , xpath_base % { ' kind ' : kind , ' val ' : val } , op = ' and ' , nexpr_parentheses = True )
2010-07-29 13:45:44 +02:00
2022-08-30 12:38:04 +02:00
if conf . config [ ' debug ' ] :
2013-04-09 12:51:28 +02:00
print ( ' [ %s ] ' % xpath )
2010-07-29 13:45:44 +02:00
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
2022-09-15 14:47:38 +02:00
2015-07-29 11:05:05 +02:00
# this function uses the logic in the api which is faster and more exact then the xpath search
2022-09-15 14:47:38 +02:00
def get_request_collection (
2022-12-07 13:01:23 +01:00
apiurl : str ,
user = None ,
group = None ,
roles = None ,
project = None ,
package = None ,
states = None ,
review_states = None ,
2023-02-03 09:57:51 +01:00
types : List [ str ] = None ,
2022-12-07 13:01:23 +01:00
ids = None ,
2023-01-25 15:25:46 +01:00
withfullhistory = False
2022-12-07 13:01:23 +01:00
) :
2022-09-15 14:47:38 +02:00
# We don't want to overload server by requesting everything.
# Let's enforce specifying at least some search criteria.
if not any ( [ user , group , project , package , ids ] ) :
2022-10-13 09:44:51 +02:00
raise oscerr . OscValueError ( " Please specify search criteria " )
2022-09-12 13:43:10 +02:00
2022-09-15 14:47:38 +02:00
query = { " view " : " collection " }
2022-09-12 13:43:10 +02:00
2022-09-15 14:47:38 +02:00
if user :
query [ " user " ] = user
2015-07-29 11:05:05 +02:00
2022-09-15 14:47:38 +02:00
if group :
query [ " group " ] = group
if roles :
query [ " roles " ] = " , " . join ( roles )
if project :
query [ " project " ] = project
if package :
if not project :
raise ValueError ( " Project must be set to query a package; see https://github.com/openSUSE/open-build-service/issues/13075 " )
query [ " package " ] = package
2015-07-29 11:05:05 +02:00
2023-02-02 13:50:51 +01:00
states = states or ( " new " , " review " , " declined " )
2022-09-15 14:47:38 +02:00
if states :
if " all " not in states :
query [ " states " ] = " , " . join ( states )
if review_states :
if " all " not in review_states :
query [ " review_states " ] = " , " . join ( review_states )
2015-07-29 11:05:05 +02:00
2022-09-15 14:47:38 +02:00
if types :
2023-02-03 09:57:51 +01:00
assert not isinstance ( types , str )
2022-09-15 14:47:38 +02:00
query [ " types " ] = " , " . join ( types )
if ids :
query [ " ids " ] = " , " . join ( ids )
2015-07-29 11:05:05 +02:00
2023-01-25 15:25:46 +01:00
if withfullhistory :
query [ " withfullhistory " ] = " 1 "
2015-07-29 11:05:05 +02:00
u = makeurl ( apiurl , [ ' request ' ] , query )
f = http_GET ( u )
res = ET . parse ( f ) . getroot ( )
requests = [ ]
for root in res . findall ( ' request ' ) :
r = Request ( )
r . read ( root )
2023-03-31 14:01:10 +02:00
# post-process results until we switch back to the /search/request
# which seems to be more suitable for such queries
exclude = False
for action in r . actions :
src_project = getattr ( action , " src_project " , None )
src_package = getattr ( action , " src_package " , None )
tgt_project = getattr ( action , " tgt_project " , None )
tgt_package = getattr ( action , " tgt_package " , None )
# skip if neither of source and target project matches
if " project " in query and query [ " project " ] not in ( src_project , tgt_project ) :
exclude = True
break
# skip if neither of source and target package matches
if " package " in query and query [ " package " ] not in ( src_package , tgt_package ) :
exclude = True
break
if not conf . config [ " include_request_from_project " ] :
if " project " in query and " package " in query :
if ( src_project , src_package ) == ( query [ " project " ] , query [ " package " ] ) :
exclude = True
break
elif " project " in query :
if src_project == query [ " project " ] :
exclude = True
break
if exclude :
continue
2015-07-29 11:05:05 +02:00
requests . append ( r )
return requests
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def get_exact_request_list (
apiurl : str ,
src_project : str ,
dst_project : str ,
src_package : Optional [ str ] = None ,
dst_package : Optional [ str ] = None ,
req_who : Optional [ str ] = None ,
req_state = ( " new " , " review " , " declined " ) ,
req_type : Optional [ str ] = None ,
) :
xpath = " "
if " all " not in req_state :
2012-01-26 13:26:31 +01:00
for state in req_state :
xpath = xpath_join ( xpath , ' state/@name= \' %s \' ' % state , op = ' or ' , inner = True )
2012-01-30 13:13:28 +01:00
xpath = ' ( %s ) ' % xpath
2012-01-26 13:26:31 +01:00
if req_who :
xpath = xpath_join ( xpath , ' (state/@who= \' %(who)s \' or history/@who= \' %(who)s \' ) ' % { ' who ' : req_who } , op = ' and ' )
xpath + = " and action[source/@project= ' %s ' " % src_project
if src_package :
xpath + = " and source/@package= ' %s ' " % src_package
xpath + = " and target/@project= ' %s ' " % dst_project
2015-08-07 10:17:40 +02:00
if dst_package :
2012-01-26 13:26:31 +01:00
xpath + = " and target/@package= ' %s ' " % dst_package
xpath + = " ] "
if req_type :
xpath + = " and action/@type= \' %s \' " % req_type
2022-08-30 12:38:04 +02:00
if conf . config [ ' debug ' ] :
2013-04-09 12:51:28 +02:00
print ( ' [ %s ] ' % xpath )
2012-01-26 13:26:31 +01:00
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
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def get_request_list (
apiurl : str ,
project = " " ,
package = " " ,
req_who = " " ,
req_state = ( " new " , " review " , " declined " ) ,
req_type = None ,
exclude_target_projects = None ,
withfullhistory = False ,
roles = None ,
) :
2022-09-15 14:47:38 +02:00
kwargs = {
" apiurl " : apiurl ,
" user " : req_who ,
" roles " : roles ,
" project " : project ,
" package " : package ,
" states " : req_state ,
2023-01-25 15:25:46 +01:00
" withfullhistory " : withfullhistory ,
2022-09-15 14:47:38 +02:00
}
2010-02-25 22:56:21 +01:00
2023-01-25 11:38:08 +01:00
if req_type is not None :
kwargs [ " types " ] = [ req_type ]
2022-09-15 14:47:38 +02:00
assert not exclude_target_projects , " unsupported "
2008-03-05 00:41:00 +01:00
2022-09-15 14:47:38 +02:00
return get_request_collection ( * * kwargs )
2022-09-12 13:43:10 +02:00
2022-09-15 14:47:38 +02:00
# old style search, this is to be removed
2022-12-07 13:01:23 +01:00
def get_user_projpkgs_request_list (
apiurl : str ,
user ,
req_state = (
" new " ,
" review " ,
2023-02-02 13:50:51 +01:00
" declined " ,
2022-12-07 13:01:23 +01:00
) ,
req_type = None ,
exclude_projects = None ,
projpkgs = None ,
) :
2011-01-23 21:21:32 +01:00
""" OBSOLETE: user involved request search is supported by OBS 2.2 server side in a better way
Return all running requests for all projects / packages where is user is involved """
2022-08-29 15:32:41 +02:00
exclude_projects = exclude_projects or [ ]
projpkgs = projpkgs or { }
2010-03-13 21:06:18 +01:00
if not projpkgs :
res = get_user_projpkgs ( apiurl , user , exclude_projects = exclude_projects )
2011-02-24 14:10:53 +01:00
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 ' ) ] = [ ]
2011-02-24 14:10:53 +01:00
projects . append ( i . get ( ' name ' ) )
2010-03-20 12:59:32 +01:00
for i in res [ ' package_id ' ] . findall ( ' package ' ) :
2011-02-24 14:10:53 +01:00
if not i . get ( ' project ' ) in projects :
2010-03-13 21:06:18 +01:00
projpkgs . setdefault ( i . get ( ' project ' ) , [ ] ) . append ( i . get ( ' name ' ) )
2016-09-13 12:34:48 +02:00
if not projpkgs :
return [ ]
2010-03-13 21:06:18 +01:00
xpath = ' '
2013-04-09 11:25:19 +02:00
for prj , pacs in projpkgs . items ( ) :
2022-08-29 13:23:29 +02:00
if not pacs :
2010-03-13 21:06:18 +01:00
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 ' )
2022-09-12 14:15:34 +02:00
if ' all ' not in req_state :
2010-03-13 21:06:18 +01:00
xp = ' '
for state in req_state :
2010-03-15 13:15:50 +01:00
xp = xpath_join ( xp , ' state/@name= \' %s \' ' % state , inner = True )
2011-02-24 14:06:15 +01:00
xpath = xpath_join ( xp , xpath , op = ' and ' , nexpr_parentheses = True )
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
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def get_request_log ( apiurl : str , 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
2022-09-12 13:43:10 +02:00
for state in [ r . state ] + r . statehistory :
2008-08-19 16:18:05 +02:00
s = frmt % ( state . name , state . who , state . when , str ( state . comment ) )
data . append ( s )
return data
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def check_existing_requests (
apiurl : str , src_project : str , src_package : str , dst_project : str , dst_package : str , ask = True
) :
reqs = get_exact_request_list (
apiurl ,
src_project ,
dst_project ,
src_package ,
dst_package ,
req_type = " submit " ,
req_state = [ " new " , " review " , " declined " ] ,
)
2017-10-06 12:32:52 +02:00
if not ask :
return True , reqs
2013-03-08 19:06:04 +01:00
repl = ' '
if reqs :
2019-03-01 20:24:31 +01:00
open_request_string = " The following submit request is already open: "
supersede_request_string = " Supersede the old request? "
if len ( reqs ) > 1 :
open_request_string = " The following submit requests are already open: "
supersede_request_string = " Supersede the old requests? "
2022-09-12 13:43:10 +02:00
print ( ' %s %s . ' %
2019-03-01 20:24:31 +01:00
( open_request_string , ' , ' . join ( [ i . reqid for i in reqs ] ) ) )
repl = raw_input ( ' %s (y/n/c) ' % supersede_request_string )
2017-04-19 11:35:14 +02:00
while repl . lower ( ) not in [ ' c ' , ' y ' , ' n ' ] :
print ( ' %s is not a valid option. ' % repl )
2019-03-01 20:24:31 +01:00
repl = raw_input ( ' %s (y/n/c) ' % supersede_request_string )
2013-03-08 19:06:04 +01:00
if repl . lower ( ) == ' c ' :
2013-04-09 12:51:28 +02:00
print ( ' Aborting ' , file = sys . stderr )
2013-03-08 19:06:04 +01:00
raise oscerr . UserAbort ( )
return repl == ' y ' , reqs
2008-08-19 16:18:05 +02:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def check_existing_maintenance_requests (
apiurl : str , src_project : str , src_packages : List [ str ] , dst_project : str , release_project , ask = True
) :
2015-08-07 10:17:40 +02:00
reqs = [ ]
for src_package in src_packages :
2022-12-07 13:01:23 +01:00
reqs + = get_exact_request_list (
apiurl ,
src_project ,
dst_project ,
src_package ,
None ,
req_type = " maintenance_incident " ,
req_state = [ " new " , " review " , " declined " ] ,
)
2017-10-06 12:32:52 +02:00
if not ask :
return True , reqs
2015-08-07 10:17:40 +02:00
repl = ' '
if reqs :
2019-03-01 20:24:31 +01:00
open_request_string = " The following maintenance incident request is already open: "
supersede_request_string = " Supersede the old request? "
if len ( reqs ) > 1 :
open_request_string = " The following maintenance incident requests are already open: "
supersede_request_string = " Supersede the old requests? "
2022-09-12 13:43:10 +02:00
print ( ' %s %s . ' %
2019-03-01 20:24:31 +01:00
( open_request_string , ' , ' . join ( [ i . reqid for i in reqs ] ) ) )
repl = raw_input ( ' %s (y/n/c) ' % supersede_request_string )
2017-04-19 11:35:14 +02:00
while repl . lower ( ) not in [ ' c ' , ' y ' , ' n ' ] :
print ( ' %s is not a valid option. ' % repl )
2019-03-01 20:24:31 +01:00
repl = raw_input ( ' %s (y/n/c) ' % supersede_request_string )
2015-08-07 10:17:40 +02:00
if repl . lower ( ) == ' c ' :
print ( ' Aborting ' , file = sys . stderr )
raise oscerr . UserAbort ( )
return repl == ' y ' , reqs
2017-08-21 09:48:50 +02:00
# old function for compat reasons. Some plugins may call this function.
# and we do not want to break the plugins.
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def get_group ( apiurl : str , group : str ) :
2017-08-21 09:48:50 +02:00
return get_group_meta ( apiurl , group )
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def get_group_meta ( apiurl : str , group : str ) :
2011-01-11 20:02:48 +01:00
u = makeurl ( apiurl , [ ' group ' , quote_plus ( group ) ] )
try :
f = http_GET ( u )
2018-12-13 15:14:06 +01:00
return b ' ' . join ( f . readlines ( ) )
2013-04-09 14:03:17 +02:00
except HTTPError :
2015-08-06 12:52:34 +02:00
print ( ' group \' %s \' not found ' % group )
2011-01-11 20:02:48 +01:00
return None
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def get_user_meta ( apiurl : str , user : str ) :
2007-05-04 23:51:54 +02:00
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 )
2018-12-13 15:14:06 +01:00
return b ' ' . join ( f . readlines ( ) )
2013-04-09 14:03:17 +02:00
except HTTPError :
2013-04-09 12:51:28 +02:00
print ( ' user \' %s \' not found ' % user )
2006-05-22 16:57:11 +02:00
return None
2006-04-20 16:26:50 +02:00
2022-09-12 13:43:10 +02:00
2014-02-11 11:56:44 +01:00
def _get_xml_data ( meta , * tags ) :
2007-09-03 18:18:37 +02:00
data = [ ]
2022-08-29 12:56:57 +02:00
if meta is not None :
2007-09-03 18:18:37 +02:00
root = ET . fromstring ( meta )
for tag in tags :
2014-02-11 11:56:44 +01:00
elm = root . find ( tag )
if elm is None or elm . text is None :
data . append ( ' - ' )
else :
data . append ( elm . text )
2009-12-12 15:02:58 +01:00
return data
2007-09-03 12:17:04 +02:00
2022-12-07 13:01:23 +01:00
def get_user_data ( apiurl : str , user : str , * tags ) :
2014-02-11 11:56:44 +01:00
""" get specified tags from the user meta """
meta = get_user_meta ( apiurl , user )
return _get_xml_data ( meta , * tags )
2022-08-29 15:39:02 +02:00
2014-02-11 11:56:44 +01:00
2022-12-07 13:01:23 +01:00
def get_group_data ( apiurl : str , group : str , * tags ) :
2017-08-21 09:48:50 +02:00
meta = get_group_meta ( apiurl , group )
2014-02-11 11:56:44 +01:00
return _get_xml_data ( meta , * tags )
2022-12-07 13:01:23 +01:00
def download ( url : str , filename , progress_obj = None , mtime = None ) :
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 )
2022-09-12 13:43:10 +02:00
( fd , tmpfile ) = tempfile . mkstemp ( dir = path , prefix = prefix , suffix = ' .osctmp ' )
2014-01-06 11:12:02 +01:00
os . fchmod ( fd , 0o644 )
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 ) :
2018-12-13 15:14:06 +01:00
if isinstance ( buf , str ) :
o . write ( bytes ( buf , " utf-8 " ) )
else :
o . write ( buf )
2010-02-05 15:17:45 +01:00
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 :
2014-01-09 14:15:30 +01:00
utime ( filename , ( - 1 , mtime ) )
2010-05-12 15:55:36 +02:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def get_source_file (
apiurl : str ,
prj : str ,
package : str ,
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 :
2019-09-16 13:33:46 +02:00
query [ ' meta ' ] = 1
2010-02-25 10:42:29 +01:00
if revision :
2010-05-22 08:22:12 +02:00
query [ ' rev ' ] = revision
2022-12-07 13:01:23 +01:00
u = makeurl (
apiurl ,
[ " source " , prj , package , pathname2url ( filename . encode ( locale . getpreferredencoding ( ) , " replace " ) ) ] ,
query = query ,
)
2010-05-12 15:55:36 +02:00
download ( u , targetfilename , progress_obj , mtime )
2010-02-25 10:42:29 +01:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def get_binary_file (
apiurl : str ,
prj : str ,
repo : str ,
arch : str ,
filename ,
package : Optional [ str ] = None ,
target_filename = None ,
target_mtime = None ,
progress_meter = False ,
) :
2010-02-25 10:42:29 +01:00
progress_obj = None
2019-05-16 09:31:38 +02:00
if progress_meter :
2022-09-09 11:46:28 +02:00
progress_obj = meter . create_text_meter ( )
2008-09-30 16:54:08 +02:00
target_filename = target_filename or filename
2007-08-16 20:15:08 +02:00
2022-03-21 17:06:55 +01:00
# create target directory if it doesn't exist
target_dir = os . path . dirname ( target_filename )
if target_dir :
try :
os . makedirs ( target_dir , 0o755 )
except OSError as e :
if e . errno != errno . EEXIST :
raise
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 )
2017-02-27 09:45:37 +01:00
if target_filename . endswith ( ' .AppImage ' ) :
os . chmod ( target_filename , 0o755 )
2007-08-16 20:15:08 +02:00
2022-09-12 13:43:10 +02:00
2006-04-20 16:26:50 +02:00
def dgst ( file ) :
2022-09-12 13:43:10 +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
2022-09-09 11:46:28 +02:00
s = hashlib . md5 ( )
2009-05-22 17:00:31 +02:00
f = open ( file , ' rb ' )
2013-04-09 11:34:46 +02:00
while True :
2006-04-20 16:26:50 +02:00
buf = f . read ( BUFSIZE )
2022-09-12 13:43:10 +02:00
if not buf :
break
2006-04-20 16:26:50 +02:00
s . update ( buf )
2007-07-13 18:01:02 +02:00
f . close ( )
2017-11-07 17:52:34 +01:00
return s . hexdigest ( )
2006-04-20 16:26:50 +02:00
2022-09-12 13:43:10 +02:00
2017-11-27 16:11:32 +01:00
def sha256_dgst ( file ) :
global BUFSIZE
f = open ( file , ' rb ' )
s = hashlib . sha256 ( )
while True :
buf = f . read ( BUFSIZE )
2022-09-12 13:43:10 +02:00
if not buf :
break
2017-11-27 16:11:32 +01:00
s . update ( buf )
f . close ( )
return s . hexdigest ( )
2006-04-20 16:26:50 +02:00
2022-09-12 13:43:10 +02:00
2006-06-08 12:30:29 +02:00
def binary ( s ) :
2022-01-24 08:57:53 +01:00
""" return ``True`` if a string is binary data using diff ' s heuristic """
2013-04-10 11:34:59 +02:00
if s and bytes ( ' \0 ' , " utf-8 " ) in s [ : 4096 ] :
2006-06-08 12:30:29 +02:00
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 """
2022-08-24 08:43:09 +02:00
with open ( fn , ' rb ' ) as f :
return binary ( f . read ( 4096 ) )
2006-06-22 14:54:58 +02:00
2022-09-12 13:43:10 +02:00
def get_source_file_diff ( dir , filename , rev , oldfilename = None , olddir = None , origfilename = None ) :
2007-07-04 14:55:26 +02:00
"""
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 . )
"""
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 ) :
2019-07-17 10:34:20 +02:00
return [ b ' Binary file \' %s \' has changed. \n ' % origfilename . encode ( ) ]
2006-05-19 22:13:29 +02:00
2010-08-27 16:24:12 +02:00
f1 = f2 = None
try :
2019-07-17 10:34:20 +02:00
f1 = open ( file1 , ' rb ' )
2010-08-27 16:24:12 +02:00
s1 = f1 . readlines ( )
f1 . close ( )
2006-06-08 12:30:29 +02:00
2019-07-17 10:34:20 +02:00
f2 = open ( file2 , ' rb ' )
2010-08-27 16:24:12 +02:00
s2 = f2 . readlines ( )
f2 . close ( )
finally :
if f1 :
f1 . close ( )
if f2 :
f2 . close ( )
2022-08-29 15:39:02 +02:00
2019-07-17 10:34:20 +02:00
from_file = b ' %s \t (revision %s ) ' % ( origfilename . encode ( ) , str ( rev ) . encode ( ) )
to_file = b ' %s \t (working copy) ' % origfilename . encode ( )
2010-08-27 16:24:12 +02:00
2022-09-12 13:43:10 +02:00
d = difflib . diff_bytes ( difflib . unified_diff , s1 , s2 ,
fromfile = from_file ,
tofile = to_file )
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 :
2019-07-17 10:34:20 +02:00
d [ 0 ] = d [ 0 ] . replace ( b ' \n ' , b ' \n ' )
d [ 1 ] = d [ 1 ] . replace ( b ' \n ' , b ' \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 ) :
2019-07-17 10:34:20 +02:00
if not line . endswith ( b ' \n ' ) :
d [ i ] + = b ' \n \\ No newline at end of file '
2022-09-12 13:43:10 +02:00
if i + 1 != len ( d ) :
2019-07-17 10:34:20 +02:00
d [ i ] + = b ' \n '
2010-08-27 16:24:12 +02:00
return d
2006-05-19 22:13:29 +02:00
2022-09-12 13:43:10 +02:00
2022-10-21 10:38:57 +02:00
def server_diff (
apiurl : str ,
old_project : str ,
old_package : str ,
old_revision : str ,
new_project : str ,
new_package : str ,
new_revision : str ,
unified = False ,
missingok = False ,
meta = False ,
expand = True ,
onlyissues = False ,
full = True ,
xml = False ,
2023-04-28 14:38:43 +02:00
files : list = None ,
2022-10-21 10:38:57 +02:00
) :
query : Dict [ str , Union [ str , int ] ] = { " cmd " : " diff " }
2010-10-19 15:25:25 +02:00
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
2011-11-09 11:51:43 +01:00
if full :
query [ ' filelimit ' ] = 0
2013-11-10 21:09:32 +01:00
query [ ' tarlimit ' ] = 0
2017-05-10 16:34:12 +02:00
if onlyissues :
query [ ' onlyissues ' ] = 1
query [ ' view ' ] = ' xml '
query [ ' unified ' ] = 0
2023-04-28 14:38:43 +02:00
if files :
query [ " file " ] = files
2007-11-29 18:22:57 +01:00
u = makeurl ( apiurl , [ ' source ' , new_project , new_package ] , query = query )
2023-04-28 14:54:18 +02:00
f = http_POST ( u , retry_on_400 = False )
2020-06-15 17:18:52 +02:00
if onlyissues and not xml :
del_issue_list = [ ]
add_issue_list = [ ]
chn_issue_list = [ ]
2017-05-10 16:34:12 +02:00
root = ET . fromstring ( f . read ( ) )
node = root . find ( ' issues ' )
for issuenode in node . findall ( ' issue ' ) :
2020-06-15 17:18:52 +02:00
if issuenode . get ( ' state ' ) == ' deleted ' :
del_issue_list . append ( issuenode . get ( ' label ' ) )
elif issuenode . get ( ' state ' ) == ' added ' :
add_issue_list . append ( issuenode . get ( ' label ' ) )
else :
chn_issue_list . append ( issuenode . get ( ' label ' ) )
string = ' added: \n ---------- \n ' + ' \n ' . join ( add_issue_list ) + \
' \n \n changed: \n ---------- \n ' + ' \n ' . join ( chn_issue_list ) + \
' \n \n deleted: \n ---------- \n ' + ' \n ' . join ( del_issue_list )
return string
2007-11-29 18:22:57 +01:00
return f . read ( )
2022-09-12 13:43:10 +02:00
2022-10-21 10:38:57 +02:00
def server_diff_noex (
apiurl : str ,
old_project : str ,
old_package : str ,
old_revision : str ,
new_project : str ,
new_package : str ,
new_revision : str ,
unified = False ,
missingok = False ,
meta = False ,
expand = True ,
onlyissues = False ,
xml = False ,
2023-04-28 14:38:43 +02:00
files : list = None ,
2022-10-21 10:38:57 +02:00
) :
2010-12-23 10:33:31 +01:00
try :
return server_diff ( apiurl ,
2022-09-12 13:43:10 +02:00
old_project , old_package , old_revision ,
new_project , new_package , new_revision ,
2023-04-28 14:38:43 +02:00
unified , missingok , meta , expand , onlyissues , True , xml , files = files )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2010-12-23 10:33:31 +01:00
msg = None
body = None
try :
2019-07-17 10:34:20 +02:00
body = e . read ( )
2022-09-12 14:15:34 +02:00
if b ' bad link ' not in body :
2019-07-17 10:34:20 +02:00
return b ' # diff failed: ' + body
2010-12-23 10:33:31 +01:00
except :
2019-07-17 10:34:20 +02:00
return b ' # diff failed with unknown error '
2010-12-23 10:33:31 +01:00
if expand :
2019-07-17 10:34:20 +02:00
rdiff = b " ## diff on expanded link not possible, showing unexpanded version \n "
2011-02-14 11:30:37 +01:00
try :
2011-05-18 17:54:33 +02:00
rdiff + = server_diff_noex ( apiurl ,
2022-09-12 13:43:10 +02:00
old_project , old_package , old_revision ,
new_project , new_package , new_revision ,
2023-04-28 14:38:43 +02:00
unified , missingok , meta , False , files = files )
2011-02-14 11:30:37 +01:00
except :
2011-05-18 17:54:33 +02:00
elm = ET . fromstring ( body ) . find ( ' summary ' )
summary = ' '
2022-10-21 10:38:57 +02:00
if elm is not None and elm . text is not None :
2011-05-18 17:54:33 +02:00
summary = elm . text
2019-07-17 10:34:20 +02:00
return b ' error: diffing failed: %s ' % summary . encode ( )
2010-12-23 10:33:31 +01:00
return rdiff
2007-11-29 18:22:57 +01:00
2022-12-07 13:01:23 +01:00
def request_diff ( apiurl : str , reqid , superseded_reqid = None ) :
2020-02-19 17:07:35 +01:00
query = { ' cmd ' : ' diff ' }
if superseded_reqid :
query [ ' diff_to_superseded ' ] = superseded_reqid
u = makeurl ( apiurl , [ ' request ' , reqid ] , query )
2010-09-02 10:29:28 +02:00
f = http_POST ( u )
return f . read ( )
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def get_request_issues ( apiurl : str , reqid ) :
2017-10-16 14:07:10 +02:00
"""
gets a request xml with the issues for the request inside and creates
a list ' issue_list ' with a dict of the relevant information for the issues .
This only works with bugtrackers we can access , like buzilla . o . o
"""
2022-09-12 13:43:10 +02:00
u = makeurl ( apiurl , [ ' request ' , reqid ] , query = { ' cmd ' : ' diff ' , ' view ' : ' xml ' , ' withissues ' : ' 1 ' } )
2017-10-16 14:07:10 +02:00
f = http_POST ( u )
request_tree = ET . parse ( f ) . getroot ( )
issue_list = [ ]
for elem in request_tree . iterfind ( ' action/sourcediff/issues/issue ' ) :
issue_id = elem . get ( ' name ' )
encode_search = ' @name= \' %s \' ' % issue_id
2022-09-12 13:43:10 +02:00
u = makeurl ( apiurl , [ ' search/issue ' ] , query = { ' match ' : encode_search } )
2017-10-16 14:07:10 +02:00
f = http_GET ( u )
collection = ET . parse ( f ) . getroot ( )
for cissue in collection :
issue = { }
for issue_detail in cissue . iter ( ) :
2018-01-22 11:00:40 +01:00
if issue_detail . text :
issue [ issue_detail . tag ] = issue_detail . text . strip ( )
2017-10-16 14:07:10 +02:00
issue_list . append ( issue )
return issue_list
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def submit_action_diff ( apiurl : str , action : Action ) :
2011-01-29 17:24:45 +01:00
""" diff a single submit action """
# backward compatiblity: only a recent api/backend supports the missingok parameter
try :
return server_diff ( apiurl , action . tgt_project , action . tgt_package , None ,
2022-09-12 13:43:10 +02:00
action . src_project , action . src_package , action . src_rev , True , True )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2011-01-29 17:24:45 +01:00
if e . code == 400 :
try :
return server_diff ( apiurl , action . tgt_project , action . tgt_package , None ,
2022-09-12 13:43:10 +02:00
action . src_project , action . src_package , action . src_rev , True , False )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2011-01-29 17:24:45 +01:00
if e . code != 404 :
raise e
root = ET . fromstring ( e . read ( ) )
2019-07-17 10:34:20 +02:00
return b ' error: \' %s \' does not exist ' % root . find ( ' summary ' ) . text . encode ( )
2011-01-29 17:24:45 +01:00
elif e . code == 404 :
root = ET . fromstring ( e . read ( ) )
2019-07-17 10:34:20 +02:00
return b ' error: \' %s \' does not exist ' % root . find ( ' summary ' ) . text . encode ( )
2011-01-29 17:24:45 +01:00
raise e
2010-09-02 10:29:28 +02:00
2022-09-12 13:43:10 +02:00
2022-10-21 10:38:57 +02:00
def make_dir (
apiurl : str , project : str , package : str , pathname = None , prj_dir = None , package_tracking = True , pkg_path = None
) :
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 ' ) .
2011-11-02 21:02:26 +01:00
If pkg_path is not None store the package ' s content in pkg_path (no project structure is created)
2008-04-02 17:30:44 +02:00
"""
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
2011-11-02 21:02:26 +01:00
if pkg_path is None :
pathname = pathname or getTransActPath ( os . path . join ( prj_dir , package ) )
pkg_path = os . path . join ( prj_dir , package )
if is_package_dir ( prj_dir ) :
# we want this to become a project directory,
# but it already is a package directory.
raise oscerr . OscIOError ( None , ' checkout_package: package/project clash. Moving myself away not implemented ' )
if not is_project_dir ( prj_dir ) :
# this directory could exist as a parent direory for one of our earlier
# checked out sub-projects. in this case, we still need to initialize it.
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' A ' , prj_dir ) )
2011-11-02 21:02:26 +01:00
Project . init_project ( apiurl , prj_dir , project , package_tracking )
if is_project_dir ( os . path . join ( prj_dir , package ) ) :
# 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
raise oscerr . OscIOError ( None , ' checkout_package: package/project clash. Moving project away not implemented ' )
else :
pathname = pkg_path
2011-11-02 19:41:47 +01:00
2011-11-02 21:02:26 +01:00
if not os . path . exists ( pkg_path ) :
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' A ' , pathname ) )
2011-11-02 21:02:26 +01:00
os . mkdir ( os . path . join ( pkg_path ) )
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
2011-11-02 21:02:26 +01:00
return pkg_path
2006-04-20 16:26:50 +02:00
2022-10-21 10:38:57 +02:00
def checkout_package (
apiurl : str ,
project : str ,
package : str ,
revision = None ,
pathname = None ,
prj_obj = None ,
expand_link = False ,
2023-02-08 11:46:16 +01:00
prj_dir : Path = None ,
2022-10-21 10:38:57 +02:00
server_service_files = None ,
service_files = None ,
progress_obj = None ,
size_limit = None ,
meta = False ,
outdir = None ,
) :
2008-07-16 17:04:37 +02:00
try :
# the project we're in might be deleted.
# that'll throw an error then.
2023-02-08 11:46:16 +01:00
olddir = Path . cwd ( )
except FileNotFoundError :
olddir = Path ( os . environ . get ( " PWD " ) )
2008-07-16 17:04:37 +02:00
if not prj_dir :
prj_dir = olddir
2022-04-08 17:38:51 +02:00
else :
2023-02-08 11:46:16 +01:00
sep = " / " if conf . config [ ' checkout_no_colon ' ] else conf . config [ ' project_separator ' ]
prj_dir = Path ( str ( prj_dir ) . replace ( ' : ' , sep ) )
2009-10-20 16:30:15 +02:00
2023-02-08 11:46:16 +01:00
root_dots = Path ( ' . ' )
2010-12-27 23:03:17 +01:00
if conf . config [ ' checkout_rooted ' ] :
2023-02-08 11:46:16 +01:00
if prj_dir . stem == ' / ' :
2022-08-04 10:09:10 +02:00
if conf . config [ ' verbose ' ] :
2013-05-27 14:26:58 +02:00
print ( " checkout_rooted ignored for %s " % prj_dir )
2010-12-27 23:03:17 +01:00
# ?? 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.
2014-08-12 15:01:16 +02:00
# At least this test should find that the parent of 'home/username/branches'
2010-12-27 23:03:17 +01:00
# is a project (hack alert). Also goto parent in this case.
2023-02-08 11:46:16 +01:00
root_dots = Path ( " ../ " )
2010-12-27 23:03:17 +01:00
elif is_project_dir ( " ../.. " ) :
# testing two levels is better than one.
2014-08-12 15:01:16 +02:00
# May happen in case of checkout_no_colon, or
# if project roots were previously inconsistent
2023-02-08 11:46:16 +01:00
root_dots = Path ( " ../../ " )
2010-12-27 23:03:17 +01:00
if is_project_dir ( root_dots ) :
2017-02-08 13:55:36 +01:00
oldproj = store_read_project ( root_dots )
2010-12-27 23:03:17 +01:00
if conf . config [ ' checkout_no_colon ' ] :
n = len ( oldproj . split ( ' : ' ) )
else :
n = 1
2023-02-08 11:46:16 +01:00
root_dots = root_dots / ( " ../ " * n )
2010-12-27 23:03:17 +01:00
2023-02-08 11:46:16 +01:00
if str ( root_dots ) != ' . ' :
2010-12-27 23:03:17 +01:00
if conf . config [ ' verbose ' ] :
2017-02-08 13:55:36 +01:00
print ( " %s is project dir of %s . Root found at %s " %
( prj_dir , oldproj , os . path . abspath ( root_dots ) ) )
2023-02-08 11:46:16 +01:00
prj_dir = root_dots / prj_dir
2010-12-27 23:03:17 +01:00
2011-11-02 19:41:47 +01:00
if not pathname :
pathname = getTransActPath ( os . path . join ( prj_dir , 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
# before we create directories and stuff, check if the package actually
# exists
2021-11-30 13:13:11 +01:00
meta_data = b ' ' . join ( show_package_meta ( apiurl , quote_plus ( project ) , quote_plus ( package ) ) )
root = ET . fromstring ( meta_data )
2022-10-21 10:38:57 +02:00
scmsync_element = root . find ( " scmsync " )
if scmsync_element is not None and scmsync_element . text is not None :
2021-11-30 13:13:11 +01:00
if not os . path . isfile ( ' /usr/lib/obs/service/obs_scm_bridge ' ) :
raise oscerr . OscIOError ( None , ' Install the obs-scm-bridge package to work on packages managed in scm (git)! ' )
2022-10-21 10:38:57 +02:00
scm_url = scmsync_element . text
2021-11-30 13:13:11 +01:00
directory = make_dir ( apiurl , project , package , pathname , prj_dir , conf . config [ ' do_package_tracking ' ] , outdir )
os . putenv ( " OSC_VERSION " , get_osc_version ( ) )
run_external ( [ ' /usr/lib/obs/service/obs_scm_bridge ' , ' --outdir ' , directory , ' --url ' , scm_url ] )
Package . init_package ( apiurl , project , package , directory , size_limit , meta , progress_obj , scm_url )
2022-08-23 12:00:08 +02:00
# add package to <prj>/.obs/_packages
if not prj_obj :
prj_obj = Project ( prj_dir )
prj_obj . set_state ( package , ' ' )
prj_obj . write_packages ( )
2021-11-30 13:13:11 +01:00
return
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 :
2011-05-23 15:26:13 +02:00
x = show_upstream_xsrcmd5 ( apiurl , project , package , revision = revision , meta = meta , include_service_files = server_service_files )
2010-01-12 17:22:47 +01:00
except :
2011-05-23 15:26:13 +02:00
x = show_upstream_xsrcmd5 ( apiurl , project , package , revision = revision , meta = meta , linkrev = ' base ' , include_service_files = server_service_files )
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
2011-11-02 21:02:26 +01:00
directory = make_dir ( apiurl , project , package , pathname , prj_dir , conf . config [ ' do_package_tracking ' ] , outdir )
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 ( )
2011-11-02 21:02:26 +01:00
# no project structure is wanted when outdir is used
if conf . config [ ' do_package_tracking ' ] and outdir is None :
2008-03-10 19:04:23 +01:00
# 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 :
2013-04-09 12:51:28 +02:00
print ( ' Running all source services local ' )
2010-06-08 11:24:10 +02:00
p . run_source_services ( )
2006-04-20 16:26:50 +02:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def replace_pkg_meta (
2022-12-20 14:42:19 +01:00
pkgmeta , new_name : str , new_prj : str , keep_maintainers = False , dst_userid = None , keep_develproject = False ,
keep_lock : bool = False ,
2022-12-07 13:01:23 +01:00
) :
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
"""
2018-12-13 15:14:06 +01:00
root = ET . fromstring ( b ' ' . join ( pkgmeta ) )
2007-11-09 19:03:19 +01:00
root . set ( ' name ' , new_name )
root . set ( ' project ' , new_prj )
2017-03-20 16:05:39 +01:00
# never take releasename, it needs to be explicit
for releasename in root . findall ( ' releasename ' ) :
root . remove ( releasename )
2008-04-30 14:28:25 +02:00
if not keep_maintainers :
for person in root . findall ( ' person ' ) :
root . remove ( person )
2019-04-17 11:42:29 +02:00
for group in root . findall ( ' group ' ) :
root . remove ( group )
2009-03-11 16:23:23 +01:00
if not keep_develproject :
for dp in root . findall ( ' devel ' ) :
root . remove ( dp )
2022-12-20 14:42:19 +01:00
if not keep_lock :
for node in root . findall ( " lock " ) :
root . remove ( node )
2013-04-10 11:34:59 +02:00
return ET . tostring ( root , encoding = ET_ENCODING )
2007-11-09 19:03:19 +01:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def link_to_branch ( apiurl : str , project : str , package : str ) :
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
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def link_pac (
src_project : str ,
src_package : str ,
dst_project : str ,
dst_package : str ,
force : bool ,
2022-12-20 16:57:36 +01:00
rev = None ,
cicount = None ,
2022-12-07 13:01:23 +01:00
disable_publish = False ,
missing_target = False ,
2022-12-20 16:57:36 +01:00
vrev = None ,
2022-12-07 13:01:23 +01:00
disable_build = 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
"""
2022-12-20 16:57:36 +01:00
if src_project == dst_project and src_package == dst_package :
raise oscerr . OscValueError ( " Cannot link package. Source and target are the same. " )
if rev and not checkRevision ( src_project , src_package , rev ) :
raise oscerr . OscValueError ( f " Revision doesn ' t exist: { rev } " )
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 )
2019-11-18 09:36:09 +01:00
root = ET . fromstring ( parse_meta_to_string ( dst_meta ) )
2011-02-22 17:52:12 +01:00
if root . get ( ' project ' ) != dst_project :
# The source comes from a different project via a project link, we need to create this instance
meta_change = True
2019-10-08 17:55:37 +02:00
except HTTPError as e :
if e . code != 404 :
2022-04-20 19:22:35 +02:00
raise
2010-04-29 15:37:47 +02:00
meta_change = True
if meta_change :
2011-12-15 15:12:13 +01:00
if missing_target :
dst_meta = ' <package name= " %s " ><title/><description/></package> ' % dst_package
else :
src_meta = show_package_meta ( apiurl , src_project , src_package )
dst_meta = replace_pkg_meta ( src_meta , dst_package , dst_project )
2009-12-21 14:24:33 +01:00
2022-11-08 15:01:37 +01:00
if disable_build or disable_publish :
2009-12-21 14:24:33 +01:00
meta_change = True
root = ET . fromstring ( ' ' . join ( dst_meta ) )
2022-11-08 15:01:37 +01:00
if disable_build :
elm = root . find ( ' build ' )
if not elm :
elm = ET . SubElement ( root , ' build ' )
elm . clear ( )
ET . SubElement ( elm , ' disable ' )
if disable_publish :
elm = root . find ( ' publish ' )
if not elm :
elm = ET . SubElement ( root , ' publish ' )
elm . clear ( )
ET . SubElement ( elm , ' disable ' )
2013-04-10 11:34:59 +02:00
dst_meta = ET . tostring ( root , encoding = ET_ENCODING )
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 :
2013-04-09 12:51:28 +02:00
print ( ' forced overwrite of existing _link file ' , file = sys . stderr )
2009-06-15 17:19:16 +02:00
else :
2013-04-09 12:51:28 +02:00
print ( file = sys . stderr )
print ( ' _link file already exists...! Aborting ' , file = sys . stderr )
2009-06-15 17:19:16 +02:00
sys . exit ( 1 )
2009-10-20 16:30:15 +02:00
2008-06-26 12:47:58 +02:00
if rev :
2012-03-02 15:44:15 +01:00
rev = ' rev= " %s " ' % rev
2012-01-25 15:51:11 +01:00
else :
rev = ' '
2009-04-21 18:52:26 +02:00
2012-03-02 15:44:15 +01:00
if vrev :
vrev = ' vrev= " %s " ' % vrev
else :
vrev = ' '
2011-12-15 15:12:13 +01:00
missingok = ' '
if missing_target :
2012-03-02 15:44:15 +01:00
missingok = ' missingok= " true " '
2011-12-15 15:12:13 +01:00
2009-05-13 09:59:01 +02:00
if cicount :
2012-03-02 15:44:15 +01:00
cicount = ' cicount= " %s " ' % cicount
2012-01-25 15:51:11 +01:00
else :
cicount = ' '
2009-05-13 09:59:01 +02:00
2013-04-09 12:51:28 +02:00
print ( ' Creating _link... ' , end = ' ' )
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 = """ \
2012-03-02 15:44:15 +01:00
< link % s package = " %s " % s % s % s % s >
2006-08-07 12:08:54 +02:00
< patches >
2012-03-02 15:44:15 +01:00
< ! - - < branch / > for a full copy , default case - - >
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 ) - - >
2013-05-10 20:57:03 +02:00
< ! - - < add name = " file.patch " / > add a patch to be applied after % % setup ( spec file only ) - - >
2023-04-26 09:33:04 +02:00
< ! - - < add name = " file.patch " / >
Add a patch to be applied after % % setup ( spec file only ) .
Patch path prefix stipping can be controlled with the " popt " attribute ,
for example ` ` popt = " 1 " ` ` that translates to % % patch - p1 .
- - >
2013-05-10 20:57:03 +02:00
< ! - - < delete name = " filename " / > delete a file - - >
2006-08-07 12:08:54 +02:00
< / patches >
< / link >
2012-03-02 15:44:15 +01:00
""" % (project, src_package, missingok, rev, vrev, 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 )
2013-04-09 12:51:28 +02:00
print ( ' Done. ' )
2006-08-07 12:08:54 +02:00
2022-03-11 09:59:08 +01:00
2022-12-07 13:01:23 +01:00
def aggregate_pac (
src_project : str ,
src_package : str ,
dst_project : str ,
dst_package : str ,
repo_map : Optional [ dict ] = None ,
disable_publish = False ,
nosources = False ,
repo_check = True ,
) :
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
2022-03-11 09:59:08 +01:00
- " repo_check " determines if presence of repos in the source and destination repos is checked
2007-10-30 14:45:54 +01:00
"""
2023-01-02 15:05:35 +01:00
if ( src_project , src_package ) == ( dst_project , dst_package ) :
raise oscerr . OscValueError ( " Cannot aggregate package. Source and target are the same. " )
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 ' ]
2022-03-11 09:59:08 +01:00
repo_map = repo_map or { }
2022-03-02 14:38:21 +01:00
# we need to remove :flavor from the package names when accessing meta
src_package_meta = src_package . split ( " : " ) [ 0 ]
dst_package_meta = dst_package . split ( " : " ) [ 0 ]
2009-12-21 14:24:33 +01:00
try :
dst_meta = meta_exists ( metatype = ' pkg ' ,
2022-03-02 14:38:21 +01:00
path_args = ( quote_plus ( dst_project ) , quote_plus ( dst_package_meta ) ) ,
2009-12-21 14:24:33 +01:00
template_args = None ,
2010-07-27 16:06:49 +02:00
create_new = False , apiurl = apiurl )
2019-11-18 09:36:09 +01:00
root = ET . fromstring ( parse_meta_to_string ( dst_meta ) )
2011-03-30 14:12:59 +02:00
if root . get ( ' project ' ) != dst_project :
# The source comes from a different project via a project link, we need to create this instance
meta_change = True
2019-10-08 17:55:37 +02:00
except HTTPError as e :
if e . code != 404 :
2022-04-20 19:22:35 +02:00
raise
2011-03-30 14:12:59 +02:00
meta_change = True
2022-03-11 09:59:08 +01:00
if repo_check :
src_repos = set ( get_repositories_of_project ( apiurl , src_project ) )
dst_repos = set ( get_repositories_of_project ( apiurl , dst_project ) )
if repo_map :
map_from = set ( repo_map . keys ( ) )
map_to = set ( repo_map . values ( ) )
# only repos that do not exist in src/dst remain
delta_from = map_from - src_repos
delta_to = map_to - dst_repos
if delta_from or delta_to :
msg = [ " The following repos in repo map do not exist " ]
if delta_from :
msg + = [ " Source repos: " + " , " . join ( sorted ( delta_from ) ) ]
if delta_to :
msg + = [ " Destination repos: " + " , " . join ( sorted ( delta_to ) ) ]
raise oscerr . OscBaseError ( " \n " . join ( msg ) )
else :
# no overlap between src and dst repos leads to the 'broken: missing repositories: <src_project>' message
if not src_repos & dst_repos :
msg = [
" The source and the destination project do not have any repository names in common. " ,
" Use repo map to specify actual repository mapping. " ,
]
raise oscerr . OscBaseError ( " \n " . join ( msg ) )
2011-03-30 14:12:59 +02:00
if meta_change :
2022-03-02 14:38:21 +01:00
src_meta = show_package_meta ( apiurl , src_project , src_package_meta )
dst_meta = replace_pkg_meta ( src_meta , dst_package_meta , dst_project )
2009-12-21 14:24:33 +01:00
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 ' )
2013-04-10 11:34:59 +02:00
dst_meta = ET . tostring ( root , encoding = ET_ENCODING )
2009-12-21 14:24:33 +01:00
if meta_change :
edit_meta ( ' pkg ' ,
2022-03-02 14:38:21 +01:00
path_args = ( dst_project , dst_package_meta ) ,
2009-12-21 14:24:33 +01:00
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
2022-03-02 14:38:21 +01:00
if ' _aggregate ' in meta_get_filelist ( apiurl , dst_project , dst_package_meta ) :
2013-04-09 12:51:28 +02:00
print ( file = sys . stderr )
print ( ' _aggregate file already exists...! Aborting ' , file = sys . stderr )
2007-10-30 14:45:54 +01:00
sys . exit ( 1 )
2013-04-09 12:51:28 +02:00
print ( ' Creating _aggregate... ' , end = ' ' )
2007-10-30 14:45:54 +01:00
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 >
2022-09-12 13:43:10 +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 / >
"""
2013-04-09 11:25:19 +02:00
for src , tgt in repo_map . items ( ) :
2010-12-21 14:09:25 +01:00
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
2022-03-02 14:38:21 +01:00
u = makeurl ( apiurl , [ ' source ' , dst_project , dst_package_meta , ' _aggregate ' ] )
2007-10-30 14:45:54 +01:00
http_PUT ( u , data = aggregate_template )
2013-04-09 12:51:28 +02:00
print ( ' Done. ' )
2006-08-07 12:08:54 +02:00
2009-11-02 09:32:15 +01:00
2022-12-07 13:01:23 +01:00
def attribute_branch_pkg (
apiurl : str ,
attribute : str ,
maintained_update_project_attribute ,
package : str ,
targetproject : str ,
return_existing = False ,
force = False ,
noaccess = False ,
add_repositories = False ,
dryrun = False ,
nodevelproject = False ,
maintenance = False ,
) :
2009-11-02 09:32:15 +01:00
"""
Branch packages defined via attributes ( via API call )
"""
2022-09-12 13:43:10 +02:00
query = { ' cmd ' : ' branch ' }
2009-11-02 09:32:15 +01:00
query [ ' attribute ' ] = attribute
if targetproject :
query [ ' target_project ' ] = targetproject
2012-01-05 16:15:29 +01:00
if dryrun :
query [ ' dryrun ' ] = " 1 "
2010-05-17 20:14:49 +02:00
if force :
query [ ' force ' ] = " 1 "
2011-05-04 12:11:24 +02:00
if noaccess :
query [ ' noaccess ' ] = " 1 "
2012-01-05 16:15:29 +01:00
if nodevelproject :
query [ ' ignoredevel ' ] = ' 1 '
2011-11-25 10:12:16 +01:00
if add_repositories :
query [ ' add_repositories ' ] = " 1 "
2012-02-09 10:04:44 +01:00
if maintenance :
query [ ' maintenance ' ] = " 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 )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2017-03-14 22:50:48 +01:00
root = ET . fromstring ( e . read ( ) )
summary = root . find ( ' summary ' )
if summary is not None and summary . text is not None :
raise oscerr . APIError ( summary . text )
msg = ' unexpected response: %s ' % ET . tostring ( root , encoding = ET_ENCODING )
2010-04-08 11:24:13 +02:00
raise oscerr . APIError ( msg )
2009-11-02 09:32:15 +01:00
2011-12-12 09:55:14 +01:00
r = None
root = ET . fromstring ( f . read ( ) )
2012-01-05 16:15:29 +01:00
if dryrun :
2011-12-12 09:55:14 +01:00
return root
# TODO: change api here and return parsed XML as class
if conf . config [ ' http_debug ' ] :
2013-04-10 11:34:59 +02:00
print ( ET . tostring ( root , encoding = ET_ENCODING ) , file = sys . stderr )
2011-12-12 09:55:14 +01:00
for node in root . findall ( ' data ' ) :
r = node . get ( ' name ' )
if r and r == ' targetproject ' :
return node . text
2012-01-05 16:15:29 +01:00
2009-11-02 09:32:15 +01:00
return r
2022-12-07 13:01:23 +01:00
def branch_pkg (
apiurl : str ,
src_project : str ,
src_package : str ,
nodevelproject = False ,
rev = None ,
linkrev = None ,
target_project : Optional [ str ] = None ,
target_package = None ,
return_existing = False ,
msg = " " ,
force = False ,
noaccess = False ,
add_repositories = False ,
add_repositories_block = None ,
add_repositories_rebuild = None ,
extend_package_names = False ,
missingok = False ,
maintenance = False ,
newinstance = False ,
disable_build = False ,
) :
2008-05-21 17:49:00 +02:00
"""
Branch a package ( via API call )
"""
2022-09-12 13:43:10 +02:00
query = { ' cmd ' : ' branch ' }
2008-06-03 15:16:55 +02:00
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 '
2011-05-04 12:11:24 +02:00
if noaccess :
query [ ' noaccess ' ] = ' 1 '
2011-11-28 14:26:30 +01:00
if add_repositories :
query [ ' add_repositories ' ] = " 1 "
2016-03-02 17:12:28 +01:00
if add_repositories_block :
query [ ' add_repositories_block ' ] = add_repositories_block
if add_repositories_rebuild :
query [ ' add_repositories_rebuild ' ] = add_repositories_rebuild
2012-02-09 10:04:44 +01:00
if maintenance :
query [ ' maintenance ' ] = " 1 "
2011-12-15 15:12:13 +01:00
if missingok :
query [ ' missingok ' ] = " 1 "
2015-07-21 13:02:48 +02:00
if newinstance :
query [ ' newinstance ' ] = " 1 "
2011-12-01 15:54:50 +01:00
if extend_package_names :
query [ ' extend_package_names ' ] = " 1 "
2009-02-10 16:49:34 +01:00
if rev :
query [ ' rev ' ] = rev
2015-10-23 11:08:30 +02:00
if linkrev :
query [ ' linkrev ' ] = linkrev
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 )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2015-07-21 13:02:48 +02:00
root = ET . fromstring ( e . read ( ) )
if missingok :
2022-04-20 19:22:35 +02:00
if root and root . get ( ' code ' ) == " not_missing " :
raise oscerr . NotMissing ( " Package exists already via project link, but link will point to given project " )
2011-02-08 16:56:16 +01:00
summary = root . find ( ' summary ' )
if summary is None :
2013-04-10 11:34:59 +02:00
raise oscerr . APIError ( ' unexpected response: \n %s ' % ET . tostring ( root , encoding = ET_ENCODING ) )
2016-04-11 10:45:40 +02:00
if not return_existing :
raise oscerr . APIError ( ' failed to branch: %s ' % summary . text )
2011-02-08 16:56:16 +01:00
m = re . match ( r " branch target package already exists: ( \ S+)/( \ S+) " , summary . text )
2009-08-20 21:28:05 +02:00
if not m :
2011-02-08 16:56:16 +01:00
e . msg + = ' \n ' + summary . text
2009-08-20 21:28:05 +02:00
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
2015-10-07 16:27:55 +02:00
root = ET . fromstring ( f . read ( ) )
2011-12-12 09:55:14 +01:00
if conf . config [ ' http_debug ' ] :
2013-04-10 11:34:59 +02:00
print ( ET . tostring ( root , encoding = ET_ENCODING ) , file = sys . stderr )
2010-02-08 19:58:14 +01:00
data = { }
2015-10-07 16:27:55 +02:00
for i in root . findall ( ' data ' ) :
2010-02-08 19:58:14 +01:00
data [ i . get ( ' name ' ) ] = i . text
2022-11-08 15:34:55 +01:00
if disable_build :
target_meta = show_package_meta ( apiurl , data [ " targetproject " ] , data [ " targetpackage " ] )
root = ET . fromstring ( b ' ' . join ( target_meta ) )
elm = root . find ( ' build ' )
if not elm :
elm = ET . SubElement ( root , ' build ' )
elm . clear ( )
ET . SubElement ( elm , ' disable ' )
target_meta = ET . tostring ( root , encoding = ET_ENCODING )
edit_meta ( ' pkg ' , path_args = ( data [ " targetproject " ] , data [ " targetpackage " ] ) , data = target_meta )
2010-02-08 19:58:14 +01:00
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
2022-12-07 13:01:23 +01:00
def copy_pac (
src_apiurl : str ,
src_project : str ,
src_package : str ,
dst_apiurl : str ,
dst_project : str ,
dst_package : str ,
client_side_copy = False ,
keep_maintainers = False ,
keep_develproject = False ,
expand = False ,
revision = None ,
comment = None ,
force_meta_update = None ,
keep_link = 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 .
"""
2023-01-02 15:21:45 +01:00
if ( src_apiurl , src_project , src_package ) == ( dst_apiurl , dst_project , dst_package ) :
2023-01-26 10:27:36 +01:00
# special cases when source and target can be the same:
# * expanding sources
# * downgrading package to an old revision
if not any ( [ expand , revision ] ) :
2023-01-02 15:21:45 +01:00
raise oscerr . OscValueError ( " Cannot copy package. Source and target are the same. " )
2006-09-21 16:33:24 +02:00
2022-09-12 13:43:10 +02:00
if not ( src_apiurl == dst_apiurl and src_project == dst_project
and src_package == dst_package ) :
2011-02-11 17:11:00 +01:00
src_meta = show_package_meta ( src_apiurl , src_project , src_package )
dst_userid = conf . get_apiurl_usr ( dst_apiurl )
src_meta = replace_pkg_meta ( src_meta , dst_package , dst_project , keep_maintainers ,
dst_userid , keep_develproject )
2012-01-09 14:30:52 +01:00
url = make_meta_url ( ' pkg ' , ( quote_plus ( dst_project ) , ) + ( quote_plus ( dst_package ) , ) , dst_apiurl )
found = None
try :
found = http_GET ( url ) . readlines ( )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2012-01-09 14:30:52 +01:00
pass
if force_meta_update or not found :
2013-04-09 12:51:28 +02:00
print ( ' Sending meta data... ' )
2012-01-09 14:30:52 +01:00
u = makeurl ( dst_apiurl , [ ' source ' , dst_project , dst_package , ' _meta ' ] )
http_PUT ( u , data = src_meta )
2006-09-21 16:33:24 +02:00
2013-04-09 12:51:28 +02:00
print ( ' Copying files... ' )
2008-04-02 16:36:23 +02:00
if not client_side_copy :
2022-09-12 13:43:10 +02:00
query = { ' cmd ' : ' copy ' , ' oproject ' : src_project , ' opackage ' : src_package }
2011-11-21 12:33:32 +01:00
if expand or keep_link :
2009-03-31 00:17:18 +02:00
query [ ' expand ' ] = ' 1 '
2011-11-21 12:33:32 +01:00
if keep_link :
query [ ' keeplink ' ] = ' 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
2009-07-15 20:53:47 +02:00
query = { ' rev ' : ' upload ' }
2016-02-05 17:16:42 +01:00
xml = show_files_meta ( src_apiurl , src_project , src_package ,
expand = expand , revision = revision )
filelist = ET . fromstring ( xml )
revision = filelist . get ( ' srcmd5 ' )
# filter out _service: files
for entry in filelist . findall ( ' entry ' ) :
# hmm the old code also checked for _service_ (but this is
# probably a relict from former times (if at all))
if entry . get ( ' name ' ) . startswith ( ' _service: ' ) :
filelist . remove ( entry )
2016-02-12 10:39:54 +01:00
tfilelist = Package . commit_filelist ( dst_apiurl , dst_project ,
dst_package , filelist , msg = comment )
todo = Package . commit_get_missing ( tfilelist )
2016-02-05 17:16:42 +01:00
for filename in todo :
print ( ' ' , filename )
# hmm ideally, we would pass a file-like (that delegates to
# streamfile) to http_PUT...
with tempfile . NamedTemporaryFile ( prefix = ' osc-copypac ' ) as f :
get_source_file ( src_apiurl , src_project , src_package , filename ,
targetfilename = f . name , revision = revision )
path = [ ' source ' , dst_project , dst_package , pathname2url ( filename ) ]
u = makeurl ( dst_apiurl , path , query = { ' rev ' : ' repository ' } )
http_PUT ( u , file = f . name )
2016-02-12 10:39:54 +01:00
tfilelist = Package . commit_filelist ( dst_apiurl , dst_project , dst_package ,
filelist , msg = comment )
todo = Package . commit_get_missing ( tfilelist )
2016-02-05 17:16:42 +01:00
if todo :
raise oscerr . APIError ( ' failed to copy: %s ' % ' , ' . join ( todo ) )
2008-03-17 22:46:42 +01:00
return ' Done. '
2006-09-21 16:33:24 +02:00
2023-01-03 14:31:42 +01:00
def lock ( apiurl : str , project : str , package : str , msg : str = None ) :
url_path = [ " source " , project ]
if package :
url_path + = [ package ]
url_query = {
" cmd " : " set_flag " ,
" flag " : " lock " ,
" status " : " enable " ,
}
if msg :
url_query [ " comment " ] = msg
_private . api . post ( apiurl , url_path , url_query )
2022-12-07 13:01:23 +01:00
def unlock_package ( apiurl : str , prj : str , pac : str , msg ) :
2013-05-27 14:56:24 +02:00
query = { ' cmd ' : ' unlock ' , ' comment ' : msg }
2012-03-15 09:54:56 +01:00
u = makeurl ( apiurl , [ ' source ' , prj , pac ] , query )
http_POST ( u )
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def unlock_project ( apiurl : str , prj : str , msg = None ) :
2013-05-27 14:56:24 +02:00
query = { ' cmd ' : ' unlock ' , ' comment ' : msg }
2012-03-15 09:54:56 +01:00
u = makeurl ( apiurl , [ ' source ' , prj ] , query )
http_POST ( u )
2022-12-07 13:01:23 +01:00
def undelete_package ( apiurl : str , prj : str , pac : str , msg = None ) :
2013-05-27 14:56:24 +02:00
query = { ' cmd ' : ' undelete ' }
2011-05-26 10:21:14 +02:00
if msg :
query [ ' comment ' ] = msg
else :
query [ ' comment ' ] = ' undeleted via osc '
u = makeurl ( apiurl , [ ' source ' , prj , pac ] , query )
2010-05-21 19:02:42 +02:00
http_POST ( u )
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def undelete_project ( apiurl : str , prj : str , msg = None ) :
2013-05-27 14:56:24 +02:00
query = { ' cmd ' : ' undelete ' }
2011-05-26 10:21:14 +02:00
if msg :
query [ ' comment ' ] = msg
else :
query [ ' comment ' ] = ' undeleted via osc '
u = makeurl ( apiurl , [ ' source ' , prj ] , query )
2010-05-21 19:02:42 +02:00
http_POST ( u )
2022-12-07 13:01:23 +01:00
def delete_package ( apiurl : str , prj : str , pac : str , force = False , msg = None ) :
2023-01-02 16:25:55 +01:00
if not force :
requests = get_request_collection ( apiurl , project = prj , package = pac )
if requests :
error_msg = \
" Package has pending requests. Deleting the package will break them. " \
" They should be accepted/declined/revoked before deleting the package. " \
" Or just use the ' force ' option "
raise oscerr . PackageError ( prj , pac , error_msg )
2011-05-23 20:42:35 +02:00
query = { }
if force :
query [ ' force ' ] = " 1 "
2012-02-17 09:13:40 +01:00
if msg :
query [ ' comment ' ] = msg
2011-05-23 20:42:35 +02:00
u = makeurl ( apiurl , [ ' source ' , prj , pac ] , query )
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
2022-09-12 13:43:10 +02:00
2023-01-02 16:25:55 +01:00
def delete_project ( apiurl : str , prj : str , force = False , msg = None , recursive = False ) :
if not recursive :
2023-01-20 10:10:50 +01:00
packages = meta_get_packagelist ( apiurl , prj )
2023-01-02 16:25:55 +01:00
if packages :
error_msg = \
" Project contains packages. It must be empty before deleting it. " \
" If you are sure that you want to remove this project and all its " \
" packages use the ' recursive ' option. "
raise oscerr . ProjectError ( prj , error_msg )
2011-05-23 20:42:35 +02:00
query = { }
if force :
query [ ' force ' ] = " 1 "
2011-05-26 10:21:14 +02:00
if msg :
query [ ' comment ' ] = msg
2011-05-23 20:42:35 +02:00
u = makeurl ( apiurl , [ ' source ' , prj ] , query )
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
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def delete_files ( apiurl : str , prj : str , pac : str , 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
2022-12-07 13:01:23 +01:00
def get_platforms ( apiurl : str ) :
2009-09-08 10:14:27 +02:00
return get_repositories ( apiurl )
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def get_repositories ( apiurl : str ) :
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 )
2022-09-12 13:43:10 +02:00
r = sorted ( node . get ( ' name ' ) for node in tree . getroot ( ) )
2006-04-20 16:26:50 +02:00
return r
2006-05-02 10:17:45 +02:00
2022-12-07 13:01:23 +01:00
def get_distributions ( apiurl : str ) :
2022-07-29 22:00:41 +02:00
""" Returns list of dicts with headers
' distribution ' , ' project ' , ' repository ' , ' reponame ' """
2010-07-28 16:04:27 +02:00
2022-07-29 22:04:58 +02:00
f = http_GET ( makeurl ( apiurl , [ ' distributions ' ] ) )
root = ET . fromstring ( b ' ' . join ( f ) )
distlist = [ ]
for node in root . findall ( ' distribution ' ) :
dmap = { }
for child in node :
if child . tag == ' name ' :
dmap [ ' distribution ' ] = child . text
elif child . tag in ( ' project ' , ' repository ' , ' reponame ' ) :
dmap [ child . tag ] = child . text
distlist . append ( dmap )
return distlist
2010-07-28 16:04:27 +02:00
2009-09-08 10:14:27 +02:00
# old compat lib call
2022-12-07 13:01:23 +01:00
def get_platforms_of_project ( apiurl : str , prj : str ) :
2009-09-08 10:14:27 +02:00
return get_repositories_of_project ( apiurl , prj )
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def get_repositories_of_project ( apiurl : str , prj : str ) :
2007-05-04 23:51:54 +02:00
f = show_project_meta ( apiurl , prj )
2018-12-13 15:14:06 +01:00
root = ET . fromstring ( b ' ' . join ( f ) )
2006-04-20 16:26:50 +02:00
2022-09-12 13:43:10 +02: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 '
2022-12-07 13:01:23 +01:00
def __init__ ( self , name : str , arch : str ) :
2009-11-17 14:39:46 +01:00
self . name = name
self . arch = arch
def __str__ ( self ) :
return self . repo_line_templ % ( self . name , self . arch )
2014-12-10 09:51:50 +01:00
def __repr__ ( self ) :
return ' Repo( %s %s ) ' % ( self . name , self . arch )
2014-07-02 22:07:01 +02:00
@staticmethod
def fromfile ( filename ) :
if not os . path . exists ( filename ) :
return [ ]
repos = [ ]
2022-07-28 19:11:29 +02:00
lines = open ( filename ) . readlines ( )
2014-07-02 22:07:01 +02:00
for line in lines :
data = line . split ( )
if len ( data ) == 2 :
repos . append ( Repo ( data [ 0 ] , data [ 1 ] ) )
elif len ( data ) == 1 :
# only for backward compatibility
repos . append ( Repo ( data [ 0 ] , ' ' ) )
return repos
@staticmethod
def tofile ( filename , repos ) :
with open ( filename , ' w ' ) as f :
for repo in repos :
f . write ( ' %s %s \n ' % ( repo . name , repo . arch ) )
2022-09-12 13:43:10 +02:00
2007-05-04 23:51:54 +02:00
def get_repos_of_project ( apiurl , prj ) :
f = show_project_meta ( apiurl , prj )
2018-12-13 15:14:06 +01:00
root = ET . fromstring ( b ' ' . 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
2022-09-12 13:43:10 +02:00
2022-10-21 10:38:57 +02:00
def get_binarylist (
apiurl : str , prj : str , repo : str , arch : str , package : Optional [ str ] = None , verbose = False , withccache = False
) :
2007-08-16 19:12:46 +02:00
what = package or ' _repository '
2020-05-05 09:58:16 +02:00
query = { }
if withccache :
query [ ' withccache ' ] = 1
u = makeurl ( apiurl , [ ' build ' , prj , repo , arch , what ] , query = query )
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 :
2022-09-12 13:43:10 +02:00
return [ node . get ( ' filename ' ) for node in tree . findall ( ' binary ' ) ]
2008-09-30 16:54:08 +02:00
else :
l = [ ]
for node in tree . findall ( ' binary ' ) :
2009-10-20 16:30:15 +02:00
f = File ( node . get ( ' filename ' ) ,
None ,
2018-03-13 14:56:33 +01:00
int ( node . get ( ' size ' ) or 0 ) or None ,
int ( node . get ( ' mtime ' ) or 0 ) or None )
2008-09-30 16:54:08 +02:00
l . append ( f )
return l
2007-08-16 12:28:32 +02:00
2022-12-07 13:01:23 +01:00
def get_binarylist_published ( apiurl : str , prj : str , repo : str , arch : str ) :
2007-08-16 19:12:46 +02:00
u = makeurl ( apiurl , [ ' published ' , prj , repo , arch ] )
f = http_GET ( u )
tree = ET . parse ( f )
2022-09-12 13:43:10 +02:00
r = [ node . get ( ' name ' ) for node in tree . findall ( ' entry ' ) ]
2007-08-16 19:12:46 +02:00
return r
2022-10-21 10:38:57 +02:00
def show_results_meta (
apiurl : str ,
prj : str ,
package : Optional [ str ] = None ,
lastbuild : Optional [ str ] = None ,
repository : Optional [ List [ str ] ] = None ,
arch : Optional [ List [ str ] ] = None ,
oldstate : Optional [ str ] = None ,
multibuild = False ,
locallink = False ,
code : Optional [ str ] = None ,
) :
2022-08-29 15:32:41 +02:00
repository = repository or [ ]
arch = arch or [ ]
2017-09-28 15:46:23 +02:00
query = [ ]
2007-08-11 14:29:38 +02:00
if package :
2017-09-28 15:46:23 +02:00
query . append ( ' package= %s ' % quote_plus ( package ) )
2012-01-23 17:26:53 +01:00
if oldstate :
2017-09-28 15:46:23 +02:00
query . append ( ' oldstate= %s ' % quote_plus ( oldstate ) )
2009-02-18 10:53:38 +01:00
if lastbuild :
2017-09-28 15:46:23 +02:00
query . append ( ' lastbuild=1 ' )
2016-11-23 15:35:09 +01:00
if multibuild :
2017-09-28 15:46:23 +02:00
query . append ( ' multibuild=1 ' )
2016-11-23 15:35:09 +01:00
if locallink :
2017-09-28 15:46:23 +02:00
query . append ( ' locallink=1 ' )
2020-06-19 08:32:00 +02:00
if code :
query . append ( ' code= %s ' % quote_plus ( code ) )
2009-05-15 09:16:26 +02:00
for repo in repository :
2017-09-28 15:46:23 +02:00
query . append ( ' repository= %s ' % quote_plus ( repo ) )
2009-05-15 09:16:26 +02:00
for a in arch :
2017-09-28 15:46:23 +02:00
query . append ( ' arch= %s ' % quote_plus ( a ) )
u = makeurl ( apiurl , [ ' build ' , prj , ' _result ' ] , query = query )
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
2022-12-07 13:01:23 +01:00
def show_prj_results_meta (
apiurl : str , prj : str , repositories : Optional [ List [ str ] ] = None , arches : Optional [ List [ str ] ] = None
) :
2017-09-28 15:55:11 +02:00
# this function is only needed for backward/api compatibility
if repositories is None :
repositories = [ ]
if arches is None :
arches = [ ]
return show_results_meta ( apiurl , prj , repository = repositories , arch = arches )
2006-09-25 17:11:03 +02:00
2016-02-07 00:55:23 +01:00
def result_xml_to_dicts ( xml ) :
# assumption: xml contains at most one status element (maybe we should
# generalize this to arbitrary status element)
root = ET . fromstring ( xml )
2007-03-13 00:21:34 +01:00
for node in root . findall ( ' result ' ) :
rmap = { }
2016-02-07 00:55:23 +01:00
rmap [ ' project ' ] = rmap [ ' prj ' ] = node . get ( ' project ' )
2010-04-20 14:37:28 +02:00
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 ' )
2018-11-26 16:42:17 +01:00
rmap [ ' dirty ' ] = node . get ( ' dirty ' ) == ' true ' or node . get ( ' code ' ) == ' blocked '
2013-06-13 16:27:58 +02:00
rmap [ ' repostate ' ] = node . get ( ' code ' )
2016-02-07 00:55:23 +01:00
rmap [ ' pkg ' ] = rmap [ ' package ' ] = rmap [ ' pac ' ] = ' '
2016-06-10 14:40:12 +02:00
rmap [ ' code ' ] = node . get ( ' code ' )
2020-10-05 10:08:52 +02:00
rmap [ ' details ' ] = node . get ( ' details ' )
2016-11-23 15:35:09 +01:00
# the way we currently use this function, there should be
# always a status element
snodes = node . findall ( ' status ' )
is_multi = len ( snodes ) > 1
2017-04-07 08:50:29 +02:00
if len ( snodes ) < 1 :
# the repository setup is broken
smap = dict ( rmap )
smap [ ' pkg ' ] = " _repository "
smap [ ' code ' ] = rmap [ ' repostate ' ]
smap [ ' details ' ] = node . get ( ' details ' )
yield smap , is_multi
continue
2016-11-23 15:35:09 +01:00
for statusnode in snodes :
smap = dict ( rmap )
smap [ ' pkg ' ] = smap [ ' package ' ] = smap [ ' pac ' ] = statusnode . get ( ' package ' )
smap [ ' code ' ] = statusnode . get ( ' code ' , ' ' )
2011-12-05 23:23:49 +01:00
details = statusnode . find ( ' details ' )
2016-11-23 15:35:09 +01:00
if details is not None :
smap [ ' details ' ] = details . text
2020-10-05 10:08:52 +02:00
if rmap [ ' code ' ] == ' broken ' :
# real error just becomes visible in details/verbose
smap [ ' code ' ] = rmap [ ' code ' ]
smap [ ' details ' ] = " repository: " + rmap [ ' details ' ]
2016-11-23 15:35:09 +01:00
yield smap , is_multi
2010-04-20 14:18:02 +02:00
2016-02-07 00:55:23 +01:00
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
2013-05-27 14:26:58 +02:00
2022-12-07 13:01:23 +01:00
def get_results ( apiurl : str , project : str , package : str , verbose = False , printJoin = " " , * args , * * kwargs ) :
2016-02-07 00:55:23 +01:00
""" returns list of/or prints a human readable status for the specified package """
# hmm the function name is a bit too generic - something like
# get_package_results_human would be better, but this would break the existing
# api (unless we keep get_results around as well)...
result_line_templ = ' %(rep)-20s %(arch)-10s %(status)s '
2016-11-23 15:35:09 +01:00
result_line_mb_templ = ' %(rep)-20s %(arch)-10s %(pkg)-30s %(status)s '
2016-02-07 00:55:23 +01:00
r = [ ]
2016-10-06 15:07:21 +02:00
printed = False
2016-11-23 15:35:09 +01:00
multibuild_packages = kwargs . pop ( ' multibuild_packages ' , [ ] )
2017-04-07 10:01:20 +02:00
show_excluded = kwargs . pop ( ' showexcl ' , False )
2020-06-19 08:32:00 +02:00
code_filter = kwargs . get ( ' code ' )
2016-02-07 00:55:23 +01:00
for results in get_package_results ( apiurl , project , package , * * kwargs ) :
r = [ ]
2016-11-23 15:35:09 +01:00
for res , is_multi in result_xml_to_dicts ( results ) :
2017-04-07 10:01:20 +02:00
if not show_excluded and res [ ' code ' ] == ' excluded ' :
continue
2013-05-27 14:26:58 +02:00
if ' _oldstate ' in res :
oldstate = res [ ' _oldstate ' ]
continue
2016-11-23 15:35:09 +01:00
if multibuild_packages :
l = res [ ' pkg ' ] . rsplit ( ' : ' , 1 )
2022-05-10 10:19:09 +02:00
if ( len ( l ) != 2 or l [ 1 ] not in multibuild_packages ) and not ( len ( l ) == 1 and " " in multibuild_packages ) :
# special case: packages without flavor when multibuild_packages contains an empty string
2016-11-23 15:35:09 +01:00
continue
2013-05-27 14:26:58 +02:00
res [ ' status ' ] = res [ ' code ' ]
2022-04-28 15:33:58 +02:00
if verbose and res [ ' details ' ] is not None :
2013-05-27 14:26:58 +02:00
if res [ ' code ' ] in ( ' unresolvable ' , ' expansion error ' ) :
lines = res [ ' details ' ] . split ( ' , ' )
2018-04-26 15:38:25 +02:00
res [ ' status ' ] + = ' : \n ' + ' \n ' . join ( lines )
2013-05-27 14:26:58 +02:00
else :
2016-06-10 14:41:35 +02:00
res [ ' status ' ] + = ' : %s ' % res [ ' details ' ]
2016-10-20 12:58:50 +02:00
elif res [ ' code ' ] in ( ' scheduled ' , ) and res [ ' details ' ] :
# highlight scheduled jobs with possible dispatch problems
res [ ' status ' ] + = ' * '
2013-06-13 16:42:25 +02:00
if res [ ' dirty ' ] :
2013-06-13 16:27:58 +02:00
if verbose :
2013-06-13 16:42:25 +02:00
res [ ' status ' ] = ' outdated (was: %s ) ' % res [ ' status ' ]
2013-06-13 16:27:58 +02:00
else :
res [ ' status ' ] + = ' * '
2016-06-10 14:41:35 +02:00
elif res [ ' code ' ] in ( ' succeeded ' , ) and res [ ' repostate ' ] != " published " :
2013-05-27 14:26:58 +02:00
if verbose :
2013-06-13 16:42:25 +02:00
res [ ' status ' ] + = ' (unpublished) '
2013-05-27 14:26:58 +02:00
else :
res [ ' status ' ] + = ' * '
2020-06-19 08:32:00 +02:00
# we need to do the code filtering again, because result_xml_to_dicts returns the code
# of the repository if the result is already prefiltered by the backend. So we need
# to filter out the repository states.
if code_filter is None or code_filter == res [ ' code ' ] :
if is_multi :
r . append ( result_line_mb_templ % res )
else :
r . append ( result_line_templ % res )
2013-05-27 14:26:58 +02:00
if printJoin :
2016-10-06 15:07:21 +02:00
if printed :
# will print a newline if already a result was printed (improves readability)
print ( )
2013-05-27 14:26:58 +02:00
print ( printJoin . join ( r ) )
2016-10-06 15:07:21 +02:00
printed = True
2016-02-07 00:55:23 +01:00
return r
2013-05-27 14:26:58 +02:00
2022-12-07 13:01:23 +01:00
def get_package_results ( apiurl : str , project : str , package : Optional [ str ] = None , wait = False , * args , * * kwargs ) :
2016-02-07 00:55:23 +01:00
""" generator that returns a the package results as an xml structure """
xml = ' '
waiting_states = ( ' blocked ' , ' scheduled ' , ' dispatching ' , ' building ' ,
' signing ' , ' finished ' )
while True :
waiting = False
try :
2018-12-13 15:14:06 +01:00
xml = b ' ' . join ( show_results_meta ( apiurl , project , package , * args , * * kwargs ) )
2016-02-07 00:55:23 +01:00
except HTTPError as e :
# check for simple timeout error and fetch again
if e . code == 502 or e . code == 504 :
# re-try result request
continue
2017-03-09 14:55:30 +01:00
root = ET . fromstring ( e . read ( ) )
if e . code == 400 and kwargs . get ( ' multibuild ' ) and re . search ( ' multibuild ' , getattr ( root . find ( ' summary ' ) , ' text ' , ' ' ) ) :
kwargs [ ' multibuild ' ] = None
kwargs [ ' locallink ' ] = None
continue
2016-02-07 00:55:23 +01:00
raise
root = ET . fromstring ( xml )
kwargs [ ' oldstate ' ] = root . get ( ' state ' )
for result in root . findall ( ' result ' ) :
if result . get ( ' dirty ' ) is not None :
waiting = True
break
elif result . get ( ' code ' ) in waiting_states :
waiting = True
break
2016-09-09 14:46:28 +02:00
else :
pkg = result . find ( ' status ' )
2016-09-09 16:24:26 +02:00
if pkg is not None and pkg . get ( ' code ' ) in waiting_states :
2016-09-09 14:46:28 +02:00
waiting = True
break
2022-08-29 15:39:02 +02:00
2016-02-07 00:55:23 +01:00
if not wait or not waiting :
2013-05-27 14:26:58 +02:00
break
2016-02-07 00:55:23 +01:00
else :
2022-05-20 12:00:44 +02:00
yield xml
2016-02-07 00:55:23 +01:00
yield xml
2010-01-13 13:35:45 +01:00
2006-04-29 22:44:09 +02:00
2022-12-07 13:01:23 +01:00
def get_prj_results (
apiurl : str ,
prj : str ,
hide_legend = False ,
csv = False ,
status_filter = None ,
name_filter = None ,
arch = None ,
repo = None ,
vertical = None ,
show_excluded = None ,
brief = False ,
) :
2022-09-12 13:43:10 +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 )
2018-12-13 15:14:06 +01:00
root = ET . fromstring ( b ' ' . join ( f ) )
2006-09-25 17:11:03 +02:00
Support a regex based name filtering in core.get_prj_results
So far, core.get_prj_results only supports a substring based name
filtering mechanism. Now, a regex based name filtering mechanism
is used. That is, if the regex matches a package name, the package
is not filtered out.
This is an API incompatible change:
- 3rd party code which looks like this is going to break:
class Foo(str):
...
def __eq__(self, other):
return ...
... = core.get_prj_results(..., name_filter=Foo())
(My gut feeling says there are no such callers. However, if this
really breaks any serious code, we can fix it in a follow-up commit)
- "osc prjresults openSUSE:Leap:15.2:Update --name-filter zypper." will
now also show "zypper-docker" etc. because the dot (".") matches any
character (except a newline). Previously, only packages that contained
the str "zypper" followed by a dot (".") were shown. The old behavior
can be restored, if the dot is escaped: "osc prjresults
openSUSE:Leap:15.2:Update --name-filter 'zypper\.'".
Of course, this affects all other special characters, too.
Additionally, if an illegal regex is passed to the --name-filter option,
an exception is raised. The previous code did not fail.
This can break existing workflows and scripts. We could avoid this by
introducing a --name-filter-regex option but this would clutter the
UI (IMHO).
A regex based name filtering feature was requested by darix.
2020-11-25 22:17:41 +01:00
if name_filter is not None :
name_filter = re . compile ( name_filter )
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 = { }
2022-08-29 12:56:57 +02:00
if root . find ( ' result ' ) is 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
2017-10-18 15:17:56 +02:00
if arch and node . get ( ' arch ' ) not in arch :
2009-10-15 16:24:12 +02:00
continue
2017-10-18 15:17:56 +02:00
if repo 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 ' )
2020-10-05 10:08:52 +02:00
if node . get ( ' details ' ) :
state + = ' details: ' + node . get ( ' details ' )
2010-01-13 13:35:45 +01:00
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
2020-06-19 08:32:00 +02:00
filters = [ ]
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
2022-09-12 13:43:10 +02:00
# filtering for Package Status
2008-05-15 20:09:24 +02:00
if status_filter :
if status_filter in buildstatus_symbols . values ( ) :
2013-07-04 21:58:28 +02:00
# a list is needed because if status_filter == "U"
# we have to filter either an "expansion error" (obsolete)
# or an "unresolvable" state
2008-05-15 20:09:24 +02:00
for txt , sym in buildstatus_symbols . items ( ) :
if sym == status_filter :
2013-07-04 21:58:28 +02:00
filters . append ( txt )
2020-06-19 08:32:00 +02:00
else :
filters . append ( status_filter )
for filt_txt in filters :
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 )
targets_to_show . append ( repo )
Support a regex based name filtering in core.get_prj_results
So far, core.get_prj_results only supports a substring based name
filtering mechanism. Now, a regex based name filtering mechanism
is used. That is, if the regex matches a package name, the package
is not filtered out.
This is an API incompatible change:
- 3rd party code which looks like this is going to break:
class Foo(str):
...
def __eq__(self, other):
return ...
... = core.get_prj_results(..., name_filter=Foo())
(My gut feeling says there are no such callers. However, if this
really breaks any serious code, we can fix it in a follow-up commit)
- "osc prjresults openSUSE:Leap:15.2:Update --name-filter zypper." will
now also show "zypper-docker" etc. because the dot (".") matches any
character (except a newline). Previously, only packages that contained
the str "zypper" followed by a dot (".") were shown. The old behavior
can be restored, if the dot is escaped: "osc prjresults
openSUSE:Leap:15.2:Update --name-filter 'zypper\.'".
Of course, this affects all other special characters, too.
Additionally, if an illegal regex is passed to the --name-filter option,
an exception is raised. The previous code did not fail.
This can break existing workflows and scripts. We could avoid this by
introducing a --name-filter-regex option but this would clutter the
UI (IMHO).
A regex based name filtering feature was requested by darix.
2020-11-25 22:17:41 +01:00
elif name_filter . search ( pkg ) is not None :
2020-06-19 08:32:00 +02:00
pacs_to_show . append ( pkg )
2022-09-12 13:43:10 +02:00
# filtering for Package Name
2008-05-15 20:09:24 +02:00
elif name_filter :
for pkg in pacs :
Support a regex based name filtering in core.get_prj_results
So far, core.get_prj_results only supports a substring based name
filtering mechanism. Now, a regex based name filtering mechanism
is used. That is, if the regex matches a package name, the package
is not filtered out.
This is an API incompatible change:
- 3rd party code which looks like this is going to break:
class Foo(str):
...
def __eq__(self, other):
return ...
... = core.get_prj_results(..., name_filter=Foo())
(My gut feeling says there are no such callers. However, if this
really breaks any serious code, we can fix it in a follow-up commit)
- "osc prjresults openSUSE:Leap:15.2:Update --name-filter zypper." will
now also show "zypper-docker" etc. because the dot (".") matches any
character (except a newline). Previously, only packages that contained
the str "zypper" followed by a dot (".") were shown. The old behavior
can be restored, if the dot is escaped: "osc prjresults
openSUSE:Leap:15.2:Update --name-filter 'zypper\.'".
Of course, this affects all other special characters, too.
Additionally, if an illegal regex is passed to the --name-filter option,
an exception is raised. The previous code did not fail.
This can break existing workflows and scripts. We could avoid this by
introducing a --name-filter-regex option but this would clutter the
UI (IMHO).
A regex based name filtering feature was requested by darix.
2020-11-25 22:17:41 +01:00
if name_filter . search ( pkg ) is not None :
2008-05-15 20:09:24 +02:00
pacs_to_show . append ( pkg )
2022-09-12 13:43:10 +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
2022-09-12 13:43:10 +02:00
pacs = [ i for i in pacs if i in pacs_to_show ]
2022-08-29 13:23:29 +02:00
if targets_to_show :
2022-09-12 13:43:10 +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 :
Fixed traceback in get_prj_results
The reason of the crash is that not all targets are always defined for
all packages. In our environment it happens when linked project is
created and sources have just been uploaded to one package.
Here is the crash:
Traceback (most recent call last):
File "../tools-testing/build-package", line 313, in <module>
sys.exit(main(sys.argv))
File "../tools-testing/build-package", line 309, in main
return build(apiurl, tproject, package, timeout)
File "../tools-testing/build-package", line 226, in build
hide_legend=True, csv=True)
File "/usr/lib/python2.7/site-packages/osc/core.py", line 5135, in get_prj_results
row = [pac] + [status[pac][tg] for tg in targets]
status[pac]]
KeyError: ('Fedora_18', 'i586', 'outdated')
Please note that this fix fixes only csv mode. For other modes osc still
can crash, but it's hard to reproduce here as we're not using them.
Signed-off-by: Ed Bartosh <bartosh@gmail.com>
2013-12-05 15:46:30 +01:00
row = [ pac ] + [ status [ pac ] [ tg ] for tg in targets if tg in status [ pac ] ]
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
2020-06-19 08:32:00 +02:00
if brief :
for pac , repo_states in status . items ( ) :
for repo , state in repo_states . items ( ) :
if filters and state not in filters :
continue
r . append ( ' %s %s %s %s ' % ( pac , repo [ 0 ] , repo [ 1 ] , state ) )
return r
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
2022-09-12 13:43:10 +02:00
for pac in pacs [ startpac : startpac + max_pacs ] :
2010-01-11 16:36:21 +01:00
r . append ( ' | ' * offset + ' ' + pac )
offset + = 1
for tg in targets :
line = [ ]
line . append ( ' ' )
2022-09-12 13:43:10 +02:00
for pac in pacs [ startpac : startpac + max_pacs ] :
2010-01-11 16:36:21 +01:00
st = ' '
2013-04-09 11:33:25 +02:00
if pac not in status or tg not in status [ pac ] :
2010-01-11 16:36:21 +01:00
# for newly added packages, status may be missing
st = ' ? '
else :
try :
st = buildstatus_symbols [ status [ pac ] [ tg ] ]
except :
2013-04-09 12:51:28 +02:00
print ( ' osc: warn: unknown status \' %s \' ... ' % status [ pac ] [ tg ] )
print ( ' please edit osc/core.py, and extend the buildstatus_symbols dictionary. ' )
2010-01-11 16:36:21 +01:00
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 :
2022-04-20 19:22:35 +02:00
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 = ' '
2013-04-09 11:33:25 +02:00
if pac not in status or tg not in status [ pac ] :
2008-02-12 13:45:06 +01:00
# 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 :
2013-04-09 12:51:28 +02:00
print ( ' osc: warn: unknown status \' %s \' ... ' % status [ pac ] [ tg ] )
print ( ' please edit osc/core.py, and extend the buildstatus_symbols dictionary. ' )
2008-05-05 14:27:34 +02:00
st = ' ? '
buildstatus_symbols [ status [ pac ] [ tg ] ] = ' ? '
2008-02-12 13:45:06 +01:00
line . append ( st )
2022-09-12 13:43:10 +02:00
line . append ( ' ' + pac )
2010-01-11 16:36:21 +01:00
r . append ( ' ' . join ( line ) )
line = [ ]
for i in range ( 0 , len ( targets ) ) :
2022-04-20 19:22:35 +02:00
line . append ( str ( i % 10 ) )
2010-01-11 16:36:21 +01:00
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 ) )
2011-09-07 18:33:07 +02:00
legend . append ( ' ? buildstatus not available (only new packages) ' )
2010-01-11 16:36:21 +01:00
if vertical :
for i in range ( 0 , len ( targets ) ) :
2022-04-20 19:22:35 +02:00
s = ' %1d %s %s ( %s ) ' % ( i % 10 , targets [ i ] [ 0 ] , targets [ i ] [ 1 ] , targets [ i ] [ 2 ] )
2010-01-11 16:36:21 +01:00
if i < len ( legend ) :
legend [ i ] + = s
else :
2022-09-12 13:43:10 +02:00
legend . append ( ' ' * 24 + s )
2010-01-11 16:36:21 +01:00
r + = legend
2006-09-25 17:11:03 +02:00
return r
2022-12-07 13:01:23 +01:00
def streamfile ( url : str , 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
2014-05-22 16:52:59 +02:00
caller . A spezial usage is bufsize = " line " to read line by line ( text ) .
2009-04-09 17:52:59 +02:00
"""
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 ' ] :
2013-04-09 12:51:28 +02:00
print ( ' \n \n Retry %d -- ' % ( retries - 1 ) , url , file = sys . stderr )
2022-09-12 13:43:10 +02:00
f = http_meth . __call__ ( url , data = data )
2010-12-01 10:22:53 +01:00
cl = f . info ( ) . get ( ' Content-Length ' )
2010-11-30 16:39:14 +01:00
if cl is not None :
2012-01-25 14:58:55 +01:00
# sometimes the proxy adds the same header again
# which yields in value like '3495, 3495'
# use the first of these values (should be all the same)
cl = cl . split ( ' , ' ) [ 0 ]
2010-11-30 16:39:14 +01:00
cl = int ( cl )
2010-02-09 20:57:10 +01:00
if progress_obj :
2018-02-02 15:47:17 +01:00
if not text :
basename = os . path . basename ( urlsplit ( url ) [ 2 ] )
else :
basename = text
progress_obj . start ( basename , cl )
2014-05-22 16:33:55 +02:00
2014-05-22 16:52:59 +02:00
if bufsize == " line " :
bufsize = 8192
xread = f . readline
else :
xread = f . read
2014-05-22 16:33:55 +02:00
read = 0
while True :
2014-05-22 16:52:59 +02:00
data = xread ( bufsize )
2022-08-29 13:23:29 +02:00
if not data :
2014-05-22 16:33:55 +02:00
break
read + = 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
2014-05-22 16:33:55 +02:00
2010-02-09 20:57:10 +01:00
if progress_obj :
2018-02-02 15:47:17 +01:00
progress_obj . end ( )
2009-04-09 18:14:29 +02:00
f . close ( )
2009-04-09 17:52:59 +02:00
2022-09-12 14:23:47 +02:00
if cl is not None and read != cl :
2010-11-30 19:10:06 +01:00
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
2012-12-15 01:50:24 +01:00
def buildlog_strip_time ( data ) :
""" Strips the leading build time from the log """
2018-12-13 15:14:06 +01:00
if isinstance ( data , str ) :
2022-07-28 19:11:29 +02:00
time_regex = re . compile ( r ' ^ \ [[^ \ ]]* \ ] ' , re . M )
2018-12-13 15:14:06 +01:00
return time_regex . sub ( ' ' , data )
else :
2022-07-28 19:11:29 +02:00
time_regex = re . compile ( br ' ^ \ [[^ \ ]]* \ ] ' , re . M )
2018-12-13 15:14:06 +01:00
return time_regex . sub ( b ' ' , data )
2012-12-15 01:50:24 +01:00
2022-12-07 13:01:23 +01:00
def print_buildlog (
apiurl : str ,
prj : str ,
package : str ,
repository : str ,
arch : str ,
offset = 0 ,
strip_time = False ,
last = False ,
lastsucceeded = False ,
) :
2008-01-03 23:10:16 +01:00
""" prints out the buildlog on stdout """
2012-03-05 10:44:09 +01:00
2018-04-16 14:57:57 +02:00
def print_data ( data , strip_time = False ) :
if strip_time :
data = buildlog_strip_time ( data )
2020-06-04 15:09:03 +02:00
# hmm calling decode_it is a bit problematic because data might begin
# or end with an, for instance, incomplete utf-8 sequence
2018-12-13 15:14:06 +01:00
sys . stdout . write ( decode_it ( data . translate ( all_bytes , remove_bytes ) ) )
2018-04-16 14:57:57 +02:00
2012-03-05 10:44:09 +01:00
# to protect us against control characters
2022-07-28 19:11:29 +02:00
all_bytes = bytes . maketrans ( b ' ' , b ' ' )
2022-09-12 13:43:10 +02:00
remove_bytes = all_bytes [ : 8 ] + all_bytes [ 14 : 32 ] # accept tabs and newlines
2012-03-05 10:44:09 +01:00
2022-09-12 13:43:10 +02:00
query = { ' nostream ' : ' 1 ' , ' start ' : ' %s ' % offset }
2013-08-13 10:38:43 +02:00
if last :
query [ ' last ' ] = 1
2019-11-14 10:50:41 +01:00
if lastsucceeded :
query [ ' lastsucceeded ' ] = 1
2018-04-16 14:57:57 +02:00
retry_count = 0
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 )
2018-04-16 14:57:57 +02:00
try :
2018-12-13 15:14:06 +01:00
for data in streamfile ( u ) :
2018-04-16 14:57:57 +02:00
offset + = len ( data )
print_data ( data , strip_time )
except IncompleteRead as e :
if retry_count > = 3 :
raise e
retry_count + = 1
data = e . partial
if len ( data ) :
offset + = len ( data )
print_data ( data , strip_time )
continue
2009-04-24 20:17:12 +02:00
if start_offset == offset :
break
2006-05-02 10:17:45 +02:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def get_dependson ( apiurl : str , project : str , repository : str , arch : str , packages = None , reverse = None ) :
2009-12-04 16:20:17 +01:00
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 ( )
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def get_buildinfo (
apiurl : str , prj : str , package : str , repository : str , arch : str , specfile = None , addlist = None , debug = None
) :
2007-05-09 11:36:55 +02:00
query = [ ]
if addlist :
for i in addlist :
query . append ( ' add= %s ' % quote_plus ( i ) )
2012-12-04 16:44:14 +01:00
if debug :
query . append ( ' debug=1 ' )
2007-05-09 11:36:55 +02:00
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 ( )
2022-12-07 13:01:23 +01:00
def get_buildconfig ( apiurl : str , prj : str , repository : str , path = None ) :
2019-03-11 16:39:04 +01:00
query = [ ]
if path :
for prp in path :
query . append ( ' path= %s ' % quote_plus ( prp ) )
u = makeurl ( apiurl , [ ' build ' , prj , repository , ' _buildconfig ' ] , query = query )
2007-04-19 10:47:22 +02:00
f = http_GET ( u )
2006-07-05 12:25:31 +02:00
return f . read ( )
2016-12-29 12:46:07 +01:00
2022-12-07 13:01:23 +01:00
def create_pbuild_config ( apiurl : str , project : str , repository : str , arch : str , project_dir ) :
2022-09-29 16:46:41 +02:00
"""
This is always replacing a possible exiting config for now
we could extend the _pbuild file easily , but what should we do with multiple instances of the _config ?
"""
# get expanded buildconfig for given project and repository
bc = get_buildconfig ( apiurl , project , repository )
if not bc :
msg = " Failed to get build config for project ' {project} ' , repository ' {repository} ' "
raise oscerr . NotFoundAPIError ( msg )
with open ( os . path . join ( project_dir , ' _config ' ) , " w " ) as f :
f . write ( decode_it ( bc ) )
# create the _pbuild file based on expanded repository path informations
pb = ET . fromstring ( ' <pbuild></pbuild> ' )
tree = ET . ElementTree ( pb )
preset = ET . SubElement ( pb , ' preset ' , name = repository , default = " " ) # default should be empty, but ET crashes
bi_text = decode_it ( get_buildinfo ( apiurl , project , ' _repository ' , repository , arch , specfile = " Name: dummy " ) )
root = ET . fromstring ( bi_text )
# cross compile setups are not yet supported
# for path in root.findall('hostsystem'):
# ET.SubElement(preset, 'hostrepo').text = path.get('url')
for path in root . findall ( ' path ' ) :
ET . SubElement ( preset , ' repo ' ) . text = path . get ( ' url ' )
ET . SubElement ( preset , ' arch ' ) . text = arch
xmlindent ( tree )
tree . write ( os . path . join ( project_dir , ' _pbuild ' ) , encoding = " utf-8 " , xml_declaration = True )
2022-12-07 13:01:23 +01:00
def get_worker_info ( apiurl : str , worker : str ) :
2016-12-29 12:46:07 +01:00
u = makeurl ( apiurl , [ ' worker ' , worker ] )
f = http_GET ( u )
2018-12-13 15:14:06 +01:00
return decode_it ( f . read ( ) )
2016-12-29 12:46:07 +01:00
2022-12-07 13:01:23 +01:00
def check_constraints ( apiurl : str , prj : str , repository : str , arch : str , package : str , constraintsfile = None ) :
query = { " cmd " : " checkconstraints " , " project " : prj , " package " : package , " repository " : repository , " arch " : arch }
u = makeurl ( apiurl , [ " worker " ] , query )
2016-12-29 12:46:07 +01:00
f = http_POST ( u , data = constraintsfile )
2018-12-13 15:14:06 +01:00
root = ET . fromstring ( b ' ' . join ( f ) )
2016-12-29 12:46:07 +01:00
return [ node . get ( ' name ' ) for node in root . findall ( ' entry ' ) ]
2022-12-07 13:01:23 +01:00
def get_source_rev ( apiurl : str , project : str , package : str , revision = None ) :
2010-12-26 21:14:40 +01:00
# 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 :
2014-08-13 11:21:55 +02:00
url = makeurl ( apiurl , [ ' source ' , project , package , ' _history ' ] , { ' rev ' : revision } )
2010-12-26 21:14:40 +01:00
else :
2013-05-27 14:26:58 +02:00
url = makeurl ( apiurl , [ ' source ' , project , package , ' _history ' ] )
2010-12-26 21:14:40 +01:00
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 :
2022-09-12 13:43:10 +02:00
return { ' version ' : None , ' error ' : ' empty revisionlist: no such package? ' }
2010-12-26 21:14:40 +01:00
e = { }
for k in ent . keys ( ) :
2013-05-27 14:26:58 +02:00
e [ k ] = ent . get ( k )
2010-12-26 21:14:40 +01:00
for k in list ( ent ) :
2013-05-27 14:26:58 +02:00
e [ k . tag ] = k . text
2010-12-26 21:14:40 +01:00
return e
2006-07-05 12:25:31 +02:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def print_jobhistory ( apiurl : str , prj : str , current_package : str , repository : str , arch : str , format = " text " , limit = 20 ) :
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
2022-08-29 12:56:57 +02:00
if limit is not None and int ( limit ) > 0 :
2010-01-12 17:22:47 +01:00
query [ ' limit ' ] = int ( limit )
2022-09-12 13:43:10 +02: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 ' :
2013-04-09 12:51:28 +02: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 ' )
st = int ( node . get ( ' starttime ' ) )
et = int ( node . get ( ' endtime ' ) )
2015-07-21 11:20:54 +02:00
endtime = time . strftime ( ' % Y- % m- %d % H: % M: % S ' , time . gmtime ( et ) )
2022-09-12 13:43:10 +02:00
waittm = et - st
if waittm > 24 * 60 * 60 :
waitbuild = " %1d d %2d h %2d m %2d s " % ( waittm / ( 24 * 60 * 60 ) , ( waittm / ( 60 * 60 ) ) % 24 , ( waittm / 60 ) % 60 , waittm % 60 )
elif waittm > 60 * 60 :
waitbuild = " %2d h %2d m %2d s " % ( waittm / ( 60 * 60 ) , ( waittm / 60 ) % 60 , waittm % 60 )
2009-02-20 12:04:45 +01:00
else :
2015-07-21 11:32:06 +02:00
waitbuild = " %2d m %2d s " % ( waittm / 60 , waittm % 60 )
2009-10-20 16:30:15 +02:00
2009-05-13 11:04:27 +02:00
if format == ' csv ' :
2013-04-09 12:51:28 +02:00
print ( ' %s | %s | %s | %s | %s | %s ' % ( endtime , package , reason , code , waitbuild , worker ) )
2009-05-13 11:04:27 +02:00
else :
2013-04-09 12:51:28 +02: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
2022-12-07 13:01:23 +01:00
def get_commitlog (
apiurl : str , prj : str , package : str , revision , format = " text " , meta = False , deleted = False , revision_upper = None
) :
2022-11-09 10:56:56 +01:00
if package is None :
package = " _project "
2010-05-25 13:59:46 +02:00
query = { }
2011-01-19 20:26:38 +01:00
if deleted :
query [ ' deleted ' ] = 1
2010-05-25 13:59:46 +02:00
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 ' ) )
2022-09-12 13:43:10 +02:00
# vrev = int(node.get('vrev')) # what is the meaning of vrev?
2009-05-05 16:01:41 +02:00
try :
2011-11-22 20:12:28 +01:00
if revision is not None and revision_upper is not None :
if rev > int ( revision_upper ) or rev < int ( revision ) :
continue
elif revision is not None and rev != int ( revision ) :
2009-05-05 16:01:41 +02:00
continue
except ValueError :
if revision != srcmd5 :
continue
2007-07-12 02:48:52 +02:00
except ValueError :
# this part should _never_ be reached but...
2022-09-12 13:43:10 +02:00
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 :
2018-12-13 15:14:06 +01:00
comment = b ' <no message> '
2009-09-05 15:46:55 +02:00
try :
requestid = node . find ( ' requestid ' ) . text . encode ( locale . getpreferredencoding ( ) , ' replace ' )
except :
requestid = " "
2015-02-17 10:26:04 +01:00
t = time . gmtime ( int ( node . find ( ' time ' ) . text ) )
2015-07-21 11:20:54 +02:00
t = time . strftime ( ' % Y- % m- %d % H: % M: % S ' , t )
2007-07-12 01:24:26 +02:00
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 ,
2022-09-12 13:43:10 +02:00
decode_it ( 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 )
2023-03-03 13:20:54 +01:00
r . append ( ' <msg> %s </msg> ' % _private . api . xml_escape ( decode_it ( comment ) ) )
2009-05-13 10:53:32 +02:00
r . append ( ' </logentry> ' )
else :
2011-05-23 16:59:16 +02:00
if requestid :
2022-07-28 19:11:29 +02:00
requestid = decode_it ( b " rq " + requestid )
2009-05-13 10:53:32 +02:00
s = ' - ' * 76 + \
2011-05-23 16:59:16 +02:00
' \n r %s | %s | %s | %s | %s | %s \n ' % ( rev , user , t , srcmd5 , version , requestid ) + \
2018-12-13 15:14:06 +01:00
' \n ' + decode_it ( comment )
2009-05-13 10:53:32 +02:00
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
2022-12-07 13:01:23 +01:00
def runservice ( apiurl : str , prj : str , package : str ) :
2010-09-01 12:44:47 +02:00
u = makeurl ( apiurl , [ ' source ' , prj , package ] , query = { ' cmd ' : ' runservice ' } )
try :
f = http_POST ( u )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2010-09-01 12:44:47 +02:00
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 ' )
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def waitservice ( apiurl : str , prj : str , package : str ) :
2016-03-03 11:05:48 +01:00
u = makeurl ( apiurl , [ ' source ' , prj , package ] , query = { ' cmd ' : ' waitservice ' } )
try :
f = http_POST ( u )
except HTTPError as e :
e . osc_msg = ' The service for project \' %s \' package \' %s \' failed ' % ( prj , package )
raise
root = ET . parse ( f ) . getroot ( )
return root . get ( ' code ' )
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def mergeservice ( apiurl : str , prj : str , package : str ) :
2016-03-03 11:05:48 +01:00
# first waiting that the service finishes and that it did not fail
waitservice ( apiurl , prj , package )
# real merge
u = makeurl ( apiurl , [ ' source ' , prj , package ] , query = { ' cmd ' : ' mergeservice ' } )
try :
f = http_POST ( u )
except HTTPError as e :
e . osc_msg = ' could not merge service files in project \' %s \' package \' %s \' ' % ( prj , package )
raise
root = ET . parse ( f ) . getroot ( )
return root . get ( ' code ' )
2010-09-01 12:44:47 +02:00
2022-12-07 13:01:23 +01:00
def rebuild ( apiurl : str , prj : str , package : str , repo : str , arch : str , code = None ) :
2022-09-12 13:43:10 +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 )
2013-04-09 14:03:17 +02:00
except HTTPError as 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 :
2022-08-24 08:43:09 +02:00
with open ( os . path . join ( dir , store , ' _project ' ) ) as f :
p = f . readline ( ) . strip ( )
2022-07-28 19:11:29 +02:00
except OSError :
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 :
2022-08-24 08:43:09 +02:00
with open ( os . path . join ( dir , store , ' _package ' ) ) as f :
p = f . readline ( ) . strip ( )
2022-07-28 19:11:29 +02:00
except OSError :
2021-11-30 13:13:11 +01:00
msg = ' Error: \' %s \' is not an osc package working copy ' % os . path . abspath ( dir )
if os . path . exists ( os . path . join ( dir , ' .svn ' ) ) :
msg + = ' \n Try svn instead of osc. '
raise oscerr . NoWorkingCopy ( msg )
return p
2022-09-12 13:43:10 +02:00
2021-11-30 13:13:11 +01:00
def store_read_scmurl ( dir ) :
2022-10-14 14:31:42 +02:00
import warnings
warnings . warn (
" osc.core.store_read_scmurl() is deprecated. "
" You should be using high-level classes such as Store, Project or Package instead. " ,
DeprecationWarning
)
2022-10-14 15:37:24 +02:00
return Store ( dir ) . scmurl
2006-04-20 16:26:50 +02:00
2022-09-12 13:43:10 +02:00
2010-09-19 23:00:19 +02:00
def store_read_apiurl ( dir , defaulturl = True ) :
2022-10-14 14:25:54 +02:00
import warnings
warnings . warn (
" osc.core.store_read_apiurl() is deprecated. "
" You should be using high-level classes such as Store, Project or Package instead. " ,
DeprecationWarning
)
return Store ( dir ) . apiurl
2007-05-04 23:51:54 +02:00
2022-09-12 13:43:10 +02:00
2019-12-04 09:45:17 +01:00
def store_read_last_buildroot ( dir ) :
global store
fname = os . path . join ( dir , store , ' _last_buildroot ' )
if os . path . exists ( fname ) :
lines = open ( fname ) . read ( ) . splitlines ( )
if len ( lines ) == 3 :
return lines
return
2022-09-12 13:43:10 +02:00
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 ' )
2018-12-13 15:14:06 +01:00
if not isinstance ( string , str ) :
string = decode_it ( string )
2010-03-04 00:31:46 +01:00
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
2022-09-12 13:43:10 +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
2022-09-12 13:43:10 +02:00
2007-05-04 23:51:54 +02:00
def store_write_apiurl ( dir , apiurl ) :
2022-10-14 15:37:24 +02:00
import warnings
warnings . warn (
" osc.core.store_write_apiurl() is deprecated. "
" You should be using high-level classes such as Store, Project or Package instead. " ,
DeprecationWarning
)
Store ( dir ) . apiurl = apiurl
2006-08-11 12:37:29 +02:00
2022-09-12 13:43:10 +02:00
2019-12-04 09:45:17 +01:00
def store_write_last_buildroot ( dir , repo , arch , vm_type ) :
store_write_string ( dir , ' _last_buildroot ' , repo + ' \n ' + arch + ' \n ' + vm_type + ' \n ' )
2022-09-12 13:43:10 +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
2022-09-12 13:43:10 +02:00
try :
os . unlink ( os . path . join ( dir , store , file ) )
except :
pass
2010-02-11 11:25:56 +01:00
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 :
2022-08-24 08:43:09 +02:00
with open ( os . path . join ( dir , store , file ) ) as f :
return f . read ( )
2010-02-11 11:25:56 +01:00
except :
return None
2022-09-12 13:43:10 +02:00
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 )
2022-09-12 13:43:10 +02:00
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
2022-12-07 13:01:23 +01:00
def abortbuild ( apiurl : str , project : str , package = None , arch = None , repo = None ) :
2013-10-28 18:29:56 +01:00
return cmdbuild ( apiurl , ' abortbuild ' , project , package , arch , 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
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def restartbuild ( apiurl : str , project : str , package = None , arch = None , repo = None ) :
2013-10-28 18:29:56 +01:00
return cmdbuild ( apiurl , ' restartbuild ' , project , package , arch , repo )
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def unpublish ( apiurl : str , project : str , package : Optional [ str ] = None , arch = None , repo = None , code = None ) :
return cmdbuild ( apiurl , " unpublish " , project , package , arch , repo , code )
2017-01-16 11:58:02 +01:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def wipebinaries ( apiurl : str , project : str , package : Optional [ str ] = None , arch = None , repo = None , code = None ) :
return cmdbuild ( apiurl , " wipe " , project , package , arch , repo , code )
2007-06-14 16:30:36 +02:00
2022-12-07 13:01:23 +01:00
def cmdbuild (
apiurl : str , cmd : str , project : str , package : Optional [ str ] = None , arch = None , repo = None , code = None , sysrq = None
) :
query = { " cmd " : cmd }
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
2018-02-09 08:47:52 +01:00
if sysrq :
query [ ' sysrq ' ] = sysrq
2007-06-14 16:30:36 +02:00
u = makeurl ( apiurl , [ ' build ' , project ] , query )
try :
f = http_POST ( u )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2013-12-01 18:55:23 +01:00
e . osc_msg = ' %s command failed for project %s ' % ( cmd , 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
2018-02-09 08:47:52 +01:00
if sysrq :
e . osc_msg + = ' sysrq= %s ' % 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
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
2019-08-22 22:53:04 +02:00
def parseRevisionOption ( string , allow_md5 = True ) :
2007-07-04 14:55:26 +02:00
"""
2007-07-04 15:48:24 +02:00
returns a tuple which contains the revisions
2007-07-04 14:55:26 +02:00
"""
2019-08-22 22:53:04 +02:00
revisions = [ None , None ]
2007-07-04 14:55:26 +02:00
if string :
2019-08-22 22:53:04 +02:00
parts = string . split ( ' : ' )
2022-04-04 10:54:59 +02:00
if len ( parts ) > 2 :
raise oscerr . OscInvalidRevision ( string )
for i , revision in enumerate ( parts , 0 ) :
2019-08-22 22:53:04 +02:00
if revision . isdigit ( ) or ( allow_md5 and revision . isalnum ( ) and len ( revision ) == 32 ) :
revisions [ i ] = revision
elif revision != ' ' and revision != ' latest ' :
2022-04-04 10:54:59 +02:00
raise oscerr . OscInvalidRevision ( string )
2019-08-22 22:53:04 +02:00
return tuple ( revisions )
2007-07-06 13:54:34 +02:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def checkRevision ( prj : str , pac : str , revision , apiurl : Optional [ str ] = 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 :
2020-10-13 19:29:19 +02:00
if int ( revision ) > int ( show_upstream_rev ( apiurl , prj , pac , meta = 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
2022-09-12 13:43:10 +02:00
2022-08-29 15:32:41 +02:00
def build_table ( col_num , data = None , headline = None , width = 1 , csv = False ) :
2007-07-15 15:49:13 +02:00
"""
This method builds a simple table .
2022-01-24 08:57:53 +01:00
Example : :
build_table ( 2 , [ ' foo ' , ' bar ' , ' suse ' , ' osc ' ] , [ ' col1 ' , ' col2 ' ] , 2 )
2007-07-15 15:49:13 +02:00
col1 col2
foo bar
suse osc
"""
2022-08-29 15:32:41 +02:00
data = data or [ ]
headline = headline or [ ]
2007-07-15 15:49:13 +02:00
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
2022-12-15 10:30:04 +01:00
data = [ str ( i ) for i in data ]
2007-07-15 15:49:13 +02:00
# 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
2022-04-20 19:22:35 +02:00
if i == col_num - 1 or csv :
2009-05-15 10:32:48 +02:00
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
2022-09-12 13:43:10 +02:00
2011-02-24 14:06:15 +01:00
def xpath_join ( expr , new_expr , op = ' or ' , inner = False , nexpr_parentheses = 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
2011-02-24 14:06:15 +01:00
surrounded ) . If nexpr_parentheses is True new_expr will be
surrounded with parentheses .
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
2011-02-24 14:06:15 +01:00
if nexpr_parentheses :
new_expr = ' ( %s ) ' % new_expr
2010-03-10 23:36:09 +01:00
return ' %s %s %s ' % ( expr , op , new_expr )
2009-08-21 03:26:37 +02:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def search ( apiurl : str , queries = None , * * kwargs ) :
2010-03-10 23:36:09 +01:00
"""
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
2017-08-17 16:47:05 +02:00
queries is a dict of optional http query parameters , which are passed
to the makeurl call , of the form
{ kindI1 : dict_or_list , . . . , kindIL : dict_or_list } ,
where kind_i1 to kind_iL are keys of kwargs .
2010-03-10 23:36:09 +01:00
"""
2017-08-17 16:47:05 +02:00
if queries is None :
queries = { }
2010-03-10 23:36:09 +01:00
res = { }
2013-04-09 11:25:19 +02:00
for urlpath , xpath in kwargs . items ( ) :
2022-09-12 13:43:10 +02:00
path = [ ' search ' ]
path + = urlpath . split ( ' _ ' ) # FIXME: take underscores as path seperators. I see no other way atm to fix OBS api calls and not breaking osc api
2017-08-17 16:47:05 +02:00
query = queries . get ( urlpath , { } )
query [ ' match ' ] = xpath
u = makeurl ( apiurl , path , query )
2010-03-10 23:36:09 +01:00
f = http_GET ( u )
res [ urlpath ] = ET . parse ( f ) . getroot ( )
return res
2009-04-09 10:21:12 +02:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def owner (
apiurl : str ,
search_term = None ,
mode = " binary " ,
attribute = None ,
project = None ,
usefilter = None ,
devel = None ,
limit = None ,
binary = None ,
) :
2012-11-22 11:37:32 +01:00
"""
Perform a binary package owner search . This is supported since OBS 2.4 .
"""
2020-08-12 09:14:16 +02:00
# binary is just for API backward compatibility
2022-08-31 12:05:33 +02:00
if not ( search_term is None ) ^ ( binary is None ) :
2020-08-12 09:14:16 +02:00
raise ValueError ( ' Either specify search_term or binary ' )
elif binary is not None :
search_term = binary
2022-08-29 15:39:02 +02:00
2012-11-22 11:37:32 +01:00
# find default project, if not specified
2020-08-12 09:14:16 +02:00
# mode can be "binary" or "package" atm
2022-09-12 13:43:10 +02:00
query = { mode : search_term }
2012-11-22 11:37:32 +01:00
if attribute :
query [ ' attribute ' ] = attribute
if project :
query [ ' project ' ] = project
if devel :
query [ ' devel ' ] = devel
2022-08-29 12:56:57 +02:00
if limit is not None :
2012-11-22 11:37:32 +01:00
query [ ' limit ' ] = limit
2022-08-29 12:56:57 +02:00
if usefilter is not None :
2012-11-22 11:37:32 +01:00
query [ ' filter ' ] = " , " . join ( usefilter )
2022-09-12 13:43:10 +02:00
u = makeurl ( apiurl , [ ' search ' , ' owner ' ] , query )
2012-11-22 11:37:32 +01:00
res = None
try :
f = http_GET ( u )
res = ET . parse ( f ) . getroot ( )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2012-11-22 11:37:32 +01:00
# old server not supporting this search
pass
return res
2022-09-12 13:43:10 +02:00
2022-12-19 14:04:01 +01:00
def set_link_rev ( apiurl : str , project : str , package : str , revision = " " , expand = False , msg : str = None ) :
2022-12-07 13:01:23 +01: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 ( )
2013-04-09 14:03:17 +02:00
except HTTPError as 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
2014-03-03 22:44:30 +01:00
revision = _set_link_rev ( apiurl , project , package , root , revision , expand = expand )
l = ET . tostring ( root , encoding = ET_ENCODING )
2022-12-19 14:04:01 +01:00
if not msg :
if revision :
msg = f " Set link revision to { revision } "
else :
msg = " Unset link revision "
url = makeurl ( apiurl , [ " source " , project , package , " _link " ] , { " comment " : msg } )
2014-03-03 22:44:30 +01:00
http_PUT ( url , data = l )
2014-05-16 10:28:47 +02:00
return revision
2009-04-09 10:21:12 +02:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def _set_link_rev ( apiurl : str , project : str , package : str , root , revision = " " , expand = False ) :
2014-03-03 22:44:30 +01:00
"""
Updates the rev attribute of the _link xml . If revision is set to None
the rev and vrev attributes are removed from the _link xml .
updates the rev attribute of the _link xml . If revision is the empty
string the latest rev of the link ' s source package is used (or the
xsrcmd5 if expand is True ) . If revision is neither None nor the empty
string the _link ' s rev attribute is set to this revision (or to the
xsrcmd5 if expand is True ) .
"""
2011-02-22 17:43:05 +01:00
src_project = root . get ( ' project ' , project )
2011-03-21 16:57:22 +01:00
src_package = root . get ( ' package ' , package )
2012-03-02 15:44:15 +01:00
vrev = None
2011-02-22 17:43:05 +01:00
if revision is None :
if ' rev ' in root . keys ( ) :
del root . attrib [ ' rev ' ]
2014-03-03 22:44:30 +01:00
if ' vrev ' in root . keys ( ) :
del root . attrib [ ' vrev ' ]
elif not revision or expand :
revision , vrev = show_upstream_rev_vrev ( apiurl , src_project , src_package , revision = revision , expand = expand )
2009-04-09 10:21:12 +02:00
2011-02-22 17:43:05 +01:00
if revision :
root . set ( ' rev ' , revision )
2012-03-02 15:44:15 +01:00
# add vrev when revision is a srcmd5
2014-03-03 22:44:30 +01:00
if vrev is not None and revision is not None and len ( revision ) > = 32 :
2012-03-02 15:44:15 +01:00
root . set ( ' vrev ' , vrev )
2011-11-17 21:33:57 +01:00
return revision
2009-04-09 10:21:12 +02:00
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
2022-09-12 13:43:10 +02: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 ) :
2013-04-09 12:51:28 +02:00
print ( ' error - \' %s \' is not a source rpm. ' % srpm , file = sys . stderr )
2007-07-23 18:03:30 +02:00
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 )
2017-09-28 14:46:40 +02:00
ret = - 1
2022-07-28 19:11:29 +02:00
with open ( srpm ) as fsrpm :
2017-10-26 14:14:30 +02:00
with open ( os . devnull , ' w ' ) as devnull :
rpm2cpio_proc = subprocess . Popen ( [ ' rpm2cpio ' ] , stdin = fsrpm ,
stdout = subprocess . PIPE )
# XXX: shell injection is possible via the files parameter, but the
# current osc code does not use the files parameter.
cpio_proc = subprocess . Popen ( [ ' cpio ' , ' -i ' ] + list ( files ) ,
stdin = rpm2cpio_proc . stdout ,
stderr = devnull )
rpm2cpio_proc . stdout . close ( )
cpio_proc . communicate ( )
rpm2cpio_proc . wait ( )
ret = rpm2cpio_proc . returncode
if not ret :
ret = cpio_proc . returncode
2007-07-23 18:03:30 +02:00
if ret != 0 :
2013-04-09 12:51:28 +02:00
print ( ' error \' %s \' - cannot extract \' %s \' ' % ( ret , srpm ) , file = sys . stderr )
2007-07-23 18:03:30 +02:00
sys . exit ( 1 )
os . chdir ( curdir )
2022-09-12 13:43:10 +02:00
2007-07-23 18:03:30 +02:00
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
2018-12-13 15:14:06 +01:00
if isinstance ( h , str ) :
isrpmstr = ' \xed \xab \xee \xdb '
else :
isrpmstr = b ' \xed \xab \xee \xdb '
if h == isrpmstr :
2007-07-23 18:03:30 +02:00
return True
else :
return False
2022-09-12 13:43:10 +02:00
2007-07-23 18:03:30 +02:00
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
2018-12-13 15:14:06 +01:00
issrcrpm = bytes ( bytearray ( [ h [ 7 ] ] ) ) . decode ( ' utf-8 ' )
if issrcrpm == ' \x01 ' :
2007-07-23 18:03:30 +02:00
return True
else :
2009-10-20 16:30:15 +02:00
return False
2007-07-30 13:12:42 +02:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def addMaintainer ( apiurl : str , prj : str , pac : str , user : str ) :
2009-06-19 15:57:27 +02:00
# for backward compatibility only
addPerson ( apiurl , prj , pac , user )
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def addPerson ( apiurl : str , prj : str , pac : str , user : str , role = " maintainer " ) :
2009-06-19 15:57:27 +02:00
""" 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
2022-08-29 12:56:57 +02:00
if data and get_user_meta ( apiurl , user ) is not None :
2019-11-18 09:36:09 +01:00
root = ET . fromstring ( parse_meta_to_string ( data ) )
2007-09-12 20:01:13 +02:00
found = False
2022-11-07 09:43:41 +01:00
for person in root . iter ( ' 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
2013-04-09 12:51:28 +02:00
print ( " user already exists " )
2007-09-12 20:01:13 +02:00
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 ) )
2013-04-09 12:51:28 +02:00
print ( ' user \' %s \' added to \' %s \' ' % ( user , pac or prj ) )
2007-09-12 20:01:13 +02:00
edit_meta ( metatype = kind ,
path_args = path ,
2013-04-10 11:34:59 +02:00
data = ET . tostring ( root , encoding = ET_ENCODING ) )
2007-09-12 20:01:13 +02:00
else :
2013-04-09 12:51:28 +02:00
print ( " osc: an error occured " )
2007-09-12 20:01:13 +02:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def delMaintainer ( apiurl : str , prj : str , pac : str , user : str ) :
2009-08-26 16:22:54 +02:00
# for backward compatibility only
delPerson ( apiurl , prj , pac , user )
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def delPerson ( apiurl : str , prj : str , pac : str , user : str , role = " maintainer " ) :
2009-08-26 16:22:54 +02:00
""" 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 )
2022-08-29 12:56:57 +02:00
if data and get_user_meta ( apiurl , user ) is not None :
2019-11-18 09:36:09 +01:00
root = ET . fromstring ( parse_meta_to_string ( data ) )
2007-09-12 20:01:13 +02:00
found = False
2022-11-07 09:43:41 +01:00
for person in root . iter ( ' 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
2013-04-09 12:51:28 +02:00
print ( " user \' %s \' removed " % user )
2007-09-12 20:01:13 +02:00
if found :
edit_meta ( metatype = kind ,
path_args = path ,
2013-04-10 11:34:59 +02:00
data = ET . tostring ( root , encoding = ET_ENCODING ) )
2007-09-12 20:01:13 +02:00
else :
2013-04-09 12:51:28 +02:00
print ( " user \' %s \' not found in \' %s \' " % ( user , pac or prj ) )
2007-09-12 20:01:13 +02:00
else :
2013-04-09 12:51:28 +02:00
print ( " an error occured " )
2008-03-10 19:04:23 +01:00
2022-09-12 13:43:10 +02:00
2022-12-07 13:01:23 +01:00
def setBugowner ( apiurl : str , prj : str , pac : str , user = None , group = None ) :
2012-11-23 12:52:05 +01:00
""" delete all bugowners (user and group entries) and set one new one in a package or project """
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 )
2014-01-24 17:01:35 +01:00
if user . startswith ( ' group: ' ) :
2022-04-20 19:22:35 +02:00
group = user . replace ( ' group: ' , ' ' )
user = None
2012-11-23 12:52:05 +01:00
if data :
2019-11-18 09:36:09 +01:00
root = ET . fromstring ( parse_meta_to_string ( data ) )
2022-11-07 09:43:41 +01:00
for group_element in root . iter ( ' group ' ) :
2022-04-20 19:22:35 +02:00
if group_element . get ( ' role ' ) == " bugowner " :
2014-01-24 10:29:00 +01:00
root . remove ( group_element )
2022-11-07 09:43:41 +01:00
for person_element in root . iter ( ' person ' ) :
2014-01-24 10:29:00 +01:00
if person_element . get ( ' role ' ) == " bugowner " :
root . remove ( person_element )
2012-11-23 12:52:05 +01:00
if user :
root . insert ( 2 , ET . Element ( ' person ' , role = ' bugowner ' , userid = user ) )
elif group :
root . insert ( 2 , ET . Element ( ' group ' , role = ' bugowner ' , groupid = group ) )
else :
2013-04-09 12:51:28 +02:00
print ( " Neither user nor group is specified " )
2012-11-23 12:52:05 +01:00
edit_meta ( metatype = kind ,
path_args = path ,
2013-04-10 11:34:59 +02:00
data = ET . tostring ( root , encoding = ET_ENCODING ) )
2012-11-23 12:52:05 +01:00
2022-09-12 13:43:10 +02: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
2022-08-29 12:56:57 +02:00
if data and show_project_meta ( apiurl , dprj ) is not None :
2019-11-18 09:36:09 +01:00
root = ET . fromstring ( parse_meta_to_string ( data ) )
2022-08-29 12:56:57 +02:00
if not root . find ( ' devel ' ) is not None :
2009-12-26 14:22:34 +01:00
ET . SubElement ( root , ' devel ' )
elem = root . find ( ' devel ' )
2009-06-18 18:20:49 +02:00
if dprj :
2011-02-22 17:52:12 +01:00
elem . set ( ' project ' , dprj )
2009-06-18 18:20:49 +02:00
else :
2011-02-22 17:52:12 +01:00
if ' project ' in elem . keys ( ) :
2009-10-20 16:30:15 +02:00
del elem . attrib [ ' project ' ]
2009-06-18 18:20:49 +02:00
if dpkg :
2011-02-22 17:52:12 +01:00
elem . set ( ' package ' , dpkg )
2009-06-18 18:20:49 +02:00
else :
2011-02-22 17:52:12 +01:00
if ' package ' in elem . keys ( ) :
2009-10-20 16:30:15 +02:00
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 ,
2013-04-10 11:34:59 +02:00
data = ET . tostring ( root , encoding = ET_ENCODING ) )
2008-05-20 10:29:54 +02:00
else :
2013-04-09 12:51:28 +02:00
print ( " osc: an error occured " )
2008-05-20 10:29:54 +02:00
2022-09-12 13:43:10 +02:00
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 ) :
2011-01-25 16:51:48 +01:00
global store
2017-06-29 14:20:58 +02:00
if not os . path . exists ( os . path . join ( pathname , store ) ) :
2008-03-15 23:51:37 +01:00
prj = prj_obj or Project ( prj_dir , False )
2017-06-29 14:20:58 +02:00
Package . init_package ( prj . apiurl , prj . name , pac_dir , pathname )
2011-01-25 16:51:48 +01:00
prj . addPackage ( pac_dir )
2013-04-09 12:51:28 +02: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
2022-08-29 12:56:57 +02:00
if node . text is not None :
2010-05-14 16:44:42 +02:00
node . text = node . text . replace ( " " , " " ) . replace ( " \n " , " " )
2021-03-21 19:13:53 +01:00
for child in node :
2010-05-14 16:44:42 +02:00
stripETxml ( child )
2022-09-12 13:43:10 +02:00
2010-09-20 11:09:43 +02:00
def addGitSource ( url ) :
service_file = os . path . join ( os . getcwd ( ) , ' _service ' )
addfile = False
2022-09-12 13:43:10 +02:00
if os . path . exists ( service_file ) :
2010-09-20 11:09:43 +02:00
services = ET . parse ( os . path . join ( os . getcwd ( ) , ' _service ' ) ) . getroot ( )
else :
services = ET . fromstring ( " <services /> " )
addfile = True
2022-09-12 13:43:10 +02:00
stripETxml ( services )
2010-09-20 11:09:43 +02:00
si = Serviceinfo ( )
s = si . addGitUrl ( services , url )
2016-04-08 09:07:38 +02:00
s = si . addTarUp ( services )
2011-01-26 17:29:43 +01:00
s = si . addRecompressTar ( services )
2014-07-22 09:31:54 +02:00
s = si . addSetVersion ( services )
2010-09-20 11:09:43 +02:00
si . read ( s )
# for pretty output
2011-01-30 21:56:21 +01:00
xmlindent ( s )
2019-04-16 16:55:06 +02:00
f = open ( service_file , ' w ' )
2013-04-10 11:34:59 +02:00
f . write ( ET . tostring ( s , encoding = ET_ENCODING ) )
2010-09-20 11:09:43 +02:00
f . close ( )
if addfile :
2022-09-12 13:43:10 +02:00
addFiles ( [ ' _service ' ] )
2010-09-20 11:09:43 +02:00
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
2022-09-12 13:43:10 +02:00
if os . path . exists ( service_file ) :
2010-05-14 16:44:42 +02:00
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
2022-09-12 13:43:10 +02:00
stripETxml ( services )
2010-05-14 16:44:42 +02:00
si = Serviceinfo ( )
s = si . addDownloadUrl ( services , url )
si . read ( s )
# for pretty output
2011-01-30 21:56:21 +01:00
xmlindent ( s )
2018-12-13 15:14:06 +01:00
f = open ( service_file , ' w ' )
2013-04-10 11:34:59 +02:00
f . write ( ET . tostring ( s , encoding = ET_ENCODING ) )
2010-05-14 16:44:42 +02:00
f . close ( )
2010-05-14 16:51:18 +02:00
if addfile :
2022-09-12 13:43:10 +02:00
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 :
2013-05-27 14:26:58 +02:00
newfiles . remove ( filename )
2010-05-17 19:24:00 +02:00
2010-08-20 14:34:41 +02:00
for filename in newfiles :
2013-05-27 14:26:58 +02:00
if filename . startswith ( ' _service:download_url: ' ) :
s = si . addVerifyFile ( services , filename )
2010-05-17 19:24:00 +02:00
# for pretty output
2011-01-30 21:56:21 +01:00
xmlindent ( s )
2018-12-13 15:14:06 +01:00
f = open ( service_file , ' w ' )
2013-04-10 11:34:59 +02:00
f . write ( ET . tostring ( s , encoding = ET_ENCODING ) )
2010-05-17 19:24:00 +02:00
f . close ( )
2010-05-14 16:44:42 +02:00
2022-09-12 13:43:10 +02:00
def addFiles ( filenames , prj_obj = None , force = False ) :
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
2022-09-26 15:47:44 +02:00
# TODO: this function needs improvement
# it should check if we're in a project or a package working copy and behave accordingly
2008-03-10 19:04:23 +01:00
# init a package dir if we have a normal dir in the "filenames"-list
2022-09-26 15:47:44 +02:00
# so that it will be find by Package.from_paths_nofail() 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 ' ] :
2022-10-14 14:25:54 +02:00
store = Store ( prj_dir )
2008-03-10 19:04:23 +01:00
prj_name = store_read_project ( prj_dir )
2022-10-14 14:25:54 +02:00
prj_apiurl = store . apiurl
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 ' ] :
2016-08-26 16:20:53 +02:00
print ( ' osc: warning: \' %s \' is already under version control ' % filename )
pacs . remove ( filename )
2009-03-16 22:29:42 +01:00
elif os . path . isdir ( filename ) and is_project_dir ( prj_dir ) :
2022-09-12 13:43:10 +02:00
raise oscerr . WrongArgs ( ' osc: cannot add a directory to a project unless '
2009-12-25 00:08:29 +01:00
' \' do_package_tracking \' is enabled in the configuration file ' )
2016-08-26 17:12:09 +02:00
2022-09-26 15:47:44 +02:00
pacs , no_pacs = Package . from_paths_nofail ( pacs )
2016-08-26 16:20:53 +02:00
for filename in no_pacs :
2016-08-26 17:12:09 +02:00
filename = os . path . normpath ( filename )
directory = os . path . join ( filename , os . pardir )
if not is_package_dir ( directory ) :
print ( ' osc: warning: \' %s \' cannot be associated to a package ' % filename )
continue
resp = raw_input ( " %s is a directory, do you want to archive it for submission? (y/n) " % ( filename ) )
if resp not in ( ' y ' , ' Y ' ) :
continue
archive = " %s .obscpio " % filename
2017-10-10 16:07:51 +02:00
todo = [ os . path . join ( p , elm )
for p , dirnames , fnames in os . walk ( filename , followlinks = False )
for elm in dirnames + fnames ]
2019-05-14 10:24:17 +02:00
enc_todo = [ b ' %s ' % elem . encode ( ) for elem in todo ]
2017-09-28 14:46:40 +02:00
with open ( archive , ' w ' ) as f :
2017-10-10 16:13:59 +02:00
cpio_proc = subprocess . Popen ( [ ' cpio ' , ' -o ' , ' -H ' , ' newc ' , ' -0 ' ] ,
2017-10-10 16:07:51 +02:00
stdin = subprocess . PIPE , stdout = f )
2019-05-14 10:24:17 +02:00
cpio_proc . communicate ( b ' \0 ' . join ( enc_todo ) )
2022-09-26 15:47:44 +02:00
pacs . extend ( Package . from_paths ( [ archive ] ) )
2016-08-26 17:12:09 +02:00
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 )
2013-04-09 12:51:28 +02:00
print ( statfrmt ( ' A ' , getTransActPath ( os . path . join ( pac . dir , os . pardir , pac . name ) ) ) )
2008-03-10 19:04:23 +01:00
for filename in pac . filenamelist_unvers :
2010-02-17 20:45:09 +01:00
if os . path . isdir ( os . path . join ( pac . dir , filename ) ) :
2013-04-09 12:51:28 +02:00
print ( ' skipping directory \' %s \' ' % os . path . join ( pac . dir , filename ) )
2010-02-17 20:45:09 +01:00
else :
pac . todo . append ( filename )
2008-03-10 19:04:23 +01:00
elif pac . name in prj . pacs_have :
2013-04-09 12:51:28 +02:00
print ( ' osc: warning: \' %s \' is already under version control ' % pac . name )
2008-03-10 19:04:23 +01:00
for filename in pac . todo :
2010-04-22 15:27:54 +02:00
if filename in pac . skipped :
continue
2021-03-11 17:52:05 +01:00
if filename in pac . excluded and not force :
2013-04-09 12:51:28 +02:00
print ( ' osc: warning: \' %s \' is excluded from a working copy ' % filename , file = sys . stderr )
2008-03-10 19:04:23 +01:00
continue
2016-08-26 16:20:53 +02:00
try :
pac . addfile ( filename )
except oscerr . PackageFileConflict as e :
fname = os . path . join ( getTransActPath ( pac . dir ) , filename )
print ( ' osc: warning: \' %s \' is already under version control ' % fname )
2008-03-10 19:04:23 +01:00
2022-09-12 13:43:10 +02:00
2008-03-10 19:04:23 +01:00
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 :
2022-01-24 08:57:53 +01:00
Examples : :
2008-03-10 19:04:23 +01:00
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 )
2022-09-12 13:43:10 +02:00
2008-03-10 19:04:23 +01:00
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 .
"""
2023-02-08 11:46:16 +01:00
path = str ( Path ( pac_dir ) ) # accept str and Path as pac_dir
return ' ' if path == ' . ' else path
2008-04-23 23:51:24 +02:00
2022-09-12 13:43:10 +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 = [ ]
2011-05-31 11:48:01 +02:00
if pac . todo :
todo = pac . todo
else :
todo = pac . filenamelist + pac . filenamelist_unvers
files = [ i for i in todo if i . endswith ( ' .changes ' ) and pac . status ( i ) in ( ' A ' , ' M ' ) ]
2010-05-09 21:06:00 +02:00
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 ' :
2019-07-17 10:34:20 +02:00
with open ( os . path . join ( pac . absdir , filename ) , ' rb ' ) as f :
2022-07-28 19:11:29 +02:00
diff . extend ( b ' + ' + line for line in f )
2009-10-20 16:30:15 +02:00
2009-04-16 15:48:37 +02:00
if diff :
2019-07-17 10:34:20 +02:00
template = parse_diff_for_commit_message ( ' ' . join ( decode_list ( diff ) ) )
2009-04-16 15:48:37 +02:00
2010-02-02 14:12:22 +01:00
return template
2022-09-12 13:43:10 +02:00
2022-08-29 15:32:41 +02:00
def parse_diff_for_commit_message ( diff , template = None ) :
template = template or [ ]
2010-02-02 14:12:22 +01:00
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 \
2022-09-12 13:43:10 +02:00
date_re . match ( line ) or \
line == ' + ' or line [ 0 : 3 ] == ' +++ ' :
2010-02-02 14:12:22 +01:00
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
2022-09-12 13:43:10 +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 :
2018-12-13 15:14:06 +01:00
states = sorted ( p . get_status ( False , ' ' , ' ? ' ) , key = cmp_to_key ( compare ) )
2010-12-26 13:33:14 +01:00
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 )
2019-07-17 10:34:20 +02:00
footer . extend ( [ ' ' . join ( decode_list ( i ) ) for i in p . get_diff ( ignoreUnversioned = True ) ] )
2010-12-26 13:33:14 +01:00
lines . extend ( get_commit_message_template ( p ) )
if template is None :
2011-06-01 09:12:10 +02:00
if lines and lines [ 0 ] == ' ' :
2011-05-31 11:48:10 +02:00
del lines [ 0 ]
2010-12-26 13:33:14 +01:00
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
2022-09-12 13:43:10 +02:00
2023-02-02 13:50:51 +01:00
def print_request_list ( apiurl , project , package = None , states = ( " new " , " review " ) , force = False ) :
2009-09-18 03:10:41 +02:00
"""
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
2022-09-15 14:47:38 +02:00
requests = get_request_collection ( apiurl , project = project , package = package , states = states )
2021-07-10 11:04:16 +02:00
msg = ' \n Pending requests for %s : %s ( %s ) '
if sys . stdout . isatty ( ) :
2022-07-28 19:11:29 +02:00
msg = f ' \033 [1m { msg } \033 [0m '
2022-08-29 13:23:29 +02:00
if package is None and requests :
2013-04-09 12:51:28 +02:00
print ( msg % ( ' project ' , project , len ( requests ) ) )
2022-08-29 13:23:29 +02:00
elif requests :
2013-04-09 12:51:28 +02:00
print ( msg % ( ' package ' , ' / ' . join ( [ project , package ] ) , len ( requests ) ) )
2009-09-18 03:10:41 +02:00
for r in requests :
2013-04-09 12:51:28 +02:00
print ( r . list_view ( ) , ' \n ' )
2010-02-11 01:47:47 +01:00
2022-09-12 13:43:10 +02:00
2016-02-10 18:19:22 +01:00
def request_interactive_review ( apiurl , request , initial_cmd = ' ' , group = None ,
ignore_reviews = False , source_buildstatus = False ) :
2010-02-11 01:47:47 +01:00
""" review the request interactively """
tmpfile = None
2010-06-29 14:32:22 +02:00
2012-10-26 15:19:00 +02:00
def safe_change_request_state ( * args , * * kwargs ) :
try :
change_request_state ( * args , * * kwargs )
return True
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2013-04-09 12:51:28 +02:00
print ( ' Server returned an error: ' , e , file = sys . stderr )
2020-07-21 13:42:24 +02:00
details = e . hdrs . get ( ' X-Opensuse-Errorcode ' )
if details :
print ( details , file = sys . stderr )
root = ET . fromstring ( e . read ( ) )
summary = root . find ( ' summary ' )
if summary is not None :
print ( summary . text , file = sys . stderr )
2013-04-09 12:51:28 +02:00
print ( ' Try -f to force the state change ' , file = sys . stderr )
2012-10-26 15:19:00 +02:00
return False
2017-09-04 10:16:02 +02:00
def safe_get_rpmlint_log ( src_actions ) :
lintlogs = [ ]
for action in src_actions :
print ( ' Type %s : ' % action . type )
disabled = show_package_disabled_repos ( apiurl , action . src_project , action . src_package )
for repo in get_repos_of_project ( apiurl , action . src_project ) :
2017-11-08 10:39:42 +01:00
if ( disabled is None ) or ( repo . name not in [ d [ ' repo ' ] for d in disabled ] ) :
2017-09-04 10:16:02 +02:00
lintlog_entry = {
2022-09-12 13:43:10 +02:00
' proj ' : action . src_project ,
' pkg ' : action . src_package ,
' repo ' : repo . name ,
' arch ' : repo . arch
}
2017-09-04 10:16:02 +02:00
lintlogs . append ( lintlog_entry )
2022-09-12 13:43:10 +02:00
print ( ' ( %i ) %s / %s / %s / %s ' % ( ( len ( lintlogs ) - 1 ) , action . src_project , action . src_package , repo . name , repo . arch ) )
2017-09-04 10:16:02 +02:00
if not lintlogs :
print ( ' No possible rpmlintlogs found ' )
return False
while True :
try :
2022-09-12 13:43:10 +02:00
lint_n = int ( raw_input ( ' Number of rpmlint log to examine (0 - %i ): ' % ( len ( lintlogs ) - 1 ) ) )
2017-09-04 10:16:02 +02:00
lintlogs [ lint_n ]
break
except ( ValueError , IndexError ) :
2022-09-12 13:43:10 +02:00
print ( ' Invalid rpmlintlog index. Please choose between 0 and %i ' % ( len ( lintlogs ) - 1 ) )
2017-09-04 10:16:02 +02:00
try :
2018-12-13 15:14:06 +01:00
print ( decode_it ( get_rpmlint_log ( apiurl , * * lintlogs [ lint_n ] ) ) )
2017-09-04 10:16:02 +02:00
except HTTPError as e :
if e . code == 404 :
print ( ' No rpmlintlog for %s %s ' % ( lintlogs [ lint_n ] [ ' repo ' ] ,
lintlogs [ lint_n ] [ ' arch ' ] ) )
else :
raise e
2010-08-31 14:15:04 +02:00
def print_request ( request ) :
2013-04-09 12:51:28 +02:00
print ( request )
2011-02-11 02:43:10 +01:00
2016-02-10 18:19:22 +01:00
def print_source_buildstatus ( src_actions , newline = False ) :
if newline :
print ( )
for action in src_actions :
print ( ' %s / %s : ' % ( action . src_project , action . src_package ) )
2016-04-22 15:16:53 +02:00
try :
print ( ' \n ' . join ( get_results ( apiurl , action . src_project , action . src_package ) ) )
except HTTPError as e :
if e . code != 404 :
raise
print ( ' unable to retrieve the buildstatus: %s ' % e )
2016-02-10 18:19:22 +01:00
2017-10-16 14:07:10 +02:00
def get_formatted_issues ( apiurl , reqid ) :
""" get issue_list and return a printable string """
issue_list = get_request_issues ( apiurl , reqid )
issues = " "
issues_nodetails = " "
# the check_list is needed to make sure that every issue is just listed
# once. Sometimes the API returns the same issue twice or more. See:
# https://github.com/openSUSE/open-build-service/issues/4044
# Once this is fixed this can be changed.
check_list = [ ]
for issue in issue_list :
if issue [ ' label ' ] in check_list :
continue
if ' summary ' in issue :
issues + = ( " ## BUG# " + issue [ ' label ' ] + " : "
2022-09-12 13:43:10 +02:00
+ issue . get ( ' summary ' ) + " : "
+ issue . get ( ' state ' , ' unknown state ' ) + ' \n ' )
2017-10-16 14:07:10 +02:00
else :
issues_nodetails + = issue [ ' label ' ] + ' '
check_list . append ( issue [ ' label ' ] )
if issues_nodetails :
issues + = ' ## No details for the issue(s): ' + issues_nodetails + ' \n '
return issues
2010-08-31 14:15:04 +02:00
print_request ( request )
2017-08-16 11:26:57 +02:00
print_comments ( apiurl , ' request ' , request . reqid )
2010-02-11 01:47:47 +01:00
try :
2017-04-05 13:39:43 +02:00
prompt = ' (a)ccept/(d)ecline/(r)evoke/c(l)one/co(m)ment/(s)kip/(c)ancel > '
2013-12-16 10:59:07 +01:00
editable_actions = request . get_actions ( ' submit ' , ' maintenance_incident ' )
2012-04-27 14:45:28 +02:00
# actions which have sources + buildresults
2013-12-16 10:59:07 +01:00
src_actions = editable_actions + request . get_actions ( ' maintenance_release ' )
if editable_actions :
2017-09-04 10:16:02 +02:00
prompt = ' d(i)ff/(a)ccept/(d)ecline/(r)evoke/(b)uildstatus/rpm(li)ntlog/c(l)one/(e)dit/co(m)ment/(s)kip/(c)ancel > '
2012-04-27 14:45:28 +02:00
elif src_actions :
# no edit for maintenance release requests
2017-09-04 10:16:02 +02:00
prompt = ' d(i)ff/(a)ccept/(d)ecline/(r)evoke/(b)uildstatus/rpm(li)ntlog/c(l)one/co(m)ment/(s)kip/(c)ancel > '
2011-01-29 23:30:54 +01:00
editprj = ' '
orequest = None
2017-04-12 17:16:09 +02:00
if source_buildstatus and src_actions :
2016-02-10 18:19:22 +01:00
print_source_buildstatus ( src_actions , newline = True )
2010-02-11 01:47:47 +01:00
while True :
2011-01-30 14:24:21 +01:00
if initial_cmd :
repl = initial_cmd
initial_cmd = ' '
else :
repl = raw_input ( prompt ) . strip ( )
2022-10-13 09:22:14 +02:00
# remember if we're accepting so we can decide whether to forward request to the parent project later on
accept = repl == " a "
2012-04-27 14:45:28 +02:00
if repl == ' i ' and src_actions :
2017-10-10 11:29:57 +02:00
req_summary = str ( request ) + ' \n '
2017-10-16 14:07:10 +02:00
issues = ' \n \n ' + get_formatted_issues ( apiurl , request . reqid )
2022-09-12 14:23:47 +02:00
if orequest is not None and tmpfile :
2011-01-29 23:30:54 +01:00
tmpfile . close ( )
tmpfile = None
2010-02-11 01:47:47 +01:00
if tmpfile is None :
2019-07-17 10:34:20 +02:00
tmpfile = tempfile . NamedTemporaryFile ( suffix = ' .diff ' , mode = ' rb+ ' )
tmpfile . write ( req_summary . encode ( ) )
tmpfile . write ( issues . encode ( ) )
2011-08-11 23:09:45 +02:00
try :
diff = request_diff ( apiurl , request . reqid )
2019-07-17 10:34:20 +02:00
tmpfile . write ( diff )
2013-04-09 14:03:17 +02:00
except HTTPError as e :
2011-08-11 23:09:45 +02:00
if e . code != 400 :
raise
# backward compatible diff for old apis
2012-04-27 14:45:28 +02:00
for action in src_actions :
2019-07-17 10:34:20 +02:00
diff = b ' old: %s / %s \n new: %s / %s \n ' % ( action . src_project . encode ( ) , action . src_package . encode ( ) ,
2022-09-12 13:43:10 +02:00
action . tgt_project . encode ( ) , action . tgt_package . encode ( ) )
2011-08-11 23:09:45 +02:00
diff + = submit_action_diff ( apiurl , action )
2019-07-17 10:34:20 +02:00
diff + = b ' \n \n '
2011-08-11 23:09:45 +02:00
tmpfile . write ( diff )
2011-08-15 17:06:04 +02: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 )
2017-08-16 11:26:57 +02:00
print_comments ( apiurl , ' request ' , request . reqid )
2010-09-17 23:03:29 +02:00
elif repl == ' s ' :
2013-04-09 12:51:28 +02:00
print ( ' skipping: # %s ' % request . reqid , file = sys . stderr )
2010-09-17 23:03:29 +02:00
break
2010-02-11 01:47:47 +01:00
elif repl == ' c ' :
2013-04-09 12:51:28 +02:00
print ( ' Aborting ' , file = sys . stderr )
2010-04-20 15:22:03 +02:00
raise oscerr . UserAbort ( )
2017-04-05 13:39:43 +02:00
elif repl == ' m ' :
2018-04-26 16:54:10 +02:00
if tmpfile is not None :
tmpfile . seek ( 0 )
2019-08-30 11:57:31 +02:00
comment = edit_message ( footer = decode_it ( tmpfile . read ( ) ) )
2018-04-26 16:54:10 +02:00
else :
comment = edit_text ( )
2017-04-05 13:39:43 +02:00
create_comment ( apiurl , ' request ' , comment , request . reqid )
2012-04-27 14:45:28 +02:00
elif repl == ' b ' and src_actions :
2016-02-10 18:19:22 +01:00
print_source_buildstatus ( src_actions )
2022-04-20 19:22:35 +02:00
elif repl == ' li ' and src_actions :
2017-09-04 10:16:02 +02:00
safe_get_rpmlint_log ( src_actions )
2013-12-16 10:59:07 +01:00
elif repl == ' e ' and editable_actions :
# this is only for editable actions
2011-01-29 23:30:54 +01:00
if not editprj :
editprj = clone_request ( apiurl , request . reqid , ' osc editrequest ' )
orequest = request
request = edit_submitrequest ( apiurl , editprj , orequest , request )
2013-12-16 10:59:07 +01:00
src_actions = editable_actions = request . get_actions ( ' submit ' , ' maintenance_incident ' )
2011-01-29 23:30:54 +01:00
print_request ( request )
prompt = ' d(i)ff/(a)ccept/(b)uildstatus/(e)dit/(s)kip/(c)ancel > '
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 ' }
2022-07-28 19:11:29 +02:00
mo = re . search ( r ' ^([adrl])(?: \ s+(-f)? \ s*-m \ s+(.*))?$ ' , repl )
2011-01-29 23:30:54 +01:00
if mo is None or orequest and mo . group ( 1 ) != ' a ' :
2013-04-09 12:51:28 +02:00
print ( ' invalid choice: \' %s \' ' % repl , file = sys . stderr )
2010-02-25 14:32:24 +01:00
continue
2010-10-26 15:47:07 +02:00
state = state_map . get ( mo . group ( 1 ) )
2012-10-26 15:19:00 +02:00
force = mo . group ( 2 ) is not None
msg = mo . group ( 3 )
2010-10-26 15:47:07 +02:00
footer = ' '
2011-01-29 23:30:54 +01:00
msg_template = ' '
if not ( state is None or request . state is None ) :
2010-10-26 15:47:07 +02:00
footer = ' changing request from state \' %s \' to \' %s \' \n \n ' \
% ( request . state . name , state )
2011-01-29 23:30:54 +01:00
msg_template = change_request_state_template ( request , state )
2017-10-10 11:29:57 +02:00
if tmpfile is None :
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
2020-01-24 09:23:24 +01:00
footer + = ' \n \n ' + decode_it ( tmpfile . read ( ) )
2010-02-11 01:47:47 +01:00
if msg is None :
2012-06-15 00:12:06 +02:00
try :
2022-09-12 13:43:10 +02:00
msg = edit_message ( footer = footer , template = msg_template )
2012-06-15 00:12:06 +02:00
except oscerr . UserAbort :
# do not abort (show prompt again)
continue
2010-02-11 01:47:47 +01:00
else :
msg = msg . strip ( ' \' ' ) . strip ( ' " ' )
2022-09-12 14:23:47 +02:00
if orequest is not None :
2011-01-29 23:30:54 +01:00
request . create ( apiurl )
2012-10-26 15:19:00 +02:00
if not safe_change_request_state ( apiurl , request . reqid , ' accepted ' , msg , force = force ) :
# an error occured
continue
2011-01-29 23:30:54 +01:00
repl = raw_input ( ' Supersede original request? (y|N) ' )
if repl in ( ' y ' , ' Y ' ) :
2012-10-26 15:19:00 +02:00
safe_change_request_state ( apiurl , orequest . reqid , ' superseded ' ,
2022-09-12 13:43:10 +02:00
' superseded by %s ' % request . reqid , request . reqid , force = force )
2011-01-29 23:30:54 +01:00
elif 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 :
2011-09-16 17:32:42 +02:00
reviews = [ r for r in request . reviews if r . state == ' new ' ]
2012-10-26 15:19:00 +02:00
if not reviews or ignore_reviews :
if safe_change_request_state ( apiurl , request . reqid , state , msg , force = force ) :
2022-10-13 09:22:14 +02:00
if accept :
from . import _private
_private . forward_request ( apiurl , request , interactive = True )
2012-10-26 15:19:00 +02:00
break
else :
# an error occured
continue
2012-04-27 15:04:06 +02:00
group_reviews = [ r for r in reviews if ( r . by_group is not None
and r . by_group == group ) ]
if len ( group_reviews ) == 1 and conf . config [ ' review_inherit_group ' ] :
review = group_reviews [ 0 ]
else :
2013-04-09 12:51:28 +02:00
print ( ' Please chose one of the following reviews: ' )
2012-04-27 15:04:06 +02:00
for i in range ( len ( reviews ) ) :
fmt = Request . format_review ( reviews [ i ] )
2013-04-09 12:51:28 +02:00
print ( ' ( %i ) ' % i , ' by %(type)-10s %(by)s ' % fmt )
2012-04-27 15:04:06 +02:00
num = raw_input ( ' > ' )
try :
num = int ( num )
except ValueError :
2013-04-09 12:51:28 +02:00
print ( ' \' %s \' is not a number. ' % num )
2012-04-27 15:04:06 +02:00
continue
if num < 0 or num > = len ( reviews ) :
2013-04-09 12:51:28 +02:00
print ( ' number \' %s \' out of range. ' % num )
2012-04-27 15:04:06 +02:00
continue
review = reviews [ num ]
2011-09-16 17:32:42 +02:00
change_review_state ( apiurl , request . reqid , state , by_user = review . by_user ,
by_group = review . by_group , by_project = review . by_project ,
by_package = review . by_package , message = 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
2022-09-12 13:43:10 +02:00
2011-01-29 23:30:54 +01:00
def edit_submitrequest ( apiurl , project , orequest , new_request = None ) :
""" edit a submit action from orequest/new_request """
actions = orequest . get_actions ( ' submit ' )
oactions = actions
2013-08-28 23:03:25 +02:00
if new_request is not None :
2011-01-29 23:30:54 +01:00
actions = new_request . get_actions ( ' submit ' )
num = 0
if len ( actions ) > 1 :
2013-04-09 12:51:28 +02:00
print ( ' Please chose one of the following submit actions: ' )
2011-01-29 23:30:54 +01:00
for i in range ( len ( actions ) ) :
2013-08-28 23:00:35 +02:00
# it is safe to use orequest because currently the formatting
# of a submit action does not need instance specific data
fmt = orequest . format_action ( actions [ i ] )
2013-04-09 12:51:28 +02:00
print ( ' ( %i ) ' % i , ' %(source)s %(target)s ' % fmt )
2011-01-29 23:30:54 +01:00
num = raw_input ( ' > ' )
try :
num = int ( num )
except ValueError :
raise oscerr . WrongArgs ( ' \' %s \' is not a number. ' % num )
if num < 0 or num > = len ( orequest . actions ) :
raise oscerr . WrongArgs ( ' number \' %s \' out of range. ' % num )
# the api replaced ':' with '_' in prj and pkg names (clone request)
package = ' %s . %s ' % ( oactions [ num ] . src_package . replace ( ' : ' , ' _ ' ) ,
2022-09-12 13:43:10 +02:00
oactions [ num ] . src_project . replace ( ' : ' , ' _ ' ) )
2011-01-29 23:30:54 +01:00
tmpdir = None
cleanup = True
try :
tmpdir = tempfile . mkdtemp ( prefix = ' osc_editsr ' )
p = Package . init_package ( apiurl , project , package , tmpdir )
p . update ( )
shell = os . getenv ( ' SHELL ' , default = ' /bin/sh ' )
olddir = os . getcwd ( )
os . chdir ( tmpdir )
2022-09-12 13:43:10 +02:00
print ( ' Checked out package \' %s \' to %s . Started a new shell ( %s ). \n '
' Please fix the package and close the shell afterwards. ' % ( package , tmpdir , shell ) )
2013-03-08 00:56:57 +01:00
run_external ( shell )
2011-01-29 23:30:54 +01:00
# the pkg might have uncommitted changes...
cleanup = False
os . chdir ( olddir )
# reread data
p = Package ( tmpdir )
modified = p . get_status ( False , ' ' , ' ? ' , ' S ' )
if modified :
2013-04-09 12:51:28 +02:00
print ( ' Your working copy has the following modifications: ' )
print ( ' \n ' . join ( [ statfrmt ( st , filename ) for st , filename in modified ] ) )
2011-01-29 23:30:54 +01:00
repl = raw_input ( ' Do you want to commit the local changes first? (y|N) ' )
if repl in ( ' y ' , ' Y ' ) :
msg = get_commit_msg ( p . absdir , [ p ] )
p . commit ( msg = msg )
cleanup = True
finally :
if cleanup :
shutil . rmtree ( tmpdir )
else :
2013-04-09 12:51:28 +02:00
print ( ' Please remove the dir \' %s \' manually ' % tmpdir )
2011-01-29 23:30:54 +01:00
r = Request ( )
for action in orequest . get_actions ( ) :
new_action = Action . from_xml ( action . to_xml ( ) )
r . actions . append ( new_action )
if new_action . type == ' submit ' :
new_action . src_package = ' %s . %s ' % ( action . src_package . replace ( ' : ' , ' _ ' ) ,
2022-09-12 13:43:10 +02:00
action . src_project . replace ( ' : ' , ' _ ' ) )
2011-01-29 23:30:54 +01:00
new_action . src_project = project
# do an implicit cleanup
new_action . opt_sourceupdate = ' cleanup '
return r
2022-09-12 13:43:10 +02:00
2022-08-29 15:32:41 +02:00
def get_user_projpkgs ( apiurl , user , role = None , exclude_projects = None , proj = True , pkg = True , maintained = False , metadata = False ) :
2010-03-13 21:06:18 +01:00
""" Return all project/packages where user is involved. """
2022-08-29 15:32:41 +02:00
exclude_projects = exclude_projects or [ ]
2010-03-13 21:06:18 +01:00
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 )
2013-04-09 14:03:17 +02:00
except HTTPError as 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
2022-07-28 19:11:29 +02:00
what = { kind : role_filter_xpath for kind in what . keys ( ) }
2013-04-09 11:33:25 +02:00
if ' package ' in what :
2010-03-13 21:06:18 +01:00
what [ ' package ' ] = xpath_join ( role_filter_xpath , excl_pkg , op = ' and ' )
2013-04-09 11:33:25 +02:00
if ' project ' in what :
2010-03-13 21:06:18 +01:00
what [ ' project ' ] = xpath_join ( role_filter_xpath , excl_prj , op = ' and ' )
res = search ( apiurl , * * what )
filter_role ( res , user , role )
return res
2022-09-12 13:43:10 +02:00
2013-03-08 00:56:57 +01:00
def run_external ( filename , * args , * * kwargs ) :
""" Executes the program filename via subprocess.call.
* args are additional arguments which are passed to the
program filename . * * kwargs specify additional arguments for
the subprocess . call function .
if no args are specified the plain filename is passed
to subprocess . call ( this can be used to execute a shell
command ) . Otherwise [ filename ] + list ( args ) is passed
to the subprocess . call function .
"""
# unless explicitly specified use shell=False
kwargs . setdefault ( ' shell ' , False )
if args :
cmd = [ filename ] + list ( args )
else :
cmd = filename
try :
return subprocess . call ( cmd , * * kwargs )
2013-04-09 11:27:02 +02:00
except OSError as e :
2013-03-08 00:56:57 +01:00
if e . errno != errno . ENOENT :
raise
raise oscerr . ExtRuntimeError ( e . strerror , filename )
2022-09-12 13:43:10 +02:00
2017-01-23 15:32:58 +01:00
def return_external ( filename , * args , * * kwargs ) :
""" Executes the program filename via subprocess.check_output.
2022-01-24 08:57:53 +01:00
` ` * args ` ` are additional arguments which are passed to the
program filename . ` ` * * kwargs ` ` specify additional arguments for
2017-01-23 15:32:58 +01:00
the subprocess . check_output function .
if no args are specified the plain filename is passed
to subprocess . check_output ( this can be used to execute a shell
command ) . Otherwise [ filename ] + list ( args ) is passed
to the subprocess . check_output function .
Returns the output of the command .
"""
if args :
cmd = [ filename ] + list ( args )
else :
cmd = filename
try :
2017-11-21 11:36:50 +01:00
# backward compatibility for python 2.6
if ' check_output ' not in dir ( subprocess ) :
process = subprocess . Popen ( cmd , stdout = subprocess . PIPE )
output , errstr = process . communicate ( )
retcode = process . poll ( )
if retcode :
error = subprocess . CalledProcessError ( retcode , cmd )
error . output = output
raise error
return output
2017-01-23 15:32:58 +01:00
return subprocess . check_output ( cmd , * * kwargs )
except OSError as e :
if e . errno != errno . ENOENT :
raise
raise oscerr . ExtRuntimeError ( e . strerror , filename )
2010-03-13 13:55:53 +01:00
# backward compatibility: local role filtering
2022-09-12 13:43:10 +02:00
2010-03-13 13:55:53 +01:00
def filter_role ( meta , user , role ) :
"""
remove all project / package nodes if no person node exists
where @userid = user and @role = role
"""
2013-04-09 11:25:19 +02:00
for kind , root in meta . items ( ) :
2010-03-13 13:55:53 +01:00
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 )
2022-09-12 13:43:10 +02:00
2022-10-21 10:38:57 +02:00
def find_default_project ( apiurl : Optional [ str ] = None , package : Optional [ str ] = None ) :
2022-05-10 09:24:43 +02:00
"""
2011-03-09 16:10:48 +01:00
look though the list of conf . config [ ' getpac_default_project ' ]
and find the first project where the given package exists in the build service .
"""
2022-08-29 13:23:29 +02:00
if not conf . config [ ' getpac_default_project ' ] :
2011-03-09 16:10:48 +01:00
return None
candidates = re . split ( ' [, ]+ ' , conf . config [ ' getpac_default_project ' ] )
if package is None or len ( candidates ) == 1 :
return candidates [ 0 ]
# search through the list, where package exists ...
for prj in candidates :
try :
2011-03-09 22:47:02 +01:00
# any fast query will do here.
show_package_meta ( apiurl , prj , package )
return prj
2014-08-12 15:01:16 +02:00
except HTTPError :
2011-03-09 22:47:02 +01:00
pass
2011-03-09 16:10:48 +01:00
return None
2022-09-12 13:43:10 +02:00
2014-01-09 14:15:30 +01:00
def utime ( filename , arg , ignore_einval = True ) :
""" wrapper around os.utime which ignore errno EINVAL by default """
try :
# workaround for bnc#857610): if filename resides on a nfs share
# os.utime might raise EINVAL
os . utime ( filename , arg )
except OSError as e :
if e . errno == errno . EINVAL and ignore_einval :
return
raise
2011-03-09 16:10:48 +01:00
2022-09-12 13:43:10 +02:00
2022-10-21 10:38:57 +02:00
def which ( name : str ) :
2014-10-01 14:45:48 +02:00
""" Searches " name " in PATH. """
name = os . path . expanduser ( name )
if os . path . isabs ( name ) :
if os . path . exists ( name ) :
return name
return None
for directory in os . environ . get ( ' PATH ' , ' ' ) . split ( ' : ' ) :
path = os . path . join ( directory , name )
if os . path . exists ( path ) :
return path
return None
2015-10-19 13:14:53 +02:00
2022-10-21 10:38:57 +02:00
def get_comments ( apiurl : str , kind , * args ) :
2017-03-02 11:03:39 +01:00
url = makeurl ( apiurl , ( ' comments ' , kind ) + args )
2015-10-19 13:14:53 +02:00
f = http_GET ( url )
return ET . parse ( f ) . getroot ( )
2022-10-21 10:38:57 +02:00
def print_comments ( apiurl : str , kind , * args ) :
2015-10-19 13:14:53 +02:00
def print_rec ( comments , indent = ' ' ) :
for comment in comments :
print ( indent , end = ' ' )
2017-03-02 11:03:39 +01:00
print ( ' ( ' , comment . get ( ' id ' ) , ' ) ' , ' On ' , comment . get ( ' when ' ) , comment . get ( ' who ' ) , ' wrote: ' )
2022-04-20 19:22:35 +02:00
text = indent + comment . text . replace ( ' \r \n ' , ' \n ' )
2015-10-19 13:14:53 +02:00
print ( ( ' \n ' + indent ) . join ( text . split ( ' \n ' ) ) )
print ( )
print_rec ( [ c for c in root if c . get ( ' parent ' ) == comment . get ( ' id ' ) ] , indent + ' ' )
2017-03-02 11:03:39 +01:00
root = get_comments ( apiurl , kind , * args )
2015-10-19 13:14:53 +02:00
comments = [ c for c in root if c . get ( ' parent ' ) is None ]
if comments :
print ( ' \n Comments: ' )
print_rec ( comments )
2022-09-12 13:43:10 +02:00
2022-10-21 10:38:57 +02:00
def create_comment ( apiurl : str , kind , comment , * args , * * kwargs ) - > Optional [ str ] :
2017-03-02 11:03:39 +01:00
query = { }
if kwargs . get ( ' parent ' ) is not None :
query = { ' parent_id ' : kwargs [ ' parent ' ] }
u = makeurl ( apiurl , ( ' comments ' , kind ) + args , query = query )
f = http_POST ( u , data = comment )
ret = ET . fromstring ( f . read ( ) ) . find ( ' summary ' )
2022-10-21 10:38:57 +02:00
if ret is None :
return None
2017-03-02 11:03:39 +01:00
return ret . text
2022-09-12 13:43:10 +02:00
2022-10-21 10:38:57 +02:00
def delete_comment ( apiurl : str , cid : str ) - > Optional [ str ] :
2017-03-02 11:03:39 +01:00
u = makeurl ( apiurl , [ ' comment ' , cid ] )
f = http_DELETE ( u )
ret = ET . fromstring ( f . read ( ) ) . find ( ' summary ' )
2022-10-21 10:38:57 +02:00
if ret is None :
return None
2017-03-02 11:03:39 +01:00
return ret . text
2022-09-12 13:43:10 +02:00
2022-10-21 10:38:57 +02:00
def get_rpmlint_log ( apiurl : str , proj : str , pkg : str , repo : str , arch : str ) :
2017-08-30 17:08:12 +02:00
u = makeurl ( apiurl , [ ' build ' , proj , repo , arch , pkg , ' rpmlint.log ' ] )
f = http_GET ( u )
return f . read ( )
2022-09-12 13:43:10 +02:00
2022-10-21 10:38:57 +02:00
def checkout_deleted_package ( apiurl : str , proj : str , pkg : str , dst ) :
2018-07-19 13:34:49 +02:00
pl = meta_get_filelist ( apiurl , proj , pkg , deleted = True )
query = { }
query [ ' deleted ' ] = 1
if os . path . isdir ( dst ) :
print ( ' Restoring in existing directory %s ' % dst )
else :
print ( ' Creating %s ' % dst )
os . makedirs ( dst )
for filename in pl :
print ( ' Restoring %s to %s ' % ( filename , dst ) )
full_file_path = os . path . join ( dst , filename )
u = makeurl ( apiurl , [ ' source ' , proj , pkg , filename ] , query = query )
with open ( full_file_path , ' wb ' ) as f :
for data in streamfile ( u ) :
f . write ( data )
print ( ' done. ' )
2022-09-12 13:43:10 +02:00
2022-10-21 10:38:57 +02:00
def vc_export_env ( apiurl : str , quiet = False ) :
2022-08-29 13:39:20 +02:00
# try to set the env variables for the user's realname and email
# (the variables are used by the "vc" script or some source service)
tag2envs = { ' realname ' : [ ' VC_REALNAME ' ] ,
' email ' : [ ' VC_MAILADDR ' , ' mailaddr ' ] }
tag2val = { }
missing_tags = [ ]
for ( tag , envs ) in tag2envs . items ( ) :
env_present = [ env for env in envs if env in os . environ ]
config_present = tag in conf . config [ ' api_host_options ' ] [ apiurl ]
if not env_present and not config_present :
missing_tags . append ( tag )
elif config_present :
tag2val [ tag ] = conf . config [ ' api_host_options ' ] [ apiurl ] [ tag ]
if missing_tags :
user = conf . get_apiurl_usr ( apiurl )
data = get_user_data ( apiurl , user , * missing_tags )
if data :
for tag in missing_tags :
val = data . pop ( 0 )
if val != ' - ' :
tag2val [ tag ] = val
elif not quiet :
msg = ' Try env %s =... ' % tag2envs [ tag ] [ 0 ]
print ( msg , file = sys . stderr )
for ( tag , val ) in tag2val . items ( ) :
for env in tag2envs [ tag ] :
os . environ [ env ] = val
2019-01-29 14:20:12 +01:00
2022-05-10 09:41:08 +02:00
class MultibuildFlavorResolver :
2022-10-21 10:38:57 +02:00
def __init__ ( self , apiurl : str , project : str , package : str , use_local = False ) :
2022-05-10 09:41:08 +02:00
self . apiurl = apiurl
self . project = project
self . package = package
# whether to use local _multibuild file or download it from server
self . use_local = use_local
def get_multibuild_data ( self ) :
"""
Retrieve contents of _multibuild file from given project / package .
Return None if the file doesn ' t exist.
"""
# use local _multibuild file
if self . use_local :
try :
2022-07-28 19:11:29 +02:00
with open ( " _multibuild " ) as f :
2022-05-10 09:41:08 +02:00
return f . read ( )
2022-07-28 19:11:29 +02:00
except OSError as e :
2022-05-10 09:41:08 +02:00
if e . errno != errno . EEXIST :
raise
return None
# use _multibuild file from server
query = { }
query [ ' expand ' ] = 1
u = makeurl ( self . apiurl , [ ' source ' , self . project , self . package , ' _multibuild ' ] , query = query )
try :
f = http_GET ( u )
except HTTPError as e :
if e . code == 404 :
return None
raise
return f . read ( )
@staticmethod
2022-12-07 13:01:23 +01:00
def parse_multibuild_data ( s : str ) :
2022-05-10 09:41:08 +02:00
"""
Return set of flavors from a string with multibuild xml .
"""
result = set ( )
# handle empty string and None
if not s :
return result
root = ET . fromstring ( s )
for node in root . findall ( " flavor " ) :
result . add ( node . text )
return result
2022-12-07 13:01:23 +01:00
def resolve ( self , patterns : List [ str ] ) :
2022-05-10 09:41:08 +02:00
"""
Return list of flavors based on given flavor ` patterns ` .
If ` patterns ` contain a glob , it ' s resolved according to _multibuild file,
values without globs are passed through .
"""
# determine if we're using globs
# yes: contact server and do glob matching
# no: use the specified values directly
use_globs = False
for pattern in patterns :
if ' * ' in pattern :
use_globs = True
break
if use_globs :
multibuild_xml = self . get_multibuild_data ( )
all_flavors = self . parse_multibuild_data ( multibuild_xml )
flavors = set ( )
for pattern in patterns :
# not a glob, use it as it is
if ' * ' not in pattern :
flavors . add ( pattern )
continue
# match the globs with flavors from server
for flavor in all_flavors :
if fnmatch . fnmatch ( flavor , pattern ) :
flavors . add ( flavor )
else :
flavors = patterns
return sorted ( flavors )
2022-12-07 13:01:23 +01:00
def resolve_as_packages ( self , patterns : List [ str ] ) :
2022-05-10 09:41:08 +02:00
"""
Return list of package : flavor based on given flavor ` patterns ` .
If a value from ` patterns ` contains a glob , it is resolved according to the _multibuild
file . Values without globs are passed through . If a value is empty string , package
without flavor is returned .
"""
flavors = self . resolve ( patterns )
packages = [ ]
for flavor in flavors :
if flavor :
packages . append ( self . package + ' : ' + flavor )
else :
# special case: no flavor
packages . append ( self . package )
return packages
2010-02-25 09:52:47 +01:00
# vim: sw=4 et