From f4b5d3652742b2e2cef60e1de4cb1f57dbdc79ad Mon Sep 17 00:00:00 2001 From: Vaclav Vorisek Date: Thu, 2 Sep 2021 16:29:52 +0200 Subject: [PATCH 1/8] Control files --- debian/changelog | 6 ++++++ debian/control | 2 +- debian/rules | 8 ++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/debian/changelog b/debian/changelog index a248eaa..b41e60f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +xivo-utils (2021.14.00) xivo-helios; urgency=medium + + * Python 3 compatibility + + -- Vaclav Vorisek Thu, 02 Sep 2021 16:29:07 +0200 + xivo-utils (2021.07.02) xivo-gaia; urgency=medium * 3990 - update change pass vm to work on MDS diff --git a/debian/control b/debian/control index d908f91..6c08ec3 100644 --- a/debian/control +++ b/debian/control @@ -8,7 +8,7 @@ Standards-Version: 3.7.2.2 Package: xivo-utils Architecture: all -Depends: ghostscript-x, xivo-lib-python, python-requests +Depends: ghostscript-x, xivo-lib-python-python3, python3-requests Provides: pf-xivo-utils Conflicts: pf-xivo-utils Replaces: pf-xivo-utils diff --git a/debian/rules b/debian/rules index ca98561..02cf9a6 100755 --- a/debian/rules +++ b/debian/rules @@ -1,5 +1,9 @@ #!/usr/bin/make -f -# -*- mode: makefile; coding: utf-8 -*- +# -*- makefile -*- -include /usr/share/cdbs/1/rules/debhelper.mk +export PYBUILD_NAME=xivo-utils +export PYBUILD_DISABLE=test + +%: + dh $@ --with python3 --buildsystem=pybuild -- GitLab From 1e7cb3a1f2d3126323cc2e28397055081b87f3c7 Mon Sep 17 00:00:00 2001 From: Vaclav Vorisek Date: Thu, 2 Sep 2021 16:33:28 +0200 Subject: [PATCH 2/8] futurize --- agi-bin/xuc-request.py | 8 +++- bin/simultcalls.py | 90 ++++++++++++++++++++++-------------------- bin/tzdataexport.py | 17 +++++--- 3 files changed, 65 insertions(+), 50 deletions(-) diff --git a/agi-bin/xuc-request.py b/agi-bin/xuc-request.py index aef52e4..b206dfc 100755 --- a/agi-bin/xuc-request.py +++ b/agi-bin/xuc-request.py @@ -13,6 +13,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from future import standard_library +standard_library.install_aliases() +from builtins import str +from builtins import object __version__ = '$Revision$' __date__ = '$Date$' __copyright__ = 'Copyright (C) 2014-2017 Avencall' @@ -24,12 +28,12 @@ import requests import logging import traceback import json -import ConfigParser +import configparser from xivo.agi import AGI agi = AGI() -xuc_config = ConfigParser.ConfigParser() +xuc_config = configparser.ConfigParser() xuc_config.readfp(open('/etc/xivo-xuc.conf')) XUC_SERVER_IP = xuc_config.get('XUC', 'XUC_SERVER_IP') XUC_SERVER_PORT = xuc_config.get('XUC', 'XUC_SERVER_PORT') diff --git a/bin/simultcalls.py b/bin/simultcalls.py index c66a4b6..f6ef942 100755 --- a/bin/simultcalls.py +++ b/bin/simultcalls.py @@ -16,6 +16,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see +from __future__ import print_function +from __future__ import division +from future import standard_library +standard_library.install_aliases() +from builtins import range +from past.utils import old_div __version__ = '$Revision$' __date__ = '$Date$' __author__ = 'Corentin Le Gall' @@ -26,7 +32,7 @@ import getopt import os import sys import time -import urllib +import urllib.request, urllib.parse, urllib.error def zero_seconds(val): global histo_seconds @@ -47,8 +53,8 @@ def gettimelength(start, length, chan1, chan2, timefmt): try: tt = time.strptime(start, timefmt) ret = [int(time.strftime('%s', tt)), int(length)] - except Exception, exc: - print '--- exception (%s) : %s ---' % (exc, start) + except Exception as exc: + print('--- exception (%s) : %s ---' % (exc, start)) ret = [] return ret @@ -71,7 +77,7 @@ try: opts = getopt.gnu_getopt(sys.argv[1:], GETOPT_SHORTOPTS, GETOPT_LONGOPTS) -except getopt.GetoptError, exc: +except getopt.GetoptError as exc: opts = ([], []) for opt, arg in opts[0]: @@ -100,23 +106,23 @@ if opts[1]: if not infile_or_ip or not sc_mode or sc_help: codename = 'simultcalls.py' # sys.argv[0] - print - print 'Usage : you should use this tool in either mode :' - print ' %s [options] -m file xivo_cdr_XXX.csv (exported CSV)' % codename - print ' %s [options] -m ip 192.168.0.4 (web service request)' % codename - print - print 'where [options] can be :' - print ' -c : the first characters of a channel name (DAHDI, SIP, IAX)' - print ' -b : in "ip" mode, the begin date,' - print ' format like 2009-11-27 (default is current day)' - print ' -e : in "ip" mode, the end date,' - print ' format like 2009-11-27 (default is current day)' - print ' -i : outputs a PNG graph under simultcalls_%Y%m%d_%H%M%S.png' - print ' -p : outputs a PostScript graph under simultcalls_%Y%m%d_%H%M%S.ps' - print ' -x : displays very briefly an X11 graph' - print ' -k : keep the temporary data files for further processing' - print ' -h : this help' - print + print() + print('Usage : you should use this tool in either mode :') + print(' %s [options] -m file xivo_cdr_XXX.csv (exported CSV)' % codename) + print(' %s [options] -m ip 192.168.0.4 (web service request)' % codename) + print() + print('where [options] can be :') + print(' -c : the first characters of a channel name (DAHDI, SIP, IAX)') + print(' -b : in "ip" mode, the begin date,') + print(' format like 2009-11-27 (default is current day)') + print(' -e : in "ip" mode, the end date,') + print(' format like 2009-11-27 (default is current day)') + print(' -i : outputs a PNG graph under simultcalls_%Y%m%d_%H%M%S.png') + print(' -p : outputs a PostScript graph under simultcalls_%Y%m%d_%H%M%S.ps') + print(' -x : displays very briefly an X11 graph') + print(' -k : keep the temporary data files for further processing') + print(' -h : this help') + print() if not infile_or_ip or not sc_mode: sys.exit(1) @@ -132,13 +138,13 @@ if sc_mode == 'ip': mode = 'restricted' if remoteip in ['127.0.0.1', 'localhost']: mode = 'private' - print 'request to %s' % remoteip + print('request to %s' % remoteip) if not sc_begin: sc_begin = today if not sc_end: sc_end = today title = '%s from %s to %s' % (remoteip, sc_begin, sc_end) - w = urllib.urlopen('https://%s/service/ipbx/json.php/%s/call_management/cdr/?act=search&dbeg=%s&dend=%s' + w = urllib.request.urlopen('https://%s/service/ipbx/json.php/%s/call_management/cdr/?act=search&dbeg=%s&dend=%s' % (remoteip, mode, sc_begin, sc_end)) wr = w.readlines() if wr: @@ -152,20 +158,20 @@ if sc_mode == 'ip': if gtl: mystats.append(gtl) else: - print 'It seems the Web Service returned an empty result :' - print ' - did you give some meaningful begin and end dates ? (%s -> %s)' % (sc_begin, sc_end) - print ' - are you on a sufficiently high XiVO version (1.0 or greater) ?' + print('It seems the Web Service returned an empty result :') + print(' - did you give some meaningful begin and end dates ? (%s -> %s)' % (sc_begin, sc_end)) + print(' - are you on a sufficiently high XiVO version (1.0 or greater) ?') sys.exit(1) elif sc_mode == 'file': # file/url mode if infile_or_ip.startswith('http:'): - f = urllib.urlopen(infile_or_ip) + f = urllib.request.urlopen(infile_or_ip) title = 'url : %s' % infile_or_ip else: f = open(infile_or_ip) title = 'file : %s' % infile_or_ip - print 'reading csv file from %s' % infile_or_ip + print('reading csv file from %s' % infile_or_ip) csvreader = csv.reader(f, delimiter = ';') for line in csvreader: nl += 1 @@ -177,21 +183,21 @@ elif sc_mode == 'file': f.close() else: - print 'unknown mode "%s" - exiting' % sc_mode + print('unknown mode "%s" - exiting' % sc_mode) sys.exit(1) t2 = time.time() -print '... (%.1f seconds spent for %d items)\n' \ - 'filling histogram' % (t2-t1, len(mystats)) +print('... (%.1f seconds spent for %d items)\n' \ + 'filling histogram' % (t2-t1, len(mystats))) if not mystats: - print 'no data found matching your channel "%s" - exiting' % sc_channel + print('no data found matching your channel "%s" - exiting' % sc_channel) sys.exit(1) # mystats is filled now starttime_seconds = mystats[0][0] -starttime_minutes = mystats[0][0]/60 +starttime_minutes = old_div(mystats[0][0],60) histo_seconds = {} histo_minutes = {} @@ -199,7 +205,7 @@ histo_minutes = {} for st in mystats: time_s = st[0] - starttime_seconds deltatime_s = st[1] - for ttime_s in xrange(time_s, time_s + deltatime_s + 1): + for ttime_s in range(time_s, time_s + deltatime_s + 1): if ttime_s in histo_seconds: histo_seconds[ttime_s] = histo_seconds[ttime_s] + 1 else: @@ -208,8 +214,8 @@ for st in mystats: zero_seconds(time_s + deltatime_s + 1) t3 = time.time() -print '... (%.1f seconds spent, %d bins filled)\n' \ - 'sorting and writing to files' % (t3-t2, len(histo_seconds)) +print('... (%.1f seconds spent, %d bins filled)\n' \ + 'sorting and writing to files' % (t3-t2, len(histo_seconds))) datfilename_s = '/tmp/stat_seconds_%s.dat' % now datfilename_m = '/tmp/stat_minutes_%s.dat' % now @@ -219,12 +225,12 @@ datfile_m = open(datfilename_m, 'w') # fill the minutes' bins and keep data around the maximal values max_s_value = 0 max_s_list = [] -hsk = histo_seconds.keys() +hsk = list(histo_seconds.keys()) hsk.sort() for h in hsk: ttime = starttime_seconds + h h0 = histo_seconds[h] - time_min = ttime/60 - starttime_minutes + time_min = old_div(ttime,60) - starttime_minutes if time_min in histo_minutes: histo_minutes[time_min] = histo_minutes[time_min] + h0 / 60.0 else: @@ -245,14 +251,14 @@ for h in hsk: datfile_s.close() # display a (possibly) short summary -print 'max simultaneous calls is %s - values around max are :' % (max_s_value) +print('max simultaneous calls is %s - values around max are :' % (max_s_value)) for mm in max_s_list: h = mm ttime = starttime_seconds + h strtime = time.strftime('%d/%m/%Y,%H:%M:%S', time.localtime(ttime)) - print ' %s %10d calls' % (strtime, histo_seconds[h]) + print(' %s %10d calls' % (strtime, histo_seconds[h])) -hmk = histo_minutes.keys() +hmk = list(histo_minutes.keys()) hmk.sort() for h in hmk: ttime = (starttime_minutes + h) * 60 @@ -262,7 +268,7 @@ for h in hmk: datfile_m.close() t4 = time.time() -print '... (%.1f seconds spent)' % (t4-t3) +print('... (%.1f seconds spent)' % (t4-t3)) # make plots if requested pstmpplot = None diff --git a/bin/tzdataexport.py b/bin/tzdataexport.py index 08e1b96..a591145 100755 --- a/bin/tzdataexport.py +++ b/bin/tzdataexport.py @@ -31,7 +31,12 @@ More info about the tz database can be found here: - http://www.twinsun.com/tz/tz-link.htm """ +from __future__ import print_function +from builtins import zip +from builtins import map +from builtins import next +from builtins import object __version__ = "$Revision$ $Date$" import datetime @@ -363,7 +368,7 @@ def _strip_line(line): def _strip_iter(seq): - return itertools.imap(lambda x: _strip_line(x), seq) + return map(lambda x: _strip_line(x), seq) def _parse_tz_source_file(lines): @@ -381,7 +386,7 @@ def _parse_tz_source_file(lines): it = _strip_iter(lines) try: while True: - cur_line = it.next() + cur_line = next(it) if _is_blank_line(cur_line): continue @@ -395,7 +400,7 @@ def _parse_tz_source_file(lines): zone_name = tokens[1] tokens = ' '.join(tokens[2:]).split(None, 3) while len(tokens) > 3: - cur_line = it.next() + cur_line = next(it) if not cur_line: # Line, after striping, is empty - go to next line continue @@ -452,12 +457,12 @@ def create_model_from_files(filenames): def export_model_to_text_file(fobj, model): - for zone_name in sorted(model.iterkeys()): + for zone_name in sorted(model.keys()): zone_info = model[zone_name] if zone_info['dst'] is None: - print >>fobj, '%-34s%10s -' % (zone_name, zone_info['utcoffset']) + print('%-34s%10s -' % (zone_name, zone_info['utcoffset']), file=fobj) else: - print >>fobj, '%-34s%10s %s' % (zone_name, zone_info['utcoffset'], _format_dst(zone_info['dst'])) + print('%-34s%10s %s' % (zone_name, zone_info['utcoffset'], _format_dst(zone_info['dst'])), file=fobj) def _format_dst(dst_dict): -- GitLab From 96b16858bebe5cfe3ae54ef36a24df26d97a9bb4 Mon Sep 17 00:00:00 2001 From: Angel Kostov Date: Wed, 2 Feb 2022 16:03:27 +0100 Subject: [PATCH 3/8] Bumped version in changelog --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index b41e60f..88d428e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -xivo-utils (2021.14.00) xivo-helios; urgency=medium +xivo-utils (2022.03.00) xivo-izar-py3; urgency=medium * Python 3 compatibility -- GitLab From 77d2cc18c33a70361a064d7df6fd1276eee9e876 Mon Sep 17 00:00:00 2001 From: Angel Kostov Date: Wed, 2 Feb 2022 16:41:08 +0100 Subject: [PATCH 4/8] Fixed package name - removed '-python3' suffix --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index 6c08ec3..8f6cf18 100644 --- a/debian/control +++ b/debian/control @@ -8,7 +8,7 @@ Standards-Version: 3.7.2.2 Package: xivo-utils Architecture: all -Depends: ghostscript-x, xivo-lib-python-python3, python3-requests +Depends: ghostscript-x, xivo-lib-python, python3-requests Provides: pf-xivo-utils Conflicts: pf-xivo-utils Replaces: pf-xivo-utils -- GitLab From c2117d1c690b593699d52511bd48d0d4258fb6a4 Mon Sep 17 00:00:00 2001 From: Tomas Taraba Date: Thu, 3 Feb 2022 09:02:59 +0100 Subject: [PATCH 5/8] 4849 - Remove python build for non-python project --- debian/rules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/rules b/debian/rules index 02cf9a6..c23724a 100755 --- a/debian/rules +++ b/debian/rules @@ -6,4 +6,4 @@ export PYBUILD_DISABLE=test %: - dh $@ --with python3 --buildsystem=pybuild + dh $@ -- GitLab From 0b1c8b154b8b3b92e25f74431ddb0252ba79d614 Mon Sep 17 00:00:00 2001 From: Etienne Allovon Date: Thu, 10 Feb 2022 12:58:51 +0100 Subject: [PATCH 6/8] 4849 - change shebang to py3 --- agi-bin/xuc-request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agi-bin/xuc-request.py b/agi-bin/xuc-request.py index b206dfc..1d8a229 100755 --- a/agi-bin/xuc-request.py +++ b/agi-bin/xuc-request.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # -*- coding: UTF-8 -*- # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -- GitLab From f5f228eeca2de9d5406aaee34a1bf629e546d3c9 Mon Sep 17 00:00:00 2001 From: Vaclav Vorisek Date: Mon, 14 Feb 2022 12:03:32 +0100 Subject: [PATCH 7/8] shebang --- asterisk-bin/change-pass-vm | 2 +- bin/simultcalls.py | 2 +- bin/tzdataexport.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/asterisk-bin/change-pass-vm b/asterisk-bin/change-pass-vm index 94a6204..fe10d98 100755 --- a/asterisk-bin/change-pass-vm +++ b/asterisk-bin/change-pass-vm @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # Copyright (C) 2006-2015 Avencall # diff --git a/bin/simultcalls.py b/bin/simultcalls.py index f6ef942..e73f905 100755 --- a/bin/simultcalls.py +++ b/bin/simultcalls.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # -*- coding: utf-8 -*- # Copyright (C) 2013 Avencall diff --git a/bin/tzdataexport.py b/bin/tzdataexport.py index a591145..19342c3 100755 --- a/bin/tzdataexport.py +++ b/bin/tzdataexport.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/python3 # -*- coding: utf-8 -*- # Copyright (C) 2010-2013 Avencall -- GitLab From dfa1e1c8a653d019677fe2a4b3472c992ed1eea2 Mon Sep 17 00:00:00 2001 From: Tomas Taraba Date: Thu, 17 Feb 2022 10:44:37 +0100 Subject: [PATCH 8/8] 4849 - Change version to xivo-izar --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 88d428e..c2a17eb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -xivo-utils (2022.03.00) xivo-izar-py3; urgency=medium +xivo-utils (2022.03.00) xivo-izar; urgency=medium * Python 3 compatibility -- GitLab