mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-13 01:06:15 +01:00
- update: support special handling for _service: files
This commit is contained in:
parent
63df61e452
commit
d8c59c8438
39
osc/core.py
39
osc/core.py
@ -1254,7 +1254,7 @@ class Package:
|
|||||||
state = 'D'
|
state = 'D'
|
||||||
elif n in self.in_conflict:
|
elif n in self.in_conflict:
|
||||||
state = 'C'
|
state = 'C'
|
||||||
elif n in self.skipped or n.startswith('_service:'):
|
elif n in self.skipped:
|
||||||
state = 'S'
|
state = 'S'
|
||||||
elif exists and exists_in_store and not known_by_meta:
|
elif exists and exists_in_store and not known_by_meta:
|
||||||
state = 'A'
|
state = 'A'
|
||||||
@ -1460,11 +1460,15 @@ rev: %s
|
|||||||
kept = []
|
kept = []
|
||||||
added = []
|
added = []
|
||||||
deleted = []
|
deleted = []
|
||||||
|
services = []
|
||||||
revfilenames = []
|
revfilenames = []
|
||||||
for f in revfiles:
|
for f in revfiles:
|
||||||
revfilenames.append(f.name)
|
revfilenames.append(f.name)
|
||||||
# treat skipped like deleted files
|
# treat skipped like deleted files
|
||||||
if f.skipped:
|
if f.skipped:
|
||||||
|
if f.name.startswith('_service:'):
|
||||||
|
services.append(f)
|
||||||
|
else:
|
||||||
deleted.append(f)
|
deleted.append(f)
|
||||||
continue
|
continue
|
||||||
# treat skipped like added files
|
# treat skipped like added files
|
||||||
@ -1478,7 +1482,7 @@ rev: %s
|
|||||||
if not f.name in revfilenames:
|
if not f.name in revfilenames:
|
||||||
deleted.append(f)
|
deleted.append(f)
|
||||||
|
|
||||||
return kept, added, deleted
|
return kept, added, deleted, services
|
||||||
|
|
||||||
def update(self, rev = None, service_files = False, limit_size = None):
|
def update(self, rev = None, service_files = False, limit_size = None):
|
||||||
import tempfile
|
import tempfile
|
||||||
@ -1487,7 +1491,7 @@ rev: %s
|
|||||||
print 'resuming broken update...'
|
print 'resuming broken update...'
|
||||||
root = ET.parse(os.path.join(self.storedir, '_in_update', '_files')).getroot()
|
root = ET.parse(os.path.join(self.storedir, '_in_update', '_files')).getroot()
|
||||||
rfiles = self.__get_files(root)
|
rfiles = self.__get_files(root)
|
||||||
kept, added, deleted = self.__get_rev_changes(rfiles)
|
kept, added, deleted, services = self.__get_rev_changes(rfiles)
|
||||||
# check if we aborted in the middle of a file update
|
# check if we aborted in the middle of a file update
|
||||||
broken_file = os.listdir(os.path.join(self.storedir, '_in_update'))
|
broken_file = os.listdir(os.path.join(self.storedir, '_in_update'))
|
||||||
broken_file.remove('_files')
|
broken_file.remove('_files')
|
||||||
@ -1532,7 +1536,9 @@ rev: %s
|
|||||||
# this can't happen
|
# this can't happen
|
||||||
elif f in deleted:
|
elif f in deleted:
|
||||||
deleted.remove(f)
|
deleted.remove(f)
|
||||||
self.__update(kept, added, deleted, ET.tostring(root), root.get('rev'), service_files)
|
if not service_files:
|
||||||
|
services = []
|
||||||
|
self.__update(kept, added, deleted, services, ET.tostring(root), root.get('rev'))
|
||||||
os.unlink(os.path.join(self.storedir, '_in_update', '_files'))
|
os.unlink(os.path.join(self.storedir, '_in_update', '_files'))
|
||||||
os.rmdir(os.path.join(self.storedir, '_in_update'))
|
os.rmdir(os.path.join(self.storedir, '_in_update'))
|
||||||
# ok everything is ok (hopefully)...
|
# ok everything is ok (hopefully)...
|
||||||
@ -1540,13 +1546,15 @@ rev: %s
|
|||||||
root = ET.fromstring(fm)
|
root = ET.fromstring(fm)
|
||||||
rfiles = self.__get_files(root)
|
rfiles = self.__get_files(root)
|
||||||
store_write_string(self.absdir, '_files', fm, subdir='_in_update')
|
store_write_string(self.absdir, '_files', fm, subdir='_in_update')
|
||||||
kept, added, deleted = self.__get_rev_changes(rfiles)
|
kept, added, deleted, services = self.__get_rev_changes(rfiles)
|
||||||
self.__update(kept, added, deleted, fm, root.get('rev'), service_files)
|
if not service_files:
|
||||||
|
services = []
|
||||||
|
self.__update(kept, added, deleted, services, fm, root.get('rev'))
|
||||||
os.unlink(os.path.join(self.storedir, '_in_update', '_files'))
|
os.unlink(os.path.join(self.storedir, '_in_update', '_files'))
|
||||||
if os.path.isdir(os.path.join(self.storedir, '_in_update')):
|
if os.path.isdir(os.path.join(self.storedir, '_in_update')):
|
||||||
os.rmdir(os.path.join(self.storedir, '_in_update'))
|
os.rmdir(os.path.join(self.storedir, '_in_update'))
|
||||||
|
|
||||||
def __update(self, kept, added, deleted, fm, rev, service_files = False):
|
def __update(self, kept, added, deleted, services, fm, rev):
|
||||||
pathn = getTransActPath(self.dir)
|
pathn = getTransActPath(self.dir)
|
||||||
# check for conflicts with existing files
|
# check for conflicts with existing files
|
||||||
for f in added:
|
for f in added:
|
||||||
@ -1560,6 +1568,7 @@ rev: %s
|
|||||||
for f in deleted:
|
for f in deleted:
|
||||||
# if the storefile doesn't exist we're resuming an aborted update:
|
# if the storefile doesn't exist we're resuming an aborted update:
|
||||||
# the file was already deleted but we cannot know this
|
# the file was already deleted but we cannot know this
|
||||||
|
# OR we're processing a _service: file (simply keep the file)
|
||||||
if os.path.isfile(os.path.join(self.storedir, f.name)) and self.status(f.name) != 'M':
|
if os.path.isfile(os.path.join(self.storedir, f.name)) and self.status(f.name) != 'M':
|
||||||
# if self.status(f.name) != 'M':
|
# if self.status(f.name) != 'M':
|
||||||
self.delete_localfile(f.name)
|
self.delete_localfile(f.name)
|
||||||
@ -1605,6 +1614,13 @@ rev: %s
|
|||||||
elif state == ' ' and self.findfilebyname(f.name).md5 != f.md5:
|
elif state == ' ' and self.findfilebyname(f.name).md5 != f.md5:
|
||||||
self.updatefile(f.name, rev, f.mtime)
|
self.updatefile(f.name, rev, f.mtime)
|
||||||
print statfrmt('U', os.path.join(pathn, f.name))
|
print statfrmt('U', os.path.join(pathn, f.name))
|
||||||
|
|
||||||
|
# checkout service files
|
||||||
|
for f in services:
|
||||||
|
get_source_file(self.apiurl, self.prjname, self.name, f.name,
|
||||||
|
targetfilename=os.path.join(self.absdir, f.name), revision=rev,
|
||||||
|
progress_obj=self.progress_obj, mtime=f.mtime, meta=self.meta)
|
||||||
|
print statfrmt('A', os.path.join(pathn, f.name))
|
||||||
store_write_string(self.absdir, '_files', fm)
|
store_write_string(self.absdir, '_files', fm)
|
||||||
self.update_local_pacmeta()
|
self.update_local_pacmeta()
|
||||||
self.update_datastructs()
|
self.update_datastructs()
|
||||||
@ -2684,7 +2700,7 @@ def edit_meta(metatype,
|
|||||||
f.sync()
|
f.sync()
|
||||||
|
|
||||||
|
|
||||||
def show_files_meta(apiurl, prj, pac, revision=None, expand=False, linkrev=None, linkrepair=False, limit_size=None, meta=False):
|
def show_files_meta(apiurl, prj, pac, revision=None, expand=False, linkrev=None, linkrepair=False, limit_size=None, meta=False, skip_service=True):
|
||||||
query = {}
|
query = {}
|
||||||
if revision:
|
if revision:
|
||||||
query['rev'] = revision
|
query['rev'] = revision
|
||||||
@ -2705,7 +2721,8 @@ def show_files_meta(apiurl, prj, pac, revision=None, expand=False, linkrev=None,
|
|||||||
root = ET.fromstring(''.join(f.readlines()))
|
root = ET.fromstring(''.join(f.readlines()))
|
||||||
for e in root.findall('entry'):
|
for e in root.findall('entry'):
|
||||||
size = e.get('size')
|
size = e.get('size')
|
||||||
if size and limit_size and int(size) > int(limit_size):
|
if size and limit_size and int(size) > int(limit_size) \
|
||||||
|
or skip_service and (e.get('name').startswith('_service:') or e.get('name').startswith('_service_')):
|
||||||
e.set('skipped', 'true')
|
e.set('skipped', 'true')
|
||||||
return ET.tostring(root)
|
return ET.tostring(root)
|
||||||
|
|
||||||
@ -5139,8 +5156,8 @@ def getStatus(pacs, prj_obj=None, verbose=False, quiet=False, excluded=False):
|
|||||||
lines.append(statfrmt(state, os.path.normpath(os.path.join(prj_obj.dir, p.name))))
|
lines.append(statfrmt(state, os.path.normpath(os.path.join(prj_obj.dir, p.name))))
|
||||||
|
|
||||||
for filename in p.todo:
|
for filename in p.todo:
|
||||||
if filename.startswith('_service:'):
|
# if filename.startswith('_service:'):
|
||||||
continue
|
# continue
|
||||||
if filename in p.excluded and not excluded:
|
if filename in p.excluded and not excluded:
|
||||||
continue
|
continue
|
||||||
# if filename in p.skipped:
|
# if filename in p.skipped:
|
||||||
|
@ -233,6 +233,29 @@ class TestUpdate(unittest.TestCase):
|
|||||||
|
|
||||||
self.__check_digests('testUpdateLimitSizeAddDelete_files', 'bigfile', 'foo', 'merge', 'nochange')
|
self.__check_digests('testUpdateLimitSizeAddDelete_files', 'bigfile', 'foo', 'merge', 'nochange')
|
||||||
|
|
||||||
|
@GET('http://localhost/source/osctest/services?rev=latest', file='testUpdateServiceFilesAddDelete_filesremote')
|
||||||
|
@GET('http://localhost/source/osctest/services/bigfile?rev=2', file='testUpdateServiceFilesAddDelete_bigfile')
|
||||||
|
@GET('http://localhost/source/osctest/services/_service%3Abar?rev=2', file='testUpdateServiceFilesAddDelete__service:bar')
|
||||||
|
@GET('http://localhost/source/osctest/services/_service%3Afoo?rev=2', file='testUpdateServiceFilesAddDelete__service:foo')
|
||||||
|
@GET('http://localhost/source/osctest/services/_meta', file='meta.xml')
|
||||||
|
def testUpdateAddDeleteServiceFiles(self):
|
||||||
|
"""
|
||||||
|
a new file was added to the remote package but isn't checked out because
|
||||||
|
of the size constraint
|
||||||
|
"""
|
||||||
|
self.__change_to_pkg('services')
|
||||||
|
osc.core.Package('.').update(service_files=True)
|
||||||
|
exp = 'A bigfile\nD _service:exists\nA _service:bar\nA _service:foo\nAt revision 2.\n'
|
||||||
|
self.assertEqual(sys.stdout.getvalue(), exp)
|
||||||
|
self.assertFalse(os.path.exists(os.path.join('.osc', '_service:bar')))
|
||||||
|
self.assertTrue(os.path.exists('_service:bar'))
|
||||||
|
self.assertEqual(open('_service:bar').read(), 'another service\n')
|
||||||
|
self.assertFalse(os.path.exists(os.path.join('.osc', '_service:foo')))
|
||||||
|
self.assertTrue(os.path.exists('_service:foo'))
|
||||||
|
self.assertEqual(open('_service:foo').read(), 'small\n')
|
||||||
|
self.assertTrue(os.path.exists('_service:exists'))
|
||||||
|
self.__check_digests('testUpdateServiceFilesAddDelete_files', '_service:foo', '_service:bar')
|
||||||
|
|
||||||
# tests to recover from an aborted/broken update
|
# tests to recover from an aborted/broken update
|
||||||
|
|
||||||
@GET('http://localhost/source/osctest/simple/foo?rev=2', file='testUpdateResume_foo')
|
@GET('http://localhost/source/osctest/simple/foo?rev=2', file='testUpdateResume_foo')
|
||||||
|
1
tests/update_fixtures/osctest/services/.osc/_apiurl
Normal file
1
tests/update_fixtures/osctest/services/.osc/_apiurl
Normal file
@ -0,0 +1 @@
|
|||||||
|
http://localhost
|
5
tests/update_fixtures/osctest/services/.osc/_files
Normal file
5
tests/update_fixtures/osctest/services/.osc/_files
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<directory name="foo" rev="1" srcmd5="b9f060f4b3640e58a1d44abc25ffb9bd" vrev="1">
|
||||||
|
<entry md5="7b1458c733a187d4f3807665ddd02cca" mtime="1282565027" name="_service:exists" size="20" skipped="true" />
|
||||||
|
<entry md5="0d62ceea6020d75154078a20d8c9f9ba" mtime="1282320303" name="foo" size="23" />
|
||||||
|
<entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" mtime="1282320303" name="merge" size="48" />
|
||||||
|
</directory>
|
@ -0,0 +1 @@
|
|||||||
|
1.0
|
1
tests/update_fixtures/osctest/services/.osc/_package
Normal file
1
tests/update_fixtures/osctest/services/.osc/_package
Normal file
@ -0,0 +1 @@
|
|||||||
|
services
|
1
tests/update_fixtures/osctest/services/.osc/_project
Normal file
1
tests/update_fixtures/osctest/services/.osc/_project
Normal file
@ -0,0 +1 @@
|
|||||||
|
osctest
|
1
tests/update_fixtures/osctest/services/.osc/foo
Normal file
1
tests/update_fixtures/osctest/services/.osc/foo
Normal file
@ -0,0 +1 @@
|
|||||||
|
This is a simple test.
|
4
tests/update_fixtures/osctest/services/.osc/merge
Normal file
4
tests/update_fixtures/osctest/services/.osc/merge
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Is it
|
||||||
|
possible to
|
||||||
|
merge this file?
|
||||||
|
I hope so...
|
2
tests/update_fixtures/osctest/services/_service:exists
Normal file
2
tests/update_fixtures/osctest/services/_service:exists
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
another service
|
||||||
|
foo
|
1
tests/update_fixtures/osctest/services/foo
Normal file
1
tests/update_fixtures/osctest/services/foo
Normal file
@ -0,0 +1 @@
|
|||||||
|
This is a simple test.
|
4
tests/update_fixtures/osctest/services/merge
Normal file
4
tests/update_fixtures/osctest/services/merge
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Is it
|
||||||
|
possible to
|
||||||
|
merge this file?
|
||||||
|
I hope so...
|
@ -0,0 +1 @@
|
|||||||
|
another service
|
@ -0,0 +1 @@
|
|||||||
|
small
|
@ -0,0 +1,5 @@
|
|||||||
|
This is a file
|
||||||
|
with a lot of
|
||||||
|
text. Foo foo
|
||||||
|
bar bar bar.
|
||||||
|
foobarfoobar
|
@ -0,0 +1,7 @@
|
|||||||
|
<directory name="foo" rev="2" srcmd5="1c5d541a029694c43d5341cabcb4f40f" vrev="2">
|
||||||
|
<entry md5="a0106bad78c9070662d5cde42ee35f23" mtime="1282564656" name="_service:bar" size="16" skipped="true" />
|
||||||
|
<entry md5="d15dbfcb847653913855e21370d83af1" mtime="1282561867" name="_service:foo" size="6" skipped="true" />
|
||||||
|
<entry md5="ed955c917012307d982b7cdd5799ff1a" mtime="1282320398" name="bigfile" size="69" />
|
||||||
|
<entry md5="0d62ceea6020d75154078a20d8c9f9ba" mtime="1282320303" name="foo" size="23" />
|
||||||
|
<entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" mtime="1282320303" name="merge" size="48" />
|
||||||
|
</directory>
|
@ -0,0 +1,7 @@
|
|||||||
|
<directory name="foo" rev="2" vrev="2" srcmd5="1c5d541a029694c43d5341cabcb4f40f">
|
||||||
|
<entry name="_service:bar" md5="a0106bad78c9070662d5cde42ee35f23" size="16" mtime="1282564656" />
|
||||||
|
<entry name="_service:foo" md5="d15dbfcb847653913855e21370d83af1" size="6" mtime="1282561867" />
|
||||||
|
<entry name="bigfile" md5="ed955c917012307d982b7cdd5799ff1a" size="69" mtime="1282320398" />
|
||||||
|
<entry name="foo" md5="0d62ceea6020d75154078a20d8c9f9ba" size="23" mtime="1282320303" />
|
||||||
|
<entry name="merge" md5="17b9e9e1a032ed44e7a584dc6303ffa8" size="48" mtime="1282320303" />
|
||||||
|
</directory>
|
Loading…
Reference in New Issue
Block a user