Pass common environment variable to scripts

This commit is contained in:
JonnyWong16 2018-03-16 18:37:50 -07:00
parent 2479533d07
commit ee041db63d
3 changed files with 47 additions and 34 deletions

View file

@ -933,3 +933,36 @@ def eval_logic_groups_to_bool(logic_groups, eval_conds):
result = result or eval_cond
return result
def get_plexpy_url(hostname=None):
if plexpy.CONFIG.ENABLE_HTTPS:
scheme = 'https'
else:
scheme = 'http'
if hostname is None and plexpy.CONFIG.HTTP_HOST == '0.0.0.0':
import socket
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.connect(('<broadcast>', 0))
hostname = s.getsockname()[0]
except socket.error:
hostname = socket.gethostbyname(socket.gethostname())
if not hostname:
hostname = 'localhost'
else:
hostname = hostname or plexpy.CONFIG.HTTP_HOST
if plexpy.CONFIG.HTTP_PORT not in (80, 443):
port = ':' + str(plexpy.CONFIG.HTTP_PORT)
else:
port = ''
if plexpy.CONFIG.HTTP_ROOT.strip('/'):
root = '/' + plexpy.CONFIG.HTTP_ROOT.strip('/')
else:
root = ''
return scheme + '://' + hostname + port + root