mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-25 17:36: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:
parent
5ea51d3918
commit
4d02380352
2
TODO
Normal file
2
TODO
Normal file
@ -0,0 +1,2 @@
|
||||
- implement 'info' command
|
||||
- 'update': handle local modifications
|
29
osc.py
29
osc.py
@ -5,7 +5,6 @@
|
||||
# and distributed under the terms of the GNU General Public Licence,
|
||||
# either version 2, or (at your option) any later version.
|
||||
|
||||
|
||||
from osclib import *
|
||||
|
||||
|
||||
@ -42,6 +41,7 @@ def main():
|
||||
project = sys.argv[2]
|
||||
package = sys.argv[3]
|
||||
print ''.join(show_package_meta(project, package))
|
||||
print ''.join(show_files_meta(project, package))
|
||||
elif len(sys.argv) == 3:
|
||||
project = sys.argv[2]
|
||||
print ''.join(show_project_meta(project))
|
||||
@ -107,6 +107,7 @@ def main():
|
||||
filenames.insert(0, i)
|
||||
|
||||
os.chdir(wd)
|
||||
check_store_version()
|
||||
|
||||
filelist = localmeta_get_filelist()
|
||||
for filename in filenames:
|
||||
@ -211,11 +212,7 @@ def main():
|
||||
for filename in files_to_delete:
|
||||
del_source_file(project, package, filename)
|
||||
print
|
||||
print 'Transmitting meta data ',
|
||||
put_source_file(project, package, os.path.join(store, '_meta'))
|
||||
|
||||
print
|
||||
|
||||
|
||||
elif cmd == 'up' or cmd == 'update':
|
||||
|
||||
@ -234,7 +231,6 @@ def main():
|
||||
wd = arg
|
||||
package = store_read_package(wd)
|
||||
project = store_read_project(wd)
|
||||
filenames = meta_get_filelist(project, package)
|
||||
|
||||
## add files which are not listed in _meta
|
||||
#for i in os.listdir(arg):
|
||||
@ -243,9 +239,30 @@ def main():
|
||||
|
||||
olddir = os.getcwd()
|
||||
os.chdir(wd)
|
||||
check_store_version()
|
||||
|
||||
# save filelist before replacing the meta file
|
||||
filenames = localmeta_get_filelist()
|
||||
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:
|
||||
if filename in disappeared:
|
||||
print 'D %s' % filename
|
||||
os.unlink(filename)
|
||||
continue
|
||||
|
||||
get_source_file(project, package, filename)
|
||||
wcfilename = os.path.join(os.pardir, os.path.basename(filename))
|
||||
|
||||
|
65
osclib.py
65
osclib.py
@ -5,6 +5,7 @@
|
||||
# and distributed under the terms of the GNU General Public Licence,
|
||||
# either version 2, or (at your option) any later version.
|
||||
|
||||
__version__ = '0.2'
|
||||
|
||||
import os
|
||||
import sys
|
||||
@ -77,13 +78,33 @@ def init_package_dir(project, package, dir):
|
||||
f.write(package + '\n')
|
||||
f.close
|
||||
|
||||
f = open('_meta', 'w')
|
||||
f.write(''.join(show_package_meta(project, package)))
|
||||
f = open('_files', 'w')
|
||||
f.write(''.join(show_files_meta(project, package)))
|
||||
f.close()
|
||||
|
||||
f = open('_osclib_version', 'w')
|
||||
f.write(__version__ + '\n')
|
||||
f.close()
|
||||
|
||||
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):
|
||||
|
||||
reader = Sax2.Reader()
|
||||
@ -100,13 +121,13 @@ def meta_get_packagelist(prj):
|
||||
def meta_get_filelist(prj, package):
|
||||
|
||||
reader = Sax2.Reader()
|
||||
u = makeurl(['source', prj, package, '_meta'])
|
||||
u = makeurl(['source', prj, package])
|
||||
f = urllib2.urlopen(u)
|
||||
doc = reader.fromStream(f)
|
||||
|
||||
r = []
|
||||
for i in doc.getElementsByTagName('file'):
|
||||
r.append(i.getAttribute('filename'))
|
||||
for i in doc.getElementsByTagName('entry'):
|
||||
r.append(i.getAttribute('name'))
|
||||
return r
|
||||
|
||||
|
||||
@ -116,29 +137,29 @@ def localmeta_addfile(filename):
|
||||
return
|
||||
|
||||
reader = Sax2.Reader()
|
||||
f = open(os.path.join(store, '_meta')).read()
|
||||
f = open(os.path.join(store, '_files')).read()
|
||||
doc = reader.fromString(f)
|
||||
|
||||
new = doc.createElement('file')
|
||||
new.setAttribute('filetype', 'source')
|
||||
new.setAttribute('filename', filename)
|
||||
new = doc.createElement('entry')
|
||||
#new.setAttribute('filetype', 'source')
|
||||
new.setAttribute('name', filename)
|
||||
doc.documentElement.appendChild(new)
|
||||
|
||||
o = open(os.path.join(store, '_meta'), 'w')
|
||||
o = open(os.path.join(store, '_files'), 'w')
|
||||
PrettyPrint(doc, stream=o)
|
||||
o.close()
|
||||
|
||||
def localmeta_removefile(filename):
|
||||
|
||||
reader = Sax2.Reader()
|
||||
f = open(os.path.join(store, '_meta')).read()
|
||||
f = open(os.path.join(store, '_files')).read()
|
||||
doc = reader.fromString(f)
|
||||
|
||||
for i in doc.getElementsByTagName('file'):
|
||||
if i.getAttribute('filename') == filename:
|
||||
for i in doc.getElementsByTagName('entry'):
|
||||
if i.getAttribute('name') == filename:
|
||||
i.parentNode.removeChild(i)
|
||||
|
||||
o = open(os.path.join(store, '_meta'), 'w')
|
||||
o = open(os.path.join(store, '_files'), 'w')
|
||||
PrettyPrint(doc, stream=o)
|
||||
o.close()
|
||||
|
||||
@ -146,12 +167,12 @@ def localmeta_removefile(filename):
|
||||
def localmeta_get_filelist():
|
||||
|
||||
reader = Sax2.Reader()
|
||||
f = open(os.path.join(store, '_meta')).read()
|
||||
f = open(os.path.join(store, '_files')).read()
|
||||
doc = reader.fromString(f)
|
||||
|
||||
r = []
|
||||
for i in doc.getElementsByTagName('file'):
|
||||
r.append(i.getAttribute('filename'))
|
||||
for i in doc.getElementsByTagName('entry'):
|
||||
r.append(i.getAttribute('name'))
|
||||
return r
|
||||
|
||||
|
||||
@ -175,6 +196,10 @@ def show_package_meta(prj, pac):
|
||||
f = urllib2.urlopen(makeurl(['source', prj, pac, '_meta']))
|
||||
return f.readlines()
|
||||
|
||||
def show_files_meta(prj, pac):
|
||||
f = urllib2.urlopen(makeurl(['source', prj, pac]))
|
||||
return f.readlines()
|
||||
|
||||
def get_user_id(user):
|
||||
u = makeurl(['person', user])
|
||||
f = urllib2.urlopen(u)
|
||||
@ -215,7 +240,7 @@ def get_file_status(prj, package, filename, filelist=None):
|
||||
status can be:
|
||||
|
||||
file storefile file present STATUS
|
||||
exists exists in _meta
|
||||
exists exists in _files
|
||||
|
||||
x x - 'D'
|
||||
x x x 'M', if digest differs, else ' '
|
||||
@ -313,9 +338,7 @@ def del_source_file(prj, package, filename):
|
||||
import othermethods
|
||||
|
||||
u = makeurl(['source', prj, package, filename])
|
||||
# not implemented in the server yet... thus, we are cheating by only removing
|
||||
# the file from _meta
|
||||
#othermethods.delfile(u, filename, username, password)
|
||||
othermethods.delfile(u, filename, username, password)
|
||||
|
||||
wcfilename = os.path.join(store, filename)
|
||||
if os.path.exists(filename): os.unlink(filename)
|
||||
|
Loading…
Reference in New Issue
Block a user