Skip to content

Commit

Permalink
Log files (log + recovery) always written under game directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoine committed Jul 8, 2021
1 parent 89d4a13 commit 9f149ff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion run
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terminal_font=$(gsettings get org.gnome.desktop.interface monospace-font-name)
game_font='square 13'
dir_path=$(dirname "$0")
log_dir="$dir_path"/.log
recovery_file="$log_dir"/log.recovery
recovery_file="$log_dir"/recovery

msg="- your previous terminal font was $terminal_font
- to recover previous font, in case of any crash from the game, please run
Expand Down
5 changes: 3 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import sys

# allows the user to play from anywhere in the system.
path = os.path.dirname(os.path.realpath(__file__)) + "/.."
sys.path.append(path)
_root = os.path.dirname(os.path.realpath(__file__)) + "/.."
sys.path.append(_root)

from src.Apple import Apple
from src.Snake import Snake

Expand Down
12 changes: 10 additions & 2 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import curses
import os

import numpy as np

# directories initializations.
_root = os.path.dirname(os.path.realpath(__file__)) + "/.."
_log = os.path.join(_root, ".log")
if not os.path.exists(_log):
os.makedirs(_log)
_log = os.path.join(_log, "log")


def log(*args, sep=' ', end='\n'):
"""
Logs a list of elements inside the 'log.log' file.
Logs a list of elements inside the './.log/log' file.
Args
----
Expand All @@ -20,7 +28,7 @@ def log(*args, sep=' ', end='\n'):
-------
None
"""
with open("log.log", 'a') as file:
with open(_log, 'a') as file:
file.write(sep.join(map(str, args)) + end)


Expand Down

0 comments on commit 9f149ff

Please sign in to comment.