forked from katiemorrisfx/KMFX-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkmfx_extrascriptpaths.py
103 lines (72 loc) · 2.19 KB
/
kmfx_extrascriptpaths.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import fx
from fx import *
import os
import os.path
import sys
'''enables autoload of scripts from additional disk paths on silhouette preferences '''
fx.prefs.add("KMFX.ExtraScriptPath1","")
fx.prefs.add("KMFX.ExtraScriptPath2","")
### you can add more paths using the same logic, just increase the numbers
# fx.prefs.add("KMFX.ExtraScriptPath3","")
# fx.prefs.add("KMFX.ExtraScriptPath4","")
skip_files = [ "__init__","__pycache__", "CVS", "tags","user_keybinds"]
def getScripts(path, package = None):
scripts = []
possible = []
dir = os.listdir(path)
for file in dir:
f = os.path.splitext(file)
name = f[0]
ext = f[1]
if name == "":
continue
if name in skip_files:
continue
if os.path.isdir(os.path.join(path, file)):
if name[0] != '.':
scripts.append(file)
continue
if ext == ".py":
scripts.append(name)
elif ext == ".pyc" or ext == ".pyo":
possible.append(name)
# merge the lists
for s in possible:
if s not in scripts:
scripts.append(s)
print("\nLoading remote/user scripts folder (", path, "):")
return scripts
for p in fx.prefs.keys():
if "KMFX.ExtraScript" in p:
this_path = fx.prefs[p]
if this_path != "":
try:
sys.path.append(fx.prefs[p])
print("trying to import extra script path: %s" % this_path)
scripts = getScripts(this_path)
# import the scripts
for s in scripts:
# filter out any folders with names in parentheses, like in AE
if len(s) > 2:
if (s[0] == '(') and (s[int(len(s)-1)] == ')'):
continue
str = "import " + s
try:
exec(str)
print( s,)
except:
import traceback
sys.stderr.write("Could not import %s module:" % s)
info = sys.exc_info()
type = info[0]
param = info[1]
tb = info[2]
traceback.print_exception(type, param, tb, file=sys.stderr)
### import the user_keybinds on the end to avoid issues with modules not loading
try:
import user_keybinds
except:
pass
except:
e = sys.exc_info()
print('Error on line %s %s %s ' % (sys.exc_info()[-1].tb_lineno, type(e).__name__, e))