[libvirt] [dockerfiles PATCH 0/4] refresh: Some minor cleanups
Andrea Bolognani (4): refresh: Get rid of self.project_name refresh: Improve project handling refresh: Look for project with startswith() refresh: Update comments refresh | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) -- 2.21.0
We don't need to access it from anywhere else, so it can be a local variable instead of an object property. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- refresh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/refresh b/refresh index 8f99042..89c2818 100755 --- a/refresh +++ b/refresh @@ -64,11 +64,12 @@ class Dockerfile: stem = path.stem[len(Dockerfile.PREFIX):] self.projects = [] + project_name = None for project in Dockerfile.PROJECTS: if stem.rfind(project + "-") >= 0: - self.project_name = project - stem = stem[len(self.project_name) + 1:] + project_name = project + stem = stem[len(project_name) + 1:] for subproject in Dockerfile.PROJECTS[project]: self.projects += [subproject] break @@ -97,7 +98,7 @@ class Dockerfile: if self.os == "fedora-rawhide": mingw_projects = [] for subproject in self.projects: - if Dockerfile.PROJECTS[self.project_name][subproject]: + if Dockerfile.PROJECTS[project_name][subproject]: mingw_projects += [subproject + "+mingw*"] self.projects += mingw_projects -- 2.21.0
Instead of adding native projects first and then coming back to add MinGW projects at a later time, add all projects in a single step. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- refresh | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/refresh b/refresh index 89c2818..b26a9f3 100755 --- a/refresh +++ b/refresh @@ -63,18 +63,15 @@ class Dockerfile: self.path = path stem = path.stem[len(Dockerfile.PREFIX):] - self.projects = [] project_name = None for project in Dockerfile.PROJECTS: if stem.rfind(project + "-") >= 0: project_name = project stem = stem[len(project_name) + 1:] - for subproject in Dockerfile.PROJECTS[project]: - self.projects += [subproject] break - if self.projects == []: + if not project_name: raise Exception("File '{}' does not have any matching " "project.".format(path)) @@ -93,15 +90,16 @@ class Dockerfile: self.os = stem self.cross_arch = None - # Fedora Rawhide is special in that we use it to perform MinGW - # builds, so we need to add the corresponding projects - if self.os == "fedora-rawhide": - mingw_projects = [] - for subproject in self.projects: - if Dockerfile.PROJECTS[project_name][subproject]: - mingw_projects += [subproject + "+mingw*"] + self.projects = [] + + for project in Dockerfile.PROJECTS[project_name]: + self.projects += [project] + # Fedora Rawhide is special in that we use it to perform MinGW + # builds, so we need to add the corresponding projects + if (self.os == "fedora-rawhide" and + Dockerfile.PROJECTS[project_name][project]): + self.projects += [project + "+mingw*"] - self.projects += mingw_projects def refresh(self, lcitool): -- 2.21.0
Using rfind() makes sense when we're looking for CROSS, since we don't know exactly where it will be, but when looking for the project we know it will be at the very beginning of the string so we should check accordingly. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- refresh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/refresh b/refresh index b26a9f3..f89b836 100755 --- a/refresh +++ b/refresh @@ -66,9 +66,9 @@ class Dockerfile: project_name = None for project in Dockerfile.PROJECTS: - if stem.rfind(project + "-") >= 0: + if stem.startswith(project + "-"): + stem = stem[len(project) + 1:] project_name = project - stem = stem[len(project_name) + 1:] break if not project_name: -- 2.21.0
This reverts some of the changes made by 7130ffe0a0e9, which is okay because they were not entirely accurate: by the time we start looking for CROSS, we have already removed the project name from the stem, so the OS name is indeed the first thing you'll find there. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- refresh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/refresh b/refresh index f89b836..6cefd79 100755 --- a/refresh +++ b/refresh @@ -65,6 +65,8 @@ class Dockerfile: project_name = None + # Now that we've removed the prefix, we expect to find the name + # of one of the known projects, followed by a dash for project in Dockerfile.PROJECTS: if stem.startswith(project + "-"): stem = stem[len(project) + 1:] @@ -78,15 +80,14 @@ class Dockerfile: cross = stem.rfind(Dockerfile.CROSS) if cross >= 0: - # If we found CROSS, then everything in between the project's - # name and the cross is the name of the OS and everything after - # it the name of the architecture we're targeting for - # cross-compilation + # If we found CROSS, then everything before it is the name of + # the OS and everything after it the name of the architecture + # we're targeting for cross-compilation self.os = stem[:cross] self.cross_arch = stem[cross + len(Dockerfile.CROSS):] else: - # Otherwise the name of the OS starts just after the project's - # name and there is no cross-compilation architecture + # Otherwise the entire stem is the name of the OS and there + # is no cross-compilation architecture self.os = stem self.cross_arch = None @@ -95,7 +96,9 @@ class Dockerfile: for project in Dockerfile.PROJECTS[project_name]: self.projects += [project] # Fedora Rawhide is special in that we use it to perform MinGW - # builds, so we need to add the corresponding projects + # builds, so we need to add the corresponding projects as well. + # If a specific project needs to have the MinGW variant included, + # the corresponding value in the dictionary will be True if (self.os == "fedora-rawhide" and Dockerfile.PROJECTS[project_name][project]): self.projects += [project + "+mingw*"] -- 2.21.0
On Fri, 2019-08-09 at 10:35 +0200, Andrea Bolognani wrote:
Andrea Bolognani (4): refresh: Get rid of self.project_name refresh: Improve project handling refresh: Look for project with startswith() refresh: Update comments
refresh | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-)
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
participants (2)
-
Andrea Bolognani -
Fabiano Fidêncio