summaryrefslogtreecommitdiffstats
path: root/ipapython
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2009-08-27 14:12:55 -0400
committerRob Crittenden <rcritten@redhat.com>2009-08-27 14:15:26 -0400
commit559c76f761ff46c0d0e7f679d24d7ca5304db101 (patch)
tree7df5b1122aca7283bc4a01bfc4afb80e6f265c68 /ipapython
parentcab55250760ad1633ed115564f83750fd91e230d (diff)
downloadfreeipa-559c76f761ff46c0d0e7f679d24d7ca5304db101.tar.gz
freeipa-559c76f761ff46c0d0e7f679d24d7ca5304db101.tar.xz
freeipa-559c76f761ff46c0d0e7f679d24d7ca5304db101.zip
Add option to the installer for uid/gid starting numbers.
This also adds a new option to the template system. If you include eval(string) in a file that goes through the templater then the string in the eval will be evaluated by the Python interpreter. This is used so one can do $UIDSTART+1. If any errors occur during the evaluation the original string is is returned, eval() and all so it is up to the developer to make sure the evaluation passes. The default value for uid and gid is now a random value between 1,000,000 and (2^31 - 1,000,000)
Diffstat (limited to 'ipapython')
-rw-r--r--ipapython/ipautil.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
index 240e0d87..47b651c1 100644
--- a/ipapython/ipautil.py
+++ b/ipapython/ipautil.py
@@ -68,7 +68,15 @@ def realm_to_suffix(realm_name):
return ",".join(terms)
def template_str(txt, vars):
- return string.Template(txt).substitute(vars)
+ val = string.Template(txt).substitute(vars)
+
+ # eval() is a special string one can insert into a template to have the
+ # Python interpreter evaluate the string. This is intended to allow
+ # math to be performed in templates.
+ pattern = re.compile('(eval\s*\(([^()]*)\))')
+ val = pattern.sub(lambda x: str(eval(x.group(2))), val)
+
+ return val
def template_file(infilename, vars):
txt = open(infilename).read()