Skip to content

Commit 798586e

Browse files
authored
Update utils.py
1 parent b3b37ac commit 798586e

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

utils.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,37 @@
22
import os
33
import getpass
44

5-
# Get the current user's home directory
65
user_home = os.path.expanduser('~')
7-
8-
# Set up logging to a user-writable directory
96
log_dir = os.path.join(user_home, '.hackeros')
107
log_file = os.path.join(log_dir, 'hacker-mode.log')
118

12-
# Ensure the log directory exists and is writable
139
try:
1410
os.makedirs(log_dir, exist_ok=True)
15-
# Verify that the directory is writable
1611
if not os.access(log_dir, os.W_OK):
1712
raise PermissionError(f"No write permission for directory: {log_dir}")
1813
except PermissionError as e:
19-
# Fallback to a temporary directory if the primary log directory is not writable
2014
log_dir = os.path.join(os.path.expanduser('~'), '.cache', 'hackeros')
2115
os.makedirs(log_dir, exist_ok=True)
2216
log_file = os.path.join(log_dir, 'hacker-mode.log')
2317
logging.warning(f"Failed to use primary log directory due to: {e}. Using fallback: {log_file}")
2418

25-
# Configure logging
2619
try:
2720
logging.basicConfig(
2821
filename=log_file,
2922
level=logging.INFO,
3023
format='%(asctime)s - %(levelname)s - %(message)s',
31-
filemode='a' # Append mode to avoid overwriting
24+
filemode='a'
3225
)
3326
except PermissionError as e:
3427
logging.basicConfig(
3528
level=logging.INFO,
3629
format='%(asctime)s - %(levelname)s - %(message)s',
37-
handlers=[logging.StreamHandler()] # Fallback to console logging
30+
handlers=[logging.StreamHandler()]
3831
)
3932
logging.error(f"Failed to open log file {log_file}: {e}. Logging to console instead.")
4033

41-
# Language setting
42-
lang = 'en' # Default language
34+
lang = 'en'
4335

44-
# Translation dictionary
4536
translations = {
4637
'en': {
4738
'settings': 'Settings',
@@ -161,5 +152,5 @@ def set_language(new_lang):
161152
logging.warning(f'Invalid language: {new_lang}')
162153

163154
def setup_language():
164-
# Placeholder for language initialization logic if needed
165155
pass
156+

0 commit comments

Comments
 (0)