13
13
from PyQt6 .QtWidgets import QApplication
14
14
15
15
from .core .logger import set_log_level , setup_logger
16
+
16
17
# import vsenv as early as possible:
17
18
# This is so other modules cannot accidentally use and lock us into a different policy.
18
19
from .core .vsenv import set_vsengine_loop
19
20
from .main import MainWindow
20
21
from .plugins import get_installed_plugins
21
22
from .plugins .abstract import FileResolverPlugin , ResolvedScript
22
- from .plugins .install import install_plugins , plugins_commands , print_available_plugins , uninstall_plugins
23
+ from .plugins .install import (
24
+ install_plugins ,
25
+ plugins_commands ,
26
+ print_available_plugins ,
27
+ uninstall_plugins ,
28
+ )
23
29
24
- __all__ = [
25
- 'main'
26
- ]
30
+ __all__ = ["main" ]
27
31
28
32
29
- def get_resolved_script (filepath : Path ) -> tuple [ResolvedScript , FileResolverPlugin | None ] | int :
33
+ def get_resolved_script (
34
+ filepath : Path ,
35
+ ) -> tuple [ResolvedScript , FileResolverPlugin | None ] | int :
30
36
for plugin in get_installed_plugins (FileResolverPlugin , False ).values ():
31
37
if plugin .can_run_file (filepath ):
32
38
return plugin .resolve_path (filepath ), plugin
33
39
34
40
if not filepath .exists ():
35
- logging .error (' Script or file path is invalid.' )
41
+ logging .error (" Script or file path is invalid." )
36
42
return 1
37
43
38
44
return ResolvedScript (filepath , str (filepath )), None
@@ -41,37 +47,53 @@ def get_resolved_script(filepath: Path) -> tuple[ResolvedScript, FileResolverPlu
41
47
def main (_args : Sequence [str ] | None = None , no_exit : bool = False ) -> int :
42
48
from .utils import exit_func
43
49
44
- parser = ArgumentParser (prog = ' VSPreview' )
50
+ parser = ArgumentParser (prog = " VSPreview" )
45
51
parser .add_argument (
46
- 'script_path_or_command' , type = str , nargs = '?' ,
47
- help = f'Path to Vapoursynth script or plugins command { "," .join (plugins_commands )} '
52
+ "script_path_or_command" ,
53
+ type = str ,
54
+ nargs = "?" ,
55
+ help = f'Path to Vapoursynth script, video file(s) or plugins command { ", " .join (plugins_commands )} ' ,
48
56
)
49
57
parser .add_argument (
50
- 'plugins' , type = str , nargs = '*' ,
51
- help = f'Plugins to { "/" .join (plugins_commands [:- 1 ])} or arguments to pass to the script environment.'
58
+ "plugins" ,
59
+ type = str ,
60
+ nargs = "*" ,
61
+ help = f'Plugins to { "/" .join (plugins_commands [:- 1 ])} or arguments to pass to the script environment.' ,
52
62
)
63
+ parser .add_argument ("--version" , "-v" , action = "version" , version = "%(prog)s 0.2b" )
53
64
parser .add_argument (
54
- '--version' , '-v' , action = 'version' , version = '%(prog)s 0.2b'
65
+ "--preserve-cwd" ,
66
+ "-c" ,
67
+ action = "store_true" ,
68
+ help = "do not chdir to script parent directory" ,
55
69
)
56
70
parser .add_argument (
57
- '--preserve-cwd' , '-c' , action = 'store_true' , help = 'do not chdir to script parent directory'
71
+ "-f" , "--frame" , type = int , help = "Frame to load initially (defaults to 0)"
58
72
)
59
- parser .add_argument ('-f' , '--frame' , type = int , help = 'Frame to load initially (defaults to 0)' )
60
73
parser .add_argument (
61
- '--vscode-setup' , type = str , choices = ['override' , 'append' , 'ignore' ], nargs = '?' , const = 'append' ,
62
- help = 'Installs launch settings in cwd\' s .vscode'
74
+ "--vscode-setup" ,
75
+ type = str ,
76
+ choices = ["override" , "append" , "ignore" ],
77
+ nargs = "?" ,
78
+ const = "append" ,
79
+ help = "Installs launch settings in cwd's .vscode" ,
63
80
)
64
81
parser .add_argument (
65
82
"--verbose" , help = "Set the logging to verbose." , action = "store_true"
66
83
)
67
84
parser .add_argument (
68
- "--force" , help = "Force the install of a plugin even if it exists already." , action = "store_true"
85
+ "--force" ,
86
+ help = "Force the install of a plugin even if it exists already." ,
87
+ action = "store_true" ,
69
88
)
70
89
parser .add_argument (
71
90
"--no-deps" , help = "Ignore downloading dependencies." , action = "store_true"
72
91
)
73
92
parser .add_argument (
74
- "--force-storage" , help = "Force override or local/global storage." , action = "store_true" , default = False
93
+ "--force-storage" ,
94
+ help = "Force override or local/global storage." ,
95
+ action = "store_true" ,
96
+ default = False ,
75
97
)
76
98
77
99
args = parser .parse_args (_args )
@@ -80,6 +102,7 @@ def main(_args: Sequence[str] | None = None, no_exit: bool = False) -> int:
80
102
81
103
if args .verbose :
82
104
from vstools import VSDebug
105
+
83
106
set_log_level (logging .DEBUG , logging .DEBUG )
84
107
VSDebug (use_logging = True )
85
108
else :
@@ -94,32 +117,34 @@ def main(_args: Sequence[str] | None = None, no_exit: bool = False) -> int:
94
117
95
118
script_path_or_command = args .script_path_or_command
96
119
97
- if not script_path_or_command and not (args .plugins and (script_path_or_command := next (iter (args .plugins )))):
98
- logging .error ('Script path required.' )
120
+ if not script_path_or_command and not (
121
+ args .plugins and (script_path_or_command := next (iter (args .plugins )))
122
+ ):
123
+ logging .error ("Script/Video path required." )
99
124
return exit_func (1 , no_exit )
100
125
101
- if script_path_or_command .startswith ('--' ) and args .plugins :
126
+ if script_path_or_command .startswith ("--" ) and args .plugins :
102
127
script_path_or_command = args .plugins .pop ()
103
128
args .plugins = [args .script_path_or_command , * args .plugins ]
104
129
105
130
if (command := script_path_or_command ) in plugins_commands :
106
- if command == ' available' :
131
+ if command == " available" :
107
132
print_available_plugins ()
108
133
return exit_func (0 , no_exit )
109
134
110
135
if not args .plugins :
111
- logging .error (' You must provide at least one plugin!' )
136
+ logging .error (" You must provide at least one plugin!" )
112
137
return exit_func (1 , no_exit )
113
138
114
139
set_log_level (logging .INFO )
115
140
116
141
plugins = list (args .plugins )
117
142
118
- if command == ' install' :
143
+ if command == " install" :
119
144
install_plugins (plugins , args .force , args .no_deps )
120
- elif command == ' uninstall' :
145
+ elif command == " uninstall" :
121
146
uninstall_plugins (plugins )
122
- elif command == ' update' :
147
+ elif command == " update" :
123
148
uninstall_plugins (plugins , True )
124
149
install_plugins (plugins , True , args .no_deps )
125
150
@@ -132,16 +157,24 @@ def main(_args: Sequence[str] | None = None, no_exit: bool = False) -> int:
132
157
133
158
script , file_resolve_plugin = script_or_err
134
159
160
+ if (
161
+ file_resolve_plugin
162
+ and hasattr (file_resolve_plugin , "_config" )
163
+ and file_resolve_plugin ._config .namespace == "dev.setsugen.vssource_load"
164
+ ):
165
+ setattr (args , "preserve_cwd" , True )
166
+
135
167
if not args .preserve_cwd :
136
168
os .chdir (script .path .parent )
137
169
138
- first_run = not hasattr (main , ' app' )
170
+ first_run = not hasattr (main , " app" )
139
171
140
172
if first_run :
141
173
main .app = QApplication (sys .argv )
142
174
set_vsengine_loop ()
143
175
else :
144
176
from .core .vsenv import get_current_environment , make_environment
177
+
145
178
make_environment ()
146
179
get_current_environment ().use ()
147
180
@@ -151,7 +184,7 @@ def main(_args: Sequence[str] | None = None, no_exit: bool = False) -> int:
151
184
152
185
def _parse_arg (kv : str ) -> tuple [str , str | int | float ]:
153
186
v : str | int | float
154
- k , v = kv .split ('=' , maxsplit = 1 )
187
+ k , v = kv .split ("=" , maxsplit = 1 )
155
188
156
189
try :
157
190
v = int (v )
@@ -161,16 +194,30 @@ def _parse_arg(kv: str) -> tuple[str, str | int | float]:
161
194
except ValueError :
162
195
...
163
196
164
- return k .strip ('--' ), v
197
+ return k .strip ("--" ), v
165
198
166
199
if args .plugins :
167
- arguments |= {k : v for k , v in map (_parse_arg , args .plugins )}
200
+ if file_resolve_plugin ._config .namespace == "dev.setsugen.vssource_load" :
201
+ additional_files = list [Path ](
202
+ Path (filepath ).resolve () for filepath in args .plugins
203
+ )
204
+ arguments .update (additional_files = additional_files )
205
+ else :
206
+ arguments |= {k : v for k , v in map (_parse_arg , args .plugins )}
168
207
169
208
main .main_window = MainWindow (
170
- Path (os .getcwd ()) if args .preserve_cwd else script .path .parent , no_exit , script .reload_enabled , args .force_storage
209
+ Path (os .getcwd ()) if args .preserve_cwd else script .path .parent ,
210
+ no_exit ,
211
+ script .reload_enabled ,
212
+ args .force_storage ,
171
213
)
172
214
main .main_window .load_script (
173
- script .path , list (arguments .items ()), False , args .frame or None , script .display_name , file_resolve_plugin
215
+ script .path ,
216
+ list (arguments .items ()),
217
+ False ,
218
+ args .frame or None ,
219
+ script .display_name ,
220
+ file_resolve_plugin ,
174
221
)
175
222
176
223
ret_code = main .app .exec ()
@@ -185,5 +232,5 @@ def _parse_arg(kv: str) -> tuple[str, str | int | float]:
185
232
return exit_func (ret_code , no_exit )
186
233
187
234
188
- if __name__ == ' __main__' :
235
+ if __name__ == " __main__" :
189
236
main ()
0 commit comments