76 lines
2.8 KiB
Python
76 lines
2.8 KiB
Python
import socket
|
|
import os
|
|
|
|
hostname = socket.gethostname()
|
|
PROD_HOST="pa_web"
|
|
|
|
ICON={}
|
|
ICON["Import"]="fa-file-upload"
|
|
ICON["Storage"]="fa-database"
|
|
ICON["Bin"]="fa-trash-alt"
|
|
|
|
if hostname == "lappy":
|
|
PA_JOB_MANAGER_HOST="localhost"
|
|
DB_URL = 'postgresql+psycopg2://pa:for_now_pa@localhost:5432/pa'
|
|
elif os.environ['FLASK_ENV'] == "development":
|
|
PA_JOB_MANAGER_HOST="localhost"
|
|
DB_URL = 'postgresql+psycopg2://pa:for_now_pa@mara.ddp.net:65432/pa'
|
|
elif os.environ['FLASK_ENV'] == "production":
|
|
PA_JOB_MANAGER_HOST="192.168.0.2"
|
|
DB_URL = 'postgresql+psycopg2://pa:for_now_pa@padb/pa'
|
|
else:
|
|
print( "ERROR: I do not know which environment (development, etc.) and which DB (on which host to use)" )
|
|
exit( -1 )
|
|
|
|
PA_JOB_MANAGER_PORT=55430
|
|
|
|
THUMBSIZE=256
|
|
|
|
def CreateSelect(name, selected, list, js=""):
|
|
str = f'<select id="{name}" name="{name}" style="color:#5bc0de;border:1px solid #5bc0de;"'
|
|
str += f'class="sm-txt form-control form-conrol-info" onChange="{js};this.form.submit()">'
|
|
for el in list:
|
|
str += '<option '
|
|
if el == selected:
|
|
str += 'selected '
|
|
str += f'>{el}</option>'
|
|
str += '</select>'
|
|
return str
|
|
|
|
def CreateFoldersSelect(selected):
|
|
str = f'<select id="folders" name="folders" style="color:#5bc0de;border:1px solid #5bc0de;"'
|
|
str += f'class="sm-txt form-control form-conrol-info" onChange="this.form.submit()">'
|
|
# if selected is true, then folders == true, so make this the selected option
|
|
if( selected ):
|
|
str += '<option selected value="True">In Folders</option>'
|
|
str += '<option value="False">Flat View</option>'
|
|
else:
|
|
str += '<option value="True">In Folders</option>'
|
|
str += '<option selected value="False">Flat View</option>'
|
|
str += '</select>'
|
|
return str
|
|
|
|
def LocationIcon(obj):
|
|
return ICON[obj.in_dir.in_path.type.name]
|
|
|
|
# translate a path type, a full FS path and a file into the full FS path of the
|
|
# symlink on the file system. To note, this is used with file == path, when we
|
|
# want to just get the symlink to the path itself, otherwise file == <path/some_filename>
|
|
### FIXME: I think this is way over-complicated, want to revist one day, with
|
|
#what params are passed in, what we need to get out -- I think the overloaded
|
|
#file/oath use case, and why sometimes we trail with a / or not and then concat
|
|
#last_dir and bit before last_dir, etc. this feels a bit too complicated for
|
|
#what it does OR we comment this much better
|
|
def SymlinkName(ptype, path, file):
|
|
sig_bit=file.replace(path, "")
|
|
last_dir=os.path.basename(path[0:-1])
|
|
|
|
if len(sig_bit) > 0 and sig_bit[-1] == '/':
|
|
last_bit = os.path.dirname(sig_bit)[0:-1]
|
|
else:
|
|
last_bit = os.path.dirname(sig_bit)
|
|
symlink = 'static/'+ptype+'/'+last_dir+'/'+last_bit
|
|
if symlink[-1] == '/':
|
|
symlink=symlink[0:-1]
|
|
return symlink
|