1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-10 06:46:15 +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:
Dr. Peter Poeml 2006-09-21 14:33:24 +00:00
parent 79092b2a86
commit c6d1d3917e
2 changed files with 76 additions and 2 deletions

View File

@ -167,11 +167,40 @@ See the examples in the _link file.
dst_package = src_package dst_package = src_package
if src_project == dst_project and src_package == dst_package: if src_project == dst_project and src_package == dst_package:
print 'error: source and destination are the same' sys.exit('osc: error: source and destination are the same')
sys.exit(1)
link_pac(src_project, src_package, dst_project, dst_package) 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): def deletepac(args):
"""deletepac: Delete a package on the server. """deletepac: Delete a package on the server.
@ -327,6 +356,9 @@ usage: osc add file1 file2 ...
for filename in pac.todo: for filename in pac.todo:
if filename in exclude_stuff: if filename in exclude_stuff:
continue continue
if filename in pac.filenamelist:
print 'osc: warning: \'%s\' is already under version control' % filename
continue
pac.addfile(filename) pac.addfile(filename)
print statfrmt('A', filename) print statfrmt('A', filename)
@ -347,6 +379,8 @@ usage: osc addremove
for filename in p.todo: for filename in p.todo:
if filename in exclude_stuff: if filename in exclude_stuff:
continue continue
if os.path.isdir(filename):
continue
state = p.status(filename) state = p.status(filename)
if state == '?': if state == '?':
p.addfile(filename) p.addfile(filename)
@ -848,6 +882,7 @@ cmd_dict = {
diff: ['diff'], diff: ['diff'],
editmeta: ['editmeta'], editmeta: ['editmeta'],
editpac: ['editpac', 'createpac'], editpac: ['editpac', 'createpac'],
copypac: ['copypac'],
editprj: ['editprj', 'createprj'], editprj: ['editprj', 'createprj'],
help: ['help'], help: ['help'],
buildhistory: ['buildhistory', 'buildhist'], buildhistory: ['buildhistory', 'buildhist'],

View File

@ -1060,6 +1060,45 @@ def link_pac(src_project, src_package, dst_project, dst_package):
print 'Done.' 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): def delete_package(prj, pac):
import othermethods import othermethods