Update Friulian translation
[glib.git] / gio / gdbus-2.0 / codegen / utils.py
blob39e046351620258c80e0f146d50d7cf85d44fd33
1 # -*- Mode: Python -*-
3 # GDBus - GLib D-Bus Library
5 # Copyright (C) 2008-2011 Red Hat, Inc.
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General
18 # Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 # Author: David Zeuthen <davidz@redhat.com>
22 import distutils.version
24 def strip_dots(s):
25 ret = ''
26 force_upper = False
27 for c in s:
28 if c == '.':
29 force_upper = True
30 else:
31 if force_upper:
32 ret += c.upper()
33 force_upper = False
34 else:
35 ret += c
36 return ret
38 def dots_to_hyphens(s):
39 return s.replace('.', '-')
41 def camel_case_to_uscore(s):
42 ret = ''
43 insert_uscore = False
44 prev_was_lower = False
45 initial = True;
46 for c in s:
47 # Keep initial underscores in camel case
48 if initial and c == '_':
49 ret += '_'
50 continue;
51 initial = False
53 if c.isupper():
54 if prev_was_lower:
55 insert_uscore = True
56 prev_was_lower = False
57 else:
58 prev_was_lower = True
59 if insert_uscore:
60 ret += '_'
61 ret += c.lower()
62 insert_uscore = False
63 return ret
65 def is_ugly_case(s):
66 if s and s.find('_') > 0:
67 return True
68 return False
70 def lookup_annotation(annotations, key):
71 if annotations:
72 for a in annotations:
73 if a.key == key:
74 return a.value
75 return None
77 def lookup_docs(annotations):
78 s = lookup_annotation(annotations, 'org.gtk.GDBus.DocString')
79 if s == None:
80 return ''
81 else:
82 return s
84 def lookup_since(annotations):
85 s = lookup_annotation(annotations, 'org.gtk.GDBus.Since')
86 if s == None:
87 return ''
88 else:
89 return s
91 def lookup_brief_docs(annotations):
92 s = lookup_annotation(annotations, 'org.gtk.GDBus.DocString.Short')
93 if s == None:
94 return ''
95 else:
96 return s
98 def version_cmp_key(key):
99 # If the 'since' version is 'UNRELEASED', compare higher than anything else
100 # If it is empty put a 0 in its place as this will
101 # allow LooseVersion to work and will always compare lower.
102 if key[0] == 'UNRELEASED':
103 v = '9999'
104 elif key[0]:
105 v = str(key[0])
106 else:
107 v = '0'
108 return (distutils.version.LooseVersion(v), key[1])