blob: 0edcdaf0f878d0319a833f158db344a2b462bf82 [file] [log] [blame]
Sergiusz Bazanski902d8602019-07-18 17:05:26 +02001import configparser
2import os
3import subprocess
4import tempfile
5
6import bazel_tools
7import bazel_tools.tools.python
8
9from bazel_tools.tools.python.runfiles import runfiles
10r = runfiles.Create()
11
Sergiusz Bazanski5f9b1ec2019-09-22 02:19:18 +020012uwsgi = r.Rlocation("pip__uWSGI_2_0_18_cp36_cp36m_linux_x86_64/scripts/uwsgi")
13print(uwsgi)
14settings = r.Rlocation("hscloud/personal/q3k/djtest/djtest/settings.py")
15print(settings)
Sergiusz Bazanski902d8602019-07-18 17:05:26 +020016
17apppath = os.path.dirname(settings)
18sitepath = os.path.dirname(apppath)
19
20pythonpath = os.environ['PYTHONPATH']
21
22# Make UWSGI ini config file
23cfgf = tempfile.NamedTemporaryFile(mode='w', delete=False)
24
25config = configparser.ConfigParser()
26config['uwsgi'] = {}
27config['uwsgi']['master'] = '1'
28config['uwsgi']['chdir'] = sitepath
29config['uwsgi']['module'] = 'djtest.wsgi'
30config['uwsgi']['env'] = 'DJANGO_SETTINGS_MODULE=djtest.settings'
31config['uwsgi']['http'] = '127.0.0.1:8080'
32config['uwsgi']['pythonpath'] = pythonpath
33
34config.write(cfgf)
35cfgf.close()
36
37args = [
38 # uwsgi from runfiles is non-chmodded, run through interpreter
39 '/lib64/ld-linux-x86-64.so.2',
40 uwsgi,
41 '--ini', cfgf.name,
42]
43
44subprocess.call(args)
45
46os.unlink(cfgf.name)