Skip to content

Commit 70abbce

Browse files
simply cosmetics
1 parent cf57144 commit 70abbce

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

smodels/experiment/databaseObj.py

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _getSHA1(filename):
5858

5959
# some mechanism to remove lock files if the download got interrupted
6060
import atexit
61-
lockfiles = set()
61+
lockfiles = set()
6262

6363
def removeLockFiles( lockfiles ):
6464
""" remove cruft lockfiles """
@@ -73,13 +73,13 @@ def removeLockFiles( lockfiles ):
7373
atexit.register ( removeLockFiles, lockfiles )
7474

7575
class Database(object):
76-
"""
76+
"""
7777
Database object. Holds a list of SubDatabases and the ExpSMS map.
7878
Delegates all calls to SubDatabases.
7979
"""
8080

8181
def __init__(self, base=None, force_load=None,
82-
progressbar=False, subpickle=True,
82+
progressbar=False, subpickle=True,
8383
combinationsmatrix=None):
8484
"""
8585
:param base: path to the database, or pickle file (string), or http
@@ -99,17 +99,15 @@ def __init__(self, base=None, force_load=None,
9999
optionally specifying signal regions, e.g. { "anaid1:SR1":
100100
( "anaid2:SR2", "anaid3" ) }
101101
"""
102-
103102
self.subs = []
104-
105103
if "_fastlim" in base: # for backwards compatibility
106104
base = base.replace("_fastlim", "+fastlim")
107105
sstrings = base.split("+")
108106
for ss in sstrings:
109107
self.subs.append(SubDatabase(ss, force_load,
110-
progressbar, subpickle,
108+
progressbar, subpickle,
111109
combinationsmatrix))
112-
110+
113111

114112
# Compute SMS dict with all results
115113
self._allExpSMSDict = ExpSMSDict(self.expResultList)
@@ -120,7 +118,7 @@ def __init__(self, base=None, force_load=None,
120118
@property
121119
def expResultList(self):
122120
"""
123-
The combined list of results, compiled from the
121+
The combined list of results, compiled from the
124122
the active results in each subdatabase.
125123
"""
126124

@@ -235,11 +233,11 @@ def getExpResults(self, analysisIDs=['all'], datasetIDs=['all'], txnames=['all']
235233
Select (filter) the results within the database satisfying the restrictions set by the arguments and returns the corresponding results.
236234
"""
237235

238-
self.selectExpResults(analysisIDs=analysisIDs, datasetIDs=datasetIDs,
239-
txnames=txnames, dataTypes=dataTypes,
236+
self.selectExpResults(analysisIDs=analysisIDs, datasetIDs=datasetIDs,
237+
txnames=txnames, dataTypes=dataTypes,
240238
useNonValidated=useNonValidated,
241239
onlyWithExpected=onlyWithExpected)
242-
240+
243241
return self.expResultList[:]
244242

245243
def selectExpResults(self, analysisIDs=['all'], datasetIDs=['all'], txnames=['all'],
@@ -420,8 +418,8 @@ def __init__(self, base=None, force_load=None,
420418
self._setParticles()
421419
self.txt_meta.printFastlimBanner()
422420
return
423-
logger.error("when initialising database: force_load=%s is not "
424-
"recognized. Valid values are: pcl, txt, None." % force_load)
421+
logger.error( f"when initialising database: force_load={force_load} is not "
422+
"recognized. Valid values are: pcl, txt, None." )
425423
raise SModelSError()
426424

427425
def __eq__(self, other):
@@ -462,16 +460,21 @@ def loadDatabase(self):
462460
it needs update, create new binary file, in
463461
case it does need an update.
464462
"""
465-
if not os.path.exists(self.pcl_meta.pathname):
466-
logger.info("Creating binary database ")
467-
logger.info("(this may take a few minutes, but it's done only once!)")
468-
self.loadTextDatabase()
469-
self.createBinaryFile()
470-
else:
471-
if self.needsUpdate():
463+
try:
464+
if not os.path.exists(self.pcl_meta.pathname):
465+
logger.info("Creating binary database ")
466+
logger.info("(this may take a few minutes, but it's done only once!)")
467+
self.loadTextDatabase()
472468
self.createBinaryFile()
473469
else:
474-
self.loadBinaryFile(lastm_only=False)
470+
if self.needsUpdate():
471+
self.createBinaryFile()
472+
else:
473+
self.loadBinaryFile(lastm_only=False)
474+
except Exception as e:
475+
import traceback
476+
logger.error ( "when loading database: {e}, {traceback.format_exc()}" )
477+
sys.exit(-1)
475478

476479
def loadTextDatabase(self):
477480
""" simply loads the textdabase """
@@ -557,7 +560,7 @@ def loadBinaryFile(self, lastm_only=False):
557560
t1 = time.time()-t0
558561
logger.info("Loaded database from %s in %.1f secs." %
559562
(self.pcl_meta.pathname, t1))
560-
self.databaseParticles = None
563+
self.databaseParticles = None
561564
try:
562565
self.databaseParticles = serializer.load(f)
563566
except EOFError as e:
@@ -669,7 +672,7 @@ def base(self):
669672
def lockFile ( self, filename : os.PathLike ):
670673
""" lock the file <filename>
671674
"""
672-
lockfile = os.path.join ( os.path.dirname ( filename ),
675+
lockfile = os.path.join ( os.path.dirname ( filename ),
673676
".lock_"+ os.path.basename ( filename ) )
674677
ctr = 0
675678
while ( ctr < 5 ):
@@ -700,7 +703,7 @@ def lockFile ( self, filename : os.PathLike ):
700703
def unlockFile ( self, filename : os.PathLike ):
701704
""" unlock the file <filename>
702705
"""
703-
lockfile = os.path.join ( os.path.dirname ( filename ),
706+
lockfile = os.path.join ( os.path.dirname ( filename ),
704707
".lock_"+ os.path.basename ( filename ) )
705708
if lockfile in lockfiles:
706709
lockfiles.remove( lockfile )
@@ -1079,7 +1082,7 @@ def setActiveExpResults(self, analysisIDs=['all'], datasetIDs=['all'], txnames=[
10791082
"""
10801083

10811084
self._activeResults = self.getExpResults(analysisIDs, datasetIDs, txnames,
1082-
dataTypes, useNonValidated,
1085+
dataTypes, useNonValidated,
10831086
onlyWithExpected)
10841087

10851088
def getExpResults(self, analysisIDs=['all'], datasetIDs=['all'], txnames=['all'],

0 commit comments

Comments
 (0)