in mysql-connector-python/cpydist/bdist_solaris.py [0:0]
def _create_pkg(self, template_name, dmg=False, sign=False, root="", identity=""):
"""Create the Solaris package using the OS dependent commands."""
self.log.info("-> _create_pkg()")
self.log.info("template_name: %s", template_name)
self.log.info("identity: %s", identity)
sun_dist_name = template_name.format(self.name, self.version)
self.sun_pkg_name = f"{sun_dist_name}.pkg"
sun_pkg_contents = os.path.join(self.sun_pkg_name, "Contents")
self.log.info("sun_dist_name: %s", sun_dist_name)
self.log.info("sun_pkg_name: %s", self.sun_pkg_name)
self.log.info("sun_pkg_contents: %s", sun_pkg_contents)
sun_path = os.path.join(root, self.dstroot)
os.chdir(sun_path)
self.log.info("Root directory for Prototype: %s", os.getcwd())
# Creating a Prototype file, this contains a table of contents of the
# Package, that is suitable to be used for the package creation tool.
self.log.info(
f"Creating Prototype file on {self.dstroot} to describe files to install"
)
prototype_path = "Prototype"
proto_tmp = "Prototype_temp"
with open(proto_tmp, "w") as f_out:
cmd = ["pkgproto", "."]
pkgp_p = subprocess.Popen(cmd, shell=False, stdout=f_out, stderr=f_out)
res = pkgp_p.wait()
if res != 0:
self.log.error(f"pkgproto command failed with: {res}")
raise ExecError(f"pkgproto command failed with: {res}")
f_out.flush()
# log Prototype contents
self.log.info("/n>> Prototype_temp contents >>/n")
with open(proto_tmp, "r") as f_in:
self.log.info(f_in.readlines())
self.log.info("/n<< Prototype_temp contents end <</n")
# Fix Prototype file, insert pkginfo and remove Prototype
self.log.info("Fixing folder permissions on Prototype contents")
with open(prototype_path, "w") as f_out:
with open(proto_tmp, "r") as f_in:
# Add pkginfo entry at beginning of the Prototype file
f_out.write("i pkginfo\n")
f_out.flush()
for line in f_in:
if line.startswith("f none Prototype"):
continue
elif line.startswith("f none pkginfo"):
continue
elif line.startswith("d"):
tokeep = line.split(" ")[:-3]
tokeep.extend(["?", "?", "?", "\n"])
f_out.write(" ".join(tokeep))
elif line.startswith("f"):
tokeep = line.split(" ")[:-2]
tokeep.extend(["root", "bin", "\n"])
f_out.write(" ".join(tokeep))
else:
f_out.write(line)
f_out.flush()
# log Prototype contents
self.log.info("/n>> Prototype contents >>/n")
with open(prototype_path, "r") as f_in:
self.log.info(f_in.readlines())
self.log.info("/n<< Prototype contents end <</n")
# Create Solaris package running the package creation command pkgmk
self.log.info("Creating package with pkgmk")
self.log.info("Root directory for pkgmk: %s", os.getcwd())
self.spawn(["pkgmk", "-o", "-r", ".", "-d", "../", "-f", prototype_path])
os.chdir("../")
if self.debug:
self.log.info("current directory: %s", os.getcwd())
# gzip the package folder
self.log.info("creating tarball")
archive_name = f"{self.sun_pkg_name}.tar.gz"
self.log.info("Creating tar archive '%s'", archive_name)
with tarfile.open(archive_name, "w|gz") as tar:
tar.add(self.name)
if self.trans:
self.log.info("Transforming package into data stream with pkgtrans")
self.log.info("Current directory: %s", os.getcwd())
self.spawn(
[
"pkgtrans",
"-s",
os.getcwd(),
os.path.join(os.getcwd(), self.sun_pkg_name),
self.name,
]
)
for base, _, files in os.walk(os.getcwd()):
for filename in files:
if filename.endswith(".gz") or filename.endswith(".pkg"):
new_name = filename.replace(
f"{self.version}",
f"{self.version}{self.version_extra}{self.platform}"
f"{self.platform_version}-{self.architecture}",
)
file_path = os.path.join(base, filename)
file_dest = os.path.join(self.started_dir, self.dist_dir, new_name)
shutil.copyfile(file_path, file_dest)
break