Skip to content

Commit

Permalink
simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
coolo committed Apr 16, 2013
1 parent 02fa6a5 commit 715c4d7
Showing 1 changed file with 186 additions and 184 deletions.
370 changes: 186 additions & 184 deletions osc-check_repo.py
Expand Up @@ -21,6 +21,8 @@ def _check_repo_change_review_state(self, opts, id, newstate, message='', supers
if supersed: query['superseded_by'] = supersed
# if message: query['comment'] = message
u = makeurl(opts.apiurl, ['request', str(id)], query=query)
print u
return
f = http_POST(u, data=message)
root = ET.parse(f).getroot()
return root.attrib['code']
Expand Down Expand Up @@ -74,194 +76,194 @@ def _check_repo_one_request(self, rq, cmd, opts):
act_id = 0
approved_actions = 0
actions = rq.findall('action')
if len(actions) > 1:
msg = "2 actions in one SR is not supported - https://github.com/coolo/factory-auto/fork_select"
if len(actions) != 1:
msg = "only one action per request is supported - create a group instead: https://github.com/SUSE/hackweek/wiki/Improved-Factory-devel-project-submission-workflow"
print "declined " + msg
self._check_repo_change_review_state(opts, id, 'declined', message=msg)
return

for act in actions:
act_id += 1
_type = act.get('type');
if (_type == "submit"):
pkg = act.find('source').get('package')
prj = act.find('source').get('project')
rev = act.find('source').get('rev')
tprj = act.find('target').get('project')
tpkg = act.find('target').get('package')

src = { 'package': pkg, 'project': prj, 'rev':rev, 'error': None }
e = []
if not pkg:
e.append('no source/package in request %d, action %d' % (id, act_id))
if not prj:
e.append('no source/project in request %d, action %d' % (id, act_id))
if len(e): src.error = '; '.join(e)

e = []
if not tpkg:
e.append('no target/package in request %d, action %d; ' % (id, act_id))
if not prj:
e.append('no target/project in request %d, action %d; ' % (id, act_id))
# it is no error, if the target package dies not exist

subm_id = "SUBMIT(%d):" % id
print "\n%s %s/%s -> %s/%s" % (subm_id,
prj, pkg,
tprj, tpkg)
try:
url = makeurl(opts.apiurl, ['status', "bsrequest?id=%d" % id])
root = ET.parse(http_GET(url)).getroot()
except urllib2.HTTPError:
print "error"
continue
if root.attrib.has_key('code'):
print ET.tostring(root)
continue
result = False
goodrepo = None
missings = {}
alldisabled = True
foundbuilding = None
foundfailed = None
foundoutdated = None
found64 = True
for repo in root.findall('repository'):
[isgood, founddisabled, r_foundbuilding, r_foundfailed, r_foundoutdated, r_missings, r_found64] = self._check_repo(repo)
for p in r_missings:
missings[p] = 1
if not founddisabled:
alldisabled = False
if isgood:
if len(missings) == 0 or os.environ.has_key("IGNORE_MISSINGS"):
goodrepo = repo
result = True
missings = {}
if r_foundbuilding:
foundbuilding = r_foundbuilding
if r_foundfailed:
foundfailed = r_foundfailed
if r_foundoutdated:
foundoutdated = r_foundoutdated
if r_found64:
found64 = r_found64

if result == False:
if foundoutdated:
msg = "the package sources were changed after submissions and the old sources never built. Please resubmit"
print "declined " + msg
self._check_repo_change_review_state(opts, id, 'declined', message=msg)
continue
if alldisabled:
msg = "the package is disabled or does not build against factory. Please fix and resubmit"
print "declined " + msg
self._check_repo_change_review_state(opts, id, 'declined', message=msg)
continue
if len(missings.keys()):
smissing = []
missings.keys().sort()
for package in missings:
request = self._check_repo_find_submit_request(opts, tprj, package)
if request:
package = "%s(rq%s)" % (package, request)
smissing.append(package)

msg = "please make sure to wait before these depencencies are in {0}: {1}".format(tprj, ', '.join(smissing))
self._check_repo_change_review_state(opts, id, 'new', message=msg)
print "updated " + msg
continue
if foundbuilding:
msg = "the package is still building for repository {0}".format(foundbuilding)
self._check_repo_change_review_state(opts, id, 'new', message=msg)
print "updated " + msg
continue
if foundfailed:
msg = "the package failed to build in repository {0} - not accepting".format(foundfailed)
self._check_repo_change_review_state(opts, id, 'new', message=msg)
print "updated " + msg
continue
if not found64:
msg = "Missing x86_64 in the repo list"
self._check_repo_change_review_state(opts, id, 'new', message=msg)
print "updated " + msg
continue

print ET.tostring(root)
continue

opts.destdir = os.path.expanduser("~/co/%s" % str(id))
opts.sources = False
opts.debug = False
opts.quiet = True
# we can assume x86_64 is there
self.do_getbinaries(None, opts, prj, pkg, goodrepo.attrib['name'], 'x86_64')

# now fetch -32bit packs
url = makeurl(opts.apiurl, ['build', prj, goodrepo.attrib['name'], 'i586', pkg])
try:
f = http_GET(url)
binaries = ET.parse(f).getroot()
for bin in binaries.findall('binary'):
fn=bin.attrib['filename']
result = re.match("(.*)-([^-]*)-([^-]*)\.([^-\.]+)\.rpm", fn)
if not result: continue
if result.group(4) != 'x86_64': continue
get_binary_file(opts.apiurl,
prj, goodrepo.attrib['name'], 'i586', fn, package = pkg, target_filename = os.path.join(opts.destdir, fn))
except urllib2.HTTPError, err:
print err
pass

url = makeurl(opts.apiurl, ['build',tprj, 'standard', 'x86_64', tpkg])
toignore = []
try:
f = http_GET(url)
binaries = ET.parse(f).getroot()
for bin in binaries.findall('binary'):
fn=bin.attrib['filename']
result = re.match("(.*)-([^-]*)-([^-]*)\.[^-\.]*.rpm", fn)
if not result: continue
toignore.append(result.group(1))
except urllib2.HTTPError, err:
print "new package?"
# now fetch -32bit pack list
url = makeurl(opts.apiurl, ['build',tprj, 'standard', 'i586', tpkg])
try:
f = http_GET(url)
binaries = ET.parse(f).getroot()
for bin in binaries.findall('binary'):
fn=bin.attrib['filename']
result = re.match("(.*)-([^-]*)-([^-]*)\.([^-\.]+)\.rpm", fn)
if not result: continue
if result.group(4) != 'x86_64': continue
toignore.append(result.group(1))
except urllib2.HTTPError, err:
print "new package?"


civs = "LC_ALL=C perl /suse/coolo/checker/repo-checker.pl '%s' '%s' 2>&1" % (opts.destdir, ','.join(toignore))
p = subprocess.Popen(civs, shell=True, stdout=subprocess.PIPE, close_fds=True)
ret = os.waitpid(p.pid, 0)[1]
checked = p.stdout.readlines()
output = ' '.join(checked).translate(None, '\033')
shutil.rmtree(opts.destdir)

if ret:
print output
self._check_repo_change_review_state(opts, id, 'new', message=output)
continue

msg="Builds for repo %s" % goodrepo.attrib['name']
self._check_repo_change_review_state(opts, id, 'accepted', message=msg)

if cmd == "list":
pass
else:
print "unknown command: %s" % cmd
else:
self._check_repo_change_review_state(opts, id, 'accepted',
message="Unchecked request type %s" % _type)
act = actions[0]
_type = act.get('type')
if _type != "submit":
self._check_repo_change_review_state(opts, id, 'accepted',
message="Unchecked request type %s" % _type)
return

pkg = act.find('source').get('package')
prj = act.find('source').get('project')
rev = act.find('source').get('rev')
tprj = act.find('target').get('project')
tpkg = act.find('target').get('package')

src = { 'package': pkg, 'project': prj, 'rev':rev, 'error': None }
e = []
if not pkg:
e.append('no source/package in request %d, action %d' % (id, act_id))
if not prj:
e.append('no source/project in request %d, action %d' % (id, act_id))
if len(e): src.error = '; '.join(e)

e = []
if not tpkg:
e.append('no target/package in request %d, action %d; ' % (id, act_id))
if not prj:
e.append('no target/project in request %d, action %d; ' % (id, act_id))
# it is no error, if the target package dies not exist

subm_id = "SUBMIT(%d):" % id
print "\n%s %s/%s -> %s/%s" % (subm_id,
prj, pkg,
tprj, tpkg)
try:
url = makeurl(opts.apiurl, ['status', "bsrequest?id=%d" % id])
root = ET.parse(http_GET(url)).getroot()
except urllib2.HTTPError:
print "error"
return
if root.attrib.has_key('code'):
print ET.tostring(root)
return
result = False
goodrepo = None
missings = {}
alldisabled = True
foundbuilding = None
foundfailed = None
foundoutdated = None
found64 = True
for repo in root.findall('repository'):
[isgood, founddisabled, r_foundbuilding, r_foundfailed, r_foundoutdated, r_missings, r_found64] = self._check_repo(repo)
for p in r_missings:
missings[p] = 1
if not founddisabled:
alldisabled = False
if isgood:
if len(missings) == 0 or os.environ.has_key("IGNORE_MISSINGS"):
goodrepo = repo
result = True
missings = {}
if r_foundbuilding:
foundbuilding = r_foundbuilding
if r_foundfailed:
foundfailed = r_foundfailed
if r_foundoutdated:
foundoutdated = r_foundoutdated
if r_found64:
found64 = r_found64

if result == False:
if foundoutdated:
msg = "the package sources were changed after submissions and the old sources never built. Please resubmit"
print "declined " + msg
self._check_repo_change_review_state(opts, id, 'declined', message=msg)
return
if alldisabled:
msg = "the package is disabled or does not build against factory. Please fix and resubmit"
print "declined " + msg
self._check_repo_change_review_state(opts, id, 'declined', message=msg)
return
if len(missings.keys()):
smissing = []
missings.keys().sort()
for package in missings:
request = self._check_repo_find_submit_request(opts, tprj, package)
if request:
package = "%s(rq%s)" % (package, request)
smissing.append(package)

msg = "please make sure to wait before these depencencies are in {0}: {1}".format(tprj, ', '.join(smissing))
self._check_repo_change_review_state(opts, id, 'new', message=msg)
print "updated " + msg
return
if foundbuilding:
msg = "the package is still building for repository {0}".format(foundbuilding)
self._check_repo_change_review_state(opts, id, 'new', message=msg)
print "updated " + msg
return
if foundfailed:
msg = "the package failed to build in repository {0} - not accepting".format(foundfailed)
self._check_repo_change_review_state(opts, id, 'new', message=msg)
print "updated " + msg
return
if not found64:
msg = "Missing x86_64 in the repo list"
self._check_repo_change_review_state(opts, id, 'new', message=msg)
print "updated " + msg
return

print ET.tostring(root)
return

opts.destdir = os.path.expanduser("~/co/%s" % str(id))
opts.sources = False
opts.debug = False
opts.quiet = True
# we can assume x86_64 is there
self.do_getbinaries(None, opts, prj, pkg, goodrepo.attrib['name'], 'x86_64')

# now fetch -32bit packs
url = makeurl(opts.apiurl, ['build', prj, goodrepo.attrib['name'], 'i586', pkg])
try:
f = http_GET(url)
binaries = ET.parse(f).getroot()
for bin in binaries.findall('binary'):
fn=bin.attrib['filename']
result = re.match("(.*)-([^-]*)-([^-]*)\.([^-\.]+)\.rpm", fn)
if not result: continue
if result.group(4) != 'x86_64': continue
get_binary_file(opts.apiurl,
prj, goodrepo.attrib['name'], 'i586', fn, package = pkg, target_filename = os.path.join(opts.destdir, fn))
except urllib2.HTTPError, err:
print err
pass

url = makeurl(opts.apiurl, ['build',tprj, 'standard', 'x86_64', tpkg])
toignore = []
try:
f = http_GET(url)
binaries = ET.parse(f).getroot()
for bin in binaries.findall('binary'):
fn=bin.attrib['filename']
result = re.match("(.*)-([^-]*)-([^-]*)\.[^-\.]*.rpm", fn)
if not result: continue
toignore.append(result.group(1))
except urllib2.HTTPError, err:
print "new package?"
# now fetch -32bit pack list
url = makeurl(opts.apiurl, ['build',tprj, 'standard', 'i586', tpkg])
try:
f = http_GET(url)
binaries = ET.parse(f).getroot()
for bin in binaries.findall('binary'):
fn=bin.attrib['filename']
result = re.match("(.*)-([^-]*)-([^-]*)\.([^-\.]+)\.rpm", fn)
if not result: continue
if result.group(4) != 'x86_64': continue
toignore.append(result.group(1))
except urllib2.HTTPError, err:
print "new package?"

civs = "LC_ALL=C perl /suse/coolo/checker/repo-checker.pl '%s' '%s' 2>&1" % (opts.destdir, ','.join(toignore))
p = subprocess.Popen(civs, shell=True, stdout=subprocess.PIPE, close_fds=True)
ret = os.waitpid(p.pid, 0)[1]
checked = p.stdout.readlines()
output = ' '.join(checked).translate(None, '\033')
shutil.rmtree(opts.destdir)

if ret:
print output
self._check_repo_change_review_state(opts, id, 'new', message=output)
return

msg="Builds for repo %s" % goodrepo.attrib['name']

self._check_repo_change_review_state(opts, id, 'accepted', message=msg)

if cmd == "list":
pass
else:
print "unknown command: %s" % cmd


def do_check_repo(self, subcmd, opts, *args):
"""${cmd_name}: checker review of submit requests.
Expand Down

0 comments on commit 715c4d7

Please sign in to comment.