本文整理汇总了Python中uliweb.orm.do_函数的典型用法代码示例。如果您正苦于以下问题:Python do_函数的具体用法?Python do_怎么用?Python do_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了do_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_single_query
def process_single_query(self, name, need_list, param):
config = self.parse_param(name, param)
count = 0
query = select(config.columns, config.condition, from_obj=[config.table])
if need_list:
if config.order_by:
query = query.order_by(*config.order_by)
if config.group_by:
query = query.group_by(*config.group_by)
if config.total:
if DEBUG:
log.debug('Query Schema {} Count:'.format(config.name))
log.debug(query.count())
count = do_(query.count()).scalar()
if config.page > 0:
query = query.limit(config.limit).offset((config.page-1)*config.limit)
if DEBUG:
log.debug('Query Schema {}:'.format(config.name))
log.debug(query)
result = {'data': [dict(row) for row in do_(query)]}
if config.total:
result['total'] = count
else:
query = query.limit(1)
if DEBUG:
log.debug('Query Schema {}:'.format(config.name))
result = list(do_(query))
if result:
result = dict(result[0])
else:
result = {}
return result
示例2: scan_step_all_path
def scan_step_all_path():
from uliweb import settings
ScanPathes = get_model("scanpathes")
ScanPathes.remove()
allext = {}
root_dp = settings.SCAN.DIR
ScanPathes(path = ".",type = "d",).save()
count = 0
Begin()
IGNORE_DIRS_SET = set(settings.SCAN.DIR_IGNORE)
for root,dirs,files in os.walk(root_dp):
root_relp = os.path.relpath(root,root_dp)
if not isinstance(root_relp,unicode):
root_relp = root_relp.decode("utf8")
sys.stdout.write(".")
rp = ScanPathes.get(ScanPathes.c.path==root_relp)
if not rp:
print "\ncan not find in db so do not scan %s"%(root)
continue
ignore_dirs = []
for dn in dirs:
dp = os.path.join(root,dn)
if os.path.islink(dp):
print "\nignore link:%s"%(dp)
ignore_dirs.append(dn)
elif dn in IGNORE_DIRS_SET:
print "\nignore dir: %s"%(dp)
ignore_dirs.append(dn)
else:
relp = os.path.relpath(dp,root_dp)
do_(ScanPathes.table.insert().values(path = relp.decode("utf8"),type = "d",parent=rp.id))
for dn in ignore_dirs:
dirs.remove(dn)
l = root.split(os.sep)
for fn in files:
fp = os.path.join(root,fn)
if not os.path.islink(fp):
p,ext = os.path.splitext(fn)
relp = os.path.relpath(fp,root_dp)
do_(ScanPathes.table.insert().values(path = relp.decode("utf8"),type = "f",ext=ext,parent=rp.id))
if allext.has_key(ext):
allext[ext] += 1
else:
allext[ext] = 1
else:
print "\nignore link:%s"%(fp)
Commit()
Exts = get_model("exts")
Exts.remove()
for i,k in enumerate(allext):
Exts(ext = k,num = allext[k]).save()
print
示例3: load_table
def load_table(table, filename, con, delimiter=',', format=None, encoding='utf-8', delete=True):
import csv
from uliweb.utils.date import to_date, to_datetime
table = reflect_table(con, table.name)
if delete:
do_(table.delete())
if not os.path.exists(filename):
log.info("The table [%s] data is not existed." % table.name)
return
f = fin = open(filename, 'rb')
try:
first_line = f.readline()
fields = first_line[1:].strip().split()
n = 1
if format:
fin = csv.reader(f, delimiter=delimiter)
for line in fin:
try:
n += 1
if not format:
line = eval(line.strip())
record = dict(zip(fields, line))
params = {}
for c in table.c:
if c.name in record:
if not format:
params[c.name] = record[c.name]
else:
if record[c.name] == 'NULL':
params[c.name] = None
else:
if isinstance(c.type, String):
params[c.name] = unicode(record[c.name], encoding)
elif isinstance(c.type, Date):
params[c.name] = to_date(to_datetime(record[c.name]))
elif isinstance(c.type, DateTime):
params[c.name] = to_datetime(record[c.name])
else:
params[c.name] = record[c.name]
ins = table.insert().values(**params)
do_(ins)
except:
log.error('Error: Line %d' % n)
raise
finally:
f.close()
示例4: api_schema_perm_update
def api_schema_perm_update(self):
value = request.POST.get('value')
schema = request.POST.get('scheme')
permid = request.POST.get('permid')
selectedRoleList = _json.loads(value)
#----delete the origin role_perm_rel
RPRModel = get_model('Role_Perm_Rel')
do_(RPRModel.table.delete().where(and_(RPRModel.c.scheme == schema, RPRModel.c.permission == permid)))
#----batch add the role_perm_rel
for s in selectedRoleList:
roleid = s.split('_')[0]
RPRModel(role=roleid, permission=permid, scheme=schema).save()
return json({"status":"OK", "value":value})
示例5: _sync_parent
def _sync_parent(self, parent):
from sqlalchemy import select, func
from uliweb.orm import do_
M = functions.get_model('async_tasks')
sql = select([M.c.status, func.count('*')], M.c.parent_task==parent.task_id,
from_obj=[M.table]).group_by(M.c.status)
status = {}
for row in do_(sql):
status[row[0]] = row[1]
queued = status.get('0', 0)
success = status.get('1', 0)
started = status.get('2', 0)
error = status.get('E', 0)
failed = status.get('F', 0)
cancel = status.get('C', 0)
if started:
parent.status = '2'
elif failed:
parent.status = 'F'
elif error:
parent.status = 'E'
elif (queued and not filter(None, [success, started, error, failed, cancel])):
parent.status = '0'
elif (success and not filter(None, [queued, started, error, failed])):
parent.status = '1'
elif (cancel and not filter(None, [queued, success, started, error, failed])):
parent.status = 'C'
示例6: handle
def handle(self, options, global_options, *args):
engine = get_engine(options, global_options)
if args:
apps = args
else:
apps = self.get_apps(global_options)
tables = get_tables(global_options.apps_dir, apps, engine=options.engine,
settings_file=global_options.settings,
local_settings_file=global_options.local_settings)
for name, t in tables.items():
exist = engine.dialect.has_table(engine.connect(), name)
if not exist:
flag = 'NOT EXISTED'
else:
try:
result = list(do_(t.select().limit(1)))
flag = 'OK'
except Exception as e:
if options.traceback:
import traceback
traceback.print_exc()
flag = 'FAILED'
if global_options.verbose or flag!='OK':
print 'Validating [%s] %s...%s' % (options.engine, name, flag)
示例7: api_org_roles_load
def api_org_roles_load(self, org_id):
page = int(request.GET.get('iDisplayStart') or 0)
psize = int(request.GET.get('iDisplayLength') or 10)
RoleModel = get_model('role')
UserModel = get_model('user')
OrgRoleModel = get_model('orgrole')
UserGroupModel = get_model('usergroup')
totalRecords = OrgRoleModel.filter(OrgRoleModel.c.organization == org_id).count()
query = select([RoleModel.c.id.label('role_id'), RoleModel.c.name.label('role_name'), OrgRoleModel.c.organization, OrgRoleModel.c.id.label('orgrole_id')]).select_from(join(RoleModel.table, OrgRoleModel.table, RoleModel.c.id == OrgRoleModel.c.role)).where(OrgRoleModel.c.organization == org_id).offset(page).limit(psize)
result = do_(query)
ret = {}
def fetch_users(orgrole_id):
ret = []
userList = UserModel.filter(OrgRoleModel.users.join_filter(OrgRoleModel.c.id == orgrole_id))
for s in userList:
ret.append({s.id:s.username})
return ret
def fetch_usergroups(orgrole_id):
ret = []
userList = UserGroupModel.filter(OrgRoleModel.usergroups.join_filter(OrgRoleModel.c.id == orgrole_id))
for s in userList:
ret.append({s.id:s.name})
return ret
ret['aaData'] = [{'role_id':s['role_id'], 'role_name':s['role_name'], 'users':fetch_users(s.orgrole_id), 'usergroups':fetch_usergroups(s.orgrole_id), 'orgrole_id':s['orgrole_id']} for s in result]
ret['iTotalRecords'] = totalRecords
ret['iTotalDisplayRecords'] = totalRecords
return json(ret)
示例8: dump_table
def dump_table(table, filename, con, std=None, delimiter=',', format=None, encoding='utf-8', inspector=None):
from uliweb.utils.common import str_value
from StringIO import StringIO
import csv
if not std:
if isinstance(filename, (str, unicode)):
std = open(filename, 'w')
else:
std = filename
else:
std = sys.stdout
#add inspector table columns process, will not use model fields but database fields
if inspector:
meta = MetaData()
table = Table(table.name, meta)
inspector.reflecttable(table, None)
result = do_(table.select())
fields = [x.name for x in table.c]
if not format:
print >>std, '#' + ' '.join(fields)
elif format == 'txt':
print >>std, '#' + ','.join(fields)
for r in result:
if not format:
print >>std, r
elif format == 'txt':
buf = StringIO()
fw = csv.writer(buf, delimiter=delimiter)
fw.writerow([str_value(x, encoding=encoding) for x in r])
print >>std, buf.getvalue().rstrip()
else:
raise Exception, "Can't support the text format %s" % format
示例9: run
def run(self):
import datetime
from decimal import Decimal
row = self.queue.get()
if row == None:
self.is_exit = 'quit'
return
data = eval(row)
if self.bulk:
self.buf.append(data)
if len(self.buf) >= self.bulk:
do_(self.sql, args=self.buf)
self.buf = []
else:
do_(self.sql, args=[data])
self.total += 1
示例10: detail
def detail(self, schema_id):
OrgModel = get_model('rbacorg')
RoleModel = get_model('role')
PermModel = get_model('Permission')
RPRModel = get_model('Role_Perm_Rel')
query = select([self.model.c.id, self.model.c.name, self.model.c.gorg, self.model.c.description, OrgModel.c.name.label('org_name')]).select_from(join(self.model.table, OrgModel.table, self.model.c.gorg == OrgModel.c.id)).where(self.model.c.id == schema_id)
schemaList = do_(query)
return {'schemaid':schema_id, 'schema_obj':schemaList.fetchone()}
示例11: api_list
def api_list(self):
page = int(request.GET.get('iDisplayStart', 0))
psize = int(request.GET.get('iDisplayLength', 10))
totalRecords = self.model.count()
query = select([self.model.c.id, self.model.c.name, self.model.c.gorg, self.model.c.description]).select_from(self.model.table).order_by(self.model.c.id.desc()).offset((page)).limit(psize)
schemaList = do_(query)
ret = {}
ret['aaData'] = [{'id':s['id'], 'name':s['name'], 'description':s['description'], 'gorg':s['gorg']} for s in schemaList]
ret['iTotalRecords'] = totalRecords
ret['iTotalDisplayRecords'] = totalRecords
return json(ret)
示例12: decide_path
def decide_path(id):
path = get_path(id)
if path.type == 'f':
return path.crbits or 0,path.crindex_bits or 0
else:
#print "dir %d crtype ?"%(id)
crbits = 0x00
crindex_bits = 0x00
for p in get_children_pathes(id):
crbits_child,crindexbits_child = decide_path(p.id)
#print "\t",p.path
#print "\t%d|%d="%(crindex_bits,crindexbits_child),
crbits |= crbits_child
crindex_bits |= crindexbits_child
#print crindex_bits
crtype = crbits2crtype(crbits)
if (path.crtype!=crtype) or (path.crbits!=crbits) or (path.crindex_bits!=crindex_bits):
do_(ScanPathes.table.update().where(ScanPathes.c.id==path.id).values(crtype=crtype,crbits=crbits,crindex_bits=crindex_bits))
print "%s\t0x%04x\t0x%08x\t%s"%(crtype2csstag(crtype)[3:8],crbits,crindex_bits,path.path)
return crbits,crindex_bits
示例13: org_roles
def org_roles(self, org_id):
SchemaModel = get_model('rbacscheme')
#----check if the organization is a global organization
Org = self.model.get(org_id)
RoleModel = get_model('role')
RPRModel = get_model('Role_Perm_Rel')
if Org.rbacscheme:
query = select([self.model.c.id, self.model.c.name, self.model.c.rbacscheme, SchemaModel.c.id.label('schema_id'), SchemaModel.c.name.label('schema_name')]).select_from(join(self.model.table, SchemaModel.table, self.model.c.rbacscheme == SchemaModel.c.id)).where(self.model.c.id == org_id)
OrgObj = do_(query).fetchone()
query = select([distinct(RoleModel.c.id), RoleModel.c.name]).select_from(join(RoleModel.table, RPRModel.table, RoleModel.c.id == RPRModel.c.role)).where(RPRModel.c.scheme == OrgObj.rbacscheme)
else:
#----global organization
query = select([self.model.c.id, self.model.c.name, self.model.c.rbacscheme, SchemaModel.c.id.label('schema_id'), SchemaModel.c.name.label('schema_name')]).select_from(join(self.model.table, SchemaModel.table, self.model.c.id == SchemaModel.c.gorg)).where(self.model.c.id == org_id)
OrgObj = do_(query).fetchone()
query = select([distinct(RoleModel.c.id), RoleModel.c.name]).select_from(join(RoleModel.table, RPRModel.table, RoleModel.c.id == RPRModel.c.role)).where(RPRModel.c.scheme == OrgObj.schema_id)
#----need to filter the rols which belone to this schema
roleList = do_(query)
roleDict = {}
for s in roleList:
roleDict[s.id] = s.name
return {'orgid':org_id, 'orgname':OrgObj.name, 'schemaname':OrgObj.schema_name, 'schema':OrgObj.rbacscheme , 'schema_id':OrgObj.schema_id, 'roleDict':roleDict}
示例14: get_paragraph_comments_count
def get_paragraph_comments_count(self, cid):
"""
获得某个章节每个paragraph评论的数目
返回结果为:
{id1:count1, id2:count2,...}
"""
from uliweb.orm import do_
from sqlalchemy.sql import select, func, and_
query = select([func.count(1), self.model_comments.c.anchor],
and_(self.model_comments.c.chapter==int(cid),
self.model_comments.c.deleted==False)).group_by(self.model_comments.c.anchor)
d = {}
for row in do_(query):
d[row[1]] = row[0]
return json(d)
示例15: dump_table
def dump_table(table, filename, con, std=None, delimiter=',', format=None,
encoding='utf-8', inspector=None, engine_name=None):
from uliweb.utils.common import str_value
from StringIO import StringIO
import csv
b = time()
if not std:
if isinstance(filename, (str, unicode)):
std = open(filename, 'w')
else:
std = filename
else:
std = sys.stdout
#add inspector table columns process, will not use model fields but database fields
if inspector:
meta = MetaData()
table = Table(table.name, meta)
inspector.reflecttable(table, None)
result = do_(table.select(), engine_name)
fields = [x.name for x in table.c]
if not format:
print >>std, ' '.join(fields)
elif format == 'txt':
print >>std, ','.join(fields)
n = 0
if format == 'txt':
fw = csv.writer(std, delimiter=delimiter)
for r in result:
n += 1
if not format:
print >>std, r
elif format == 'txt':
fw.writerow([str_value(x, encoding=encoding, newline_escape=True) for x in r])
else:
raise Exception, "Can't support the text format %s" % format
return 'OK (%d/%lfs)' % (n, time()-b)