summaryrefslogtreecommitdiffstats
path: root/quickrun.py
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2014-08-25 16:40:21 -0400
committerPatrick Uiterwijk <puiterwijk@redhat.com>2014-08-27 18:15:03 -0400
commita06b990c66c32909b8872ac2f5d825c6b7316a3a (patch)
tree408e56adfea23800a48db98dfd650dd535ded7d5 /quickrun.py
parentf7b6d96d284f78b8ee94d252b37e874dc32baf2b (diff)
downloadipsilon-a06b990c66c32909b8872ac2f5d825c6b7316a3a.tar.gz
ipsilon-a06b990c66c32909b8872ac2f5d825c6b7316a3a.tar.xz
ipsilon-a06b990c66c32909b8872ac2f5d825c6b7316a3a.zip
Restore ability to run from checkout
also adds quickrun.py script to make it easy. Signed-off-by: Simo Sorce <simo@redhat.com> Reviewed-by: Patrick Uiterwijk <puiterwijk@redhat.com>
Diffstat (limited to 'quickrun.py')
-rwxr-xr-xquickrun.py98
1 files changed, 98 insertions, 0 deletions
diff --git a/quickrun.py b/quickrun.py
new file mode 100755
index 0000000..caa9627
--- /dev/null
+++ b/quickrun.py
@@ -0,0 +1,98 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2014 Simo Sorce <simo@redhat.com>
+#
+# see file 'COPYING' for use and warranty information
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import argparse
+import os
+import subprocess
+from string import Template
+
+
+logger = None
+
+
+def parse_args():
+ parser = argparse.ArgumentParser(description=\
+ 'Run a test Ipsilon instance from the checkout directory')
+ parser.add_argument('--workdir', default=os.path.join(os.getcwd(), 'tmp'),
+ help="Directory in which db/session files are stored")
+ return vars(parser.parse_args())
+
+
+CONF_TEMPLATE='''
+[global]
+debug = True
+
+log.screen = True
+base.mount = "/idp"
+base.dir = "${BASEDIR}"
+admin.config.db = "${ADMINDB}"
+user.prefs.db = "${USERSDB}"
+
+tools.sessions.on = True
+tools.sessions.storage_type = "file"
+tools.sessions.storage_path = "${WORKDIR}/sessions"
+tools.sessions.timeout = 60
+'''
+
+ADMIN_TEMPLATE='''
+CREATE TABLE login_config (name TEXT,option TEXT,value TEXT);
+INSERT INTO login_config VALUES('global', 'order', 'testauth');
+'''
+
+USERS_TEMPLATE='''
+CREATE TABLE users(name TEXT, option TEXT, value TEXT);
+INSERT INTO users VALUES('admin', 'is_admin', '1');
+'''
+
+if __name__ == '__main__':
+
+ args = parse_args()
+
+ penv = dict()
+ penv.update(os.environ)
+ penv['PYTHONPATH'] = './'
+
+ if not os.path.exists(args['workdir']):
+ os.makedirs(args['workdir'])
+ os.makedirs(os.path.join(args['workdir'], 'sessions'))
+
+ admin_db = os.path.join(args['workdir'], 'adminconfig.sqlite')
+ sql = os.path.join(args['workdir'], 'admin.sql')
+ with open(sql, 'w+') as f:
+ f.write(ADMIN_TEMPLATE)
+ subprocess.call(['sqlite3', '-init', sql, admin_db, '.quit'])
+
+ users_db = os.path.join(args['workdir'], 'users.sqlite')
+ sql = os.path.join(args['workdir'], 'users.sql')
+ with open(sql, 'w+') as f:
+ f.write(USERS_TEMPLATE)
+ subprocess.call(['sqlite3', '-init', sql, users_db, '.quit'])
+
+ t = Template(CONF_TEMPLATE)
+ text = t.substitute({'BASEDIR': os.getcwd(),
+ 'WORKDIR': args['workdir'],
+ 'ADMINDB': admin_db,
+ 'USERSDB': users_db})
+ conf = os.path.join(args['workdir'], 'ipsilon.conf')
+ with open(conf, 'w+') as f:
+ f.write(text)
+
+
+ p = subprocess.Popen(['./ipsilon/ipsilon', conf], env=penv)
+ p.wait()