Skip to content

Commit

Permalink
Merge pull request #1387 from pierotofy/console
Browse files Browse the repository at this point in the history
Safer console writes
  • Loading branch information
pierotofy authored Sep 11, 2023
2 parents 2c2b75a + df24590 commit ec908cd
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions app/classes/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,23 @@ def output(self):

def append(self, text):
if os.path.isdir(self.parent_dir):
# Write
if not os.path.isdir(self.base_dir):
os.makedirs(self.base_dir, exist_ok=True)
try:
# Write
if not os.path.isdir(self.base_dir):
os.makedirs(self.base_dir, exist_ok=True)

with open(self.file, "a") as f:
f.write(text)
except IOError:
logger.warn("Cannot append to console file: %s" % self.file)

with open(self.file, "a") as f:
f.write(text)

def reset(self, text = ""):
if os.path.isdir(self.parent_dir):
if not os.path.isdir(self.base_dir):
os.makedirs(self.base_dir, exist_ok=True)

with open(self.file, "w") as f:
f.write(text)

try:
if not os.path.isdir(self.base_dir):
os.makedirs(self.base_dir, exist_ok=True)

with open(self.file, "w") as f:
f.write(text)
except IOError:
logger.warn("Cannot reset console file: %s" % self.file)

0 comments on commit ec908cd

Please sign in to comment.