in fix_android_dependencies.py [0:0]
def get_toml_dependencies(toml_file):
"""Gets a dictionary of all TOML dependencies."""
# This code assumes the [versions] block will always be first
# True = read [versions] block; False = read [libraries] or [plugins] block
reading_versions = True
versions = {}
deps = {}
try:
with open(toml_file, 'r') as f:
lines = f.readlines()
for line in lines:
# skip empty lines or comments
if line.strip() == '' or line.startswith("#"):
continue
if '[versions]' in line:
reading_versions = True
continue
if '[libraries]' in line or '[plugins]' in line:
reading_versions = False
continue
# Versions
if reading_versions:
version_match = re.search(VERSION_RE, line)
if version_match:
key = version_match.group(1).strip()
value = version_match.group(2)
versions[key] = {'curr_version': value, 'original_line': line}
# Libraries and Plugins
else:
deps.update(get_toml_dependency(line, versions))
except FileNotFoundError:
print('This project does not contain a ' + RELATIVE_PATH_TO_TOML + ' file.')
return deps