Skip to content

Commit ff1f745

Browse files
authored
Replace zipfile for CMake -E tar in the linux_install.py script (#615)
* Replace zipfile for CMake -E tar * Change default path of static analysis fix #614
1 parent dee212c commit ff1f745

File tree

2 files changed

+32
-36
lines changed

2 files changed

+32
-36
lines changed

resources/ci_cd/linux_install.py

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,20 @@
1414
the minimal installation archive.
1515
1616
"""
17-
import io
1817
import os
1918
import sys
20-
import zipfile
19+
import tempfile
20+
import urllib.request
2121

22+
from distutils.spawn import find_executable
2223
from pathlib import Path
23-
from urllib import request
24+
from subprocess import call
2425
from urllib.error import URLError
25-
from zipfile import ZipFile, ZipInfo
26-
27-
28-
class ZipFileWithPermissions(ZipFile):
29-
"""Custom ZipFile class handling file permissions.
30-
31-
Code from https://stackoverflow.com/a/54748564
32-
"""
33-
34-
def _extract_member(self, member, targetpath, pwd):
35-
if not isinstance(member, ZipInfo):
36-
member = self.getinfo(member)
37-
38-
targetpath = super()._extract_member(member, str(targetpath), pwd)
39-
attr = member.external_attr >> 16
40-
41-
if attr != 0:
42-
Path(targetpath).chmod(attr)
43-
44-
return targetpath
4526

4627

4728
def main():
4829
rti_minimal_package_url = os.getenv("RTI_MIN_PACKAGE_URL")
49-
30+
temp_dir = Path(tempfile.gettempdir())
5031
if not rti_minimal_package_url:
5132
sys.exit(
5233
"Environment variable RTI_MIN_PACKAGE_URL not found, skipping..."
@@ -59,23 +40,38 @@ def main():
5940
except FileNotFoundError:
6041
sys.exit("The RTI_INSTALLATION_PATH does not exist.")
6142

43+
cmake_command = find_executable("cmake")
44+
if cmake_command is None:
45+
sys.exit("CMake must be installed in order to use the script.")
46+
6247
try:
63-
resp = request.urlopen(rti_minimal_package_url)
48+
rti_zipped_file_name = Path(
49+
urllib.request.url2pathname(rti_minimal_package_url)
50+
).name
51+
rti_zipped_file_path = temp_dir.joinpath(rti_zipped_file_name)
52+
urllib.request.urlretrieve(
53+
rti_minimal_package_url, rti_zipped_file_path
54+
)
6455
except URLError as e:
6556
sys.exit("Error opening the URL: {}".format(e))
6657

67-
print("Extracting minimal installation.")
68-
6958
try:
70-
with ZipFileWithPermissions(io.BytesIO(resp.read())) as rti_zipfile:
71-
bad_file_name = rti_zipfile.testzip()
72-
73-
if bad_file_name:
74-
sys.exit("Bad file found in the archive.")
59+
return_value = call(
60+
[
61+
cmake_command,
62+
"-E",
63+
"tar",
64+
"xf",
65+
str(rti_zipped_file_path),
66+
"--format=zip",
67+
],
68+
cwd=rti_installation_path,
69+
)
70+
except FileNotFoundError:
71+
sys.exit("The CMake executable could not be found.")
7572

76-
rti_zipfile.extractall(rti_installation_path)
77-
except zipfile.BadZipFile as e:
78-
sys.exit("Error opening zip file: {}".format(e))
73+
if return_value:
74+
sys.exit("There were error extracting the package")
7975

8076

8177
if __name__ == "__main__":

resources/ci_cd/linux_static_analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def find_connext_dir() -> Path:
5252
def parse_args() -> argparse.Namespace:
5353
"""Parse the CLI options."""
5454
parser = argparse.ArgumentParser()
55-
parser.add_argument("--build-dir", type=Path, default="examples/build")
55+
parser.add_argument("--build-dir", type=Path, default="build")
5656
parser.add_argument("--connext-dir", type=Path)
5757
args = parser.parse_args()
5858

0 commit comments

Comments
 (0)