Exemple #1
0
def get_log_path(client_name):
        if portable.is_admin():
                log_path = os.path.join(LOG_DIR, client_name)
        else:
                user_name = portable.get_username()
                log_path = os.path.join(LOG_DIR, client_name + "_" + user_name)
        return log_path
Exemple #2
0
    def setUp(self):
        """Prepare the test for execution.
                """
        pkg5unittest.Pkg5TestCase.setUp(self)

        self.__scratch_dir = tempfile.mkdtemp(dir=self.test_root)
        # Explicitly convert these to strings as they will be
        # converted by history to deal with minidom issues.
        self.__userid = str(portable.get_userid())
        self.__username = str(portable.get_username())
        self.__h = history.History(root_dir=self.__scratch_dir)
        self.__h.client_name = "pkg-test"
Exemple #3
0
        def setUp(self):
                """Prepare the test for execution.
                """
                pkg5unittest.Pkg5TestCase.setUp(self)

                self.__scratch_dir = tempfile.mkdtemp(dir=self.test_root)
                # Explicitly convert these to strings as they will be
                # converted by history to deal with minidom issues.
                self.__userid = str(portable.get_userid())
                self.__username = str(portable.get_username())
                self.__h = history.History(root_dir=self.__scratch_dir)
                self.__h.client_name = "pkg-test"
Exemple #4
0
    def __setattr__(self, name, value):
        if name == "client_args":
            raise AttributeError("'history' object attribute '{0}' "
                                 "is read-only.".format(name))

        if not name.startswith("operation_"):
            return object.__setattr__(self, name, value)

        ops = object.__getattribute__(self, "_History__operations")
        if name == "operation_name":
            if not ops:
                ops = []
                object.__setattr__(self, "_History__operations", ops)

            ops.append({"pathname": None, "operation": _HistoryOperation()})
        elif not ops:
            raise AttributeError(
                "'history' object attribute '{0}' "
                "cannot be set before 'operation_name'.".format(name))

        op = ops[-1]["operation"]
        setattr(op, name[len("operation_"):], value)

        # Access to the class attributes is done through object instead
        # of just referencing self to avoid any of the special logic in
        # place interfering with logic here.
        if name == "operation_name":
            # Before a new operation starts, clear exception state
            # for the current one so that when this one ends, the
            # last operation's exception won't be recorded to this
            # one.  If the error hasn't been recorded by now, it
            # doesn't matter anyway, so should be safe to clear.
            sys.exc_clear()

            # Mark the operation as having started and record
            # other, relevant information.
            op.start_time = misc.time_to_timestamp(None)
            try:
                op.username = portable.get_username()
            except KeyError:
                op.username = "******"
            op.userid = portable.get_userid()

            ca = None
            if sys.argv[0]:
                ca = [sys.argv[0]]
            else:
                # Fallback for clients that provide no value.
                ca = [self.client_name]

            ca.extend(sys.argv[1:])
            object.__setattr__(self, "client_args", ca)
            object.__setattr__(self, "client_version", pkg.VERSION)

        elif name == "operation_result":
            # Record when the operation ended.
            op.end_time = misc.time_to_timestamp(None)

            # Some operations shouldn't be saved -- they're merely
            # included in the stack for completeness or to support
            # client functionality.
            if op.name not in DISCARDED_OPERATIONS and \
                value != RESULT_NOTHING_TO_DO:
                # Write current history and last operation to a
                # file.
                self.__save()

            # Discard it now that it is no longer needed.
            del ops[-1]
        def __setattr__(self, name, value):
                if name == "client_args":
                        raise AttributeError("'history' object attribute '%s' "
                            "is read-only." % name)

                if not name.startswith("operation_"):
                        return object.__setattr__(self, name, value)

                ops = object.__getattribute__(self, "_History__operations")
                if name == "operation_name":
                        if not ops:
                                ops = []
                                object.__setattr__(self,
                                    "_History__operations", ops)

                        ops.append({
                            "pathname": None,
                            "operation": _HistoryOperation()
                        })
                elif not ops:
                        raise AttributeError("'history' object attribute '%s' "
                            "cannot be set before 'operation_name'." % name)

                op = ops[-1]["operation"]
                setattr(op, name[len("operation_"):], value)

                # Access to the class attributes is done through object instead
                # of just referencing self to avoid any of the special logic in
                # place interfering with logic here.
                if name == "operation_name":
                        # Before a new operation starts, clear exception state
                        # for the current one so that when this one ends, the
                        # last operation's exception won't be recorded to this
                        # one.  If the error hasn't been recorded by now, it
                        # doesn't matter anyway, so should be safe to clear.
                        sys.exc_clear()

                        # Mark the operation as having started and record
                        # other, relevant information.
                        op.start_time = misc.time_to_timestamp(None)
                        op.username = portable.get_username()
                        op.userid = portable.get_userid()

                        ca = None
                        if sys.argv[0]:
                                ca = [sys.argv[0]]
                        else:
                                # Fallback for clients that provide no value.
                                ca = [self.client_name]

                        ca.extend(sys.argv[1:])
                        object.__setattr__(self, "client_args", ca)
                        object.__setattr__(self, "client_version", pkg.VERSION)

                elif name == "operation_result":
                        # Record when the operation ended.
                        op.end_time = misc.time_to_timestamp(None)

                        # Some operations shouldn't be saved -- they're merely
                        # included in the stack for completeness or to support
                        # client functionality.
                        if op.name not in DISCARDED_OPERATIONS:
                                # Write current history and last operation to a
                                # file.
                                self.__save()

                        # Discard it now that it is no longer needed.
                        del ops[-1]