-
Notifications
You must be signed in to change notification settings - Fork 0
/
eelutil.py
72 lines (59 loc) · 1.87 KB
/
eelutil.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os.path
import shutil
import sys
import eel
import settings
def getRootPath()->str:
"""
Retrieves the current root folder wether running in dev or application
:return: The path to the root folder with a tailing slash
:rtype: str
"""
if '--develop' in sys.argv:
return eel._get_real_path('public') + '/'
return eel._get_real_path('build') + '/'
def getFilePath(filename:str)->str:
"""
:param filename:
:type filename:
:return:
:rtype:
"""
return getRootPath()+filename
def getFileURL(filename:str)->str:
"""
Retrieves a URL that can be passed to JS in order to load files that have been created through python.
"""
if '--develop' in sys.argv:
return settings.REACT_DEV_PATH + filename
return settings.EEL_PATH + filename
def createTmpFolder(tmpFolderName:str = 'tmp')->str:
"""
Creates a temp Folder for sharing files between python and react
:param tmpFolderName: The name of the foler
:type tmpFolderName: str
:return: the full path that can be used in python to write into folder.
:rtype: str
"""
rp = getRootPath()
if not os.path.isdir(rp+tmpFolderName):
os.mkdir(rp + tmpFolderName)
return rp + tmpFolderName
def removeTmpFolder(tmpFolderName:str = 'tmp'):
"""
Removes the given tmp folder and all its contents from root path
:param tmpFolderName: Name of folder to delete, nothing happens if it is empty
:type tmpFolderName: str
"""
rp = getRootPath()
if not os.path.isdir(rp + tmpFolderName):
return
shutil.rmtree(rp + tmpFolderName)
def emptyTmpFolder(tmpFolderName:str = 'tmp'):
"""
Will empty the given tmp directory, by deletion and recreation
:param tmpFolderName: Tmp directory name
:type tmpFolderName: str
"""
removeTmpFolder(tmpFolderName)
createTmpFolder(tmpFolderName)