use cmdln instead of argparse

allows to add more commands in addition to run the totest manager
This commit is contained in:
Ludwig Nussel 2015-04-14 13:39:48 +02:00
parent a646ebb298
commit a309a1c7a5

View File

@ -7,12 +7,13 @@
# (C) 2014 coolo@suse.de, openSUSE.org # (C) 2014 coolo@suse.de, openSUSE.org
# Distribute under GPLv2 or GPLv3 # Distribute under GPLv2 or GPLv3
import argparse import cmdln
import json import json
import os import os
import re import re
import sys import sys
import urllib2 import urllib2
import logging
from xml.etree import cElementTree as ET from xml.etree import cElementTree as ET
@ -272,10 +273,14 @@ class ToTestBase(object):
baseurl = ['source', project, package] baseurl = ['source', project, package]
url = self.api.makeurl(baseurl, query=query) url = self.api.makeurl(baseurl, query=query)
if self.dryrun:
print "release %s/%s (%s)"%(project, package, set_release)
else:
self.api.retried_POST(url) self.api.retried_POST(url)
def update_totest(self, snapshot): def update_totest(self, snapshot):
print 'Updating snapshot %s' % snapshot print 'Updating snapshot %s' % snapshot
if not self.dryrun:
self.api.switch_flag_in_prj('openSUSE:%s:ToTest' % self.project, flag='publish', state='disable') self.api.switch_flag_in_prj('openSUSE:%s:ToTest' % self.project, flag='publish', state='disable')
for product in self.ftp_products: for product in self.ftp_products:
@ -289,6 +294,7 @@ class ToTestBase(object):
def publish_factory_totest(self): def publish_factory_totest(self):
print 'Publish ToTest' print 'Publish ToTest'
if not self.dryrun:
self.api.switch_flag_in_prj('openSUSE:%s:ToTest' % self.project, flag='publish', state='enable') self.api.switch_flag_in_prj('openSUSE:%s:ToTest' % self.project, flag='publish', state='enable')
def totest_is_publishing(self): def totest_is_publishing(self):
@ -330,11 +336,11 @@ class ToTestBase(object):
if self.totest_is_publishing(): if self.totest_is_publishing():
can_publish = False can_publish = False
if can_publish and not self.dryrun: if can_publish:
self.publish_factory_totest() self.publish_factory_totest()
can_release = False # we have to wait can_release = False # we have to wait
if can_release and not self.dryrun: if can_release:
self.update_totest(new_snapshot) self.update_totest(new_snapshot)
def release(self): def release(self):
@ -471,36 +477,74 @@ class ToTest132(ToTestBase):
raise Exception("can't find 13.2 version") raise Exception("can't find 13.2 version")
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Commands to work with staging projects')
parser.add_argument('project', metavar='P', type=str, default='Factory',
help='openSUSE version to make the check (Factory, 13.2)')
parser.add_argument('-D', '--dryrun', dest="dryrun", action="store_true", default=False,
help="dry run: do not actually publish")
parser.add_argument("--osc-debug", action="store_true", help="osc debug output")
args = parser.parse_args() class CommandlineInterface(cmdln.Cmdln):
def __init__(self, *args, **kwargs):
cmdln.Cmdln.__init__(self, args, kwargs)
totest_class = { self.totest_class = {
'Factory': ToTestFactory, 'Factory': ToTestFactory,
'Factory:PowerPC': ToTestFactoryPowerPC, 'Factory:PowerPC': ToTestFactoryPowerPC,
'Factory:ARM': ToTestFactoryARM, 'Factory:ARM': ToTestFactoryARM,
'13.2': ToTest132, '13.2': ToTest132,
} }
if args.project not in totest_class: def get_optparser(self):
print 'Project %s not recognized. Possible values [%s]' % (args.project, parser = cmdln.CmdlnOptionParser(self)
', '.join(totest_class)) parser.add_option("--dry", action="store_true", help="dry run")
parser.print_help() parser.add_option("--debug", action="store_true", help="debug output")
exit(-1) parser.add_option("--verbose", action="store_true", help="verbose")
parser.add_option("--osc-debug", action="store_true", help="osc debug output")
return parser
def postoptparse(self):
logging.basicConfig()
self.logger = logging.getLogger(self.optparser.prog)
if (self.options.debug):
self.logger.setLevel(logging.DEBUG)
elif (self.options.verbose):
self.logger.setLevel(logging.INFO)
osc.conf.get_config() osc.conf.get_config()
Config('openSUSE:%s' % args.project) if (self.options.osc_debug):
if (args.osc_debug):
osc.conf.config['debug'] = True osc.conf.config['debug'] = True
totest = totest_class[args.project](args.project, args.dryrun) def _setup_totest(self, project):
# use this for initial release Config('openSUSE:%s' % project)
#totest.release()
if project not in self.totest_class:
msg = 'Project %s not recognized. Possible values [%s]' % (project, ', '.join(self.totest_class))
raise CmdlnUserError()
return self.totest_class[project](project, self.options.dry)
@cmdln.option("-f", "--force", action="store_true",
help="force something")
def do_run(self, subcmd, opts, project = 'Factory'):
"""${cmd_name}: run the ToTest Manager
${cmd_usage}
${cmd_option_list}
"""
totest = self._setup_totest(project)
totest.totest() totest.totest()
def do_release(self, subcmd, opts, project = 'Factory'):
"""${cmd_name}: manually release all media. Use with caution!
${cmd_usage}
${cmd_option_list}
"""
totest = self._setup_totest(project)
totest.release()
if __name__ == "__main__":
app = CommandlineInterface()
sys.exit( app.main() )
# vim: sw=4 et