Skip to content

Commit

Permalink
Create db dir if it doesn't exist (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasodonnell authored Jan 11, 2024
1 parent 2efb0b6 commit d182a13
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion smart-runner.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
; /dev/sdc

[database]
file = /var/lib/smart-runner.json
file = /var/lib/smart-runner/smart-runner.json

; short SMART test settings (these tests typically take a few minutes)
[short]
Expand Down
4 changes: 2 additions & 2 deletions smart-runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def main():
for disk in disks:
for test in [longTest, shortTest]:
logger.info(
"Processing {} SMART test for {}...".format(
"Checking {} SMART test for {}...".format(
test.testType.value,
disk.disk,
)
Expand Down Expand Up @@ -149,7 +149,7 @@ def main():
continue
except TooManyDisksException as e:
logger.warning(
"Can't run {} SMART test for {} {} disk(s) have already ran, skipping...".format(
"Can't run {} SMART test for {} {} disk(s) have already been tested, skipping...".format(
test.testType.value,
disk.disk,
test.disksPerRun,
Expand Down
2 changes: 1 addition & 1 deletion smart_runner/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __getConfig__(self):
"database": ConfigDict(
{
"file": config.get(
"database", "file", fallback="/var/lib/smart-runner.json"
"database", "file", fallback="/var/lib/smart-runner/smart-runner.json"
),
}
),
Expand Down
3 changes: 3 additions & 0 deletions smart_runner/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def __readDbFile__(self):

def __writeDbFile__(self):
try:
# create dir of db file if it does not exist
Path(self.dbFile).parent.mkdir(parents=True, exist_ok=True)

with open(self.dbFile, "w") as file:
dump(self.__db__, file, indent=4, sort_keys=True)
except Exception as e:
Expand Down
10 changes: 7 additions & 3 deletions smart_runner/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ def needsShortTest(self, frequencyDays):
if self.lastShortTestDate is None and self.lastLongTestDate is None:
return True

if self.lastShortTestDate is None:
nextShortTestDate = self.lastLongTestDate + timedelta(
days=frequencyDays
)

return datetime.now() >= nextShortTestDate

if self.lastLongTestDate is None:
nextShortTestDate = self.lastShortTestDate + timedelta(
days=frequencyDays
)

return datetime.now() >= nextShortTestDate

if self.lastShortTestDate is None:
return True

nextShortTestDate = max(
[self.lastShortTestDate, self.lastLongTestDate]
) + timedelta(days=frequencyDays)
Expand Down

0 comments on commit d182a13

Please sign in to comment.