blob: a5c325ed5df8d22aff718504c087b41e925c123c [file] [log] [blame]
import configparser
import os
import subprocess
import tempfile
import bazel_tools
import bazel_tools.tools.python
from elftools.elf.elffile import ELFFile
from elftools.elf.segments import InterpSegment
from bazel_tools.tools.python.runfiles import runfiles
r = runfiles.Create()
uwsgi = r.Rlocation("pydeps_pypi__uWSGI_2_0_18/uWSGI-2.0.18.data/scripts/uwsgi")
settings = r.Rlocation("hscloud/personal/q3k/djtest/djtest/settings.py")
# uwsgi from runfiles is non-chmodded, we have to run it through its interpreter
ld = None
with open(uwsgi, 'rb') as f:
elffile = ELFFile(f)
for segment in elffile.iter_segments():
if isinstance(segment, InterpSegment):
ld = segment.get_interp_name()
if ld is None:
raise Exception("could not find interpreter/ld.so path in uwsgi - failing")
apppath = os.path.dirname(settings)
sitepath = os.path.dirname(apppath)
pythonpath = os.environ['PYTHONPATH']
# Make UWSGI ini config file
cfgf = tempfile.NamedTemporaryFile(mode='w', delete=False)
config = configparser.ConfigParser()
config['uwsgi'] = {}
config['uwsgi']['master'] = '1'
config['uwsgi']['chdir'] = sitepath
config['uwsgi']['module'] = 'djtest.wsgi'
config['uwsgi']['env'] = 'DJANGO_SETTINGS_MODULE=djtest.settings'
config['uwsgi']['http'] = '127.0.0.1:8080'
config['uwsgi']['pythonpath'] = pythonpath
config.write(cfgf)
cfgf.close()
args = [
ld,
uwsgi,
'--ini', cfgf.name,
]
subprocess.call(args)
os.unlink(cfgf.name)