Adapt munin script to python3

print is a function in Python 3
closes #1421
This commit is contained in:
Alexandre Morignot 2015-08-12 20:18:45 +02:00 committed by Florent
commit 75f196e4d5
2 changed files with 58 additions and 55 deletions

View file

@ -19,6 +19,8 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import os import os
import sys import sys
import locale import locale
@ -44,33 +46,33 @@ class BoobankMuninPlugin(object):
self.cache = None self.cache = None
def display_help(self): def display_help(self):
print 'boobank-munin is a plugin for munin' print('boobank-munin is a plugin for munin')
print '' print('')
print 'Copyright(C) 2010-2011 Romain Bignon' print('Copyright(C) 2010-2011 Romain Bignon')
print '' print('')
print 'To use it, create a symlink /etc/munin/plugins/boobank to this script' print('To use it, create a symlink /etc/munin/plugins/boobank to this script')
print 'and add this section in /etc/munin/plugin-conf.d/munin-node:' print('and add this section in /etc/munin/plugin-conf.d/munin-node:')
print '' print('')
print '[boobank]' print('[boobank]')
print 'user romain' print('user romain')
print 'group romain' print('group romain')
print 'env.HOME /home/romain' print('env.HOME /home/romain')
print '# The weboob directory path.' print('# The weboob directory path.')
print 'env.weboob_path /home/romain/.config/weboob/' print('env.weboob_path /home/romain/.config/weboob/')
print '# Monitored accounts. If this parameter is missing, all accounts' print('# Monitored accounts. If this parameter is missing, all accounts')
print '# will be displayed.' print('# will be displayed.')
print 'env.boobank_monitored 0125XXXXXXXXXXXX@bnporc 0125XXXXXXXXXXXX@bnporc' print('env.boobank_monitored 0125XXXXXXXXXXXX@bnporc 0125XXXXXXXXXXXX@bnporc')
print '# To prevent mass connections to bank websites, results are cached.' print('# To prevent mass connections to bank websites, results are cached.')
print '# You can set here the expiration delay (in seconds).' print('# You can set here the expiration delay (in seconds).')
print 'env.boobank_cache_expire 7200' print('env.boobank_cache_expire 7200')
print '# If enabled, coming operations are added to the value of accounts\'' print('# If enabled, coming operations are added to the value of accounts\'')
print '# balance.' print('# balance.')
print 'env.boobank_add_coming 1' print('env.boobank_add_coming 1')
print '# Cumulate accounts values' print('# Cumulate accounts values')
print 'env.boobank_cumulate 1' print('env.boobank_cumulate 1')
print '' print('')
print 'When you change configuration, you can use this command to reset cache:' print('When you change configuration, you can use this command to reset cache:')
print '$ boobank-munin --reset' print('$ boobank-munin --reset')
def clear_cache(self): def clear_cache(self):
for name in ('boobank-munin', 'boobank-munin-config'): for name in ('boobank-munin', 'boobank-munin-config'):
@ -114,7 +116,7 @@ class BoobankMuninPlugin(object):
try: try:
f = open(filename, 'w') f = open(filename, 'w')
except IOError as e: except IOError as e:
print >>sys.stderr, 'Unable to create the cache file %s: %s' % (filename, e) print('Unable to create the cache file %s: %s' % (filename, e), file=sys.stderr)
return return
self.cache = f self.cache = f
@ -181,7 +183,7 @@ class BoobankMuninPlugin(object):
def print_errors(self, errors): def print_errors(self, errors):
for backend, err, backtrace in errors: for backend, err, backtrace in errors:
print >>sys.stderr, (u'%s(%s): %s' % (type(err).__name__, backend.name, err)).encode(sys.stdout.encoding or locale.getpreferredencoding(), 'replace') print((u'%s(%s): %s' % (type(err).__name__, backend.name, err)).encode(sys.stdout.encoding or locale.getpreferredencoding(), 'replace'), file=sys.stderr)
if isinstance(err, BrowserIncorrectPassword): if isinstance(err, BrowserIncorrectPassword):
self.weboob.backends_config.edit_backend(backend.name, backend.NAME, {'_enabled': 'false'}) self.weboob.backends_config.edit_backend(backend.name, backend.NAME, {'_enabled': 'false'})
@ -211,7 +213,7 @@ class BoobankMuninPlugin(object):
elif cmd == 'config': elif cmd == 'config':
self.config() self.config()
elif cmd == 'autoconf': elif cmd == 'autoconf':
print 'no' print('no')
sys.exit(1) sys.exit(1)
elif cmd == 'suggest': elif cmd == 'suggest':
sys.exit(1) sys.exit(1)

View file

@ -83,6 +83,7 @@
# Example: env.category bank # Example: env.category bank
# For some running examples, see at the end of the script # For some running examples, see at the end of the script
from __future__ import print_function
import os import os
import sys import sys
@ -144,28 +145,28 @@ class GenericMuninPlugin(object):
def display_help(self): def display_help(self):
print 'generic-munin is a plugin for munin' print('generic-munin is a plugin for munin')
print '' print('')
print 'Copyright(C) 2013 Romain Bignon, Florent Fourcot' print('Copyright(C) 2013 Romain Bignon, Florent Fourcot')
print '' print('')
print 'To use it, create a symlink /etc/munin/plugins/nameyouwant to this script' print('To use it, create a symlink /etc/munin/plugins/nameyouwant to this script')
print 'and add this section in /etc/munin/plugin-conf.d/munin-node:' print('and add this section in /etc/munin/plugin-conf.d/munin-node:')
print '' print('')
print '[nameyouwant]' print('[nameyouwant]')
print 'user romain' print('user romain')
print 'group romain' print('group romain')
print 'env.HOME /home/romain' print('env.HOME /home/romain')
print '# The weboob directory path.' print('# The weboob directory path.')
print 'env.weboob_path /home/romain/.config/weboob/' print('env.weboob_path /home/romain/.config/weboob/')
print '# Monitored objects. If this parameter is missing, all objects' print('# Monitored objects. If this parameter is missing, all objects')
print '# will be displayed.' print('# will be displayed.')
print 'env.id_monitored myid@backend1 otherid@backend2' print('env.id_monitored myid@backend1 otherid@backend2')
print '# To prevent mass connections to websites, results are cached.' print('# To prevent mass connections to websites, results are cached.')
print '# You can set here the expiration delay (in seconds).' print('# You can set here the expiration delay (in seconds).')
print 'env.cache_expire 7200' print('env.cache_expire 7200')
print '# Cumulate values' print('# Cumulate values')
print 'env.cumulate 1' print('env.cumulate 1')
print '' print('')
def cachepath(self, name): def cachepath(self, name):
tmpdir = os.path.join(self.weboob.workdir, "munin") tmpdir = os.path.join(self.weboob.workdir, "munin")
@ -202,7 +203,7 @@ class GenericMuninPlugin(object):
try: try:
f = open(filename, 'w') f = open(filename, 'w')
except IOError as e: except IOError as e:
print >>sys.stderr, 'Unable to create the cache file %s: %s' % (filename, e) print('Unable to create the cache file %s: %s' % (filename, e), file=sys.stderr)
return return
self.cache = f self.cache = f
@ -318,7 +319,7 @@ class GenericMuninPlugin(object):
def print_errors(self, errors): def print_errors(self, errors):
for backend, err, backtrace in errors: for backend, err, backtrace in errors:
print >>sys.stderr, (u'%s(%s): %s' % (type(err).__name__, backend.name, err)).encode(sys.stdout.encoding or locale.getpreferredencoding(), 'replace') print((u'%s(%s): %s' % (type(err).__name__, backend.name, err)).encode(sys.stdout.encoding or locale.getpreferredencoding(), 'replace'), file=sys.stderr)
if isinstance(err, BrowserIncorrectPassword): if isinstance(err, BrowserIncorrectPassword):
self.weboob.backends_config.edit_backend(backend.name, backend.NAME, {'_enabled': 'false'}) self.weboob.backends_config.edit_backend(backend.name, backend.NAME, {'_enabled': 'false'})
@ -347,7 +348,7 @@ class GenericMuninPlugin(object):
elif cmd == 'config': elif cmd == 'config':
self.config() self.config()
elif cmd == 'autoconf': elif cmd == 'autoconf':
print 'no' print('no')
sys.exit(1) sys.exit(1)
elif cmd == 'suggest': elif cmd == 'suggest':
sys.exit(1) sys.exit(1)