Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

- Log ConnectionError exceptions #196

Open
wants to merge 15 commits into
base: future
Choose a base branch
from
Open
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Place your settings in this file to overwrite default and user settings.
{
"editor.insertSpaces": false
}
16 changes: 9 additions & 7 deletions onedrive_d/od_glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import sys
import logging
import logging.handlers
import atexit
import json
from calendar import timegm
Expand Down Expand Up @@ -44,7 +45,7 @@ def get_logger(level=logging.DEBUG, file_path=None):
logger_instance.setLevel(level)
if file_path is not None:
logger_instance.propagate = False
logger_fh = logging.FileHandler(file_path, 'a')
logger_fh = logging.handlers.WatchedFileHandler(file_path, 'a')
logger_fh.setLevel(level)
logger_instance.addHandler(logger_fh)
atexit.register(flush_log_at_shutdown)
Expand Down Expand Up @@ -118,8 +119,6 @@ class ConfigSet:
'LAST_RUN_TIMESTAMP': '1970-01-01T00:00:00+0000'
}

logger = get_logger()

OS_HOSTNAME = os.uname()[1]
OS_USERNAME = os.getenv('SUDO_USER')

Expand All @@ -129,9 +128,12 @@ class ConfigSet:
def __init__(self, setup_mode=False):
# no locking is necessary because the code is run way before multithreading
if not ConfigSet.initialized:
if ConfigSet.OS_USERNAME is None or ConfigSet.OS_USERNAME == '':
ConfigSet.OS_USERNAME = os.getenv('USER')
if ConfigSet.OS_USERNAME is None or ConfigSet.OS_USERNAME == '':
if not ConfigSet.OS_USERNAME:
for env_key in ['USER', 'LOGNAME']:
ConfigSet.OS_USERNAME = os.getenv(env_key)
if ConfigSet.OS_USERNAME:
break
if not ConfigSet.OS_USERNAME:
get_logger().critical('cannot find current logged-in user.')
sys.exit(1)
ConfigSet.OS_USER_ID = getpwnam(ConfigSet.OS_USERNAME).pw_uid
Expand Down Expand Up @@ -166,7 +168,7 @@ def __init__(self, setup_mode=False):
self.ignore_list = od_ignore_list.IgnoreList(
ConfigSet.APP_IGNORE_FILE, ConfigSet.params['ONEDRIVE_ROOT_PATH'])
else:
ConfigSet.logger.info('ignore list file was not found.')
get_logger().info('ignore list file was not found.')
ConfigSet.ignore_list = None

def set_root_path(self, path):
Expand Down
9 changes: 6 additions & 3 deletions onedrive_d/od_mon_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ def cleanup(self):
self.entrymgr.close()
self.logger.debug('entry manager closed.')
if self.inotify_thread is not None:
self.inotify_thread.stop()
self.inotify_thread.join()
self.logger.debug('inotify thread stopped.')
try:
self.inotify_thread.stop()
self.inotify_thread.join()
self.logger.debug('inotify thread stopped.')
except Exception as e:
self.logger.exception('inotify cleanup exception')
if self.taskmgr is not None:
self.taskmgr.clean_tasks()
self.logger.debug('task queue cleaned.')
Expand Down
Loading