当前位置: 首页>>代码示例>>Python>>正文


Python search.DbContainer类代码示例

本文整理汇总了Python中pyasm.search.DbContainer的典型用法代码示例。如果您正苦于以下问题:Python DbContainer类的具体用法?Python DbContainer怎么用?Python DbContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DbContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: execute

    def execute(my):
        my.buffer = cStringIO.StringIO()

        try:
            try:

                # clear the main container for this thread
                Container.create()

                # clear the buffer
                WebContainer.clear_buffer()

                # initialize the web environment object and register it
                adapter = my.get_adapter()
                WebContainer.set_web(adapter)

                # get the display
                my._get_display()

            except SetupException, e:
                '''Display setup exception in the interface'''
                print "Setup exception: ", e.__str__()
                DbContainer.rollback_all()
                ExceptionLog.log(e)
                my.writeln("<h3>Tactic Setup Error</h3>" )
                my.writeln("<pre>" )
                my.writeln(e.__str__() )
                my.writeln("</pre>" )

            except DatabaseException, e:
                from tactic.ui.startup import DbConfigPanelWdg
                config_wdg = DbConfigPanelWdg()
                my.writeln("<pre>")
                my.writeln(config_wdg.get_buffer_display())
                my.writeln("</pre>")
开发者ID:talha81,项目名称:TACTIC-DEV,代码行数:35,代码来源:app_server.py

示例2: __init__

    def __init__(my, port=''):

        # It is possible on startup that the database is not running.
        from pyasm.search import DbContainer, DatabaseException, Sql

        try:
            sql = DbContainer.get("sthpw")
            if sql.get_database_type() != "MongoDb":
                # before batch, clean up the ticket with a NULL code
                if os.getenv('TACTIC_MODE') != 'production':
                    sql.do_update('DELETE from "ticket" where "code" is NULL;')
                else:
                    start_port = Config.get_value("services", "start_port")
                    if start_port:
                        start_port = int(start_port)
                    else:
                        start_port = 8081
                    if port and int(port) == start_port:
                         sql.do_update('DELETE from "ticket" where "code" is NULL;')
        except DatabaseException, e:
            # TODO: need to work on this
            print "ERROR: could not connect to [sthpw] database"
            #os.environ["TACTIC_CONFIG_PATH"] = Config.get_default_config_path()
            #Sql.set_default_vendor("Sqlite")

            Config.set_tmp_config()
            Config.reload_config()

            # try connecting again
            try:
                sql = DbContainer.get("sthpw")
            except:
                print "Could not connect to the database."
                raise
开发者ID:funic,项目名称:TACTIC,代码行数:34,代码来源:cherrypy_startup.py

示例3: __init__

    def __init__(self, project_code=None, login_code=None, site=None):
        self.set_app_server("batch")

        if not site:
            # if not explicitly set, keep the current site
           site = Site.get_site() 


        plugin_dir = Environment.get_plugin_dir()
        if plugin_dir not in sys.path:
            sys.path.insert(0, plugin_dir)

        super(Batch,self).__init__()

        self.login_code = login_code

        # clear the main container
        Container.create()

        if site:
            Site.set_site(site)

        # set this as the environment
        if not project_code:
            self.context = self.get_default_context()
        else:
            self.context = project_code

        Environment.set_env_object( self )

        # set up the security object
        security = Security()
        Environment.set_security(security)

        self._do_login()
        site_dir = Environment.get_site_dir()
        if site_dir not in sys.path:
            sys.path.insert(0, site_dir)

        # set the project
        from pyasm.biz import Project

        if self.context == "batch":
            Project.set_project("admin")
        else:
            Project.set_project(self.context)

        self.initialize_python_path()


        # start workflow engine
        #from pyasm.command import Workflow
        #Workflow().init()

        DbContainer.commit_thread_sql()
开发者ID:mincau,项目名称:TACTIC,代码行数:55,代码来源:batch.py

示例4: start

 def start():
     
     scheduler = Scheduler.get()
     scheduler.start_thread()
     task = TransactionQueueManager(
         #check_interval=0.1,
         max_jobs_completed=20
     )
     task.cleanup_db_jobs()
     scheduler.add_single_task(task, mode='threaded', delay=1)
     # important to close connection after adding tasks
     DbContainer.close_all()
开发者ID:mincau,项目名称:TACTIC,代码行数:12,代码来源:run_transaction_cmd.py

示例5: execute

            def execute(self):
                start = time.time()
                #Batch()

                #print "refresh caches ..."
                caches = CacheContainer.get_all_caches()
                for key, cache in caches.items():
                    #print "... %s" % key, cache
                    cache.init_cache()
                #print "... %s seconds" % (time.time() - start)

                DbContainer.commit_thread_sql()
                DbContainer.close_all()
开发者ID:mincau,项目名称:TACTIC,代码行数:13,代码来源:cache_startup.py

示例6: start

    def start(cls):
        
        task = WatchServerFolderTask()

        scheduler = Scheduler.get()
        scheduler.add_single_task(task, 3)
        #scheduler.add_interval_task(task, 1)

        scheduler.start_thread()
        # important to close connection after adding tasks
        DbContainer.close_all()

        return scheduler
开发者ID:0-T-0,项目名称:TACTIC,代码行数:13,代码来源:watch_handoff_folder.py

示例7: execute

    def execute(self):

        if not self.login_name:
            self.login_name = self.kwargs.get('login');

        # invalidate the ticket
        security = Environment.get_security()
        ticket = security.get_ticket()

        if ticket == None:
            return


        login_name = ticket.get_value("login")
        print "Signing out: ", login_name

        # expire the ticket

        from pyasm.security import Site
        site = Site.get()
        if site:
            Site.set_site("default")

        try:
            from pyasm.search import Sql, DbContainer
            sql = DbContainer.get("sthpw")
            ticket.set_value("expiry", sql.get_timestamp_now(), quoted=False)
            ticket.commit()
        except:
            if site:
                Site.pop_site()
开发者ID:mincau,项目名称:TACTIC,代码行数:31,代码来源:sign_out_cmd.py

示例8: delete

    def delete(my,log=False):
        column = my.get_value("name")

        search_type = my.get_value("search_type")
        search_type_obj = SearchType.get(search_type)

        table = search_type_obj.get_table()
        database = search_type_obj.get_database()

        # remove it from the table
        if log:
            AlterTableUndo.log_drop(database, table, column)
            sql = DbContainer.get(database)
            try:

                from pyasm.search.sql import Sql
                if Sql.get_database_type() == 'SQLServer':
                    statement = 'ALTER TABLE [%s] DROP "%s" %s' % \
                        (table, column)
                else:
                    statement = 'ALTER TABLE "%s" DROP COLUMN "%s"' % (table, column) 

                sql.do_update(statement)
            except SqlException, e:
                print("WARNING: %s" % e )
开发者ID:0-T-0,项目名称:TACTIC,代码行数:25,代码来源:custom_property.py

示例9: execute

 def execute(my):
     import cherrypy
     print
     print "Stopping TACTIC ..."
     print 
     print " ... stopping Schduler"
     scheduler = Scheduler.get()
     scheduler.stop()
     print " ... stopping Cherrypy"
     cherrypy.engine.stop()
     cherrypy.engine.exit()
     print " ... closing DB connections"
     DbContainer.close_all_global_connections()
     print " ... kill current process"
     Common.kill()
     print "Done."
开发者ID:0-T-0,项目名称:TACTIC,代码行数:16,代码来源:cache_startup.py

示例10: _test_time

    def _test_time(my):
        """ test timezone related behavior"""
        sobject = SearchType.create("sthpw/task")
        sobject.set_value("project_code", "unittest")
        sobject.set_value("bid_start_date", "2014-11-11 05:00:00")
        time = sobject.get_value("bid_start_date")
        my.assertEquals(time, "2014-11-11 05:00:00")

        sobject.commit()

        time = sobject.get_value("bid_start_date")
        my.assertEquals(time, "2014-11-11 05:00:00")
        from pyasm.search import DbContainer

        sql = DbContainer.get("sthpw")
        db_value = sql.do_query("SELECT bid_start_date from task where id = %s" % sobject.get_id())

        # 2014-11-11 00:00:00 is actually written to the database
        my.assertEquals(db_value[0][0].strftime("%Y-%m-%d %H:%M:%S %Z"), "2014-11-11 00:00:00 ")

        # an sType specified without a project but with an id could be a common human error
        # but it should handle that fine
        obj1 = Search.eval('@SOBJECT(unittest/person?project=unittest["id", "%s"])' % sobject.get_id(), single=True)
        obj2 = Search.eval('@SOBJECT(unittest/person?id=2["id", "%s"])' % sobject.get_id(), single=True)
        obj3 = Search.eval('@SOBJECT(sthpw/task?id=2["id", "%s"])' % sobject.get_id(), single=True)
        task = Search.eval('@SOBJECT(sthpw/task["id", "%s"])' % sobject.get_id(), single=True)

        # EST and GMT diff is 5 hours
        my.assertEquals(task.get_value("bid_start_date"), "2014-11-11 05:00:00")
开发者ID:pombredanne,项目名称:TACTIC,代码行数:29,代码来源:biz_test.py

示例11: execute

    def execute(my):
        database = "sthpw" 

        sql = DbContainer.get(database)
        value_array = sql.do_query("select code, cc from (select code, count(code) as cc from file group by code order by cc desc) as X where cc > 1;")
        #value_array = sql.do_query("select code, cc from (select code, count(code) as cc from file group by code order by cc desc) as X;")

        print "found [%s] pairs" % len(value_array)

        for count, value_list in enumerate(value_array):
            if count >= BATCH:
                break

            # get the file object
            file_code = value_list[0]
            search = Search("sthpw/file")
            search.add_filter("code", file_code)
            files = search.get_sobjects()

            #if len(files) == 1:
            #    continue

            for file in files:
                project_code = file.get_value("project_code")
                if not project_code:
                    print "WARNING: file [%s] has no project_code" % file_code
                    continue

                project = Project.get_by_code(project_code)
                initials = project.get_initials()

                id = file.get_id()
                new_file_code = "%s%s" % (id, initials)
                if file_code == new_file_code:
                    continue

                print "-"*20
                print "switching: ", file_code, "to", new_file_code


                snapshot_code = file.get_value("snapshot_code")
                snapshot = Snapshot.get_by_code(snapshot_code)
                assert snapshot

                snapshot_xml = snapshot.get_xml_value("snapshot")
                print snapshot_xml.to_string()
                node = snapshot_xml.get_node("snapshot/file[@file_code='%s']" % file_code)
                Xml.set_attribute(node, "file_code", new_file_code)
                print snapshot_xml.to_string()

                assert node


                # set the file_code
                file.set_value("code", new_file_code)
                file.commit()

                # set the snapshot
                snapshot.set_value("snapshot", snapshot_xml.to_string() )
                snapshot.commit()
开发者ID:0-T-0,项目名称:TACTIC,代码行数:60,代码来源:fix_duplicate_file_code.py

示例12: get_columns

    def get_columns(cls, db_resource, table):
        from pyasm.search import DbResource, DbContainer
        sql = DbContainer.get(db_resource)
        conn = sql.get_connection()
        collection = conn.get_collection(table)

        # FIXME:
        # This just gets the first one to discover the columns.  This is
        # not accurate because each item in a collection can contain
        # different "attributes". The key here is to define a location
        # for where this "schema" description is stored
        result = collection.find_one()
        if not result:
            return ['_id']
        else:
            columns = result.keys()

            # assume existence of both code and _id
            #if "code" in columns:
            #    columns.remove("code")
            #columns.insert(0, "code")

            if "_id" in columns:
                columns.remove("_id")
            columns.insert(0, "_id")


            return columns
开发者ID:mincau,项目名称:TACTIC,代码行数:28,代码来源:mongodb.py

示例13: fix_debug_log_id

def fix_debug_log_id():

    db = DbContainer.get("sthpw")

    sql = '''
BEGIN TRANSACTION;

CREATE TABLE t_backup (
    id integer PRIMARY KEY AUTOINCREMENT,
    "category" character varying(256),
    "level" character varying(256),
    "message" text,
    "timestamp" timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    "login" character varying(256),
    "s_status" character varying(30)
);

INSERT INTO t_backup SELECT "id", "category", "level", "message", "timestamp", "login", "s_status" FROM %(table)s;

DROP TABLE %(table)s;
ALTER TABLE t_backup RENAME TO %(table)s;
COMMIT;

    ''' % {"table": "debug_log"}

    conn = db.conn
    conn.executescript(sql)
开发者ID:Southpaw-TACTIC,项目名称:Team,代码行数:27,代码来源:fix_table_id.py

示例14: fix_notification_login_id

def fix_notification_login_id():

    db = DbContainer.get("sthpw")

    sql = '''
BEGIN TRANSACTION;

CREATE TABLE t_backup (
    id integer PRIMARY KEY AUTOINCREMENT,
    notification_log_id integer,
    "login" character varying(256),
    "type" character varying(256),
    project_code character varying(256),
    "timestamp" timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO t_backup SELECT id, notification_log_id, "login", "type", project_code, "timestamp" FROM %(table)s;

DROP TABLE %(table)s;
ALTER TABLE t_backup RENAME TO %(table)s;
COMMIT;

    ''' % {"table": "notification_login"}

    conn = db.conn
    conn.executescript(sql)
开发者ID:Southpaw-TACTIC,项目名称:Team,代码行数:26,代码来源:fix_table_id.py

示例15: has_table

    def has_table(my, search_type):
        if isinstance(search_type, basestring):
            search_type = SearchType.get(search_type)


        # in search type database == project 
        project_code = search_type.get_project_code()

        # get the db_resource for this project
        db_resource = my.get_project_db_resource()

        # get the table
        table = search_type.get_table()
        if not table:
            return False

        try:
            # looking up a database's tables other than the current one
            sql = DbContainer.get(db_resource)
            tables = sql.get_tables()
            has_table = table in tables
        except Exception, e:
            print "WARNING: in Project.has_table(): table [%s] not found" % table
            print "Message: ", e
            has_table = False
开发者ID:davidsouthpaw,项目名称:TACTIC,代码行数:25,代码来源:project.py


注:本文中的pyasm.search.DbContainer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。