Example #1
0
    def execute(my):
        if not my.transaction_log:
            search = Search("sthpw/transaction_log")
            search.add_filter("type", "undo")

            # get the current project.  If the project is admin, then undo
            # works differently
            project = Project.get_global_project_code()
            assert project
            search.add_filter("namespace", project)

            user = Environment.get_user_name()
            assert user
            search.add_filter("login", user)

            search.add_order_by("timestamp desc")

            search.add_limit(1)
            my.transaction_log = search.get_sobject()

        if not my.transaction_log:
            print("WARNING: No transaction log found for undo")
            return CommandExitException()

        my.transaction_log.undo(ignore_files=my.ignore_files)

        my.transaction_log.set_value("type", "redo")
        my.transaction_log.commit()

        # undo triggers a special sync
        # if this is a sync undo, then do not propgate remote undos
        if not my.is_sync:
            my.transaction_log.trigger_remote_undo()
Example #2
0
    def execute(my):
        if not my.transaction_log:
            search = Search("sthpw/transaction_log")
            search.add_filter("type", "undo")

            # get the current project.  If the project is admin, then undo
            # works differently
            project = Project.get_global_project_code()
            assert project
            search.add_filter("namespace", project)

            user = Environment.get_user_name()
            assert user
            search.add_filter("login", user)

            search.add_order_by("timestamp desc")

            search.add_limit(1)
            my.transaction_log = search.get_sobject()

        if not my.transaction_log:
            print("WARNING: No transaction log found for undo")
            return CommandExitException()

        my.transaction_log.undo(ignore_files=my.ignore_files)

        my.transaction_log.set_value("type", "redo")
        my.transaction_log.commit()

        # undo triggers a special sync
        # if this is a sync undo, then do not propgate remote undos
        if not my.is_sync:
            my.transaction_log.trigger_remote_undo()
Example #3
0
    def create(cls,
               command,
               transaction_data,
               description,
               title='',
               state=None):
        user_name = Environment.get_user_name()
        #namespace = Environment.get_env_object().get_context_name()
        from pyasm.biz import Project
        namespace = Project.get_global_project_code()

        # TODO: need to add a ticket column to the transaction_log table
        security = Environment.get_security()
        ticket = security.get_ticket_key()

        #transaction_data = transaction_data.replace("\\", "\\\\")

        length_before = len(transaction_data)
        cutoff = 10 * 1024
        if length_before > cutoff:
            import zlib, binascii
            transaction_data = Common.process_unicode_string(transaction_data)
            ztransaction_data = binascii.hexlify(
                zlib.compress(transaction_data))
            ztransaction_data = "zlib:%s" % ztransaction_data
            length_after = len(ztransaction_data)
            print "transaction log compress: ", "%s%%" % int(
                float(length_after) / float(length_before) *
                100), "[%s] to [%s]" % (length_before, length_after)
        else:
            ztransaction_data = transaction_data

        # a new entry deletes all redos for that user
        TransactionLog.delete_all_redo()

        log = SObjectFactory.create("sthpw/transaction_log")
        log.set_value("login", user_name)
        log.set_value("command", command)
        log.set_value("transaction", ztransaction_data)
        log.set_value("title", title)
        log.set_value("description", description)
        log.set_value("type", "undo")
        log.set_value("namespace", namespace)
        log.set_value("ticket", ticket)
        if state:
            log.set_value("state", state)

        server = Config.get_value("install", "server")
        if server:
            log.set_value("server_code", server)

        log.commit(triggers=False)

        # FIXME:
        # only do an sobject log before the cutoff ... above this it gets
        # very slow.  Need a way of doing very fast inserts
        if length_before <= cutoff:
            cls.create_sobject_log(log, transaction_data)
        return log
Example #4
0
    def create(cls, command, transaction_data, description, title='', state=None, keywords=None):
        user_name = Environment.get_user_name()
        #namespace = Environment.get_env_object().get_context_name()
        from pyasm.biz import Project
        namespace = Project.get_global_project_code()

        # TODO: need to add a ticket column to the transaction_log table
        security = Environment.get_security()
        ticket = security.get_ticket_key()

        #transaction_data = transaction_data.replace("\\", "\\\\")

        length_before = len(transaction_data)
        cutoff = 10*1024
        if length_before > cutoff:
            import zlib, binascii
            transaction_data = Common.process_unicode_string(transaction_data)
            ztransaction_data = binascii.hexlify(zlib.compress(transaction_data))
            ztransaction_data = "zlib:%s" % ztransaction_data
            length_after = len(ztransaction_data)
            print "transaction log compress: ", "%s%%" % int(float(length_after)/float(length_before)*100), "[%s] to [%s]" % (length_before, length_after)
        else:
            ztransaction_data = transaction_data

        # a new entry deletes all redos for that user
        TransactionLog.delete_all_redo()


        log = SObjectFactory.create("sthpw/transaction_log")
        log.set_value("login", user_name)
        log.set_value("command", command)
        log.set_value("transaction", ztransaction_data)
        log.set_value("title", title)
        log.set_value("description", description)
        log.set_value("type", "undo")
        log.set_value("namespace", namespace)
        log.set_value("ticket", ticket)
        if state:
            log.set_value("state", state)

        if keywords:
            log.set_value("keywords", keywords)

        server = Config.get_value("install", "server")
        if server:
            log.set_value("server_code", server)

        log.commit(triggers=False)



        # FIXME:
        # only do an sobject log before the cutoff ... above this it gets
        # very slow.  Need a way of doing very fast inserts
        if length_before <= cutoff:
            cls.create_sobject_log(log, transaction_data)
        return log
Example #5
0
    def execute(self):
        import time
        start = time.time()

        security = Environment.get_security()
        ticket = security.get_ticket_key()

        if not self.transaction_log:
            search = Search("sthpw/transaction_log")
            search.add_filter("type", "redo")

            # get the current project
            project = Project.get_global_project_code()
            search.add_filter("namespace", project)

            user = Environment.get_user_name()
            search.add_filter("login", user)

            search.add_order_by("timestamp")
            search.add_limit(1)

            self.transaction_log = search.get_sobject()

        if not self.transaction_log:
            return CommandExitException()

        base_dir = self.kwargs.get("base_dir")

        self.transaction_log.redo(ignore=self.ignore, base_dir=base_dir)
        self.transaction_log.set_value("type", "undo")
        self.transaction_log.commit()

        # get the transaction and set it to not record this transaction
        transaction = Transaction.get()
        transaction.set_record(False)

        # update the change timestamps
        transaction.update_change_timestamps(self.transaction_log)

        print "RedoCmd: ", time.time() - start
        print
Example #6
0
    def execute(my):
        import time
        start = time.time()

        security = Environment.get_security()
        ticket = security.get_ticket_key()

        if not my.transaction_log:
            search = Search("sthpw/transaction_log")
            search.add_filter("type", "redo")

            # get the current project
            project = Project.get_global_project_code()
            search.add_filter("namespace", project)

            user = Environment.get_user_name()
            search.add_filter("login", user)

            search.add_order_by("timestamp")
            search.add_limit(1)

            my.transaction_log = search.get_sobject()

        if not my.transaction_log:
            return CommandExitException()

        base_dir = my.kwargs.get("base_dir")

        my.transaction_log.redo(ignore=my.ignore, base_dir=base_dir)
        my.transaction_log.set_value("type", "undo")
        my.transaction_log.commit()

        # get the transaction and set it to not record this transaction
        transaction = Transaction.get()
        transaction.set_record(False)

        # update the change timestamps
        transaction.update_change_timestamps(my.transaction_log)

        print "RedoCmd: ", time.time() - start
        print
Example #7
0
    def get_by_search_type(search_type_obj, database):

        search_type = search_type_obj.get_base_key()

        # This is here to prevent an infinite loop
        if search_type == "sthpw/search_object":
            return

        if search_type == None:
            search_type = "sthpw/search_object"

        # if it already exists, then get the cached data
        cache_name = "SObjectConfig:sobject_configs_list"
        config_list = Container.get(cache_name)
        if config_list == None:
            config_list = {}
            Container.put(cache_name, config_list)

        if config_list.has_key(search_type):
            return config_list[search_type]

        # get the real search_type implementation to find the paths
        tmp = search_type.split("/")
        if len(tmp) == 2:
            sub_dir = tmp[0]
            search_key = tmp[1]
        else:
            sub_dir = tmp[0]
            search_key = tmp[2]

        filename = "%s-conf.xml" % search_key

        config = None

        # start with the site directory for overrides
        env = Environment.get_env_object()
        site_dir = env.get_site_dir()

        # This assumes that the context and the database are the same
        #context = search_type_obj.get_database()
        context = database
        # build up the file path and load in the config file
        if context == "sthpw":
            #from search import SearchType
            #project = SearchType.get_global_project()
            from pyasm.biz import Project
            project_code = Project.get_global_project_code()
            conf_path = "%s/sites/%s/config/sthpw/sobject/%s" \
                % (site_dir,project_code,filename)
        else:
            conf_path = "%s/sites/%s/config/sobject/%s" \
                % (site_dir,context,filename)

        if os.path.exists(conf_path):
            # load in the config path
            config = SObjectConfig(conf_path)

        else:

            # build the path from the site directory
            env = Environment.get_env_object()
            site_dir = env.get_site_dir()
            conf_path = "%s/sites/%s/config/sobject/%s" \
                % (site_dir,sub_dir,filename)

        if os.path.exists(conf_path):
            # load in config file
            config = SObjectConfig(conf_path)

        else:
            base_dir = Environment.get_install_dir()
            conf_path = "%s/src/config/%s/sobject/%s" \
                % (base_dir, sub_dir,  filename)

            if os.path.exists(conf_path):
                # load in config file
                config = SObjectConfig(conf_path)

        # store in container
        config_list[search_type] = config

        return config
Example #8
0
    def get_by_search_type(search_type_obj, database):

        search_type = search_type_obj.get_base_key()

        # This is here to prevent an infinite loop
        if search_type == "sthpw/search_object":
            return

        if search_type == None:
            search_type = "sthpw/search_object"
            

        # if it already exists, then get the cached data
        cache_name = "SObjectConfig:sobject_configs_list"
        config_list = Container.get(cache_name)
        if config_list == None:
            config_list = {}
            Container.put(cache_name, config_list)

        if config_list.has_key(search_type):
            return config_list[search_type]


        # get the real search_type implementation to find the paths
        tmp = search_type.split("/")
        if len(tmp) == 2:
            sub_dir = tmp[0]
            search_key = tmp[1]
        else:
            sub_dir = tmp[0]
            search_key = tmp[2]

        filename = "%s-conf.xml" % search_key

        config = None


        # start with the site directory for overrides
        env = Environment.get_env_object()
        site_dir = env.get_site_dir()


        # This assumes that the context and the database are the same
        #context = search_type_obj.get_database()
        context = database
        # build up the file path and load in the config file
        if context == "sthpw":
            #from search import SearchType
            #project = SearchType.get_global_project()
            from pyasm.biz import Project
            project_code = Project.get_global_project_code()
            conf_path = "%s/sites/%s/config/sthpw/sobject/%s" \
                % (site_dir,project_code,filename)
        else:
            conf_path = "%s/sites/%s/config/sobject/%s" \
                % (site_dir,context,filename)


        if os.path.exists(conf_path):
            # load in the config path
            config = SObjectConfig( conf_path );

        else:

            # build the path from the site directory
            env = Environment.get_env_object()
            site_dir = env.get_site_dir()
            conf_path = "%s/sites/%s/config/sobject/%s" \
                % (site_dir,sub_dir,filename)


        if os.path.exists(conf_path):
            # load in config file
            config = SObjectConfig( conf_path );

        else:
            base_dir = Environment.get_install_dir()
            conf_path = "%s/src/config/%s/sobject/%s" \
                % (base_dir, sub_dir,  filename)

            if os.path.exists(conf_path):
                # load in config file
                config = SObjectConfig( conf_path );

    
        # store in container
        config_list[search_type] = config

        return config
Example #9
0
    def get_display(self):

        #WebContainer.register_cmd("pyasm.admin.UndoLogCbk")

        # add a time filter
        div = DivWdg()
        div.add_color('background', 'background', -10)
        div.add_color('color', 'color')
        div.add_style("padding: 15px")
        div.add_border()
        project = ''
        # add a project filter
        if self.all_namespaces_flag:
            span = SpanWdg("Project: ")
            span.add_color('color', 'color')
            project_select = FilterSelectWdg("project")
            project_select.add_empty_option(label="-- All Projects --")
            project_select.set_option("query", "sthpw/project|code|title")
            span.add(project_select)
            div.add(span)

            project = project_select.get_value()
        else:
            from pyasm.biz import Project
            project = Project.get_global_project_code()

        # add a time filter
        from pyasm.prod.web import DateFilterWdg
        select = DateFilterWdg("undo_time_filter",
                               label="Show Transaction Log From: ")
        select.set_label(
            ["1 Hour Ago", "Today", "1 Day Ago", "1 Week Ago", "1 Month Ago"])
        select.set_value(["1 Hour", "today", "1 Day", "1 Week", "1 Month"])
        select.set_option("default", "1 Hour")
        div.add(select)

        time_interval = select.get_value()

        self.add(div)

        if not self.all_users_flag:
            user = Environment.get_user_name()
        else:
            span = SpanWdg(css="med")
            span.add("User: "******"user")
            user_select.set_option("query", "sthpw/login|login|login")
            user_select.add_empty_option()
            span.add(user_select)
            div.add(span)

            user = user_select.get_value()

        transaction_log = TransactionLog.get( user_name=user, \
            namespace=project, time_interval=time_interval)

        from tactic.ui.panel import FastTableLayoutWdg, TableLayoutWdg
        table = FastTableLayoutWdg(search_type="sthpw/transaction_log",
                                   view="table",
                                   show_shelf='false',
                                   show_select="false")
        #table = TableLayoutWdg(search_type="sthpw/transaction_log", view="table", mode='simple', show_row_select="false")
        table.set_sobjects(transaction_log)
        #table.set_refresh_mode("table")
        self.add(table)

        return super(UndoLogWdg, self).get_display()
Example #10
0
    def get_display(self):

        #WebContainer.register_cmd("pyasm.admin.UndoLogCbk")

        # add a time filter
        div = DivWdg()
        div.add_color('background','background', -10)
        div.add_color('color','color')
        div.add_style("padding: 15px")
        div.add_border()
        project = ''
        # add a project filter
        if self.all_namespaces_flag:
            span = SpanWdg("Project: ")
            span.add_color('color','color')
            project_select = FilterSelectWdg("project")
            project_select.add_empty_option(label="-- All Projects --")
            project_select.set_option("query", "sthpw/project|code|title")
            span.add(project_select)
            div.add(span)

            project = project_select.get_value()
        else:
            from pyasm.biz import Project
            project = Project.get_global_project_code()


        # add a time filter
        from pyasm.prod.web import DateFilterWdg
        select = DateFilterWdg("undo_time_filter", label="Show Transaction Log From: ")
        select.set_label(["1 Hour Ago", "Today", "1 Day Ago", "1 Week Ago", "1 Month Ago"])
        select.set_value(["1 Hour", "today", "1 Day", "1 Week", "1 Month"])
        select.set_option("default", "1 Hour")
        div.add(select)

        time_interval = select.get_value() 

        self.add(div)

        if not self.all_users_flag:
            user = Environment.get_user_name()
        else:
            span = SpanWdg(css="med")
            span.add("User: "******"user")
            user_select.set_option("query", "sthpw/login|login|login")
            user_select.add_empty_option()
            span.add(user_select)
            div.add(span)

            user = user_select.get_value()

        transaction_log = TransactionLog.get( user_name=user, \
            namespace=project, time_interval=time_interval)

        from tactic.ui.panel import FastTableLayoutWdg, TableLayoutWdg
        table = FastTableLayoutWdg(search_type="sthpw/transaction_log", view="table", show_shelf='false', show_select="false")
        #table = TableLayoutWdg(search_type="sthpw/transaction_log", view="table", mode='simple', show_row_select="false")
        table.set_sobjects(transaction_log)
        #table.set_refresh_mode("table")
        self.add(table)

        return super(UndoLogWdg, self).get_display()