mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-04 02:26:16 +01:00
- add a tentative 'updatepacmetafromspec' subcommand, which takes package
metadata from a specfile - handle HTTP error codes != 404 when reading metadata in edit_meta()
This commit is contained in:
parent
2b6cd72037
commit
b9f53cbfb7
6
TODO
6
TODO
@ -30,3 +30,9 @@ split functionality that needs prj/pac as commandline arguments into a seperate
|
|||||||
implement a package search / indexing
|
implement a package search / indexing
|
||||||
|
|
||||||
|
|
||||||
|
> BTW: Can I upload a src.rpm instead of a tarball also?
|
||||||
|
no, because not all tools will be able to handle a src.rpm. And you will not
|
||||||
|
be able to build non rpm packages from it.
|
||||||
|
But someone could patch the commandline tool osc to import a src.rpm by
|
||||||
|
extracting it (hint hint ;)
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ Available subcommands:
|
|||||||
results_meta
|
results_meta
|
||||||
status (st)
|
status (st)
|
||||||
update (up)
|
update (up)
|
||||||
|
updatepacmetafromspec
|
||||||
|
|
||||||
""" % get_osc_version()
|
""" % get_osc_version()
|
||||||
|
|
||||||
@ -122,6 +123,21 @@ usage: editmeta FooPrj # edit meta of project 'FooPrj'
|
|||||||
edit_meta(project, None)
|
edit_meta(project, None)
|
||||||
|
|
||||||
|
|
||||||
|
def updatepacmetafromspec(args):
|
||||||
|
"""Update package meta information from a specfile
|
||||||
|
|
||||||
|
usage: 1. updatepacmetafromspec # current dir
|
||||||
|
2. updatepacmetafromspec dir1 dir2 ...
|
||||||
|
"""
|
||||||
|
args = parseargs(args)
|
||||||
|
pacs = findpacs(args)
|
||||||
|
|
||||||
|
for p in pacs:
|
||||||
|
|
||||||
|
p.read_meta_from_spec()
|
||||||
|
p.update_pac_meta()
|
||||||
|
|
||||||
|
|
||||||
def diff(args):
|
def diff(args):
|
||||||
"""diff: Generates a diff, to view the local changes
|
"""diff: Generates a diff, to view the local changes
|
||||||
|
|
||||||
@ -563,6 +579,7 @@ cmd_dict = {
|
|||||||
'addremove': addremove,
|
'addremove': addremove,
|
||||||
'checkin': checkin,
|
'checkin': checkin,
|
||||||
'checkout': checkout,
|
'checkout': checkout,
|
||||||
|
'updatepacmetafromspec': updatepacmetafromspec,
|
||||||
'diff': diff,
|
'diff': diff,
|
||||||
'editmeta': editmeta,
|
'editmeta': editmeta,
|
||||||
'help': help,
|
'help': help,
|
||||||
|
71
osc/core.py
71
osc/core.py
@ -358,6 +358,66 @@ rev: %s
|
|||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
def read_meta_from_spec(self):
|
||||||
|
specfile = os.path.join(self.dir, self.name + '.spec')
|
||||||
|
name, summary, descr = read_meta_from_spec(specfile)
|
||||||
|
|
||||||
|
if name != self.name:
|
||||||
|
print 'name from spec does not match name of package... this is probably a problem'
|
||||||
|
sys.exit(1)
|
||||||
|
self.summary = summary
|
||||||
|
self.descr = descr
|
||||||
|
|
||||||
|
|
||||||
|
def update_pac_meta(self):
|
||||||
|
import othermethods
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
(f, filename) = tempfile.mkstemp(prefix = 'osc_editmeta.', suffix = '.xml', dir = '/tmp')
|
||||||
|
|
||||||
|
try:
|
||||||
|
m = show_package_meta(self.prjname, self.name)
|
||||||
|
except urllib2.HTTPError, e:
|
||||||
|
if e.code == 404:
|
||||||
|
print 'package does not exist yet... creating it'
|
||||||
|
m = new_package_templ % (pac, username)
|
||||||
|
else:
|
||||||
|
print 'error getting package meta for project \'%s\' package \'%s\':' % (prj, pac)
|
||||||
|
print e
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
f = open(filename, 'w')
|
||||||
|
f.write(''.join(m))
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
tree = ET.parse(filename)
|
||||||
|
tree.find('title').text = self.summary
|
||||||
|
tree.find('description').text = ''.join(self.descr)
|
||||||
|
tree.write(filename)
|
||||||
|
|
||||||
|
# FIXME: escape stuff for xml
|
||||||
|
print '*' * 36, 'old', '*' * 36
|
||||||
|
print ''.join(m)
|
||||||
|
print '*' * 36, 'new', '*' * 36
|
||||||
|
tree.write(sys.stdout)
|
||||||
|
print '*' * 72
|
||||||
|
|
||||||
|
# FIXME: for testing...
|
||||||
|
# open the new description in $EDITOR instead?
|
||||||
|
repl = raw_input('Write? (y/N) ')
|
||||||
|
if repl == 'y':
|
||||||
|
print 'Sending meta data...',
|
||||||
|
u = makeurl(['source', self.prjname, self.name, '_meta'])
|
||||||
|
othermethods.putfile(u, filename, username, password)
|
||||||
|
print 'Done.'
|
||||||
|
else:
|
||||||
|
print 'discarding', filename
|
||||||
|
|
||||||
|
os.unlink(filename)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def is_project_dir(d):
|
def is_project_dir(d):
|
||||||
if os.path.exists(os.path.join(d, store, '_project')) and not \
|
if os.path.exists(os.path.join(d, store, '_project')) and not \
|
||||||
os.path.exists(os.path.join(d, store, '_package')):
|
os.path.exists(os.path.join(d, store, '_package')):
|
||||||
@ -685,20 +745,30 @@ def edit_meta(prj, pac):
|
|||||||
(f, filename) = tempfile.mkstemp(prefix = 'osc_editmeta.', suffix = '.xml', dir = '/tmp')
|
(f, filename) = tempfile.mkstemp(prefix = 'osc_editmeta.', suffix = '.xml', dir = '/tmp')
|
||||||
|
|
||||||
if pac:
|
if pac:
|
||||||
|
# package meta
|
||||||
u = makeurl(['source', prj, pac, '_meta'])
|
u = makeurl(['source', prj, pac, '_meta'])
|
||||||
try:
|
try:
|
||||||
m = show_package_meta(prj, pac)
|
m = show_package_meta(prj, pac)
|
||||||
except urllib2.HTTPError, e:
|
except urllib2.HTTPError, e:
|
||||||
if e.code == 404:
|
if e.code == 404:
|
||||||
m = new_package_templ % (pac, username)
|
m = new_package_templ % (pac, username)
|
||||||
|
else:
|
||||||
|
print 'error getting package meta for project \'%s\' package \'%s\':' % (prj, pac)
|
||||||
|
print e
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
# project meta
|
||||||
u = makeurl(['source', prj, '_meta'])
|
u = makeurl(['source', prj, '_meta'])
|
||||||
try:
|
try:
|
||||||
m = show_project_meta(prj)
|
m = show_project_meta(prj)
|
||||||
except urllib2.HTTPError, e:
|
except urllib2.HTTPError, e:
|
||||||
if e.code == 404:
|
if e.code == 404:
|
||||||
m = new_project_templ % (prj, username)
|
m = new_project_templ % (prj, username)
|
||||||
|
else:
|
||||||
|
print 'error getting package meta for project \'%s\':' % prj
|
||||||
|
print e
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
f = open(filename, 'w')
|
f = open(filename, 'w')
|
||||||
f.write(''.join(m))
|
f.write(''.join(m))
|
||||||
@ -720,7 +790,6 @@ def edit_meta(prj, pac):
|
|||||||
print 'Done.'
|
print 'Done.'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def show_files_meta(prj, pac):
|
def show_files_meta(prj, pac):
|
||||||
f = urllib2.urlopen(makeurl(['source', prj, pac]))
|
f = urllib2.urlopen(makeurl(['source', prj, pac]))
|
||||||
return f.readlines()
|
return f.readlines()
|
||||||
|
Loading…
Reference in New Issue
Block a user