12
12
import tempfile
13
13
import wget
14
14
15
- from collections import deque
16
15
from pathlib import Path
17
16
from typing import Tuple
18
17
from zipfile import ZipFile
19
18
20
19
from west import log
21
20
22
- DEFAULT_MATTER_PATH = Path (__file__ ).parents [2 ]
21
+ MATTER_PATH = Path (__file__ ).parents [2 ]
23
22
24
23
25
- def find_zap (root : Path = Path .cwd (), max_depth : int = 2 ):
24
+ def find_zap (root : Path = Path .cwd (), max_depth : int = 1 ):
26
25
"""
27
26
Find *.zap file in the given directory or its subdirectories.
28
27
"""
29
- zap_files = []
30
- search_dirs = deque ()
31
- search_dirs .append ((root , max_depth ))
32
-
33
- while search_dirs :
34
- search_dir , max_depth = search_dirs .popleft ()
35
-
36
- for name in search_dir .iterdir ():
37
- if name .is_file () and (name .suffix .lower () == '.zap' ):
38
- zap_files .append (search_dir / name )
39
- continue
40
- if name .is_dir () and (max_depth > 0 ):
41
- search_dirs .append ((search_dir / name , max_depth - 1 ))
42
-
43
- # At most one ZAP file found in the selected location, return immediately.
44
- if len (zap_files ) <= 1 :
45
- return zap_files [0 ] if zap_files else None
46
-
47
- # Otherwise, ask a user to choose the ZAP file to edit.
48
- for i , zap_file in enumerate (zap_files ):
49
- print (f'{ i } . { zap_file .relative_to (root )} ' )
50
-
51
- while True :
52
- try :
53
- maxind = len (zap_files ) - 1
54
- prompt = f'Select file to edit (0-{ maxind } ): '
55
- return zap_files [int (input (prompt ))]
56
- except Exception :
57
- pass
28
+ subdirs = []
29
+ for name in root .iterdir ():
30
+ if name .is_file () and (name .suffix .lower () == '.zap' ):
31
+ return root / name
32
+ if name .is_dir () and (max_depth > 0 ):
33
+ subdirs .append (name )
34
+ for subdir in subdirs :
35
+ if zap := find_zap (root / subdir , max_depth - 1 ):
36
+ return zap
37
+ return None
58
38
59
39
60
40
def existing_file_path (arg : str ) -> Path :
@@ -67,16 +47,6 @@ def existing_file_path(arg: str) -> Path:
67
47
raise argparse .ArgumentTypeError (f'invalid file path: \' { arg } \' ' )
68
48
69
49
70
- def existing_dir_path (arg : str ) -> Path :
71
- """
72
- Helper function to validate directory path argument.
73
- """
74
- p = Path (arg )
75
- if p .is_dir ():
76
- return p
77
- raise argparse .ArgumentTypeError (f'invalid directory path: \' { arg } \' ' )
78
-
79
-
80
50
class ZapInstaller :
81
51
INSTALL_DIR = Path ('.zap-install' )
82
52
ZAP_URL_PATTERN = 'https://github.com/project-chip/zap/releases/download/v%04d.%02d.%02d-nightly/%s.zip'
@@ -201,15 +171,15 @@ def update_zap_if_needed(self) -> None:
201
171
recommended_version = self .get_recommended_version ()
202
172
current_version = self .get_current_version ()
203
173
204
- log .inf (f'ZAP installation directory: { self .install_path } ' )
174
+ if current_version == recommended_version :
175
+ log .inf ('ZAP is up to date: {0}.{1}.{2}' .format (* recommended_version ))
176
+ return
205
177
206
178
if current_version :
207
- verdict = 'up to date' if current_version == recommended_version else 'outdated'
208
- log .inf ('Found ZAP {}.{}.{} ({})' .format (* current_version , verdict ))
179
+ log .inf ('Found ZAP version: {0}.{1}.{2}' .format (* current_version ))
209
180
210
- if current_version != recommended_version :
211
- log .inf ('Installing ZAP {}.{}.{}' .format (* recommended_version ))
212
- self .install_zap (recommended_version )
181
+ log .inf ('Installing ZAP version: {0}.{1}.{2}' .format (* recommended_version ))
182
+ self .install_zap (recommended_version )
213
183
214
184
@staticmethod
215
185
def set_exec_permission (path : Path ) -> None :
0 commit comments