2to3/manual: check_xbps.py

This commit is contained in:
Sven Velt 2020-12-29 22:19:34 +01:00
parent c2336a1cd2
commit 45f23e6450

View file

@ -1,8 +1,8 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
##################################################################### #####################################################################
# (c) 2016-2017 by Sven Velt, Germany # # (c) 2016- by Sven Velt, Germany #
# sven-mymonplugins@velt.biz # # sven-mymonplugins@velt.biz #
# # # #
# This file is part of "velt.biz - My Monitoring Plugins" # # This file is part of "velt.biz - My Monitoring Plugins" #
@ -23,24 +23,24 @@
# along with this file. If not, see <http://www.gnu.org/licenses/>. # # along with this file. If not, see <http://www.gnu.org/licenses/>. #
##################################################################### #####################################################################
import os
import subprocess import subprocess
import sys import sys
import time import time
try: try:
from monitoringplugin import MonitoringPlugin from MyMonPlugin import MonitoringPlugin
except ImportError: except ImportError:
print '==========================' print('==========================')
print 'AIKS! Python import error!' print('AIKS! Python import error!')
print '==========================\n' print('==========================\n')
print 'Could not find "monitoringplugin.py"!\n' print('Could not find class "MonitoringPlugin"!\n')
print 'Did you download "%s"' % os.path.basename(sys.argv[0]) print('Did you download "%s"' % os.path.basename(sys.argv[0]))
print 'without "monitoringplugin.py"?\n' print('without "MyMonPlugin/"?\n')
print 'Please go back to' print('Please go back to')
print 'https://gogs.velt.biz/velt.biz/MyMonPlugins and download it,' print('https://gogs.velt.biz/velt.biz/MyMonPlugins and:')
print 'or even better:' print('- get a full archive at http://gogs.velt.biz/velt.biz/MyMonPlugins/releases')
print 'get a full archive at http://gogs.velt.biz/velt.biz/MyMonPlugins/releases' print('- or a master snapshot at http://gogs.velt.biz/velt.biz/MyMonPlugins/archive/master.tar.gz\n')
print 'or a master snapshot at http://gogs.velt.biz/velt.biz/MyMonPlugins/archive/master.tar.gz\n'
sys.exit(127) sys.exit(127)
@ -98,10 +98,10 @@ def run_command(cmdline, needs_sudo=False):
(sout,serr) = cmd.communicate() (sout,serr) = cmd.communicate()
plugin.verbose(2, 'Runtime %.3fs' % (time.time() - tstart, ) ) plugin.verbose(2, 'Runtime %.3fs' % (time.time() - tstart, ) )
sout = sout.rstrip().split('\n') sout = sout.rstrip().decode('utf-8').split('\n')
if sout == ['']: if sout == ['']:
sout = [] sout = []
serr = serr.rstrip().split('\n') serr = serr.rstrip().decode('utf-8').split('\n')
if serr == ['']: if serr == ['']:
serr = [] serr = []
@ -145,7 +145,7 @@ elif rc not in [0, 6]:
action = {'remove':[], 'update':[], 'install':[], 'configure':[]} action = {'remove':[], 'update':[], 'install':[], 'configure':[]}
arch = {} arch = {}
repo = {} repo = {}
downby = 0L downby = 0
for line in sout: for line in sout:
cols = line.split(' ') cols = line.split(' ')
@ -169,9 +169,9 @@ for line in sout:
# Count bytes to download # Count bytes to download
if len(cols) == 5: if len(cols) == 5:
downby += long(cols[4]) downby += int(cols[4])
else: else:
downby += long(cols[5]) downby += int(cols[5])
if len(sout) == 0: if len(sout) == 0:
plugin.remember_check('Updates', plugin.RETURNCODE['OK'], 'Everything uptodate') plugin.remember_check('Updates', plugin.RETURNCODE['OK'], 'Everything uptodate')
@ -184,7 +184,7 @@ else:
l = len(pkgs) l = len(pkgs)
out.append('%s package%s to %s' % (l, l != 1 and 's' or '', act) ) out.append('%s package%s to %s' % (l, l != 1 and 's' or '', act) )
l and multiline.append('%s(%s): %s' % (act, l, ', '.join(pkgs)) ) l and multiline.append('%s(%s): %s' % (act, l, ', '.join(pkgs)) )
for act in action.keys(): for act in list(action.keys()):
pkgs = action.pop(act) pkgs = action.pop(act)
pkgs.sort() pkgs.sort()
l = len(pkgs) l = len(pkgs)
@ -196,9 +196,9 @@ else:
out += ' - %s to download' % plugin.value_to_human_binary(downby, 'B') out += ' - %s to download' % plugin.value_to_human_binary(downby, 'B')
stats = 'Statistics: ' stats = 'Statistics: '
for (k, v) in arch.iteritems(): for (k, v) in arch.items():
stats += '%sx %s, ' % (v, k) stats += '%sx %s, ' % (v, k)
for (k, v) in repo.iteritems(): for (k, v) in repo.items():
stats += '%s from %s, ' % (v, k) stats += '%s from %s, ' % (v, k)
multiline.append(stats[:-2]) multiline.append(stats[:-2])