本文整理汇总了Python中pyasm.search.Search.get_statement方法的典型用法代码示例。如果您正苦于以下问题:Python Search.get_statement方法的具体用法?Python Search.get_statement怎么用?Python Search.get_statement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasm.search.Search
的用法示例。
在下文中一共展示了Search.get_statement方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_connections
# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import get_statement [as 别名]
def get_connections(cls, sobjects, direction="dst", context='', context_filters=[], src_search=None):
'''return a Search instance if src_search is provided'''
if not sobjects and not src_search:
return []
search = Search(SObjectConnection)
if direction == "dst":
prefix = "src"
else:
prefix = "dst"
if src_search:
search.add_filter("%s_search_type" % prefix, src_search.get_search_type() )
search.add_search_filter('%s_search_id'%prefix, src_search, op="in")
else:
search_types = [x.get_search_type() for x in sobjects]
search_ids = [x.get_id() for x in sobjects]
if len(Common.get_unique_list(search_types)) == 1:
search.add_filter("%s_search_type" % prefix, search_types[0] )
search.add_filters("%s_search_id" % prefix, search_ids)
else:
search.add_op("begin")
for search_type, search_id in zip(search_types, search_ids):
search.add_op("begin")
search.add_filter("%s_search_type" % prefix, search_type )
search.add_filter("%s_search_id" % prefix, search_id )
search.add_op("and")
search.add_op("or")
if context:
search.add_filter("context", context)
elif context_filters:
search.add_op_filters(context_filters)
if src_search:
return search
# cache for connection sobjects
key = search.get_statement()
cache = Container.get("SObjectConnection:cache")
if cache == None:
cache = {}
Container.put("SObjectConnection:cache", cache)
ret_val = cache.get(key)
if ret_val != None:
return ret_val
connections = search.get_sobjects()
return connections
示例2: get_connections
# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import get_statement [as 别名]
def get_connections(cls, sobjects, direction="dst", context='', context_filters=[]):
if not sobjects:
return []
search_types = [x.get_search_type() for x in sobjects]
search_ids = [x.get_id() for x in sobjects]
if direction == "dst":
prefix = "src"
else:
prefix = "dst"
search = Search(SObjectConnection)
search.add_op("begin")
for search_type, search_id in zip(search_types, search_ids):
search.add_op("begin")
search.add_filter("%s_search_type" % prefix, search_type )
search.add_filter("%s_search_id" % prefix, search_id )
search.add_op("and")
search.add_op("or")
if context:
search.add_filter("context", context)
elif context_filters:
search.add_op_filters(context_filters)
key = search.get_statement()
cache = Container.get("SObjectConnection:cache")
if cache == None:
cache = {}
Container.put("SObjectConnection:cache", cache)
ret_val = cache.get(key)
if ret_val != None:
return ret_val
connections = search.get_sobjects()
return connections
示例3: handle_search
# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import get_statement [as 别名]
def handle_search(my):
# this is an absolute expression
my.search_expr = my.kwargs.get("search_expr")
my.search_type = my.kwargs.get("search_type")
if not my.search_type:
my.search_type = 'sthpw/task'
if my.search_expr:
search = Search.eval(my.search_expr)
else:
my.op_filters = my.kwargs.get("filters")
if my.op_filters:
if isinstance(my.op_filters, basestring):
my.op_filters = eval(my.op_filters)
search = Search(my.search_type)
if my.op_filters:
search.add_op_filters(my.op_filters)
my.start_column = my.kwargs.get('start_date_col')
if not my.start_column:
my.start_column = 'bid_start_date'
my.end_column = my.kwargs.get('end_date_col')
if not my.end_column:
my.end_column = 'bid_end_date'
search.add_op('begin')
if my.handler:
my.handler.alter_search(search)
search.add_op('or')
my.start_date = datetime(my.year, my.month, 1)
next_month = my.month+1
next_year = my.year
if next_month > 12:
next_month = 1
next_year += 1
my.end_date = datetime(next_year, next_month, 1)
my.end_date = my.end_date - timedelta(days=1)
# outer begin
search.add_op('begin')
search.add_op('begin')
search.add_date_range_filter(my.start_column, my.start_date, my.end_date)
search.add_date_range_filter(my.end_column, my.start_date, my.end_date)
search.add_op('or')
search.add_op('begin')
search.add_filter(my.start_column, my.start_date, op='<=')
search.add_filter(my.end_column, my.end_date, op='>=')
search.add_op('and')
search.add_op('or')
search.add_order_by(my.start_column)
print "search: ", search.get_statement()
my.sobjects = search.get_sobjects()
示例4: get_transaction_info
# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import get_statement [as 别名]
def get_transaction_info(my):
remote_server = my.get_remote_server()
search_keys = my.kwargs.get("search_keys")
project_code = my.kwargs.get("project_code")
if not project_code:
project_code = Project.get_project_code()
print "search_keys: ", search_keys
if search_keys:
search_keys_str = "|".join(search_keys)
# need to get the code from the search_keys
codes = []
for search_key in search_keys:
# HACK
parts = search_key.split("code=")
code = parts[1]
codes.append(code)
codes_str = "|".join(codes)
filters = [
['code','in',codes_str]
]
remote_codes = remote_server.query("sthpw/transaction_log", filters=filters, columns=['code'], order_bys=['timestamp'])
elif my.start_expr:
start_date = my.get_date(my.start_expr)
# FIXME: this only works with Postgres
filters = [
['timestamp', '>', str(start_date)],
]
if project_code:
filters.append( ['namespace', project_code] )
remote_codes = remote_server.query("sthpw/transaction_log", filters=filters, columns=['code'], order_bys=['timestamp'])
else:
raise TacticException("No start date expression given")
print "# remote codes: ", len(remote_codes)
# get all of the local transactions with the same filters
search = Search("sthpw/transaction_log")
search.add_column("code")
search.add_filter("namespace", project_code)
search.add_op_filters(filters)
search.add_order_by("timestamp")
print "search: ", search.get_statement()
local_codes = search.get_sobjects()
print "local codes: ", local_codes
lset = set()
for lt in local_codes:
lcode = lt.get_value("code")
if not lcode:
continue
lset.add(lcode)
rset = set()
for rt in remote_codes:
rcode = rt.get("code")
if not rcode:
continue
rset.add(rcode)
info = {}
remote_diff = rset.difference(lset)
local_diff = lset.difference(rset)
# go get the missing remote transactions
filters = [['code', 'in', "|".join(remote_diff)]]
remote_transactions = remote_server.query("sthpw/transaction_log", filters=filters, order_bys=['timestamp'])
for i, transaction in enumerate(remote_transactions):
sobject = SearchType.create("sthpw/transaction_log")
sobject.data = transaction
remote_transactions[i] = sobject
info['remote_transactions'] = remote_transactions
search = Search("sthpw/transaction_log")
search.add_filters("code", local_diff)
search.add_order_by("timestamp")
local_transactions = search.get_sobjects()
info['local_transactions'] = local_transactions
local_paths = []
for transaction in local_transactions:
paths = my.get_file_paths(transaction)
if not paths:
#.........这里部分代码省略.........
示例5: get_connected_sobjects
# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import get_statement [as 别名]
def get_connected_sobjects(cls, sobject, direction="dst", order_by=None, context='', filters=None):
'''get the sobjects that are connect to this sobject.'''
search_type = sobject.get_search_type()
search_id = sobject.get_id()
if direction == "dst":
prefixA = "dst"
prefixB = "src"
else:
prefixA = "src"
prefixB = "dst"
search = Search(SObjectConnection)
search.add_filter("%s_search_type" % prefixA, search_type )
search.add_filter("%s_search_id" % prefixA, search_id )
if context:
search.add_filter("context", context)
if order_by:
search.add_order_by(order_by)
key = search.get_statement()
cache = Container.get("SObjectConnection:cache")
if cache == None:
cache = {}
Container.put("SObjectConnection:cache", cache)
ret_val = cache.get(key)
if ret_val != None:
return ret_val
connections = search.get_sobjects()
src_sobjects = []
for connection in connections:
src_search_type = connection.get_value("%s_search_type" % prefixB)
src_search_id = connection.get_value("%s_search_id" % prefixB)
# TODO: this could be made faster because often, these will be
# of the same stype
if not filters:
src = Search.get_by_id(src_search_type, src_search_id)
else:
src_search = Search(src_search_type)
src_search.add_filter("id", src_search_id)
src_search.add_op_filters(filters)
src = src_search.get_sobject()
#if not src.is_retired():
# don't check for retired here. check it at the caller for
# css manipulation
if src:
src_sobjects.append(src)
else:
print "WARNING: connection sobject does not exist .. deleting"
connection.delete()
cache[key] = connections, src_sobjects
return connections, src_sobjects
示例6: get_connected_sobjects
# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import get_statement [as 别名]
def get_connected_sobjects(cls, sobjects, direction="dst", order_by=None, context='', filters=None):
'''get the sobjects that are connect to this sobject.'''
unique_stype = False
single_sobject = False
src_search_types = []
src_search_ids = []
if not sobjects:
return [], []
if isinstance(sobjects, list):
search_types = [x.get_search_type() for x in sobjects]
search_ids = [x.get_id() for x in sobjects]
if len(Common.get_unique_list(search_types)) == 1:
unique_stype = True
else:
search_types = [sobjects.get_search_type()]
search_ids = [sobjects.get_id()]
unique_stype = True
single_sobject = True
if direction == "dst":
prefixA = "dst"
prefixB = "src"
else:
prefixA = "src"
prefixB = "dst"
connections = []
if unique_stype:
search = Search(SObjectConnection)
search.add_filter("%s_search_type" % prefixA, search_types[0] )
search.add_filters("%s_search_id" % prefixA, search_ids )
if context:
search.add_filter("context", context)
if order_by:
search.add_order_by(order_by)
key = search.get_statement()
cache = Container.get("SObjectConnection:cache")
if cache == None:
cache = {}
Container.put("SObjectConnection:cache", cache)
ret_val = cache.get(key)
if ret_val != None:
return ret_val
connections = search.get_sobjects()
"""
new_search = Search(src_search_types[0])
select = new_search.get_select()
from_table = new_search.get_table()
to_table = 'connection'
from_col = 'id'
to_col = 'src_search_id'
select.add_join(from_table, to_table, from_col, to_col, join='INNER', database2='sthpw')
"""
else:
raise TacticException('Only unique stypes are supported for the passed in sobjects')
src_sobjects = []
src_stype = None
src_stypes = SObject.get_values(connections, "%s_search_type" % prefixB, unique=True)
src_ids = SObject.get_values(connections, "%s_search_id" % prefixB, unique=True)
if len(src_stypes) == 1:
src_stype = src_stypes[0]
if src_stype:
single_src_ids = len(src_ids) == 1
if not filters and single_src_ids:
src = Search.get_by_id(src_stype, src_ids[0])
src_sobjects.append(src)
else:
new_search = Search(src_stype)
if single_src_ids:
new_search.add_filter('id', src_ids[0])
else:
new_search.add_filters('id', src_ids)
if filters:
new_search.add_op_filters(filters)
src_sobjects = new_search.get_sobjects()
else:
for connection in connections:
src_search_type = connection.get_value("%s_search_type" % prefixB)
src_search_id = connection.get_value("%s_search_id" % prefixB)
# TODO: this could be made faster because often, these will be
# of the same stype
#.........这里部分代码省略.........