From b4f12399ce021fa9915e3329a6488b8c05a5c236 Mon Sep 17 00:00:00 2001 From: Progfou Date: Mon, 2 Nov 2015 13:43:42 -0500 Subject: [PATCH] =?utf8?q?wcs-dynexport=20:=20tentative=20de=20correction=20?= =?utf8?q?du=20probl=C3=A8me=20de=20g=C3=A9n=C3=A9ration=20du=20last-run.log?= =?utf8?q?=20(=C3=A9chec).?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- wcs/wcs-dynexport | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/wcs/wcs-dynexport b/wcs/wcs-dynexport index 689b43e..f6726f4 100755 --- a/wcs/wcs-dynexport +++ b/wcs/wcs-dynexport @@ -77,6 +77,7 @@ Please go to ${location}""" sys.exit(0) def http_reply_and_exit(data, mime_type='text/html', charset='utf-8'): + if data is None: data = '' # références horaires current_time = time.time() mtime = time.gmtime(current_time) @@ -203,12 +204,16 @@ def get_wcs_form_data(domain, form): os.umask(0022) logname = _make_wcs_cache_name(domain, form, 'last-run.log') - logging.basicConfig(level=logging.DEBUG, - format='%(asctime)s %(levelname)s %(message)s', - filename=os.path.join(WCS_CACHE_DIR, logname), - filemode='w') + logger = logging.getLogger('wcs-dynexport') + logger.setLevel(logging.DEBUG) + log_formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') + log_handler = logging.FileHandler(os.path.join(WCS_CACHE_DIR, logname)) + log_handler.setLevel(logging.DEBUG) + log_handler.setFormatter(log_formatter) + logger.addHandler(log_handler) - logging.info('Début.') + logger.info('Début.') + log_handler.flush() set_wcs_publisher(domain) from wcs.formdef import FormDef @@ -247,7 +252,7 @@ def get_wcs_form_data(domain, form): liste_attachements = {} for object in formdef.data_class().select(): if object.user is None: - logging.warning("Dossier '%s' sans utilisateur associé ?!?"\ + logger.warning("Dossier '%s' sans utilisateur associé ?!?"\ " On ignore...", object.id) continue @@ -317,7 +322,7 @@ def get_wcs_form_data(domain, form): m = magicmime.file(p).split()[0].strip(';') extension = mimetypes.guess_extension(m) except: - logging.warning("Type de fichier inconnu pour '%s'.", p) + logger.warning("Type de fichier inconnu pour '%s'.", p) extension = None if extension is not None: extension = extension[1:] @@ -326,7 +331,7 @@ def get_wcs_form_data(domain, form): result[field_name] = "%s.%s" % (field_name, extension) qfiles[field_name] = data.qfilename else: - logging.warning("Type de champ inconnu '%s' pour '%s' (%s).", + logger.warning("Type de champ inconnu '%s' pour '%s' (%s).", field.__class__.__name__, field_name, field.label) num_dossier = result['num_dossier'] @@ -349,7 +354,7 @@ def get_wcs_form_data(domain, form): data = json.dumps(result, ensure_ascii=False).encode('utf-8') set_wcs_cache(domain, form, 'data_%s.json' % filename, data) - logging.info("Dossier '%s' : %s.", + logger.info("Dossier '%s' : %s.", filename, result['wcs_workflow_status']) data = json.dumps(liste_attachements, ensure_ascii=False).encode('utf-8') @@ -361,7 +366,8 @@ def get_wcs_form_data(domain, form): set_wcs_cache(domain, form, 'liste-dossiers.json', data) metadata.update({'dossiers': liste_dossiers}) - logging.info('Fin.') + logger.info('Fin.') + log_handler.flush() data = json.dumps(metadata, ensure_ascii=False).encode('utf-8') set_wcs_cache(domain, form, 'metadata.json', data) @@ -370,7 +376,7 @@ def get_wcs_form_data(domain, form): # try: # extract_data(formdef, OUTPUT_DIRECTORY) # except: -# logging.exception("Interruption du traitement pour cause d'erreur !") +# logger.exception("Interruption du traitement pour cause d'erreur !") #-------------------------------------------------------------------------- # gestion des requêtes web -- 1.7.10.4