18
18
"""
19
19
20
20
import argparse
21
- import os , sys
21
+ import os
22
+ import sys
22
23
from collections .abc import Mapping
23
24
from textwrap import dedent
24
25
27
28
do_connect ,
28
29
do_disconnect ,
29
30
do_edit ,
31
+ do_eval ,
32
+ do_exec ,
30
33
do_filesystem ,
31
34
do_mount ,
32
- do_umount ,
33
- do_exec ,
34
- do_eval ,
35
- do_run ,
36
35
do_resume ,
36
+ do_run ,
37
37
do_soft_reset ,
38
+ do_umount ,
38
39
)
39
40
from .mip import do_mip
40
41
from .repl import do_repl
@@ -93,7 +94,9 @@ def _bool_flag(cmd_parser, name, short_name, default, description):
93
94
def argparse_connect ():
94
95
cmd_parser = argparse .ArgumentParser (description = "connect to given device" )
95
96
cmd_parser .add_argument (
96
- "device" , nargs = 1 , help = "Either list, auto, id:x, port:x, or any valid device name/path"
97
+ "device" ,
98
+ nargs = 1 ,
99
+ help = "Either list, auto, id:x, port:x, or any valid device name/path" ,
97
100
)
98
101
return cmd_parser
99
102
@@ -126,7 +129,10 @@ def argparse_repl():
126
129
help = "saves a copy of the REPL session to the specified path" ,
127
130
)
128
131
cmd_parser .add_argument (
129
- "--inject-code" , type = str , required = False , help = "code to be run when Ctrl-J is pressed"
132
+ "--inject-code" ,
133
+ type = str ,
134
+ required = False ,
135
+ help = "code to be run when Ctrl-J is pressed" ,
130
136
)
131
137
cmd_parser .add_argument (
132
138
"--inject-file" ,
@@ -146,7 +152,11 @@ def argparse_eval():
146
152
def argparse_exec ():
147
153
cmd_parser = argparse .ArgumentParser (description = "execute the string" )
148
154
_bool_flag (
149
- cmd_parser , "follow" , "f" , True , "follow output until the expression completes (default)"
155
+ cmd_parser ,
156
+ "follow" ,
157
+ "f" ,
158
+ True ,
159
+ "follow output until the expression completes (default)" ,
150
160
)
151
161
cmd_parser .add_argument ("expr" , nargs = 1 , help = "expression to execute" )
152
162
return cmd_parser
@@ -155,7 +165,11 @@ def argparse_exec():
155
165
def argparse_run ():
156
166
cmd_parser = argparse .ArgumentParser (description = "run the given local script" )
157
167
_bool_flag (
158
- cmd_parser , "follow" , "f" , True , "follow output until the script completes (default)"
168
+ cmd_parser ,
169
+ "follow" ,
170
+ "f" ,
171
+ True ,
172
+ "follow output until the script completes (default)" ,
159
173
)
160
174
cmd_parser .add_argument ("path" , nargs = 1 , help = "path to script to execute" )
161
175
return cmd_parser
@@ -333,21 +347,21 @@ def load_user_config():
333
347
config .commands = {}
334
348
335
349
# Get config file name.
336
- path = os .getenv ("XDG_CONFIG_HOME" )
350
+ path = None
351
+ for var in ["XDG_CONFIG_HOME" , "HOME" , "USERPROFILE" ]:
352
+ path = os .getenv (var )
353
+ if path :
354
+ break
337
355
if path is None :
338
- path = os .getenv ("HOME" )
339
- if path is None :
340
- return config
341
- path = os .path .join (path , ".config" )
342
- path = os .path .join (path , _PROG )
343
- config_file = os .path .join (path , "config.py" )
356
+ return config
357
+ config_file = os .path .join (path , ".config" , _PROG , "config.py" )
344
358
345
359
# Check if config file exists.
346
360
if not os .path .exists (config_file ):
347
361
return config
348
362
349
363
# Exec the config file in its directory.
350
- with open (config_file ) as f :
364
+ with open (config_file , encoding = "utf-8" ) as f :
351
365
config_data = f .read ()
352
366
prev_cwd = os .getcwd ()
353
367
os .chdir (path )
0 commit comments