Skip to content

Commit

Permalink
Fixed active_version overwriting on reopening, ESS-1154
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniele Paganelli committed Oct 27, 2016
1 parent 07cdddb commit ded692b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions misura/canon/indexer/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def open_file(self, path=False, uid='', mode='a', title='', header=True, version
raise RuntimeError("File %s not found." % path)

try:
print 'opening existing file', path, mode
self.log.debug('opening existing file', path, mode)
self.test = tables.openFile(path, mode=mode)
self.path = path
except:
Expand All @@ -79,9 +79,12 @@ def open_file(self, path=False, uid='', mode='a', title='', header=True, version
if not self.has_node('/userdata'):
self.create_group('/', 'userdata')
self.set_attributes('/userdata', attrs={'active_version': ''})
elif not version:
version = self.get_node_attr('/userdata', 'active_version')
if self.has_node('/conf'):
if self.has_node_attr('/conf', 'uid'):
self.uid = self.get_node_attr('/conf', 'uid')

self.set_version(version)
else:
self.conf = option.ConfigurationProxy()
Expand Down Expand Up @@ -133,22 +136,26 @@ def set_version(self, newversion=-1):
if '/userdata' in self.test:
newversion = self.test.get_node_attr(
'/userdata', 'active_version')
self.log.debug('Found active version', newversion)
else:
newversion = getattr(self.test.root.conf.attrs, 'versions', '')
self.log.debug('Take latest version', newversion)
self._lock.release()

if not isinstance(newversion, basestring):
newversion = '/ver_{}'.format(newversion)

if self.version == newversion and self.conf:
self.log.debug('Not changing version!', self.version, newversion)
return True

self._change_version(newversion)
self.load_conf()
self.header(refresh=True)
return True

def _change_version(self, new_version):
self.log.debug('Changing version to', new_version)
self.version = str(new_version)
self._set_attributes(
'/userdata', attrs={'active_version': new_version})
Expand Down

0 comments on commit ded692b

Please sign in to comment.