1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-26 01:46:13 +01:00

- save the osclib version in the store directory

- adapt to the new deployed API version:
  - filelist is no longer in _meta, but comes seperately
  - now really DELETE files, now that it is supported
- 'update': fix handling of files that were deleted in the repository
- add TODO file
This commit is contained in:
Dr. Peter Poeml 2006-04-28 15:37:25 +00:00
parent 5ea51d3918
commit 4d02380352
3 changed files with 69 additions and 27 deletions

2
TODO Normal file
View File

@ -0,0 +1,2 @@
- implement 'info' command
- 'update': handle local modifications

29
osc.py
View File

@ -5,7 +5,6 @@
# and distributed under the terms of the GNU General Public Licence, # and distributed under the terms of the GNU General Public Licence,
# either version 2, or (at your option) any later version. # either version 2, or (at your option) any later version.
from osclib import * from osclib import *
@ -42,6 +41,7 @@ def main():
project = sys.argv[2] project = sys.argv[2]
package = sys.argv[3] package = sys.argv[3]
print ''.join(show_package_meta(project, package)) print ''.join(show_package_meta(project, package))
print ''.join(show_files_meta(project, package))
elif len(sys.argv) == 3: elif len(sys.argv) == 3:
project = sys.argv[2] project = sys.argv[2]
print ''.join(show_project_meta(project)) print ''.join(show_project_meta(project))
@ -107,6 +107,7 @@ def main():
filenames.insert(0, i) filenames.insert(0, i)
os.chdir(wd) os.chdir(wd)
check_store_version()
filelist = localmeta_get_filelist() filelist = localmeta_get_filelist()
for filename in filenames: for filename in filenames:
@ -211,11 +212,7 @@ def main():
for filename in files_to_delete: for filename in files_to_delete:
del_source_file(project, package, filename) del_source_file(project, package, filename)
print print
print 'Transmitting meta data ',
put_source_file(project, package, os.path.join(store, '_meta'))
print
elif cmd == 'up' or cmd == 'update': elif cmd == 'up' or cmd == 'update':
@ -234,7 +231,6 @@ def main():
wd = arg wd = arg
package = store_read_package(wd) package = store_read_package(wd)
project = store_read_project(wd) project = store_read_project(wd)
filenames = meta_get_filelist(project, package)
## add files which are not listed in _meta ## add files which are not listed in _meta
#for i in os.listdir(arg): #for i in os.listdir(arg):
@ -243,9 +239,30 @@ def main():
olddir = os.getcwd() olddir = os.getcwd()
os.chdir(wd) os.chdir(wd)
check_store_version()
# save filelist before replacing the meta file
filenames = localmeta_get_filelist()
os.chdir(store) os.chdir(store)
# update filelist
f = open('_files', 'w')
f.write(''.join(show_files_meta(project, package)))
f.close()
# which files do no longer exist upstream?
disappeared = []
upstream_files = meta_get_filelist(project, package)
for filename in filenames:
if filename not in upstream_files:
disappeared.append(filename)
for filename in filenames: for filename in filenames:
if filename in disappeared:
print 'D %s' % filename
os.unlink(filename)
continue
get_source_file(project, package, filename) get_source_file(project, package, filename)
wcfilename = os.path.join(os.pardir, os.path.basename(filename)) wcfilename = os.path.join(os.pardir, os.path.basename(filename))

View File

@ -5,6 +5,7 @@
# and distributed under the terms of the GNU General Public Licence, # and distributed under the terms of the GNU General Public Licence,
# either version 2, or (at your option) any later version. # either version 2, or (at your option) any later version.
__version__ = '0.2'
import os import os
import sys import sys
@ -77,13 +78,33 @@ def init_package_dir(project, package, dir):
f.write(package + '\n') f.write(package + '\n')
f.close f.close
f = open('_meta', 'w') f = open('_files', 'w')
f.write(''.join(show_package_meta(project, package))) f.write(''.join(show_files_meta(project, package)))
f.close()
f = open('_osclib_version', 'w')
f.write(__version__ + '\n')
f.close() f.close()
return return
def check_store_version():
try:
v = open(os.path.join(store, '_osclib_version')).read().strip()
except:
v = ''
if v != __version__:
print
print 'the osc metadata of your working copy'
print ' %s' % os.getcwd()
print 'has the wrong version (%s), should be %s' % (v, __version__)
print 'please do a fresh checkout'
print
sys.exit(1)
def meta_get_packagelist(prj): def meta_get_packagelist(prj):
reader = Sax2.Reader() reader = Sax2.Reader()
@ -100,13 +121,13 @@ def meta_get_packagelist(prj):
def meta_get_filelist(prj, package): def meta_get_filelist(prj, package):
reader = Sax2.Reader() reader = Sax2.Reader()
u = makeurl(['source', prj, package, '_meta']) u = makeurl(['source', prj, package])
f = urllib2.urlopen(u) f = urllib2.urlopen(u)
doc = reader.fromStream(f) doc = reader.fromStream(f)
r = [] r = []
for i in doc.getElementsByTagName('file'): for i in doc.getElementsByTagName('entry'):
r.append(i.getAttribute('filename')) r.append(i.getAttribute('name'))
return r return r
@ -116,29 +137,29 @@ def localmeta_addfile(filename):
return return
reader = Sax2.Reader() reader = Sax2.Reader()
f = open(os.path.join(store, '_meta')).read() f = open(os.path.join(store, '_files')).read()
doc = reader.fromString(f) doc = reader.fromString(f)
new = doc.createElement('file') new = doc.createElement('entry')
new.setAttribute('filetype', 'source') #new.setAttribute('filetype', 'source')
new.setAttribute('filename', filename) new.setAttribute('name', filename)
doc.documentElement.appendChild(new) doc.documentElement.appendChild(new)
o = open(os.path.join(store, '_meta'), 'w') o = open(os.path.join(store, '_files'), 'w')
PrettyPrint(doc, stream=o) PrettyPrint(doc, stream=o)
o.close() o.close()
def localmeta_removefile(filename): def localmeta_removefile(filename):
reader = Sax2.Reader() reader = Sax2.Reader()
f = open(os.path.join(store, '_meta')).read() f = open(os.path.join(store, '_files')).read()
doc = reader.fromString(f) doc = reader.fromString(f)
for i in doc.getElementsByTagName('file'): for i in doc.getElementsByTagName('entry'):
if i.getAttribute('filename') == filename: if i.getAttribute('name') == filename:
i.parentNode.removeChild(i) i.parentNode.removeChild(i)
o = open(os.path.join(store, '_meta'), 'w') o = open(os.path.join(store, '_files'), 'w')
PrettyPrint(doc, stream=o) PrettyPrint(doc, stream=o)
o.close() o.close()
@ -146,12 +167,12 @@ def localmeta_removefile(filename):
def localmeta_get_filelist(): def localmeta_get_filelist():
reader = Sax2.Reader() reader = Sax2.Reader()
f = open(os.path.join(store, '_meta')).read() f = open(os.path.join(store, '_files')).read()
doc = reader.fromString(f) doc = reader.fromString(f)
r = [] r = []
for i in doc.getElementsByTagName('file'): for i in doc.getElementsByTagName('entry'):
r.append(i.getAttribute('filename')) r.append(i.getAttribute('name'))
return r return r
@ -175,6 +196,10 @@ def show_package_meta(prj, pac):
f = urllib2.urlopen(makeurl(['source', prj, pac, '_meta'])) f = urllib2.urlopen(makeurl(['source', prj, pac, '_meta']))
return f.readlines() return f.readlines()
def show_files_meta(prj, pac):
f = urllib2.urlopen(makeurl(['source', prj, pac]))
return f.readlines()
def get_user_id(user): def get_user_id(user):
u = makeurl(['person', user]) u = makeurl(['person', user])
f = urllib2.urlopen(u) f = urllib2.urlopen(u)
@ -215,7 +240,7 @@ def get_file_status(prj, package, filename, filelist=None):
status can be: status can be:
file storefile file present STATUS file storefile file present STATUS
exists exists in _meta exists exists in _files
x x - 'D' x x - 'D'
x x x 'M', if digest differs, else ' ' x x x 'M', if digest differs, else ' '
@ -313,9 +338,7 @@ def del_source_file(prj, package, filename):
import othermethods import othermethods
u = makeurl(['source', prj, package, filename]) u = makeurl(['source', prj, package, filename])
# not implemented in the server yet... thus, we are cheating by only removing othermethods.delfile(u, filename, username, password)
# the file from _meta
#othermethods.delfile(u, filename, username, password)
wcfilename = os.path.join(store, filename) wcfilename = os.path.join(store, filename)
if os.path.exists(filename): os.unlink(filename) if os.path.exists(filename): os.unlink(filename)