Skip to content

Commit

Permalink
[NCL-6816] Stop using tempfile.mkdtemp in bacon_install.py
Browse files Browse the repository at this point in the history
We should stop using it because the temp folder is not cleaned up after
the method is called. It is replaced with:
```
with tempfile.TemporaryDirectory() as temp_folder:
```
since cleanup of the temp folder happens once we exit the 'with' clause.
  • Loading branch information
thescouser89 committed Nov 19, 2021
1 parent ba54eeb commit 42a5aa9
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions bacon_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,30 +283,30 @@ def __get_latest_version(self):
snapshot version
"""

temp_folder = tempfile.mkdtemp()
download_maven_metadata_xml(self.maven_url, temp_folder)
root = ET.parse(temp_folder + "/maven-metadata.xml").getroot()
with tempfile.TemporaryDirectory() as temp_folder:
download_maven_metadata_xml(self.maven_url, temp_folder)
root = ET.parse(temp_folder + "/maven-metadata.xml").getroot()

if self.__is_snapshot():
latest_tags = root.findall("versioning/versions/version")
if self.__is_snapshot():
latest_tags = root.findall("versioning/versions/version")

# choose the one listed last. This might bite us in the future
latest_tag = latest_tags[-1]
else:
latest_tag = root.find("versioning/latest")
# choose the one listed last. This might bite us in the future
latest_tag = latest_tags[-1]
else:
latest_tag = root.find("versioning/latest")

return latest_tag.text
return latest_tag.text

def __get_latest_snapshot_version(self):

url = self.maven_url + self.latest_version
temp_folder = tempfile.mkdtemp()
download_maven_metadata_xml(url, temp_folder)
with tempfile.TemporaryDirectory() as temp_folder:
download_maven_metadata_xml(url, temp_folder)

root = ET.parse(temp_folder + "/maven-metadata.xml").getroot()
root = ET.parse(temp_folder + "/maven-metadata.xml").getroot()

latest_tag = root.findall("versioning/snapshotVersions/snapshotVersion")
return latest_tag[0].find("value").text
latest_tag = root.findall("versioning/snapshotVersions/snapshotVersion")
return latest_tag[0].find("value").text

def __create_bacon_shell_script(self):

Expand Down

0 comments on commit 42a5aa9

Please sign in to comment.