Merge pull request #223 from lnussel/master

add --verbose and --dry options, add cpio module
This commit is contained in:
Alberto Planas 2014-08-27 13:25:32 +02:00
commit 497aec2405
4 changed files with 121 additions and 12 deletions

View File

@ -94,7 +94,7 @@ def _check_repo_download(self, request):
_errors_printed = set()
def _check_repo_group(self, id_, requests):
def _check_repo_group(self, id_, requests, debug = False):
print '> Check group [%s]' % ', '.join(r.str_compact() for r in requests)
if not all(self.checkrepo.is_buildsuccess(r) for r in requests if r.action_type != 'delete'):
@ -205,7 +205,7 @@ def _check_repo_group(self, id_, requests):
execution_plan = defaultdict(list)
DEBUG_PLAN = 0
DEBUG_PLAN = debug
# Get all the (project, repo, disturl) where the disturl is
# compatible with the request. For the same package we can have
@ -379,6 +379,8 @@ def _print_request_and_specs(self, request_and_specs):
@cmdln.option('-p', '--project', dest='project', metavar='PROJECT', default='Factory',
help='select a different project instead of openSUSE:Factory')
@cmdln.option('-s', '--skip', action='store_true', help='skip review')
@cmdln.option('-n', '--dry', action='store_true', help='dry run, don\'t change review state')
@cmdln.option('-v', '--verbose', action='store_true', help='verbose output')
def do_check_repo(self, subcmd, opts, *args):
"""${cmd_name}: Checker review of submit requests.
@ -390,7 +392,7 @@ def do_check_repo(self, subcmd, opts, *args):
${cmd_option_list}
"""
self.checkrepo = CheckRepo(self.get_api_url(), opts.project)
self.checkrepo = CheckRepo(self.get_api_url(), opts.project, readonly = opts.dry)
if opts.skip:
if not len(args):
@ -470,6 +472,6 @@ def do_check_repo(self, subcmd, opts, *args):
# Sort the groups, from high to low. This put first the stating
# projects also
for id_, reqs in sorted(groups.items(), reverse=True):
self._check_repo_group(id_, reqs)
self._check_repo_group(id_, reqs, debug=opts.verbose)
print
print

View File

@ -79,10 +79,8 @@ def tt_overall_result(self, snapshot):
'opensuse-FTT-DVD-x86_64-Build-update_123@64bit',
'opensuse-FTT-GNOME-Live-i686-Build-gnome-live@32bit', # broken in 20140813
'opensuse-FTT-GNOME-Live-x86_64-Build-gnome-live@64bit', # broken in 20140814
'opensuse-FTT-GNOME-Live-x86_64-Build-gnome-live@USBboot_64',
'opensuse-FTT-KDE-Live-i686-Build-kde-live@32bit', # broken in 20140813
'opensuse-FTT-KDE-Live-x86_64-Build-kde-live@64bit', # broken in 20140814
'opensuse-FTT-KDE-Live-x86_64-Build-kde-live@USBboot_64',
'opensuse-FTT-NET-i586-Build-lvm@32bit',
'opensuse-FTT-NET-i586-Build-lxde@32bit',
'opensuse-FTT-NET-x86_64-Build-lxde@64bit',
@ -92,9 +90,6 @@ def tt_overall_result(self, snapshot):
'opensuse-FTT-Rescue-CD-i686-Build-rescue@32bit',
'opensuse-FTT-Rescue-CD-x86_64-Build-rescue@64bit',
'opensuse-FTT-DVD-i586-Build-kde@USBboot_32',
'opensuse-FTT-DVD-x86_64-Build-kde@USBboot_64',
'opensuse-FTT-NET-i586-Build-kde@USBboot_32',
'opensuse-FTT-NET-x86_64-Build-kde@USBboot_64',
]
if len(jobs) < 80: # not yet scheduled

View File

@ -118,7 +118,7 @@ class Request(object):
class CheckRepo(object):
def __init__(self, apiurl, opensuse='Factory'):
def __init__(self, apiurl, opensuse='Factory', readonly = False):
"""CheckRepo constructor."""
self.apiurl = apiurl
self.opensuse = opensuse
@ -129,6 +129,7 @@ class CheckRepo(object):
# groups = { staging: [ids,], }
self.groups = {}
self._staging()
self.readonly = readonly
def _staging(self):
"""Preload the groups of related request associated by the same
@ -187,6 +188,9 @@ class CheckRepo(object):
code = 404
url = makeurl(self.apiurl, ('request', str(request_id)), query=query)
if self.readonly:
print "DRY RUN: POST %s"%url
return 200
try:
root = ET.parse(http_POST(url, data=message)).getroot()
code = root.attrib['code']
@ -896,11 +900,17 @@ class CheckRepo(object):
"""
if request.is_shadow_devel:
url = makeurl(self.apiurl, ('source', request.shadow_src_project, request.src_package))
http_DELETE(url)
if self.readonly:
print "DRY RUN: DELETE %s"%url
else:
http_DELETE(url)
for sub_prj, sub_pkg in self.staging.get_sub_packages(request.src_package,
request.shadow_src_project):
url = makeurl(self.apiurl, ('source', sub_prj, sub_pkg))
http_DELETE(url)
if self.readonly:
print "DRY RUN: DELETE %s"%url
else:
http_DELETE(url)
def _whatdependson(self, request):
"""Return the list of packages that depends on the one in the

102
osclib/cpio.py Normal file
View File

@ -0,0 +1,102 @@
#!/usr/bin/python
# Copyright (c) 2014 SUSE Linux Products GmbH
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import struct
class Cpio(object):
def __init__(self, buf):
self.buf = buf
self.off = 0
def __iter__(self):
return self
def next(self):
f = CpioFile(self.off, self.buf)
if f.fin():
raise StopIteration
self.off = self.off+f.length()
return f
class CpioFile(object):
def __init__(self, off, buf):
self.off = off
self.buf = buf
if off&3:
raise Exception("invalid offset %d"% off)
fmt = "6s8s8s8s8s8s8s8s8s8s8s8s8s8s"
off = self.off + struct.calcsize(fmt)
fields = struct.unpack(fmt, buf[self.off:off])
if fields[0] != "070701":
raise Exception("invalid cpio header %s"%self.c_magic)
names = ("c_ino", "c_mode", "c_uid", "c_gid",
"c_nlink", "c_mtime", "c_filesize",
"c_devmajor", "c_devminor", "c_rdevmajor",
"c_rdevminor", "c_namesize", "c_check")
for (n, v) in zip(names, fields[1:]):
setattr(self, n, int(v, 16))
nlen = self.c_namesize - 1
self.name = struct.unpack('%ds'%nlen, buf[off:off+nlen])[0]
off = off + nlen + 1
if off&3:
off = off + 4-(off&3) # padding
self.payloadstart = off
def fin(self):
return self.name == 'TRAILER!!!'
def __str__(self):
return "[%s %d]"%(self.name, self.c_filesize)
def header(self):
return self.buf[self.payloadstart:self.payloadstart+self.c_filesize]
def length(self):
l = self.payloadstart-self.off + self.c_filesize
if self.c_filesize&3:
l = l + 4-(self.c_filesize&3)
return l
if __name__ == '__main__':
from optparse import OptionParser
parser = OptionParser()
parser.add_option("--debug", action="store_true", help="debug output")
parser.add_option("--verbose", action="store_true", help="verbose")
(options, args) = parser.parse_args()
for fn in args:
fh = open(fn, 'rb')
cpio = Cpio(fh.read())
for i in cpio:
print i
ofh = open(i.name, 'wb')
ofh.write(i.header())
ofh.close()
# vim: sw=4 et