コード例 #1
0
ファイル: arch.py プロジェクト: omniosorg/pkg5
def get_isainfo():
    """Return a list of strings constituting the architecture tags for the
    invoking system."""
    buf = NULL
    buf1 = _get_sysinfo(lib.SI_ARCHITECTURE_64)
    buf2 = _get_sysinfo(lib.SI_ARCHITECTURE_32)

    if buf1 == NULL and buf2 == NULL:
        return
    if buf1 == NULL and buf2:
        buf = buf2
    if buf2 == NULL and buf1:
        buf = buf1

    from pkg.misc import force_text
    # ffi.string returns a bytes
    if buf == NULL:
        buf1 = force_text(ffi.string(ffi.cast("char *", buf1)))
        buf2 = force_text(ffi.string(ffi.cast("char *", buf2)))
        robj = [buf1, buf2]
    else:
        buf = force_text(ffi.string(ffi.cast("char *", buf)))
        robj = [buf]

    return robj
コード例 #2
0
    def test_release_note_7(self):
        # check that multiple release notes are composited properly
        self.pkg("install [email protected]")
        self.pkg("install -v [email protected] [email protected]")
        uni_out = force_text(self.output, "utf-8")
        # we indent the release notes for readability, so a strict
        # index or compare won't work unless we remove indenting
        # this works for our test cases since they have no leading
        # spaces

        # removing indent
        uni_out = "\n".join((n.lstrip() for n in uni_out.split("\n")))

        uni_out.index(self.multi_unicode)
        uni_out.index(self.multi_ascii)

        # repeat test using history to make sure everything is there.
        # do as unpriv. user

        self.pkg("history -n 1 -HN", su_wrap=True)
        uni_out = force_text(self.output, "utf-8")
        # we indent the release notes for readability, so a strict
        # index or compare won't work unless we remove indenting
        # this works for our test cases since they have no leading
        # spaces

        # removing indent
        uni_out = "\n".join((n.lstrip() for n in uni_out.split("\n")))

        uni_out.index(self.multi_unicode)
        uni_out.index(self.multi_ascii)
        self.pkg("uninstall '*'")
コード例 #3
0
 def test_release_note_6(self):
         # test parsable unicode
         self.pkg("install --parsable 0 [email protected]")
         self.pkg("history -n 1 -N")
         force_text(self.output, "utf-8").index(u"Моё судно на воздушной подушке полно угрей")
         force_text(self.output, "utf-8").index(u"Eels are best smoked")
         self.pkg("uninstall '*'")
コード例 #4
0
ファイル: t_actuators.py プロジェクト: oracle/solaris-ips
    def test_release_note_8(self):
        # verify that temporary file is correctly written with /n characters
        self.pkg("-D GenerateNotesFile=1 install [email protected]")
        # find name of file containing release notes in output.
        for field in force_text(self.output, "utf-8").split(u" "):
            try:
                if field.index(u"release-note"):
                    break
            except:
                pass
        else:
            assert "output file not found" == 0

        # make sure file is readable by everyone
        assert (stat.S_IMODE(os.stat(field).st_mode) == 0o644)

        # read release note file and check to make sure
        # entire contents are there verbatim
        with open(field, encoding="utf-8") as f:
            release_note = force_text(f.read())

        # Note the package name is prepended to the release note
        # and so it needs to be added here.
        concatted = "\npkg://test/hovercraft\n" + self.multi_unicode
        assert concatted == release_note
        self.pkg("uninstall '*'")
コード例 #5
0
ファイル: sysattr.py プロジェクト: thenovum/pkg5
def fgetattr(filename, compact=False):
    """Get the list of set system attributes for file specified by 'path'.
    Returns a list of verbose attributes by default. If 'compact' is True,
    return a string consisting of compact option identifiers."""

    from pkg.misc import force_text
    if not isinstance(filename, six.string_types):
        raise TypeError("filename must be string type")

    cattrs = ffi.new("char[F_ATTR_ALL]")
    response = ffi.new("nvlist_t **")
    # ffi.gc return a new cdata object that points to the same data. Later,
    # when this new cdata object is garbage-collected, the destructor
    # (in this case 'lib.nvlist_free' will be called.
    response[0] = ffi.gc(response[0], lib.nvlist_free)
    bval = ffi.new("boolean_t *")
    pair = ffi.NULL
    next_pair = ffi.new("nvpair_t *")
    attr_list = []

    fd = os.open(filename, os.O_RDONLY)
    if fd == -1:
        raise OSError(ffi.errno, os.strerror(ffi.errno), filename)

    if lib.fgetattr(fd, lib.XATTR_VIEW_READWRITE, response):
        os.close(fd)
        raise OSError(ffi.errno, os.strerror(ffi.errno), filename)
    os.close(fd)

    count = 0
    pair = lib.nvlist_next_nvpair(response[0], pair)
    while pair != ffi.NULL:
        name = lib.nvpair_name(pair)
        next_pair = lib.nvlist_next_nvpair(response[0], pair)
        # we ignore all non-boolean attrs
        if lib.nvpair_type(pair) != lib.DATA_TYPE_BOOLEAN_VALUE:
            pair = next_pair
            continue

        if lib.nvpair_value_boolean_value(pair, bval) != 0:
            raise OSError("could not read attr value")

        if bval[0]:
            if compact:
                if count >= F_ATTR_ALL:
                    raise OSError("Too many system attributes found")
                cattrs[count] = lib.attr_to_option(lib.name_to_attr(name))[0]
                count += 1
            else:
                # ffi.string returns a bytes
                string = force_text(ffi.string(name))
                if string:
                    attr_list.append(string)
        pair = next_pair

    if compact:
        cattrs = force_text(ffi.string(cattrs))
        return cattrs
    return attr_list
コード例 #6
0
    def getstate(obj, je_state=None):
        """Returns the serialized state of this object in a format
                that that can be easily stored using JSON, pickle, etc."""

        return [[misc.force_text(k), v, True]
                for k, v in six.iteritems(obj.__inherited)
                ] + [[misc.force_text(k), v, False]
                     for k, v in six.iteritems(obj.__local)]
コード例 #7
0
ファイル: arch.py プロジェクト: omniosorg/pkg5
def get_platform():
    """Return the platform tag ("i86pc") for the invoking system."""
    buf = _get_sysinfo(lib.SI_PLATFORM)
    if buf == NULL:
        return
    from pkg.misc import force_text
    return force_text(ffi.string(ffi.cast("char *", buf)))
コード例 #8
0
ファイル: arch.py プロジェクト: omniosorg/pkg5
def get_release():
    """Return the release string ("5.11") for the invoking system."""
    buf = _get_sysinfo(lib.SI_RELEASE)
    if buf == NULL:
        return
    from pkg.misc import force_text
    return force_text(ffi.string(ffi.cast("char *", buf)))
コード例 #9
0
 def test_release_note_5(self):
         # test unicode character in release notes
         self.pkg("install -n [email protected]")
         force_text(self.output, "utf-8").index(u"Моё судно на воздушной подушке полно угрей")
         force_text(self.output, "utf-8").index(u"Eels are best smoked")
         self.pkg("install -v [email protected]")
         force_text(self.output, "utf-8").index(u"Моё судно на воздушной подушке полно угрей")
         force_text(self.output, "utf-8").index(u"Eels are best smoked")
         self.pkg("uninstall '*'")
コード例 #10
0
ファイル: sysattr.py プロジェクト: thenovum/pkg5
def get_attr_dict():
    """Get a dictionary containing all supported system attributes in the form:

        { <verbose_name>: <compact_option>,
          ...
        }
    """

    from pkg.misc import force_text
    sys_attrs = {}
    for i in range(F_ATTR_ALL):
        if not is_supported(i):
            continue
        key = force_text(ffi.string(lib.attr_to_name(i)))
        value = force_text(ffi.string(lib.attr_to_option(i)))
        sys_attrs.setdefault(key, value)
    return sys_attrs
コード例 #11
0
    def test_help_character_encoding(self):
        """Verify help command output for ja_JP.eucJP locale.
                Match against the expected output"""

        # This is a test case for CR 7166082.
        # It compares the output of "pkg --help" command against
        # the expected output for ja_JP.eucJP locale.
        # If first 4 lines of "pkg --help" command output modified
        # in the future then this test case will also need to be
        # modified.

        ret, out = self.cmdline_run("/usr/bin/locale -a",
                                    out=True,
                                    coverage=False)
        line = " ".join(out.split())
        m = re.search(r"ja_JP.eucJP", line)
        if not m:
            raise pkg5unittest.TestSkippedException(
                "The "
                "test system must have the ja_JP.eucJP locale "
                "installed to run this test.")

        eucJP_encode_file = os.path.join(self.ro_data_root,
                                         "pkg.help.eucJP.expected.out")
        f = codecs.open(eucJP_encode_file, encoding="eucJP")

        locale_env = {"LC_ALL": "ja_JP.eucJP"}
        ret, out, err = self.pkg("help -v",
                                 env_arg=locale_env,
                                 out=True,
                                 stderr=True)
        cmd_out = force_text(err, encoding="eucJP")
        # Take only 4 lines from "pkg --help" command output.
        u_out = cmd_out.splitlines()[:4]

        n = 0
        # The expected output file contain 4 lines and command output
        # is also 4 lines.
        while n < 4:
            cmd_line = u_out[n]
            # Remove \n from readline()
            file_line = f.readline()[:-1]

            self.assertEqual(cmd_line, file_line)
            n = n + 1

        f.close()