-
Notifications
You must be signed in to change notification settings - Fork 120
/
global_statics.py
37 lines (27 loc) · 1022 Bytes
/
global_statics.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
import os
import sys
from pathlib import Path
from tempfile import gettempdir
import _ctypes
try:
from os import getuid
except:
# Windows does not have getuid(), so define to simply return 'tmp'
def getuid():
return 'tmp'
def cleanup_remove_files(lib_file, log_file):
if os.path.isfile(lib_file):
[os.remove(s) for s in [lib_file, log_file]]
def cleanup_unload_lib(lib):
# Clean-up the in-memory dynamic linked libraries.
# This is not really necessary, as these programs are not that large, but with the new random
# naming scheme which is required on Windows OS'es to deal with updates to a Parcels' kernel.
if lib is not None:
_ctypes.FreeLibrary(lib._handle) if sys.platform == 'win32' else _ctypes.dlclose(lib._handle)
def get_package_dir():
fpath = Path(__file__)
return fpath.parent.parent
def get_cache_dir():
directory = os.path.join(gettempdir(), "parcels-%s" % getuid())
Path(directory).mkdir(exist_ok=True)
return directory