3 # Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING
9 from string import Template
16 parser = argparse.ArgumentParser(description=\
17 'Run a test Ipsilon instance from the checkout directory')
18 parser.add_argument('--workdir', default=os.path.join(os.getcwd(), 'qrun'),
19 help="Directory in which db/session files are stored")
20 parser.add_argument('--cleanup', '-c', action='store_true', default=False,
21 help="Wipe workdir before starting")
22 return vars(parser.parse_args())
25 CONF_TEMPLATE="templates/install/ipsilon.conf"
28 CREATE TABLE login_config (name TEXT,option TEXT,value TEXT);
29 INSERT INTO login_config VALUES('global', 'enabled', 'testauth');
33 CREATE TABLE users(name TEXT, option TEXT, value TEXT);
34 INSERT INTO users VALUES('admin', 'is_admin', '1');
39 os.makedirs(os.path.join(workdir, 'sessions'))
41 admin_db = os.path.join(workdir, 'adminconfig.sqlite')
42 sql = os.path.join(workdir, 'admin.sql')
43 with open(sql, 'w+') as f:
44 f.write(ADMIN_TEMPLATE)
45 subprocess.call(['sqlite3', '-init', sql, admin_db, '.quit'])
47 users_db = os.path.join(workdir, 'userprefs.sqlite')
48 sql = os.path.join(workdir, 'users.sql')
49 with open(sql, 'w+') as f:
50 f.write(USERS_TEMPLATE)
51 subprocess.call(['sqlite3', '-init', sql, users_db, '.quit'])
53 trans_db = os.path.join(workdir, 'transactions.sqlite')
54 cachedir = os.path.join(workdir, 'cache')
56 with open(CONF_TEMPLATE) as f:
57 conf_template = f.read()
58 t = Template(conf_template)
59 text = t.substitute({'debugging': 'True',
61 'staticdir': os.getcwd(),
69 'sessval': os.path.join(workdir, 'sessions'),
72 conf = os.path.join(workdir, 'ipsilon.conf')
73 with open(conf, 'w+') as f:
77 if __name__ == '__main__':
82 penv.update(os.environ)
83 penv['PYTHONPATH'] = os.getcwd()
85 schema_init = os.path.join(os.getcwd(), 'ipsilon/install/ipsilon-upgrade-database')
86 exe = os.path.join(os.getcwd(), 'ipsilon/ipsilon')
89 shutil.rmtree(args['workdir'])
91 if not os.path.exists(args['workdir']):
92 conf = config(args['workdir'])
94 conf = os.path.join(args['workdir'], 'ipsilon.conf')
96 if not os.path.exists(os.path.join(args['workdir'], 'ui')):
97 os.symlink(os.path.join(os.getcwd(), 'ui'),
98 os.path.join(args['workdir'], 'ui'))
100 if not os.path.exists(os.path.join(args['workdir'], 'cache')):
101 # This is only used in quickrun. Apache serves this directly
102 os.makedirs(os.path.join(args['workdir'], 'cache'))
104 os.chdir(args['workdir'])
106 p = subprocess.Popen([schema_init, conf], env=penv)
109 if p.returncode == 0:
110 p = subprocess.Popen([exe, conf], env=penv)