Skip to content

Commit

Permalink
Replace zipfile for CMake -E tar in the linux_install.py script (#615)
Browse files Browse the repository at this point in the history
* Replace zipfile for CMake -E tar
* Change default path of static analysis
fix #614
  • Loading branch information
lulivi committed Jul 5, 2023
1 parent dee212c commit ff1f745
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
66 changes: 31 additions & 35 deletions resources/ci_cd/linux_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,20 @@
the minimal installation archive.
"""
import io
import os
import sys
import zipfile
import tempfile
import urllib.request

from distutils.spawn import find_executable
from pathlib import Path
from urllib import request
from subprocess import call
from urllib.error import URLError
from zipfile import ZipFile, ZipInfo


class ZipFileWithPermissions(ZipFile):
"""Custom ZipFile class handling file permissions.
Code from https://stackoverflow.com/a/54748564
"""

def _extract_member(self, member, targetpath, pwd):
if not isinstance(member, ZipInfo):
member = self.getinfo(member)

targetpath = super()._extract_member(member, str(targetpath), pwd)
attr = member.external_attr >> 16

if attr != 0:
Path(targetpath).chmod(attr)

return targetpath


def main():
rti_minimal_package_url = os.getenv("RTI_MIN_PACKAGE_URL")

temp_dir = Path(tempfile.gettempdir())
if not rti_minimal_package_url:
sys.exit(
"Environment variable RTI_MIN_PACKAGE_URL not found, skipping..."
Expand All @@ -59,23 +40,38 @@ def main():
except FileNotFoundError:
sys.exit("The RTI_INSTALLATION_PATH does not exist.")

cmake_command = find_executable("cmake")
if cmake_command is None:
sys.exit("CMake must be installed in order to use the script.")

try:
resp = request.urlopen(rti_minimal_package_url)
rti_zipped_file_name = Path(
urllib.request.url2pathname(rti_minimal_package_url)
).name
rti_zipped_file_path = temp_dir.joinpath(rti_zipped_file_name)
urllib.request.urlretrieve(
rti_minimal_package_url, rti_zipped_file_path
)
except URLError as e:
sys.exit("Error opening the URL: {}".format(e))

print("Extracting minimal installation.")

try:
with ZipFileWithPermissions(io.BytesIO(resp.read())) as rti_zipfile:
bad_file_name = rti_zipfile.testzip()

if bad_file_name:
sys.exit("Bad file found in the archive.")
return_value = call(
[
cmake_command,
"-E",
"tar",
"xf",
str(rti_zipped_file_path),
"--format=zip",
],
cwd=rti_installation_path,
)
except FileNotFoundError:
sys.exit("The CMake executable could not be found.")

rti_zipfile.extractall(rti_installation_path)
except zipfile.BadZipFile as e:
sys.exit("Error opening zip file: {}".format(e))
if return_value:
sys.exit("There were error extracting the package")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion resources/ci_cd/linux_static_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def find_connext_dir() -> Path:
def parse_args() -> argparse.Namespace:
"""Parse the CLI options."""
parser = argparse.ArgumentParser()
parser.add_argument("--build-dir", type=Path, default="examples/build")
parser.add_argument("--build-dir", type=Path, default="build")
parser.add_argument("--connext-dir", type=Path)
args = parser.parse_args()

Expand Down

0 comments on commit ff1f745

Please sign in to comment.