mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-24 11:12:14 +01:00
- add 'copypac' subcommand, to copy a complete package to a new package, possibly cross-project
- don't die if user tries to 'add' a file which is already versioned - don't die if 'addremove' encounters directories
This commit is contained in:
parent
79092b2a86
commit
c6d1d3917e
@ -167,11 +167,40 @@ See the examples in the _link file.
|
||||
dst_package = src_package
|
||||
|
||||
if src_project == dst_project and src_package == dst_package:
|
||||
print 'error: source and destination are the same'
|
||||
sys.exit(1)
|
||||
sys.exit('osc: error: source and destination are the same')
|
||||
link_pac(src_project, src_package, dst_project, dst_package)
|
||||
|
||||
|
||||
def copypac(args):
|
||||
""""Copy" a package, possibly cross-project.
|
||||
|
||||
usage: osc copypac SOURCEPRJ SOURCEPAC DESTPRJ [DESTPAC]
|
||||
|
||||
The DESTPAC name is optional; the source packages' name will be used if
|
||||
DESTPAC is omitted.
|
||||
|
||||
"""
|
||||
|
||||
if not args or len(args) < 3:
|
||||
print 'missing argument'
|
||||
print
|
||||
print copypac.func_doc
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
src_project = args[0]
|
||||
src_package = args[1]
|
||||
dst_project = args[2]
|
||||
if len(args) > 3:
|
||||
dst_package = args[3]
|
||||
else:
|
||||
dst_package = src_package
|
||||
|
||||
if src_project == dst_project and src_package == dst_package:
|
||||
sys.exit('osc: error: source and destination are the same')
|
||||
copy_pac(src_project, src_package, dst_project, dst_package)
|
||||
|
||||
|
||||
def deletepac(args):
|
||||
"""deletepac: Delete a package on the server.
|
||||
|
||||
@ -327,6 +356,9 @@ usage: osc add file1 file2 ...
|
||||
for filename in pac.todo:
|
||||
if filename in exclude_stuff:
|
||||
continue
|
||||
if filename in pac.filenamelist:
|
||||
print 'osc: warning: \'%s\' is already under version control' % filename
|
||||
continue
|
||||
|
||||
pac.addfile(filename)
|
||||
print statfrmt('A', filename)
|
||||
@ -347,6 +379,8 @@ usage: osc addremove
|
||||
for filename in p.todo:
|
||||
if filename in exclude_stuff:
|
||||
continue
|
||||
if os.path.isdir(filename):
|
||||
continue
|
||||
state = p.status(filename)
|
||||
if state == '?':
|
||||
p.addfile(filename)
|
||||
@ -848,6 +882,7 @@ cmd_dict = {
|
||||
diff: ['diff'],
|
||||
editmeta: ['editmeta'],
|
||||
editpac: ['editpac', 'createpac'],
|
||||
copypac: ['copypac'],
|
||||
editprj: ['editprj', 'createprj'],
|
||||
help: ['help'],
|
||||
buildhistory: ['buildhistory', 'buildhist'],
|
||||
|
39
osc/core.py
39
osc/core.py
@ -1060,6 +1060,45 @@ def link_pac(src_project, src_package, dst_project, dst_package):
|
||||
print 'Done.'
|
||||
|
||||
|
||||
def copy_pac(src_project, src_package, dst_project, dst_package):
|
||||
"""
|
||||
create a copy of a package
|
||||
"""
|
||||
|
||||
import othermethods
|
||||
import tempfile
|
||||
|
||||
src_meta = show_package_meta(src_project, src_package)
|
||||
|
||||
# replace project and package name
|
||||
# using a string buffer
|
||||
# and create the package
|
||||
tree = ET.parse(StringIO(''.join(src_meta)))
|
||||
root = tree.getroot()
|
||||
root.set('name', dst_package)
|
||||
root.set('project', dst_project)
|
||||
buf = StringIO()
|
||||
tree.write(buf)
|
||||
src_meta = buf.getvalue()
|
||||
|
||||
print 'Sending meta data...'
|
||||
u = makeurl(['source', dst_project, dst_package, '_meta'])
|
||||
othermethods.putfile(u, username, password, strbuf=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_project, src_package):
|
||||
print ' ', n
|
||||
get_source_file(src_project, src_package, n, targetfilename=n)
|
||||
u = makeurl(['source', dst_project, dst_package, pathname2url(n)])
|
||||
othermethods.putfile(u, username, password, file = n)
|
||||
os.unlink(n)
|
||||
print 'Done.'
|
||||
os.rmdir(tmpdir)
|
||||
|
||||
|
||||
def delete_package(prj, pac):
|
||||
import othermethods
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user