mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-27 02:16:12 +01:00
- 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.
This commit is contained in:
parent
8ce42e2dd9
commit
2493ea555a
@ -565,6 +565,8 @@ class Osc(cmdln.Cmdln):
|
|||||||
return 1
|
return 1
|
||||||
aggregate_pac(src_project, src_package, dst_project, dst_package)
|
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',
|
@cmdln.option('-t', '--to-apiurl', metavar='URL',
|
||||||
help='URL of destination api server. Default is the source api server.')
|
help='URL of destination api server. Default is the source api server.')
|
||||||
def do_copypac(self, subcmd, opts, *args):
|
def do_copypac(self, subcmd, opts, *args):
|
||||||
@ -607,8 +609,16 @@ class Osc(cmdln.Cmdln):
|
|||||||
src_apiurl == dst_apiurl:
|
src_apiurl == dst_apiurl:
|
||||||
print >>sys.stderr, 'Error: source and destination are the same.'
|
print >>sys.stderr, 'Error: source and destination are the same.'
|
||||||
return 1
|
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):
|
def do_deletepac(self, subcmd, opts, project, package):
|
||||||
|
42
osc/core.py
42
osc/core.py
@ -2246,12 +2246,16 @@ def aggregate_pac(src_project, src_package, dst_project, dst_package):
|
|||||||
print 'Done.'
|
print 'Done.'
|
||||||
|
|
||||||
def copy_pac(src_apiurl, src_project, src_package,
|
def copy_pac(src_apiurl, src_project, src_package,
|
||||||
dst_apiurl, dst_project, dst_package):
|
dst_apiurl, dst_project, dst_package,
|
||||||
"""
|
server_side = False):
|
||||||
create a copy of a package
|
|
||||||
"""
|
"""
|
||||||
|
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 = show_package_meta(src_apiurl, src_project, src_package)
|
||||||
src_meta = replace_pkg_meta(src_meta, dst_package, dst_project)
|
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'])
|
u = makeurl(dst_apiurl, ['source', dst_project, dst_package, '_meta'])
|
||||||
http_PUT(u, data=src_meta)
|
http_PUT(u, data=src_meta)
|
||||||
|
|
||||||
# copy one file after the other
|
|
||||||
print 'Copying files...'
|
print 'Copying files...'
|
||||||
tmpdir = tempfile.mkdtemp(prefix='osc_copypac', dir='/tmp')
|
if server_side:
|
||||||
os.chdir(tmpdir)
|
query = {'cmd': 'copy', 'oproject': src_project, 'opackage': src_package }
|
||||||
for n in meta_get_filelist(src_apiurl, src_project, src_package):
|
u = makeurl(dst_apiurl, ['source', dst_project, dst_package], query=query)
|
||||||
print ' ', n
|
f = http_POST(u)
|
||||||
get_source_file(src_apiurl, src_project, src_package, n, targetfilename=n)
|
return f.read()
|
||||||
u = makeurl(dst_apiurl, ['source', dst_project, dst_package, pathname2url(n)])
|
|
||||||
http_PUT(u, file = n)
|
else:
|
||||||
os.unlink(n)
|
# copy one file after the other
|
||||||
print 'Done.'
|
import tempfile
|
||||||
os.rmdir(tmpdir)
|
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):
|
def delete_package(apiurl, prj, pac):
|
||||||
|
Loading…
Reference in New Issue
Block a user