Merge "fix and update roomservice" into android-11

This commit is contained in:
bigbiff
2021-06-05 18:37:04 +00:00
committed by Gerrit Code Review
+120 -44
View File
@@ -51,8 +51,13 @@ gerrit_url = "gerrit.twrp.me"
def check_repo_exists(git_data, device):
re_match = "^android_device_.*_{device}$".format(device=device)
matches = filter(lambda x: re.match(re_match, x), git_data)
if device.count("_") < 2:
re_match = "^android_device_.*_{device}$".format(device=device)
else:
re_match = "^android_device.*_{device}$".format(device=device)
matches = list(filter(lambda x: re.match(re_match, x), git_data))
if len(matches) != 1:
raise Exception("{device} not found,"
"exiting roomservice".format(device=device))
@@ -69,10 +74,10 @@ def search_gerrit_for_device(device):
git_req = urllib.request.Request(git_search_url)
try:
response = urllib.request.urlopen(git_req)
except urllib.request.HTTPError as e:
except urllib.request.HTTPError:
print("There was an issue connecting to gerrit."
" Please try again in a minute")
except urllib.request.URLError as e:
" Please try again in a minute")
except urllib.request.URLError:
print("WARNING: No network connection available.")
else:
# Skip silly gerrit "header"
@@ -84,15 +89,27 @@ def search_gerrit_for_device(device):
def parse_device_directory(device_url, device):
pattern = "^android_device_(?P<vendor>.+)_{}$".format(device)
if device.count("_") < 2:
pattern = "^android_device_(?P<vendor>.+)_{}$".format(device)
else:
pattern = "^android_device_{}$".format(device)
match = re.match(pattern, device_url)
if match is None:
raise Exception("Invalid project name {}".format(device_url))
return "device/{vendor}/{device}".format(
vendor=match.group('vendor'),
device=device,
)
if device.count('_') < 2:
return "device/{vendor}/{device}".format(
vendor=match.group('vendor'),
device=device,
)
else:
vendor = device.split('_')[0]
return "device/{vendor}/{device}".format(
vendor=vendor,
device=device,
)
# Thank you RaYmAn
@@ -106,20 +123,44 @@ def iterate_manifests():
try:
man = ES.parse(file)
man = man.getroot()
except IOError, ES.ParseError:
except (IOError, ES.ParseError):
print("WARNING: error while parsing %s" % file)
else:
for project in man.findall("project"):
yield project
def iterate_manifests_remove_project():
files = []
for file in os.listdir(local_manifest_dir):
if file.endswith(".xml"):
files.append(os.path.join(local_manifest_dir, file))
files.append('.repo/manifest.xml')
for file in files:
try:
man = ES.parse(file)
man = man.getroot()
except (IOError, ES.ParseError):
print("WARNING: error while parsing %s" % file)
else:
for project in man.findall("remove-project"):
yield project
def check_project_exists(url, revision, path):
for project in iterate_manifests():
if project.get("name") == url and project.get("revision") == revision and project.get("path") == path:
if project.get("name") == url \
and project.get("revision") == revision \
and project.get("path") == path:
return True
return False
def check_remove_project_exists(url):
for project in iterate_manifests_remove_project():
if project.get("name") == url:
return True
return False
def check_target_exists(directory):
return os.path.isdir(directory)
@@ -158,12 +199,23 @@ def create_manifest_project(url, directory,
})
return project
def create_remove_project(url):
remove_project_exists = check_remove_project_exists(url)
if remove_project_exists:
return None
project = ES.Element("remove-project",
attrib={
"name": url
})
return project
def append_to_manifest(project):
try:
lm = ES.parse('/'.join([local_manifest_dir, "roomservice.xml"]))
lm = lm.getroot()
except IOError, ES.ParseError:
except (IOError, ES.ParseError):
lm = ES.Element("manifest")
lm.append(project)
return lm
@@ -221,6 +273,7 @@ def parse_dependency_file(location):
raise Exception("ERROR: malformed dependency file")
return dependencies
# if there is any conflict with existing and new
# delete the roomservice.xml file and create new
def check_manifest_problems(dependencies):
@@ -228,22 +281,26 @@ def check_manifest_problems(dependencies):
repository = dependency.get("repository")
target_path = dependency.get("target_path")
revision = dependency.get("revision", default_rev)
remote = dependency.get("remote", default_rem)
# check for existing projects
for project in iterate_manifests():
if project.get("revision") is not None and project.get("path") is not None:
if project.get("path") == target_path and project.get("revision") != revision:
print("WARNING: detected conflict in revisions for repository ", repository)
current_dependency = str(project.get(repository))
file = ES.parse('/'.join([local_manifest_dir, "roomservice.xml"]))
file_root = file.getroot()
for current_project in file_root.findall('project'):
new_dependency = str(current_project.find('revision'))
if new_dependency == current_dependency:
file_root.remove(current_project)
file.write('/'.join([local_manifest_dir, "roomservice.xml"]))
return
if project.get("revision") is not None \
and project.get("path") is not None \
and project.get("path") == target_path \
and project.get("revision") != revision:
print("WARNING: detected conflict in revisions for repository ",
repository)
current_dependency = str(project.get(repository))
file = ES.parse('/'.join([local_manifest_dir,
"roomservice.xml"]))
file_root = file.getroot()
for current_project in file_root.findall('project'):
new_dependency = str(current_project.find('revision'))
if new_dependency == current_dependency:
file_root.remove(current_project)
file.write('/'.join([local_manifest_dir, "roomservice.xml"]))
return
def create_dependency_manifest(dependencies):
projects = []
@@ -252,22 +309,40 @@ def create_dependency_manifest(dependencies):
target_path = dependency.get("target_path")
revision = dependency.get("revision", default_rev)
remote = dependency.get("remote", default_rem)
override = dependency.get("override", None)
remove = dependency.get("remove", None)
# not adding an organization should default to android_team
# only apply this to github
if remote == "github":
if "/" not in repository:
repository = '/'.join([android_team, repository])
project = create_manifest_project(repository,
target_path,
remote=remote,
revision=revision)
if project is not None:
manifest = append_to_manifest(project)
write_to_manifest(manifest)
projects.append(target_path)
if remove is not None:
#print("found remove in ", repository)
project = create_remove_project(remove)
if project is not None:
manifest = append_to_manifest(project)
#print(ES.tostring(manifest).decode())
write_to_manifest(manifest)
else:
if override is not None:
#print("found override in ", repository)
project = create_remove_project(override)
if project is not None:
manifest = append_to_manifest(project)
#print(ES.tostring(manifest).decode())
write_to_manifest(manifest)
# not adding an organization should default to android_team
# only apply this to github
if remote == "github":
if "/" not in repository:
repository = '/'.join([android_team, repository])
project = create_manifest_project(repository,
target_path,
remote=remote,
revision=revision)
if project is not None:
manifest = append_to_manifest(project)
write_to_manifest(manifest)
projects.append(target_path)
if len(projects) > 0:
os.system("repo sync -f --no-clone-bundle %s" % " ".join(projects))
os.system("repo sync --force-sync --no-clone-bundle %s" % " ".join(projects))
def create_common_dependencies_manifest(dependencies):
@@ -293,7 +368,7 @@ def create_common_dependencies_manifest(dependencies):
if common_deps is not None:
print("Looking for dependencies on: ",
dependency['target_path'])
dependency['target_path'])
check_manifest_problems(common_deps)
create_dependency_manifest(common_deps)
create_common_dependencies_manifest(common_deps)
@@ -310,6 +385,7 @@ def fetch_dependencies(device):
create_common_dependencies_manifest(dependencies)
fetch_device(device)
def check_device_exists(device):
location = parse_device_from_folder(device)
if location is None:
@@ -325,15 +401,15 @@ def fetch_device(device):
device_url = git_data['id']
device_dir = parse_device_directory(device_url, device)
project = create_manifest_project(device_url,
device_dir,
remote=default_team_rem)
device_dir,
remote=default_team_rem)
if project is not None:
manifest = append_to_manifest(project)
write_to_manifest(manifest)
# In case a project was written to manifest, but never synced
if project is not None or not check_target_exists(device_dir):
print("syncing the device config")
os.system('repo sync -f --no-clone-bundle %s' % device_dir)
os.system('repo sync --force-sync --no-clone-bundle %s' % device_dir)
if __name__ == '__main__':