adds 'latest' state

This commit is contained in:
Stanislav Shamilov 2024-12-04 19:17:18 +02:00
parent d7f6451535
commit 0434249881
2 changed files with 67 additions and 8 deletions

View file

@ -17,7 +17,9 @@ def sdkmanager_runner(module, **kwargs):
state=cmd_runner_fmt.as_map(_state_map),
name=cmd_runner_fmt.as_list(),
update=cmd_runner_fmt.as_fixed("--update"),
installed=cmd_runner_fmt.as_fixed("--list_installed")
installed=cmd_runner_fmt.as_fixed("--list_installed"),
list=cmd_runner_fmt.as_fixed('--list'),
newer=cmd_runner_fmt.as_fixed("--newer")
),
**kwargs
)
@ -47,6 +49,12 @@ class AndroidSdkManager(object):
_RE_INSTALLED_PACKAGES = (
re.compile(r'^\s+(?P<name>\S+)\s+\|\s+(?P<version>\S+)\s+\|\s(?P<description>.+)\s\|\s+(\S+)$')
)
_RE_UPDATABLE_PACKAGES_HEADER = re.compile(r'^Available Updates:$')
# Example: ' platform-tools | 27.0.0 | 35.0.2'
_RE_UPDATABLE_PACKAGE = (
re.compile(r'^\s+(?P<name>\S+)\s+\|\s+(?P<old_version>\S+)\s+\|\s+(?P<new_version>\S+)\s*$')
)
def __init__(self, runner):
self.runner = runner
@ -74,6 +82,39 @@ class AndroidSdkManager(object):
i += 1
return packages
def get_updatable_packages(self):
with self.runner('list newer') as ctx:
rc, stdout, stderr = ctx.run()
data = stdout.split('\n')
updatable_section_found = False
i = 0
lines_count = len(data)
packages = set()
dbg = []
while i < lines_count:
if not updatable_section_found:
updatable_section_found = self._RE_UPDATABLE_PACKAGES_HEADER.match(data[i])
if updatable_section_found:
# Table has the following structure. Once it is found, 2 lines need to be skipped
#
# Available Updates: <--- we are here
# ID | Installed | Available
# ------- | ------- | -------
# platform-tools | 27.0.0 | 35.0.2 <--- skip to here
i += 3 # skip table header
else:
i += 1 # just iterate next until we find the section's header
continue
else:
p = self._RE_UPDATABLE_PACKAGE.match(data[i])
dbg.append((data[i], p is not None))
if p:
packages.add(Package(p.group('name')))
i += 1
return packages
def install_packages(self, packages):
self.apply_packages_changes(packages, 'present')
@ -88,4 +129,3 @@ class AndroidSdkManager(object):
# raise ValueError(command_arg)
with self.runner('state name') as ctx:
ctx.run(name=command_arg, state=state)