summaryrefslogtreecommitdiffstats
path: root/git_config.py
diff options
context:
space:
mode:
Diffstat (limited to 'git_config.py')
-rw-r--r--git_config.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/git_config.py b/git_config.py
index cee33e92..6b1f7107 100644
--- a/git_config.py
+++ b/git_config.py
@@ -122,6 +122,43 @@ class GitConfig(object):
122 return self.defaults.Has(name, include_defaults=True) 122 return self.defaults.Has(name, include_defaults=True)
123 return False 123 return False
124 124
125 def GetInt(self, name):
126 """Returns an integer from the configuration file.
127
128 This follows the git config syntax.
129
130 Args:
131 name: The key to lookup.
132
133 Returns:
134 None if the value was not defined, or is not a boolean.
135 Otherwise, the number itself.
136 """
137 v = self.GetString(name)
138 if v is None:
139 return None
140 v = v.strip()
141
142 mult = 1
143 if v.endswith('k'):
144 v = v[:-1]
145 mult = 1024
146 elif v.endswith('m'):
147 v = v[:-1]
148 mult = 1024 * 1024
149 elif v.endswith('g'):
150 v = v[:-1]
151 mult = 1024 * 1024 * 1024
152
153 base = 10
154 if v.startswith('0x'):
155 base = 16
156
157 try:
158 return int(v, base=base) * mult
159 except ValueError:
160 return None
161
125 def GetBoolean(self, name): 162 def GetBoolean(self, name):
126 """Returns a boolean from the configuration file. 163 """Returns a boolean from the configuration file.
127 None : The value was not defined, or is not a boolean. 164 None : The value was not defined, or is not a boolean.