Project

General

Profile

Evolution #6256

grep fait planter manage_schedule

Added by Joël Cuissinat over 7 years ago. Updated over 7 years ago.

Status:
Fermé
Priority:
Normal
Assigned To:
Category:
-
Start date:
11/04/2013
Due date:
11/08/2013
% Done:

100%

Estimated time:
1.00 h
Spent time:
Distribution:
EOLE 2.4

Description

Et ce n'est sûrement pas le seul script qui pose problème :o

root@sphynx:~# /usr/share/eole/sbin/manage_schedule -l 
Tâches planifiées EOLE :
 * les tâches hebdomadaires se feront le vendredi à 05:33 (hors sauvegarde)
  - avant sauvegarde
   + Mise à jour du serveur (majauto)

root@sphynx:~# /usr/share/eole/sbin/manage_schedule -l | grep maj
Traceback (most recent call last):
  File "/usr/share/eole/sbin/manage_schedule", line 81, in <module>
    main()
  File "/usr/share/eole/sbin/manage_schedule", line 59, in main
    display_schedules()
  File "/usr/lib/python2.7/dist-packages/pyeole/schedule.py", line 112, in display_schedules
    print "   +", schedules['{0}.description'.format(sched)], \
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in position 5: ordinal not in range(128)

Associated revisions

Revision 737ea1d7 (diff)
Added by Gwenael Remond over 7 years ago

encoding utf-8 obligatoire pour tous les programmes python, fixes #6256

History

#1 Updated by Daniel Dehennin over 7 years ago

Le problème vient du pipe qui fait que la sortie standard du script python n’est plus un tty.

Python ne peut donc pas découvrir que la sortie est en UTF-8.

Il faut remplacer les print par des log..

Les bibliothèques doivent utiliser le code suivant :

from logging import getLogger
log = getLogger(__name__)

log.critical(u"This is a “critical” message.")
log.error(u"This is an “error” message.")
log.warn(u"This is a “warning” message.")
log.info(u"This is an “informational” message.")
log.debug(u"This is a “debuging” message.")

Les programmes devant gérer la sortie vers les utilisateurs doivent utiliser le code suivant :

from pyeole.log import init_logging, set_formatter

# Logger for the application, use level=u'info' to display normal informational message
log = init_logging(name=u'myapp', level='uinfo')

# Do not prefix warning, error and critical log of the current program with “myapp - ”
set_formatter(log, u'stderr', u'brief')

# Logger for a sub-library, we only want warnings
# This logger is never used by ourself.
sublib = init_logging(name=u'pyeole.sublib', level=u'warning')

# Root logger for any other logger, display only errors
# This logger must be defined last since non-root logger reset the root logger
# This logger is never used by ourself.
root_log = init_logging(name=u'root', level=u'error')

### Main code of the application

log.critical(u"This is a “critical” message.")
log.error(u"This is an “error” message.")
log.warn(u"This is a “warning” message.")
log.info(u"This is an “informational” message.")
log.debug(u"This is a “debuging” message.")

#2 Updated by Gwenael Remond over 7 years ago

il faudrait que globalement l'ioencoding PYTHONIOENCODING soit prérèglé.

root@eolebase:~# /usr/share/eole/sbin/manage_schedule -l|grep pouet
Traceback (most recent call last):
  File "/usr/share/eole/sbin/manage_schedule", line 81, in <module>
    main()
  File "/usr/share/eole/sbin/manage_schedule", line 59, in main
    display_schedules()
  File "/usr/lib/python2.7/dist-packages/pyeole/schedule.py", line 112, in display_schedules
    print "   +", schedules['{0}.description'.format(sched)], \
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 29: ordinal not in range(128)
root@eolebase:~# export PYTHONIOENCODING='UTF8'
root@eolebase:~# /usr/share/eole/sbin/manage_schedule -l|grep pouet
root@eolebase:~# 

#3 Updated by Joël Cuissinat over 7 years ago

commençons par ajouter la variable d'environnement ...

#4 Updated by Daniel Dehennin over 7 years ago

  • Target version changed from Eole 2.4-beta1 to Eole 2.4-beta2

#5 Updated by Gwenael Remond over 7 years ago

  • Status changed from Nouveau to Résolu
  • % Done changed from 0 to 100

#6 Updated by Gwenael Remond over 7 years ago

  • Status changed from Résolu to En attente d'informations
  • Assigned To set to Gwenael Remond
  • % Done changed from 100 to 0

#7 Updated by Gwenael Remond over 7 years ago

  • Status changed from En attente d'informations to Résolu

#8 Updated by Gwenael Remond over 7 years ago

  • % Done changed from 0 to 100

#9 Updated by Joël Cuissinat over 7 years ago

  • Due date set to 11/08/2013
  • Status changed from Résolu to Fermé
  • Start date set to 11/04/2013
root@amon:~# /usr/share/eole/sbin/manage_schedule -l | grep maj
   + Mise à jour blacklist du serveur (majblacklist)
   + Mise à jour du serveur (majauto)

Also available in: Atom PDF