1516N/A#!/usr/bin/python
290N/A#
290N/A# CDDL HEADER START
290N/A#
290N/A# The contents of this file are subject to the terms of the
290N/A# Common Development and Distribution License (the "License").
290N/A# You may not use this file except in compliance with the License.
290N/A#
290N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
290N/A# or http://www.opensolaris.org/os/licensing.
290N/A# See the License for the specific language governing permissions
290N/A# and limitations under the License.
290N/A#
290N/A# When distributing Covered Code, include this CDDL HEADER in each
290N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
290N/A# If applicable, add the following below this CDDL HEADER, with the
290N/A# fields enclosed by brackets "[]" replaced with your own identifying
290N/A# information: Portions Copyright [yyyy] [name of copyright owner]
290N/A#
290N/A# CDDL HEADER END
290N/A#
3339N/A# Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
290N/A#
290N/A
290N/A"""
290N/AMost of the generic unix methods of our superclass can be used on
290N/ASolaris. For the following methods, there is a Solaris-specific
290N/Aimplementation in the 'arch' extension module.
290N/A"""
290N/A
1231N/Aimport os
3339N/Aimport six
1231N/Aimport subprocess
1231N/Aimport tempfile
1231N/A
3339N/Afrom .os_unix import \
383N/A get_group_by_name, get_user_by_name, get_name_by_gid, get_name_by_uid, \
3275N/A get_usernames_by_gid, is_admin, get_userid, get_username, chown, rename, \
3275N/A remove, link, copyfile, split_path, get_root, assert_mode
1933N/Afrom pkg.portable import ELF, EXEC, PD_LOCAL_PATH, UNFOUND, SMF_MANIFEST
1933N/A
290N/Aimport pkg.arch as arch
3033N/Afrom pkg.sysattr import fgetattr, fsetattr
3033N/Afrom pkg.sysattr import get_attr_dict as get_sysattr_dict
290N/A
290N/Adef get_isainfo():
290N/A return arch.get_isainfo()
290N/A
290N/Adef get_release():
290N/A return arch.get_release()
290N/A
290N/Adef get_platform():
290N/A return arch.get_platform()
1231N/A
1908N/Adef get_file_type(actions):
1231N/A t_fd, t_path = tempfile.mkstemp()
1231N/A t_fh = os.fdopen(t_fd, "w")
1231N/A for a in actions:
1500N/A t_fh.write(os.path.join(a.attrs[PD_LOCAL_PATH]) + "\n")
1231N/A t_fh.close()
1231N/A res = subprocess.Popen(["/usr/bin/file", "-f", t_path],
1231N/A stdout=subprocess.PIPE).communicate()[0].splitlines()
1231N/A remove(t_path)
1231N/A assert(len(actions) == len(res))
1231N/A for i, file_out in enumerate(res):
1231N/A file_out = file_out.strip()
3339N/A # ensure we can manipulate the string
3339N/A if isinstance(file_out, bytes) and six.PY3:
3339N/A file_out = file_out.decode("utf-8")
1231N/A a = actions[i]
1500N/A proto_file = a.attrs[PD_LOCAL_PATH]
1231N/A colon_cnt = proto_file.count(":") + 1
1231N/A tmp = file_out.split(":", colon_cnt)
1231N/A res_file_name = ":".join(tmp[0:colon_cnt])
1231N/A if res_file_name != proto_file:
3158N/A raise RuntimeError("pf:{0} rfn:{1} file_out:{2}".format(
3158N/A proto_file, res_file_name, file_out))
1231N/A file_type = tmp[colon_cnt].strip().split()
1231N/A joined_ft = " ".join(file_type)
1231N/A if file_type[0] == "ELF":
1231N/A yield ELF
1231N/A elif file_type[0] == "executable":
1231N/A yield EXEC
1231N/A elif joined_ft == "cannot open: No such file or directory":
1231N/A yield UNFOUND
1933N/A elif file_type[0] == "XML":
1933N/A from pkg.flavor.smf_manifest import is_smf_manifest
1933N/A if is_smf_manifest(proto_file):
1933N/A yield SMF_MANIFEST
1933N/A else:
1933N/A yield joined_ft
1231N/A else:
1933N/A yield joined_ft