Skip to content

Commit

Permalink
Merge branch 'jb45864-python3' into 'master'
Browse files Browse the repository at this point in the history
Jb45864 python3

See merge request mer-core/commhistory-daemon!36
  • Loading branch information
blam committed Jul 8, 2020
2 parents b5006bd + 823ef30 commit 343c451
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 80 deletions.
2 changes: 1 addition & 1 deletion rpm/commhistory-daemon.spec
Expand Up @@ -25,7 +25,7 @@ BuildRequires: qt5-qttools
BuildRequires: qt5-qttools-linguist
BuildRequires: libqofono-qt5-devel >= 0.89
BuildRequires: libqofonoext-devel
BuildRequires: python
BuildRequires: python3-base
BuildRequires: systemd
Requires: libcommhistory-qt5 >= 1.9.33
Requires: libqofono-qt5 >= 0.66
Expand Down
2 changes: 1 addition & 1 deletion src/TpExtensions/all.xml
Expand Up @@ -2,7 +2,7 @@
xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"
xmlns:xi="http://www.w3.org/2001/XInclude">

<tp:title>Commhistoryd telepathy-qt4 extensions</tp:title>
<tp:title>Commhistoryd telepathy-qt extensions</tp:title>

<xi:include href="connection.xml"/>

Expand Down
2 changes: 1 addition & 1 deletion src/contactauthorizationlistener.cpp
Expand Up @@ -90,7 +90,7 @@ void ContactAuthorizationListener::slotConnectionReady(const Tp::ConnectionPtr&
break;
}
}
#else // TODO: enable this back when tp-qt4 declares metatype for Tp::ConnectionPtr
#else // TODO: enable this back when tp-qt declares metatype for Tp::ConnectionPtr
// and type Tp::Account::connection property
QVariantMap filter;
filter.insert(QLatin1String("connection"), QVariant::fromValue(connection));
Expand Down
6 changes: 3 additions & 3 deletions src/src.pro
Expand Up @@ -114,12 +114,12 @@ mmshandler.source_flags = -l MmsHandler
EXTENSIONS_DIR = $$IN_PWD/TpExtensions
EXTENSIONS_GENERATED_DIR = $$EXTENSIONS_DIR/.gen
TOOLS_DIR = $$IN_PWD/../tools
PYTHON = $$TOOLS_DIR/python.sh 2.6
PYTHON = python3
MOC = $$TOOLS_DIR/mocwrapper.sh

XINCLUDATOR = $$TOOLS_DIR/xincludator.py
CONSTANTS_GEN = $$TOOLS_DIR/qt4-constants-gen.py
CLIENT_GEN = $$TOOLS_DIR/qt4-client-gen.py
CONSTANTS_GEN = $$TOOLS_DIR/qt-constants-gen.py
CLIENT_GEN = $$TOOLS_DIR/qt-client-gen.py

HEADERS += TpExtensions/connection.h \
TpExtensions/Connection
Expand Down
2 changes: 1 addition & 1 deletion tests/stubs/TelepathyQt/cli-properties.h
@@ -1,5 +1,5 @@
/*
* This file contains D-Bus client proxy classes generated by qt4-client-gen.py.
* This file contains D-Bus client proxy classes generated by qt-client-gen.py.
*
* This file can be distributed under the same terms as the specification from
* which it was generated.
Expand Down
2 changes: 1 addition & 1 deletion tests/stubs/TpExtensions/constants.h
@@ -1,4 +1,4 @@
/* Generated from CommHistory telepathy-qt4 extensions
/* Generated from CommHistory telepathy-qt extensions
*/

#include <QFlags>
Expand Down
32 changes: 16 additions & 16 deletions tools/libqt4codegen.py → tools/libqtcodegen.py
@@ -1,6 +1,6 @@
"""Library code for Qt4 D-Bus-related code generation.
"""Library code for Qt D-Bus-related code generation.
The master copy of this library is in the telepathy-qt4 repository -
The master copy of this library is in the telepathy-qt repository -
please make any changes there.
"""

Expand All @@ -21,12 +21,12 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

from sys import maxint
from sys import maxsize
import re
from libtpcodegen import get_by_path, get_descendant_text, NS_TP, xml_escape


class _Qt4TypeBinding:
class _QtTypeBinding:
def __init__(self, val, inarg, outarg, array_val, custom_type, array_of,
array_depth=None):
self.val = val
Expand Down Expand Up @@ -70,11 +70,11 @@ def binding_from_usage(sig, tptype, custom_lists, external=False, explicit_own_n
custom_type = False
array_of = None

if natives.has_key(sig):
if sig in natives:
typename, pass_by_ref, array_name = natives[sig]
val = typename
inarg = (pass_by_ref and ('const %s&' % val)) or val
elif sig[0] == 'a' and natives.has_key(sig[1]) and natives[sig[1]][2]:
elif sig[0] == 'a' and sig[1] in natives and natives[sig[1]][2]:
val = natives[sig[1]][2]
if explicit_own_ns:
val = explicit_own_ns + '::' + val
Expand All @@ -97,7 +97,7 @@ def binding_from_usage(sig, tptype, custom_lists, external=False, explicit_own_n
extra_list_nesting += 1
tptype = tptype[:-2]

assert custom_lists.has_key(tptype), ('No array version of custom type %s in the spec, but array version used' % tptype)
assert tptype in custom_lists, ('No array version of custom type %s in the spec, but array version used' % tptype)
val = custom_lists[tptype] + 'List' * extra_list_nesting
else:
val = tptype
Expand All @@ -107,7 +107,7 @@ def binding_from_usage(sig, tptype, custom_lists, external=False, explicit_own_n
assert False, 'Don\'t know how to map type (%s, %s)' % (sig, tptype)

outarg = val + '&'
return _Qt4TypeBinding(val, inarg, outarg, None, custom_type, array_of)
return _QtTypeBinding(val, inarg, outarg, None, custom_type, array_of)

def binding_from_decl(name, array_name, array_depth=None, external=False, explicit_own_ns=''):
val = name.replace('_', '')
Expand All @@ -117,15 +117,15 @@ def binding_from_decl(name, array_name, array_depth=None, external=False, explic
val = explicit_own_ns + '::' + val
inarg = 'const %s&' % val
outarg = '%s&' % val
return _Qt4TypeBinding(val, inarg, outarg, array_name.replace('_', ''), True, None, array_depth)
return _QtTypeBinding(val, inarg, outarg, array_name.replace('_', ''), True, None, array_depth)

def extract_arg_or_member_info(els, custom_lists, externals, typesns, docstring_indent=' * ', docstring_brackets=None, docstring_maxwidth=80):
names = []
docstrings = []
bindings = []

for el in els:
names.append(get_qt4_name(el))
names.append(get_qt_name(el))
docstrings.append(format_docstring(el, docstring_indent, docstring_brackets, docstring_maxwidth))

sig = el.getAttribute('type')
Expand All @@ -148,8 +148,8 @@ def format_docstring(el, indent=' * ', brackets=None, maxwidth=80):

if docstring_el.getAttribute('xmlns') == 'http://www.w3.org/1999/xhtml':
splitted = ''.join([el.toxml() for el in docstring_el.childNodes]).strip(' ').strip('\n').split('\n')
level = min([not match and maxint or match.end() - 1 for match in [re.match('^ *[^ ]', line) for line in splitted]])
assert level != maxint
level = min([not match and maxsize or match.end() - 1 for match in [re.match('^ *[^ ]', line) for line in splitted]])
assert level != maxsize
lines = [line[level:].replace('\\', '\\\\') for line in splitted]
else:
content = xml_escape(get_descendant_text(docstring_el).replace('\n', ' ').strip())
Expand Down Expand Up @@ -225,7 +225,7 @@ def gather_custom_lists(spec, typesns):
custom_lists[tptype] = array_val
custom_lists[ns + '::' + tptype] = ns + '::' + array_val
if array_depth >= 2:
for i in xrange(array_depth):
for i in range(array_depth):
custom_lists[tptype + ('[]' * (i+1))] = (
array_val + ('List' * i))
custom_lists[ns + '::' + tptype + ('[]' * (i+1))] = (
Expand All @@ -240,7 +240,7 @@ def get_headerfile_cmd(realinclude, prettyinclude, indent=' * '):
else:
return ''

def get_qt4_name(el):
def get_qt_name(el):
name = el.getAttribute('name')

if el.localName in ('method', 'signal', 'property'):
Expand All @@ -255,9 +255,9 @@ def get_qt4_name(el):
if name[0].isupper() and name[1].islower():
name = name[0].lower() + name[1:]

return qt4_identifier_escape(name.replace('_', ''))
return qt_identifier_escape(name.replace('_', ''))

def qt4_identifier_escape(str):
def qt_identifier_escape(str):
built = (str[0].isdigit() and ['_']) or []

for c in str:
Expand Down
2 changes: 1 addition & 1 deletion tools/libtpcodegen.py
Expand Up @@ -171,7 +171,7 @@ class _SignatureIter:
def __init__(self, string):
self.remaining = string

def next(self):
def __next__(self):
if self.remaining == '':
raise StopIteration

Expand Down
37 changes: 0 additions & 37 deletions tools/python.sh

This file was deleted.

21 changes: 11 additions & 10 deletions tools/qt4-client-gen.py → tools/qt-client-gen.py
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
#
# Copyright (C) 2008 Collabora Limited <http://www.collabora.co.uk>
# Copyright (C) 2008 Nokia Corporation
Expand All @@ -19,11 +19,12 @@

from sys import argv
import xml.dom.minidom
import functools
import codecs
from getopt import gnu_getopt

from libtpcodegen import NS_TP, get_descendant_text, get_by_path
from libqt4codegen import binding_from_usage, extract_arg_or_member_info, format_docstring, gather_externals, gather_custom_lists, get_headerfile_cmd, get_qt4_name, qt4_identifier_escape
from libqtcodegen import binding_from_usage, extract_arg_or_member_info, format_docstring, gather_externals, gather_custom_lists, get_headerfile_cmd, get_qt_name, qt_identifier_escape

class Generator(object):
def __init__(self, opts):
Expand All @@ -43,7 +44,7 @@ def __init__(self, opts):
self.visibility = opts.get('--visibility', '')
ifacedom = xml.dom.minidom.parse(opts['--ifacexml'])
specdom = xml.dom.minidom.parse(opts['--specxml'])
except KeyError, k:
except KeyError as k:
assert False, 'Missing required parameter %s' % k.args[0]

self.hs = []
Expand All @@ -57,7 +58,7 @@ def __call__(self):
# Output info header and includes
self.h("""\
/*
* This file contains D-Bus client proxy classes generated by qt4-client-gen.py.
* This file contains D-Bus client proxy classes generated by qt-client-gen.py.
*
* This file can be distributed under the same terms as the specification from
* which it was generated.
Expand Down Expand Up @@ -113,7 +114,7 @@ class PendingOperation;

# Output interface proxies
def ifacenodecmp(x, y):
xname, yname = [self.namespace + '::' + node.getAttribute('name').replace('/', '').replace('_', '') + 'Interface' for node in x, y]
xname, yname = [self.namespace + '::' + node.getAttribute('name').replace('/', '').replace('_', '') + 'Interface' for node in (x, y)]

if xname == self.mainiface:
return -1
Expand All @@ -122,7 +123,7 @@ def ifacenodecmp(x, y):
else:
return cmp(xname, yname)

self.ifacenodes.sort(cmp=ifacenodecmp)
self.ifacenodes = sorted(self.ifacenodes, key=functools.cmp_to_key(ifacenodecmp))
for ifacenode in self.ifacenodes:
self.do_ifacenode(ifacenode)

Expand All @@ -135,8 +136,8 @@ def ifacenodecmp(x, y):
self.h("Q_DECLARE_METATYPE(" + self.namespace + "::" + classname + "*)\n")

# Write output to files
(codecs.getwriter('utf-8')(open(self.headerfile, 'w'))).write(''.join(self.hs))
(codecs.getwriter('utf-8')(open(self.implfile, 'w'))).write(''.join(self.bs))
(codecs.getwriter('utf-8')(open(self.headerfile, 'wb'))).write(''.join(self.hs))
(codecs.getwriter('utf-8')(open(self.implfile, 'wb'))).write(''.join(self.bs))

def do_ifacenode(self, ifacenode):
# Extract info
Expand Down Expand Up @@ -408,7 +409,7 @@ def do_method(self, method):
inargs = []
outargs = []

for i in xrange(len(args)):
for i in range(len(args)):
if args[i].getAttribute('direction') == 'out':
outargs.append(i)
else:
Expand Down Expand Up @@ -492,7 +493,7 @@ def do_signal(self, signal):
%s\
""" % (name, format_docstring(signal, ' * ')))

for i in xrange(len(argnames)):
for i in range(len(argnames)):
assert argnames[i] != None, 'Name missing from argument at index %d for signal %s' % (i, name)
if argdocstrings[i]:
self.h("""\
Expand Down
8 changes: 4 additions & 4 deletions tools/qt4-constants-gen.py → tools/qt-constants-gen.py
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
#
# Copyright (C) 2008 Collabora Limited <http://www.collabora.co.uk>
# Copyright (C) 2008 Nokia Corporation
Expand All @@ -23,15 +23,15 @@
from getopt import gnu_getopt

from libtpcodegen import NS_TP, get_descendant_text, get_by_path
from libqt4codegen import format_docstring
from libqtcodegen import format_docstring

class Generator(object):
def __init__(self, opts):
try:
self.namespace = opts['--namespace']
self.must_define = opts.get('--must-define', None)
dom = xml.dom.minidom.parse(opts['--specxml'])
except KeyError, k:
except KeyError as k:
assert False, 'Missing required parameter %s' % k.args[0]

self.define_prefix = None
Expand All @@ -46,7 +46,7 @@ def __init__(self, opts):
self.out = codecs.getwriter('utf-8')(stdout)

def h(self, code):
self.out.write(code)
self.out.buffer.write(code.encode('utf-8'))

def __call__(self):
# Header
Expand Down
8 changes: 4 additions & 4 deletions tools/xincludator.py
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3

from sys import argv, stdout, stderr
import codecs, locale
Expand All @@ -11,7 +11,7 @@

def xincludate(dom, base, dropns = []):
remove_attrs = []
for i in xrange(dom.documentElement.attributes.length):
for i in range(dom.documentElement.attributes.length):
attr = dom.documentElement.attributes.item(i)
if attr.prefix == 'xmlns':
if attr.localName in dropns:
Expand All @@ -35,5 +35,5 @@ def xincludate(dom, base, dropns = []):
dom = xml.dom.minidom.parse(argv[0])
xincludate(dom, argv[0])
xml = dom.toxml()
stdout.write(xml)
stdout.write('\n')
stdout.buffer.write(xml.encode('utf-8'))
stdout.buffer.write(b'\n')

0 comments on commit 343c451

Please sign in to comment.