forked from morevnaproject-org/papagayo-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.py
38 lines (30 loc) · 1.07 KB
/
utilities.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
import imp
import os
import sys
def main_is_frozen():
return (hasattr(sys, "frozen") or # new py2exe
hasattr(sys, "importers") or # old py2exe
imp.is_frozen("__main__")) # tools/freeze
def get_main_dir():
if main_is_frozen():
return os.path.abspath(os.path.dirname(sys.executable))
return os.path.dirname(os.path.abspath(__file__))
def which(program):
def is_exe(fpath):
if os.name == 'nt':
return os.path.isfile(fpath) or os.path.isfile(fpath + ".exe") or os.path.isfile(fpath + ".bat")
else:
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
program = os.path.realpath(program)
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
exe_file = os.path.realpath(exe_file)
if is_exe(exe_file):
return exe_file
return None