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