Skip to content

Commit

Permalink
- use cmd=branch&dryrun=1 for search of maintained packages to get sa…
Browse files Browse the repository at this point in the history
…me result as on branching
  • Loading branch information
adrianschroeter committed Jan 5, 2012
1 parent 836423d commit 3651508
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
0.134
-
#
# Features which requires OBS 2.3
#
- support dryrun of branching to preview the expected result. "osc sm" is doing this now by default.

0.133
- add --meta option also to "list", "cat" and "less" commands
Expand Down
55 changes: 33 additions & 22 deletions osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2671,24 +2671,34 @@ def do_maintenancerequest(self, subcmd, opts, *args):
'(\'osc bco\' is a shorthand for this option)' )
@cmdln.option('-a', '--attribute', metavar='ATTRIBUTE',
help='Use this attribute to find affected packages (default is OBS:Maintained)')
@cmdln.option('--noaccess', action='store_true',
help='Create a hidden project')
@cmdln.option('-u', '--update-project-attribute', metavar='UPDATE_ATTRIBUTE',
help='Use this attribute to find update projects (default is OBS:UpdateProject) ')
@cmdln.option('--dryrun', action='store_true',
help='Just simulate the action and report back the result.')
@cmdln.option('--noaccess', action='store_true',
help='Create a hidden project')
@cmdln.option('--nodevelproject', action='store_true',
help='do not follow a defined devel project ' \
'(primary project where a package is developed)')
@cmdln.alias('sm')
@cmdln.alias('maintained')
def do_mbranch(self, subcmd, opts, *args):
"""${cmd_name}: Multiple branch of a package
"""${cmd_name}: Search or banch multiple instances of a package
This command is used for searching all relevant instances of packages
and creating links of them in one project.
This is esp. used for maintenance updates. It can also be used to branch
all packages marked before with a given attribute.
[See http://en.opensuse.org/openSUSE:Build_Service_Concept_Maintenance
for information on this topic.]
This command is used for creating multiple links of defined version of a package
in one project. This is esp. used for maintenance updates.
The branched package will live in
home:USERNAME:branches:ATTRIBUTE:PACKAGE
if nothing else specified.
usage:
osc sm [SOURCEPACKAGE] [-a ATTRIBUTE]
osc mbranch [ SOURCEPACKAGE [ TARGETPROJECT ] ]
${cmd_option_list}
"""
Expand All @@ -2710,23 +2720,31 @@ def do_mbranch(self, subcmd, opts, *args):
if len(args) >= 2:
tproject = args[1]

r = attribute_branch_pkg(apiurl, maintained_attribute, maintained_update_project_attribute, \
package, tproject, noaccess = opts.noaccess)
if subcmd == 'sm' or subcmd == 'maintained':
opts.dryrun = 1

if r is None:
result = attribute_branch_pkg(apiurl, maintained_attribute, maintained_update_project_attribute, \
package, tproject, noaccess = opts.noaccess, nodevelproject=opts.nodevelproject, dryrun=opts.dryrun)

if result is None:
print >>sys.stderr, 'ERROR: Attribute branch call came not back with a project.'
sys.exit(1)

print "Project " + r + " created."
if opts.dryrun:
for r in result.findall('package'):
print " ", r.get('project'), r.get('package')
return

print "Project " + result + " created."

if opts.checkout:
Project.init_project(apiurl, r, r, conf.config['do_package_tracking'])
print statfrmt('A', r)
Project.init_project(apiurl, result, result, conf.config['do_package_tracking'])
print statfrmt('A', result)

# all packages
for package in meta_get_packagelist(apiurl, r):
for package in meta_get_packagelist(apiurl, result):
try:
checkout_package(apiurl, r, package, expand_link = True, prj_dir = r)
checkout_package(apiurl, result, package, expand_link = True, prj_dir = result)
except:
print >>sys.stderr, 'Error while checkout package:\n', package

Expand Down Expand Up @@ -5836,7 +5854,6 @@ def do_my(self, subcmd, opts, type):
help='search binary packages')
@cmdln.option('-B', '--baseproject', metavar='PROJECT',
help='search packages built for PROJECT (implies --binary)')
@cmdln.alias('sm')
@cmdln.alias('se')
@cmdln.alias('bse')
def do_search(self, subcmd, opts, *args):
Expand All @@ -5848,7 +5865,6 @@ def do_search(self, subcmd, opts, *args):
usage:
osc search \'search term\' <options>
osc sm \'source package name\' ('osc search --maintained')
osc bse ... ('osc search --binary')
osc se 'perl(Foo::Bar)' ('osc --package perl-Foo-Bar')
${cmd_option_list}
Expand Down Expand Up @@ -5886,8 +5902,6 @@ def build_xpath(attr, what, substr = False):
if opts.substring and opts.exact:
raise oscerr.WrongOptions('Sorry, the options \'--substring\' and \'--exact\' are mutually exclusive')

if subcmd == 'sm' or opts.maintained:
opts.package = True
if not opts.substring:
opts.exact = True
if subcmd == 'bse' or opts.baseproject:
Expand Down Expand Up @@ -5930,10 +5944,7 @@ def build_xpath(attr, what, substr = False):
xpath = xpath_join(xpath, build_xpath('title', search_term, opts.substring), inner=True)
xpath = xpath_join(xpath, build_xpath('description', search_term, opts.substring), inner=True)
what = {'project': xpath, 'package': xpath}
if subcmd == 'sm' or opts.maintained:
xpath = xpath_join(xpath, '(project/attribute/@name=\'%(attr)s\' or attribute/@name=\'%(attr)s\')' % {'attr': conf.config['maintained_attribute']}, op='and')
what = {'package': xpath}
elif opts.project and not opts.package:
if opts.project and not opts.package:
what = {'project': xpath}
elif not opts.project and opts.package:
what = {'package': xpath}
Expand Down
9 changes: 8 additions & 1 deletion osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4293,18 +4293,22 @@ def aggregate_pac(src_project, src_package, dst_project, dst_package, repo_map =
print 'Done.'


def attribute_branch_pkg(apiurl, attribute, maintained_update_project_attribute, package, targetproject, return_existing=False, force=False, noaccess=False, add_repositories=False):
def attribute_branch_pkg(apiurl, attribute, maintained_update_project_attribute, package, targetproject, return_existing=False, force=False, noaccess=False, add_repositories=False, dryrun=False, nodevelproject=False):
"""
Branch packages defined via attributes (via API call)
"""
query = { 'cmd': 'branch' }
query['attribute'] = attribute
if targetproject:
query['target_project'] = targetproject
if dryrun:
query['dryrun'] = "1"
if force:
query['force'] = "1"
if noaccess:
query['noaccess'] = "1"
if nodevelproject:
query['ignoredevel'] = '1'
if add_repositories:
query['add_repositories'] = "1"
if package:
Expand All @@ -4323,6 +4327,9 @@ def attribute_branch_pkg(apiurl, attribute, maintained_update_project_attribute,
raise oscerr.APIError(msg)

r = f.read()
if dryrun:
return ET.fromstring(r)

r = r.split('targetproject">')[1]
r = r.split('</data>')[0]
return r
Expand Down

0 comments on commit 3651508

Please sign in to comment.