Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce Database Overwriting #73

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions armi/bookkeeping/db/database3.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,14 @@ def initDB(self):
interface stack (so that all the parameters have been updated) while the Main
Interface interacts first.
"""
if self.cs["reloadDBName"].lower() == (self.cs.caseTitle + ".h5").lower():
databaseName = self.cs.caseTitle + ".h5"
if os.path.exists(os.path.abspath(databaseName)):
raise ValueError(
"It appears that reloadDBName is the same as the case "
"title. This could lead to data loss! Rename the reload DB or the "
"case."
"There is already a database file {}.\nIt would be overwritten. "
"Please rename your case (settings file) to a name that does not yet "
"have a database.".format(os.path.abspath(databaseName))
)
self._db = Database3(self.cs.caseTitle + ".h5", "w")
self._db = Database3(databaseName, "w")
self._db.open()

# Grab geomString here because the DB-level has no access to the reactor or
Expand Down
4 changes: 3 additions & 1 deletion armi/bookkeeping/tests/test_databaseInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,14 @@ def test_convertDatabase(self):
class TestBadName(unittest.TestCase):
def test_badDBName(self):
cs = settings.Settings(os.path.join(TEST_ROOT, "armiRun.yaml"))
cs["reloadDBName"] = "aRmIRuN.h5" # weird casing to confirm robust checking
dbi = DatabaseInterface(None, cs)
with open("aRmIRuN.h5", "w"): # check case insensitive
pass # just make file, don't do anything with it
with self.assertRaises(ValueError):
# an error should be raised when the database loaded from
# has the same name as the run to avoid overwriting.
dbi.initDB()
os.remove("aRmIRuN.h5")


class TestStandardFollowOn(unittest.TestCase):
Expand Down