From 2493ea555a1fe141da2da76faad467220c64b8db Mon Sep 17 00:00:00 2001 From: "Dr. Peter Poeml" Date: Mon, 17 Mar 2008 21:46:42 +0000 Subject: [PATCH] - copypac: do a server-side copy (via a single api call) when used with -s / --server-side. This might be the default behaviour later. An option to specify the source revision is missing yet. --- osc/commandline.py | 14 ++++++++++++-- osc/core.py | 42 +++++++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/osc/commandline.py b/osc/commandline.py index 3aee5706..afaa812e 100755 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -565,6 +565,8 @@ class Osc(cmdln.Cmdln): return 1 aggregate_pac(src_project, src_package, dst_project, dst_package) + @cmdln.option('-s', '--server-side', action='store_true', + help='do a (faster) server-side copy') @cmdln.option('-t', '--to-apiurl', metavar='URL', help='URL of destination api server. Default is the source api server.') def do_copypac(self, subcmd, opts, *args): @@ -607,8 +609,16 @@ class Osc(cmdln.Cmdln): src_apiurl == dst_apiurl: print >>sys.stderr, 'Error: source and destination are the same.' return 1 - copy_pac(src_apiurl, src_project, src_package, - dst_apiurl, dst_project, dst_package) + + if opts.server_side and src_apiurl != dst_apiurl: + print >>sys.stderr, 'Error: a server-side copy can\'t be done to ' \ + 'copy from one API host to another.' + return 1 + + r = copy_pac(src_apiurl, src_project, src_package, + dst_apiurl, dst_project, dst_package, + server_side=opts.server_side) + print r def do_deletepac(self, subcmd, opts, project, package): diff --git a/osc/core.py b/osc/core.py index a9758363..eb3a0ca9 100755 --- a/osc/core.py +++ b/osc/core.py @@ -2246,12 +2246,16 @@ def aggregate_pac(src_project, src_package, dst_project, dst_package): print 'Done.' def copy_pac(src_apiurl, src_project, src_package, - dst_apiurl, dst_project, dst_package): - """ - create a copy of a package + dst_apiurl, dst_project, dst_package, + server_side = False): """ + Create a copy of a package. - import tempfile + 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. + + """ src_meta = show_package_meta(src_apiurl, src_project, src_package) src_meta = replace_pkg_meta(src_meta, dst_package, dst_project) @@ -2260,18 +2264,26 @@ def copy_pac(src_apiurl, src_project, src_package, u = makeurl(dst_apiurl, ['source', dst_project, dst_package, '_meta']) http_PUT(u, data=src_meta) - # copy one file after the other print 'Copying files...' - tmpdir = tempfile.mkdtemp(prefix='osc_copypac', dir='/tmp') - os.chdir(tmpdir) - for n in meta_get_filelist(src_apiurl, src_project, src_package): - print ' ', n - get_source_file(src_apiurl, src_project, src_package, n, targetfilename=n) - u = makeurl(dst_apiurl, ['source', dst_project, dst_package, pathname2url(n)]) - http_PUT(u, file = n) - os.unlink(n) - print 'Done.' - os.rmdir(tmpdir) + if server_side: + query = {'cmd': 'copy', 'oproject': src_project, 'opackage': src_package } + 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 + import tempfile + tmpdir = tempfile.mkdtemp(prefix='osc_copypac', dir='/tmp') + os.chdir(tmpdir) + for n in meta_get_filelist(src_apiurl, src_project, src_package): + print ' ', n + get_source_file(src_apiurl, src_project, src_package, n, targetfilename=n) + u = makeurl(dst_apiurl, ['source', dst_project, dst_package, pathname2url(n)]) + http_PUT(u, file = n) + os.unlink(n) + os.rmdir(tmpdir) + return 'Done.' def delete_package(apiurl, prj, pac):