Fix error handling + Fix error.log path
This commit is contained in:
@@ -6,7 +6,6 @@ import glob
|
||||
import json
|
||||
import shutil
|
||||
import logging
|
||||
import traceback
|
||||
from pathlib import Path
|
||||
import urllib.request as curl
|
||||
|
||||
@@ -63,7 +62,7 @@ def template_with_base(content, title=None):
|
||||
|
||||
# same regex as in `api/v1/contribute/index.php`
|
||||
regex_bundle_id = re.compile(r'^[A-Za-z0-9\.\-]{1,155}$')
|
||||
logging.basicConfig(filename=os.path.join(os.pardir, "error.log"),
|
||||
logging.basicConfig(filename=path_root('error.log'),
|
||||
format='%(asctime)s %(message)s',
|
||||
filemode='a')
|
||||
logger = logging.getLogger()
|
||||
@@ -91,8 +90,6 @@ def app_name(bundle_id, fallback=None):
|
||||
|
||||
|
||||
def err(scope, msg, logOnly=False):
|
||||
if isinstance(msg, Exception):
|
||||
msg = traceback.format_exc()
|
||||
logger.error('[{}] {}'.format(scope, msg))
|
||||
if not logOnly:
|
||||
print(' [ERROR] ' + msg)
|
||||
|
||||
14
src/main.py
14
src/main.py
@@ -2,6 +2,7 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
import common_lib as mylib
|
||||
import bundle_combine
|
||||
import bundle_download
|
||||
@@ -63,6 +64,7 @@ def combine_and_update(bundle_ids, where=None):
|
||||
def import_update():
|
||||
print('checking incoming data ...')
|
||||
needs_update = set()
|
||||
then_delete = set()
|
||||
for fname, bid in mylib.enum_newly_added():
|
||||
if bid == '_manually':
|
||||
# TODO: notify admin that manual action is required
|
||||
@@ -72,10 +74,15 @@ def import_update():
|
||||
else:
|
||||
print(' ' + bid)
|
||||
needs_update.add(bid)
|
||||
os.remove(fname)
|
||||
then_delete.add(fname)
|
||||
print('')
|
||||
if len(needs_update) > 0:
|
||||
combine_and_update(needs_update)
|
||||
if len(then_delete) > 0:
|
||||
print('cleanup _in folder ...')
|
||||
for x in then_delete:
|
||||
os.remove(fname)
|
||||
print('')
|
||||
|
||||
|
||||
def tracker_update():
|
||||
@@ -109,5 +116,6 @@ try:
|
||||
if len(params) == 0:
|
||||
print_usage_and_exit()
|
||||
del_id(params) # ['_manually']
|
||||
except Exception as e:
|
||||
mylib.err('critical', e)
|
||||
except Exception:
|
||||
mylib.err('critical', traceback.format_exc(), logOnly=True)
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user