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


Python SPTDate.now方法代码示例

本文整理汇总了Python中pyasm.common.SPTDate.now方法的典型用法代码示例。如果您正苦于以下问题:Python SPTDate.now方法的具体用法?Python SPTDate.now怎么用?Python SPTDate.now使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyasm.common.SPTDate的用法示例。


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

示例1: accesshandler

# 需要导入模块: from pyasm.common import SPTDate [as 别名]
# 或者: from pyasm.common.SPTDate import now [as 别名]
def accesshandler(request):

    cookies = Cookie.get_cookies(request)

    # if login ticket cookie does not exist, then deny
    if not cookies.has_key('login_ticket'):
        # just refuse access
        return apache.HTTP_FORBIDDEN

    ticket = cookies['login_ticket'].value
    if not ticket:
        return apache.HTTP_FORBIDDEN

    server = TacticServerStub.get(protocol='local')
    expr = "@SOBJECT(sthpw/ticket['ticket','%s'])" % ticket
    sobject = server.eval(expr, single=True)
    now = SPTDate.now()
    expiry = sobject.get("expiry")
    if expiry and expiry < str(now):
        return apache.HTTP_FORBIDDEN

    request.add_common_vars()
    path = str(request.subprocess_env['REQUEST_URI'])
    if path == None:
        return apache.HTTP_FORBIDDEN


    # FIXME: find some mechanism which is more acceptable ... like /icons
    #if path.find("_icon_") != -1:
    #    return apache.OK

    return apache.OK
开发者ID:0-T-0,项目名称:TACTIC,代码行数:34,代码来源:asset_security.py

示例2: _test_time

# 需要导入模块: from pyasm.common import SPTDate [as 别名]
# 或者: from pyasm.common.SPTDate import now [as 别名]
    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')


        # test NOW() auto conversion
        sobj = SearchType.create('sthpw/note')
        sobj.set_value('process','TEST')
        sobj.set_value('note','123')
        my.assertEquals(sobj.get_value('timestamp'), "")
        sobj.commit()

        # this is local commited time converted back to GMT
        committed_time = sobj.get_value('timestamp')
        
        from dateutil import parser
        committed_time = parser.parse(committed_time)

        from pyasm.common import SPTDate
        now = SPTDate.now()
        diff = now - committed_time
        # should be roughly the same minute, not hours apart
        my.assertEquals(diff.seconds < 60, True)
开发者ID:0-T-0,项目名称:TACTIC,代码行数:50,代码来源:biz_test.py

示例3: test_time

# 需要导入模块: from pyasm.common import SPTDate [as 别名]
# 或者: from pyasm.common.SPTDate import now [as 别名]
def test_time():

    from pyasm.search import SearchType
    sobj = SearchType.create('sthpw/note')
    sobj.set_value('process','TEST')
    sobj.set_value('note','123')
    sobj.commit()


    sobj.set_value('note', 'new note')
    sobj.commit()

    # check change_timestamp
    change_t = Search.eval("@SOBJECT(sthpw/change_timestamp['search_type','sthpw/note']['search_code','%s'])"%sobj.get_code(), single=True)
    if change_t:
        change_t_timestamp = change_t.get('timestamp')
        change_t_timestamp = parser.parse(change_t_timestamp)

        from pyasm.common import SPTDate
        now = SPTDate.now()

        diff = now - change_t_timestamp
        # should be roughly the same minute, not hours apart
        print "Change timestamp diff is ", diff.seconds 
开发者ID:0-T-0,项目名称:TACTIC,代码行数:26,代码来源:dynamic_update_wdg.py

示例4: execute

# 需要导入模块: from pyasm.common import SPTDate [as 别名]
# 或者: from pyasm.common.SPTDate import now [as 别名]
    def execute(my):

        start = time.time()

        from pyasm.common import SPTDate
        timestamp = SPTDate.now()
        timestamp = SPTDate.add_gmt_timezone(timestamp)
        timestamp = SPTDate.convert_to_local(timestamp)
        format = '%Y-%m-%d %H:%M:%S'
        timestamp = timestamp.strftime(format)


        updates = my.kwargs.get("updates")
        if isinstance(updates, basestring):
            updates = jsonloads(updates)

        last_timestamp = my.kwargs.get("last_timestamp")
        #assert last_timestamp
        if not last_timestamp:
            my.info = {
                "updates": {},
                "timestamp": timestamp
            }
            return

        last_timestamp = parser.parse(last_timestamp)
        last_timestamp = SPTDate.add_gmt_timezone(last_timestamp)
        #last_timestamp = last_timestamp - timedelta(hours=24)


        #print "last: ", last_timestamp

        # get out all of the search_keys
        client_keys = set()
        for id, values_list in updates.items():
            if isinstance(values_list, dict):
                values_list = [values_list]

            for values in values_list:
                handler = values.get("handler")
                if handler:
                    handler = Common.create_from_class_path(handler)
                    search_key = handler.get_search_key()
                else:
                    search_key = values.get("search_key")

                if search_key:
                    client_keys.add(search_key)

        # find all of the search that have changed
        changed_keys = set()
        for check_type in ['sthpw/change_timestamp', 'sthpw/sobject_log']:
            search = Search(check_type)
            search.add_filter("timestamp", last_timestamp, op=">")
            search.add_filters("search_type", ["sthpw/sobject_log", "sthpw/status_log"], op="not in")
            #print search.get_statement()
            changed_sobjects = search.get_sobjects()
            for sobject in changed_sobjects:
                search_type = sobject.get_value("search_type")
                search_code = sobject.get_value("search_code")
                if search_type.startswith("sthpw/"):
                    search_key = "%s?code=%s" % (search_type, search_code)
                else:
                    search_key = "%s&code=%s" % (search_type, search_code)
                changed_keys.add(u'%s'%search_key)

        intersect_keys = client_keys.intersection(changed_keys)

        #for x in client_keys:
        #    print x
        #print "---"
        #print "changed_keys: ", changed_keys
        #print "---"
        #print "intersect_keys: ", intersect_keys


        from pyasm.web import HtmlElement

        results = {}
        for id, values_list in updates.items():

            if isinstance(values_list, dict):
                values_list = [values_list]


            for values in values_list:

                handler = values.get("handler")
                if handler:
                    handler = Common.create_from_class_path(handler)
                    search_key = handler.get_search_key()
                else:
                    search_key = values.get("search_key")

                if search_key and search_key not in intersect_keys:
                    continue

                # evaluate any compare expressions
                compare = values.get("compare")
                if compare:
#.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:TACTIC,代码行数:103,代码来源:dynamic_update_wdg.py

示例5: execute

# 需要导入模块: from pyasm.common import SPTDate [as 别名]
# 或者: from pyasm.common.SPTDate import now [as 别名]
    def execute(my):

        start = time.time()

        from pyasm.common import SPTDate
        timestamp = SPTDate.now()
        timestamp = SPTDate.add_gmt_timezone(timestamp)
        timestamp = SPTDate.convert_to_local(timestamp)
        format = '%Y-%m-%d %H:%M:%S'
        timestamp = timestamp.strftime(format)
        
        updates = my.kwargs.get("updates")
        if isinstance(updates, basestring):
            updates = jsonloads(updates)
        last_timestamp = my.kwargs.get("last_timestamp")
        #assert last_timestamp
        if not last_timestamp:
            my.info = {
                "updates": {},
                "timestamp": timestamp
            }
            return

        last_timestamp = parser.parse(last_timestamp)
        last_timestamp = SPTDate.add_gmt_timezone(last_timestamp)
        
        # give 2 seconds of extra room 
        last_timestamp = last_timestamp - timedelta(seconds=2)


        # get out all of the search_keys
        client_keys = set()
        client_stypes = set()
        for id, values_list in updates.items():
            if isinstance(values_list, dict):
                values_list = [values_list]

            for values in values_list:
                handler = values.get("handler")
                if handler:
                    handler = Common.create_from_class_path(handler)
                    # it could be a list
                    search_key = handler.get_search_key()
                else:
                    search_key = values.get("search_key")

                if search_key:
                    if isinstance(search_key, list):
                        search_key_set = set(search_key)
                    else:
                        search_key_set = set()
                        search_key_set.add(search_key)
                    client_keys.update(search_key_set)

                stype = values.get("search_type")
                if stype:
                    client_stypes.add(stype)

        # find all of the search that have changed
        changed_keys = set()
        changed_types = set()
        for check_type in ['sthpw/change_timestamp', 'sthpw/sobject_log']:
            search = Search(check_type)
            search.add_filter("timestamp", last_timestamp, op=">")
            search.add_filters("search_type", ["sthpw/sobject_log", "sthpw/status_log"], op="not in")
            changed_sobjects = search.get_sobjects()
            for sobject in changed_sobjects:
                search_type = sobject.get_value("search_type")
                search_code = sobject.get_value("search_code")
                if search_type.startswith("sthpw/"):
                    search_key = "%s?code=%s" % (search_type, search_code)
                else:
                    search_key = "%s&code=%s" % (search_type, search_code)
                changed_keys.add(u'%s'%search_key)
                changed_types.add(search_type)

        intersect_keys = client_keys.intersection(changed_keys)



        from pyasm.web import HtmlElement

        results = {}
        for id, values_list in updates.items():
            if isinstance(values_list, dict):
                values_list = [values_list]

            for values in values_list:

                handler = values.get("handler")
                if handler:
                    handler = Common.create_from_class_path(handler)
                    # handler can return a list of search_keys
                    search_key = handler.get_search_key()
                else:
                    search_key = values.get("search_key")

                stype = values.get("search_type")
                if search_key:
                    if isinstance(search_key, list):
#.........这里部分代码省略.........
开发者ID:0-T-0,项目名称:TACTIC,代码行数:103,代码来源:dynamic_update_wdg.py


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