summaryrefslogtreecommitdiff
path: root/qface/helper
diff options
context:
space:
mode:
Diffstat (limited to 'qface/helper')
-rw-r--r--qface/helper/generic.py52
-rw-r--r--qface/helper/qtcpp.py6
2 files changed, 55 insertions, 3 deletions
diff --git a/qface/helper/generic.py b/qface/helper/generic.py
new file mode 100644
index 0000000..713952d
--- /dev/null
+++ b/qface/helper/generic.py
@@ -0,0 +1,52 @@
+import json
+import hashlib
+
+
+def jsonify(symbol):
+ """ returns json format for symbol """
+ try:
+ # all symbols have a toJson method, try it
+ return json.dumps(symbol.toJson(), indent=' ')
+ except AttributeError:
+ pass
+ return json.dumps(symbol, indent=' ')
+
+
+def upper_first(s):
+ """ uppercase first letter """
+ s = str(s)
+ return s[0].upper() + s[1:]
+
+
+def lower_first(s):
+ s = str(s)
+ return s[0].lower() + s[1:]
+
+
+def hash(symbol, hash_type='sha1'):
+ """ create a hash code from symbol """
+ code = hashlib.new(hash_type)
+ code.update(str(symbol).encode('utf-8'))
+ return code.hexdigest()
+
+
+def path(symbol):
+ """ replaces '.' with '/' """
+ return str(symbol).replace('.', '/')
+
+
+def identifier(s):
+ return str(s).lower().replace('.', '_')
+
+
+def get_filters():
+ return {
+ 'jsonify': jsonify,
+ 'upper_first': upper_first,
+ 'lower_first': lower_first,
+ 'upperfirst': upper_first,
+ 'lowerfirst': lower_first,
+ 'hash': hash,
+ 'path': path,
+ 'identifier': identifier,
+ }
diff --git a/qface/helper/qtcpp.py b/qface/helper/qtcpp.py
index aeae6f0..c9e6835 100644
--- a/qface/helper/qtcpp.py
+++ b/qface/helper/qtcpp.py
@@ -36,7 +36,7 @@ class Filters(object):
return 'QVariant()'
elif t.is_void:
return ''
- elif t.is_enum:
+ elif t.is_enumeration:
value = next(iter(t.reference.members))
return '{0}::{0}Enum::{1}'.format(symbol.type, value)
elif symbol.kind == 'enum':
@@ -58,7 +58,7 @@ class Filters(object):
@staticmethod
def parameterType(symbol):
prefix = Filters.classPrefix
- if symbol.type.is_enum:
+ if symbol.type.is_enumeration:
return '{0}::{0}Enum {1}'.format(symbol.type, symbol)
if symbol.type.is_void or symbol.type.is_primitive:
if symbol.type.is_string:
@@ -88,7 +88,7 @@ class Filters(object):
def returnType(symbol):
prefix = Filters.classPrefix
t = symbol.type
- if t.is_enum:
+ if t.is_enumeration:
return '{0}::{0}Enum'.format(symbol.type)
if symbol.type.is_void or symbol.type.is_primitive:
if t.is_string: