mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-26 12:12:11 +01:00
- add 'editmeta' subcommand: Edit project/package meta information, creating
new project or package if it doesn't exist. The user interface is $EDITOR - gracedully handle unknown subcommands
This commit is contained in:
parent
773ae5b122
commit
17de02b604
@ -25,6 +25,7 @@ Available subcommands:
|
||||
checkin (ci)
|
||||
checkout (co)
|
||||
diff
|
||||
editmeta
|
||||
help
|
||||
history (hist)
|
||||
id
|
||||
@ -98,6 +99,29 @@ usage: meta Apache # show meta of project 'Apache'
|
||||
print ''.join(show_project_meta(project))
|
||||
|
||||
|
||||
def editmeta(args):
|
||||
"""Edit project/package meta information
|
||||
If the named project or package does not exist, it will be created.
|
||||
|
||||
usage: editmeta FooPrj # edit meta of project 'FooPrj'
|
||||
editmeta FooPrj barpackage # edit meta of package 'barpackage'
|
||||
"""
|
||||
|
||||
if not args:
|
||||
print 'missing argument'
|
||||
print meta.func_doc
|
||||
sys.exit(1)
|
||||
|
||||
if len(args) == 2:
|
||||
project = args[0]
|
||||
package = args[1]
|
||||
edit_meta(project, package)
|
||||
|
||||
elif len(args) == 1:
|
||||
project = args[0]
|
||||
edit_meta(project, None)
|
||||
|
||||
|
||||
def diff(args):
|
||||
"""diff: Generates a diff, to view the local changes
|
||||
|
||||
@ -536,6 +560,7 @@ cmd_dict = {
|
||||
'checkin': checkin,
|
||||
'checkout': checkout,
|
||||
'diff': diff,
|
||||
'editmeta': editmeta,
|
||||
'help': help,
|
||||
'history': history,
|
||||
'id': userid, # <- small difference here
|
||||
@ -569,6 +594,10 @@ def main():
|
||||
args = None
|
||||
|
||||
# run subcommand
|
||||
if cmd not in cmd_dict:
|
||||
print 'unknown command \'%s\'' % cmd
|
||||
print "Type 'osc help' for usage."
|
||||
sys.exit(1)
|
||||
cmd_dict[cmd](args)
|
||||
|
||||
|
||||
|
63
osc/core.py
63
osc/core.py
@ -26,6 +26,26 @@ store = '.osc'
|
||||
exclude_stuff = [store, '.svn', 'CVS']
|
||||
|
||||
|
||||
new_project_templ = """\
|
||||
<project name="NewProjectName">
|
||||
<title>Short title of NewProject</title>
|
||||
<description>This project aims at providing some foo and bar.
|
||||
|
||||
It also does some weird stuff.
|
||||
</description>
|
||||
<person role="maintainer" userid="%s" />
|
||||
</project>
|
||||
"""
|
||||
|
||||
new_package_templ = """\
|
||||
<package name="%s">
|
||||
<title>Title of NewPackage</title>
|
||||
<description>DESCIPTION</description>
|
||||
<person role="maintainer" userid="%s"/>
|
||||
</package>
|
||||
"""
|
||||
|
||||
|
||||
class File:
|
||||
"""represent a file, including its metadata"""
|
||||
def __init__(self, name, md5, size, mtime):
|
||||
@ -651,6 +671,49 @@ def show_package_meta(prj, pac):
|
||||
return f.readlines()
|
||||
|
||||
|
||||
def edit_meta(prj, pac):
|
||||
import othermethods
|
||||
import tempfile
|
||||
|
||||
(f, filename) = tempfile.mkstemp(prefix = 'osc_editmeta.', suffix = '.xml', dir = '/tmp')
|
||||
|
||||
if pac:
|
||||
u = makeurl(['source', prj, pac, '_meta'])
|
||||
try:
|
||||
m = show_package_meta(prj, pac)
|
||||
except urllib2.HTTPError, e:
|
||||
if e.code == 404:
|
||||
m = new_package_templ % (pac, username)
|
||||
|
||||
else:
|
||||
u = makeurl(['source', prj, '_meta'])
|
||||
try:
|
||||
m = show_project_meta(prj)
|
||||
except urllib2.HTTPError, e:
|
||||
if e.code == 404:
|
||||
m = new_project_templ % username
|
||||
|
||||
f = open(filename, 'w')
|
||||
f.write(''.join(m))
|
||||
f.close()
|
||||
|
||||
timestamp = os.stat(filename).st_mtime
|
||||
|
||||
editor = os.getenv('EDITOR', default='vim')
|
||||
os.system('%s %s' % (editor, filename))
|
||||
|
||||
if os.stat(filename).st_mtime == timestamp:
|
||||
print 'File unchanged. Not saving.'
|
||||
os.unlink(filename)
|
||||
|
||||
else:
|
||||
print 'Sending meta data...',
|
||||
othermethods.putfile(u, filename, username, password)
|
||||
os.unlink(filename)
|
||||
print 'Done.'
|
||||
|
||||
|
||||
|
||||
def show_files_meta(prj, pac):
|
||||
f = urllib2.urlopen(makeurl(['source', prj, pac]))
|
||||
return f.readlines()
|
||||
|
Loading…
x
Reference in New Issue
Block a user