1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-10 06:46:15 +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:
Dr. Peter Poeml 2006-05-31 12:13:26 +00:00
parent 2b6cd72037
commit b9f53cbfb7
3 changed files with 93 additions and 1 deletions

6
TODO
View File

@ -30,3 +30,9 @@ split functionality that needs prj/pac as commandline arguments into a seperate
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 ;)

View File

@ -39,6 +39,7 @@ Available subcommands:
results_meta
status (st)
update (up)
updatepacmetafromspec
""" % get_osc_version()
@ -122,6 +123,21 @@ usage: editmeta FooPrj # edit meta of project 'FooPrj'
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):
"""diff: Generates a diff, to view the local changes
@ -563,6 +579,7 @@ cmd_dict = {
'addremove': addremove,
'checkin': checkin,
'checkout': checkout,
'updatepacmetafromspec': updatepacmetafromspec,
'diff': diff,
'editmeta': editmeta,
'help': help,

View File

@ -358,6 +358,66 @@ rev: %s
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):
if os.path.exists(os.path.join(d, store, '_project')) and not \
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')
if pac:
# package meta
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:
print 'error getting package meta for project \'%s\' package \'%s\':' % (prj, pac)
print e
sys.exit(1)
else:
# project meta
u = makeurl(['source', prj, '_meta'])
try:
m = show_project_meta(prj)
except urllib2.HTTPError, e:
if e.code == 404:
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.write(''.join(m))
@ -720,7 +790,6 @@ def edit_meta(prj, pac):
print 'Done.'
def show_files_meta(prj, pac):
f = urllib2.urlopen(makeurl(['source', prj, pac]))
return f.readlines()