|
11 | 11 | from west.commands import WestCommand # your extension must subclass this |
12 | 12 | from west import log # use this for user output |
13 | 13 |
|
| 14 | +from pathlib import Path |
| 15 | +import yaml |
| 16 | +import os |
14 | 17 |
|
15 | | -class Gigadevice(WestCommand): |
| 18 | +REPO_ROOT = Path(__file__).absolute().parents[2] |
| 19 | +"""Repository root (used for input/output default folders).""" |
| 20 | + |
| 21 | + |
| 22 | +class Install: |
| 23 | + def __init__(self, config=REPO_ROOT / 'zephyr' / 'west' / 'gigadevice.yml'): |
| 24 | + self.config = self.parse_config(config) |
| 25 | + self.pyocd_install() |
| 26 | + |
| 27 | + def parse_config(self, config): |
| 28 | + with open(config, 'r') as f: |
| 29 | + return yaml.safe_load(f) |
| 30 | + |
| 31 | + def pyocd_install(self): |
| 32 | + for pyocd_packages in self.config['pyocd-packages']: |
| 33 | + self.pyocd_install_one(pyocd_packages) |
16 | 34 |
|
| 35 | + def pyocd_install_one(self, package): |
| 36 | + print(package) |
| 37 | + if 'url' in package: |
| 38 | + self.pyocd_install_one_from_url(package) |
| 39 | + else: |
| 40 | + self.pyocd_install_one_from_mdk(package) |
| 41 | + |
| 42 | + def pyocd_install_one_from_mdk(self, package): |
| 43 | + # run shell command: pyocd pack install package['pack'] |
| 44 | + os.system('echo pyocd pack install ' + package['pack']) |
| 45 | + pass |
| 46 | + |
| 47 | + def pyocd_install_one_from_url(self, package): |
| 48 | + file_name = '%s.rar' % package['pack'] |
| 49 | + # Download from url to tmp folder |
| 50 | + log.inf('download', package['url'], 'to', file_name) |
| 51 | + # unrar file to tmp folder |
| 52 | + os.system(f'echo unrar x ${file_name}') |
| 53 | + # find pack file in tmp folder |
| 54 | + # check pack file hash value |
| 55 | + # storage pack file to support folder |
| 56 | + pass |
| 57 | + |
| 58 | + |
| 59 | +class Gigadevice(WestCommand): |
17 | 60 | def __init__(self): |
18 | 61 | super().__init__( |
19 | 62 | 'gigadevice', # gets stored as self.name |
@@ -45,8 +88,6 @@ def do_run(self, args, unknown_args): |
45 | 88 | # required is BAR |
46 | 89 | match args.command: |
47 | 90 | case 'install': |
48 | | - log.inf('command is', args.command) |
49 | | - log.inf('we can install some pack for pyocd') |
50 | | - log.inf('TODO: RUN: pyocd pack install gd32e103') |
| 91 | + Install() |
51 | 92 | case _: |
52 | | - log.inf('command is', args.command) |
| 93 | + log.inf('command is', args.command, REPO_ROOT) |
0 commit comments