本文整理汇总了Python中utils.print_log函数的典型用法代码示例。如果您正苦于以下问题:Python print_log函数的具体用法?Python print_log怎么用?Python print_log使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print_log函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plog
def plog(msg, error_log):
log = []
for s in error_log:
log.append(' Line %s: Column %s: %s' % (s.line, s.column, s.message))
log = '\n'+'\n'.join(log)
#print_log('Schemas validity ERROR:', str(schema.error_log))
print_log(msg, log)
示例2: do_dispatch
def do_dispatch(self, session, request):
""" dispatch request to the relevant processor """
method = request['method']
params = request.get('params', [])
suffix = method.split('.')[-1]
if session is not None:
if suffix == 'subscribe':
session.subscribe_to_service(method, params)
prefix = request['method'].split('.')[0]
try:
p = self.processors[prefix]
except:
print_log("error: no processor for", prefix)
return
p.add_request(session, request)
if method in ['server.version']:
session.version = params[0]
try:
session.protocol_version = float(params[1])
except:
pass
示例3: run
def run(self):
print_log( ("SSL" if self.use_ssl else "TCP") + " server started on port %d"%self.port)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((self.host, self.port))
sock.listen(5)
while not self.shared.stopped():
#if self.use_ssl: print_log("SSL: socket listening")
try:
connection, address = sock.accept()
except:
traceback.print_exc(file=sys.stdout)
time.sleep(0.1)
continue
#if self.use_ssl: print_log("SSL: new session", address)
try:
session = TcpSession(self.dispatcher, connection, address, use_ssl=self.use_ssl, ssl_certfile=self.ssl_certfile, ssl_keyfile=self.ssl_keyfile)
except BaseException, e:
error = str(e)
print_log("cannot start TCP session", error, address)
connection.close()
time.sleep(0.1)
continue
client_req = TcpClientRequestor(self.dispatcher, session)
client_req.start()
responder = TcpClientResponder(session)
responder.start()
示例4: get
def get(self):
sharepoint = self.db.get("SELECT * FROM `options` WHERE `key` = 'share'")
type = self.arguments.get('type')
print type
share = self.db.get(
"SELECT `share_fb`,`share_tw`,`share_gg`,`like` FROM `user` WHERE `uid`=%s", self.current_user['uid'])
if (share['share_fb']==0 and type=="1") or (share['share_tw']==0 and type=="2") or (share['share_gg']==0 and type=="3"):
prize = int(sharepoint['values'])
self.db.execute(
"UPDATE `user` SET `points` = `points` + %s, \
`total_points` = `total_points` + %s , \
`share_points` = `share_points`+ %s "
"WHERE `scopeid` = %s" %(prize, prize, prize, self.arguments.get('scopeid')))
if type=="1":
self.db.execute(
"UPDATE `user` SET `share_fb` = 1 WHERE `uid`=%s", self.current_user['uid'])
elif type=="2":
self.db.execute(
"UPDATE `user` SET `share_tw` = 1 WHERE `uid`=%s", self.current_user['uid'])
elif type=="3":
self.db.execute(
"UPDATE `user` SET `share_gg` = 1 WHERE `uid`=%s", self.current_user['uid'])
order="分享紅利"
ad="分享紅利"
self.db.execute(
"INSERT INTO `callback_order`(`order`,`ad`,`user`,`platform`,`ad_source`,`points`,`appType`)"
"VALUES(%s,%s,%s,%s,%s,%s,1)", order,ad,self.current_user['uid'],3,2,prize)
self.db.execute(
"INSERT INTO `global_orders` (uid, points, last, type, note,appType)"
"VALUES (%s, %s, %s, %s, %s, 1)",
self.current_user['uid'], prize, self.current_user['points'], 2, ad)
elif (share['like']==0 and type=="4"):
likepoint = self.db.get("SELECT * FROM `options` WHERE `key` ='like'")
prize = int(likepoint['values'])
self.db.execute(
"UPDATE `user` SET `points` = `points` + %s, \
`total_points` = `total_points` + %s , \
`share_points` = `share_points`+ %s , \
`like` = '1'"
"WHERE `scopeid` = %s" %(prize, prize, prize, self.arguments.get('scopeid')))
order="fb點贊紅利"
ad="fb點贊紅利"
self.db.execute(
"INSERT INTO `callback_order`(`order`,`ad`,`user`,`platform`,`ad_source`,`points`,`appType`)"
"VALUES(%s,%s,%s,%s,%s,%s,1)", order,ad,self.current_user['uid'],3,11,prize)
self.db.execute(
"INSERT INTO `global_orders` (uid, points, last, type, note,appType)"
"VALUES (%s, %s, %s, %s, %s, 1)",
self.current_user['uid'], prize, self.current_user['points'], 11, ad)
else:
prize = 0
user_info=self.db.get(
"SELECT `points` from `user` WHERE `uid` = %s", self.current_user['uid'])
log_path = self.config['log']['fblike_log']
utils.print_log('fblike', log_path, self.request.uri+"uid="+str(self.current_user['uid'])+"points="+str(prize))
self.return_result({
"points":user_info['points'],
"bonus":prize,
})
示例5: process
def process(arg):
global not_deleted_list, update_time
curs = _connect.cursor()
res = curs.execute("SELECT BookId FROM libbook WHERE NOT (Deleted&1) and FileType = 'fb2' ")
not_deleted_list = curs.fetchall()
not_deleted_list = set([i[0] for i in not_deleted_list])
curs.execute('SELECT * FROM librusec')
update_time = curs.fetchone()[0]
for fn in walk(arg):
for ftype, z_filename, data in read_file(fn, zip_charset='utf-8'):
process_file(fn, ftype, z_filename, data)
if options.search_deleted:
deleted = set()
for fn in walk(options.search_deleted):
bookid = base_name(fn, '.fb2.zip')
try:
bookid = int(bookid)
except ValueError:
continue
if bookid in not_deleted_list:
deleted.append(fn)
for fn in deleted:
for ftype, z_filename, data in read_file(fn, zip_charset='utf-8'):
ret = process_file(fn, ftype, z_filename, data)
if ret:
print_log('restore deleted:', bookid)
print
print 'processed:', stats.total
print 'passed:', stats.passed
print 'fixed:', stats.fixed
print 'errors:', stats.errors
if options.not_found:
fd = open(options.not_found, 'w')
for bookid in not_deleted_list:
print >> fd, bookid
示例6: get_bookid
def get_bookid(filename, fb2):
global _connect
# search bookid in fb2
if options.search_id and fb2 is not None:
find = xpath('/m:FictionBook/m:description/m:custom-info')
bookid = None
for e in find(fb2):
bid = e.get('librusec-book-id')
if bid is not None:
try:
bookid = int(bid)
except:
pass
else:
return bookid
# search bookid by filename
try:
bookid = int(filename)
except ValueError:
curs = _connect.cursor()
curs.execute("SELECT BookId FROM libbookold WHERE FileName = ?",
(filename,))
res = curs.fetchone()
if res is None:
print_log('ERROR: file not found in db:', filename, level=3)
return None
return res[0]
return bookid
示例7: get
def get(self, platform):
log_path = self.config['log']['callback_log']
utils.print_log('callback', log_path, self.request.uri)
params = {}
if platform == 'youmiios':
self.platform = 1
params['sign'] = self.get_argument('sign','')
sign = self.check_sign_ios()
elif platform == 'youmiaos':
self.platform = 2
params['sign'] = self.get_argument('sig','')
sign = self.check_sign_aos()
else:
self.write('what the fuck?')
keys = ['order', 'ad', 'adid', 'user', 'points', \
'price', 'time', 'device']
for key in keys:
params[key] = self.get_argument(key, '')
if not params:
self.write('arguments is required')
return
if sign != params['sign']:
self.write('invalid sign')
return
self.save_order(**params)
self.write('ok')
示例8: do_dispatch
def do_dispatch(self, session, request):
""" dispatch request to the relevant processor """
method = request["method"]
params = request.get("params", [])
suffix = method.split(".")[-1]
if session is not None:
if suffix == "subscribe":
session.subscribe_to_service(method, params)
# store session and id locally
request["id"] = self.store_session_id(session, request["id"])
prefix = request["method"].split(".")[0]
try:
p = self.processors[prefix]
except:
print_log("error: no processor for", prefix)
return
p.add_request(request)
if method in ["server.version"]:
session.version = params[0]
try:
session.protocol_version = float(params[1])
except:
pass
示例9: get
def get(self):
signInfo = self.db.get(
"SELECT * FROM `user_sign` WHERE `uid` = %s",
self.current_user['uid'])
log_path = self.config['log']['signinfo_log']
day1 = self.db.get("SELECT * FROM `options` WHERE `key` = 'sign_prize1'")
day2 = self.db.get("SELECT * FROM `options` WHERE `key` = 'sign_prize2'")
day3 = self.db.get("SELECT * FROM `options` WHERE `key` = 'sign_prize3'")
day4 = self.db.get("SELECT * FROM `options` WHERE `key` = 'sign_prize4'")
day5 = self.db.get("SELECT * FROM `options` WHERE `key` = 'sign_prize5'")
day6 = self.db.get("SELECT * FROM `options` WHERE `key` = 'sign_prize6'")
sign_prize = 5
if signInfo:
times = signInfo['time']
#print (datetime.datetime.now().date()-(times+datetime.timedelta(hours=8)).date()).days
#print (datetime.datetime.now().date()-times.date()).days
if 0<=(datetime.datetime.now().date()-times.date()).days<=1:
#print times
#print "days"
int = (signInfo['day']+1)%6
#print str(int)+"int"
if int==2:
sign_prize=day2['values']
if int==3:
sign_prize=day3['values']
if int==4:
sign_prize=day4['values']
if int==5:
sign_prize=day5['values']
if int==6:
sign_prize=day6['values']
if int==0:
sign_prize=day6['values']
times = signInfo['time']-datetime.timedelta(hours=8)
else:
sign_prize=day1['values']
times =0
utils.print_log('signinfo', log_path, self.request.uri+"&lastSignTime:"+str(times)+"&user:"+str(self.current_user['uid'])+"&NextSignPoint:"+str(sign_prize))
#print str(times)+"times"
#timeArray = time.localtime(time.time())
#otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
#print time.time()
#print otherStyleTime
taskInfo = self.db.get("SELECT * FROM `global_orders` WHERE `type`=6 AND `uid`=%s \
AND DATE_SUB(CURDATE(), INTERVAL 5 DAY) <= date(record_time) LIMIT 1", self.current_user['uid'])
if taskInfo :
showInterstitial = 0
signable = True
else:
showInterstitial = 1
signable = False
self.return_result({
"sign_time":times,
"current_time":long(time.time()),
"reward_points":sign_prize,
"showInterstitial":showInterstitial,
"signable":signable,
#"user":self.current_user['uid'],
})
示例10: process
def process(self, session, request):
method = request['method']
params = request['params']
result = None
if method in ['server.stop', 'server.info', 'server.debug']:
try:
password = request['params'][0]
except:
password = None
if password != self.password:
self.push_response(session,
{'id': request['id'],
'result': None,
'error': 'incorrect password'})
return
if method == 'server.banner':
result = self.banner.replace('\\n', '\n')
elif method == 'server.peers.subscribe':
result = self.get_peers()
elif method == 'server.version':
result = VERSION
elif method == 'server.stop':
self.shared.stop()
result = 'stopping, please wait until all threads terminate.'
elif method == 'server.info':
result = map(lambda s: {"time": s.time,
"name": s.name,
"address": s.address,
"version": s.version,
"subscriptions": len(s.subscriptions)},
self.dispatcher.request_dispatcher.get_sessions())
elif method == 'server.debug':
try:
s = request['params'][1]
except:
s = None
if s:
from guppy import hpy
h = hpy()
bp = self.dispatcher.request_dispatcher.processors['blockchain']
try:
result = str(eval(s))
except:
result = "error"
else:
print_log("unknown method", method)
if result != '':
self.push_response(session, {'id': request['id'], 'result': result})
示例11: run
def run(self):
while not self.shared.stopped():
request, session = self.queue.get(10000000000)
try:
self.process(request, session)
except:
traceback.print_exc(file=sys.stdout)
print_log("processor terminating")
示例12: unknown_endtag
def unknown_endtag(self, name):
if name == 'fictionbook':
# sgmllib workaround
name = 'FictionBook'
if name not in self.NESTABLE_TAGS:
# unknown tag
print_log('unknown end tag:', name, level=2)
self.handle_data('</%s>' % name)
return
BeautifulSoup.BeautifulStoneSoup.unknown_endtag(self, name)
示例13: stop_session
def stop_session(fd):
try:
# unregister before we close s
poller.unregister(fd)
except:
print_log("unregister error", fd)
traceback.print_exc(file=sys.stdout)
session = self.fd_to_session.pop(fd)
# this will close the socket
session.stop()
示例14: run
def run(self):
ircname = self.getname()
while not self.processor.shared.stopped():
try:
s = socket.socket()
s.connect(("irc.freenode.net", 6667))
s.settimeout(300)
except:
s.close()
time.sleep(10)
continue
try:
s.send("USER electrum 0 * :" + self.host + " " + ircname + "\n")
s.send("NICK " + self.nick + "\n")
s.send("JOIN #electrum\n")
sf = s.makefile("r", 0)
t = 0
while not self.processor.shared.stopped():
line = sf.readline().rstrip("\r\n").split()
if not line:
continue
if line[0] == "PING":
s.send("PONG " + line[1] + "\n")
elif "353" in line: # answer to /names
k = line.index("353")
for item in line[k + 1 :]:
if item.startswith(self.prepend):
s.send("WHO %s\n" % item)
elif "352" in line: # answer to /who
# warning: this is a horrible hack which apparently works
k = line.index("352")
try:
ip = socket.gethostbyname(line[k + 4])
except:
print_log("gethostbyname error", line[k + 4])
continue
name = line[k + 6]
host = line[k + 9]
ports = line[k + 10 :]
self.peers[name] = (ip, host, ports)
if time.time() - t > 5 * 60:
self.processor.push_response({"method": "server.peers", "params": [self.get_peers()]})
s.send("NAMES #electrum\n")
t = time.time()
self.peers = {}
except:
traceback.print_exc(file=sys.stdout)
finally:
sf.close()
s.close()
print_log("quitting IRC")
示例15: nova_aggregate_add_host
def nova_aggregate_add_host(self, aggregate, host):
result = False
try:
add_result = self.nova.aggregates.add_host(aggregate, host)
print_log('Add host<%s> to aggregate<%s>, result : %s ' % (host, aggregate, add_result), logging.INFO)
result = True
except:
print_log('Exception when add host<%s> to aggregate<%s>, Exception : %s ' %
(host, aggregate, traceback.format_exc()), logging.ERROR)
return result