mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-21 20:30:21 -07:00
minor refactoring of sdkmanager parsing
This commit is contained in:
parent
6d756e2271
commit
4441be779f
1 changed files with 28 additions and 47 deletions
|
@ -83,60 +83,41 @@ class AndroidSdkManager(object):
|
||||||
def get_installed_packages(self):
|
def get_installed_packages(self):
|
||||||
with self.runner('installed sdk_root channel') as ctx:
|
with self.runner('installed sdk_root channel') as ctx:
|
||||||
rc, stdout, stderr = ctx.run()
|
rc, stdout, stderr = ctx.run()
|
||||||
|
return self._parse_packages(stdout, self._RE_INSTALLED_PACKAGES_HEADER, self._RE_INSTALLED_PACKAGE)
|
||||||
data = stdout.split('\n')
|
|
||||||
|
|
||||||
installed_section_found = False
|
|
||||||
i = 0
|
|
||||||
lines_count = len(data)
|
|
||||||
packages = set()
|
|
||||||
|
|
||||||
while i < lines_count:
|
|
||||||
|
|
||||||
if not installed_section_found:
|
|
||||||
installed_section_found = self._RE_INSTALLED_PACKAGES_HEADER.match(data[i])
|
|
||||||
if installed_section_found:
|
|
||||||
i += 3
|
|
||||||
else:
|
|
||||||
i += 1
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
p = self._RE_INSTALLED_PACKAGE.search(data[i])
|
|
||||||
if p:
|
|
||||||
package = Package(p.group('name'))
|
|
||||||
packages.add(package)
|
|
||||||
i += 1
|
|
||||||
return packages
|
|
||||||
|
|
||||||
def get_updatable_packages(self):
|
def get_updatable_packages(self):
|
||||||
with self.runner('list newer sdk_root channel') as ctx:
|
with self.runner('list newer sdk_root channel') as ctx:
|
||||||
rc, stdout, stderr = ctx.run()
|
rc, stdout, stderr = ctx.run()
|
||||||
data = stdout.split('\n')
|
return self._parse_packages(stdout, self._RE_UPDATABLE_PACKAGES_HEADER, self._RE_UPDATABLE_PACKAGE)
|
||||||
|
|
||||||
updatable_section_found = False
|
@staticmethod
|
||||||
i = 0
|
def _parse_packages(stdout, header_regexp, row_regexp):
|
||||||
lines_count = len(data)
|
data = stdout.split('\n')
|
||||||
packages = set()
|
|
||||||
|
|
||||||
while i < lines_count:
|
updatable_section_found = False
|
||||||
if not updatable_section_found:
|
i = 0
|
||||||
updatable_section_found = self._RE_UPDATABLE_PACKAGES_HEADER.match(data[i])
|
lines_count = len(data)
|
||||||
if updatable_section_found:
|
packages = set()
|
||||||
# Table has the following structure. Once it is found, 2 lines need to be skipped
|
|
||||||
#
|
while i < lines_count:
|
||||||
# Available Updates: <--- we are here
|
if not updatable_section_found:
|
||||||
# ID | Installed | Available
|
updatable_section_found = header_regexp.match(data[i])
|
||||||
# ------- | ------- | -------
|
if updatable_section_found:
|
||||||
# platform-tools | 27.0.0 | 35.0.2 <--- skip to here
|
# Table has the following structure. Once it is found, 2 lines need to be skipped
|
||||||
i += 3 # skip table header
|
#
|
||||||
else:
|
# Available Updates: <--- we are here
|
||||||
i += 1 # just iterate next until we find the section's header
|
# ID | Installed | Available
|
||||||
continue
|
# ------- | ------- | -------
|
||||||
|
# platform-tools | 27.0.0 | 35.0.2 <--- skip to here
|
||||||
|
i += 3 # skip table header
|
||||||
else:
|
else:
|
||||||
p = self._RE_UPDATABLE_PACKAGE.match(data[i])
|
i += 1 # just iterate next until we find the section's header
|
||||||
if p:
|
continue
|
||||||
packages.add(Package(p.group('name')))
|
else:
|
||||||
i += 1
|
p = row_regexp.match(data[i])
|
||||||
|
if p:
|
||||||
|
packages.add(Package(p.group('name')))
|
||||||
|
i += 1
|
||||||
return packages
|
return packages
|
||||||
|
|
||||||
def install_packages(self, packages):
|
def install_packages(self, packages):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue