本文整理汇总了Python中aspen.log函数的典型用法代码示例。如果您正苦于以下问题:Python log函数的具体用法?Python log怎么用?Python log使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了log函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: log_result_of_request
def log_result_of_request(website, response, request):
"""Log access. With our own format (not Apache's).
"""
if website.logging_threshold > 0: # short-circuit
return
# What was the URL path translated to?
# ====================================
fs = getattr(request, 'fs', '')
if fs.startswith(website.www_root):
fs = fs[len(website.www_root):]
if fs:
fs = '.'+fs
else:
fs = '...' + fs[-21:]
msg = "%-24s %s" % (request.line.uri.path.raw, fs)
# Where was response raised from?
# ===============================
filename, linenum = response.whence_raised()
if filename is not None:
response = "%s (%s:%d)" % (response, filename, linenum)
else:
response = str(response)
# Log it.
# =======
aspen.log("%-36s %s" % (response, msg))
示例2: payday
def payday():
# Wire things up.
# ===============
env = wireup.env()
wireup.db(env)
wireup.billing(env)
# Lazily import the billing module.
# =================================
# This dodges a problem where db in billing is None if we import it from
# gratipay before calling wireup.billing.
from gratipay.billing.payday import Payday
try:
Payday.start().run()
except KeyboardInterrupt:
pass
except:
import aspen
import traceback
aspen.log(traceback.format_exc())
示例3: hit_balanced
def hit_balanced(self, participant_id, balanced_account_uri, amount):
"""We have a purported balanced_account_uri. Try to use it.
"""
typecheck( participant_id, unicode
, balanced_account_uri, unicode
, amount, Decimal
)
try_charge_amount = (amount + FEE[0]) * FEE[1]
try_charge_amount = try_charge_amount.quantize( FEE[0]
, rounding=ROUND_UP
)
charge_amount = try_charge_amount
also_log = ''
if charge_amount < MINIMUM:
charge_amount = MINIMUM # per Balanced
also_log = ', rounded up to $%s' % charge_amount
fee = try_charge_amount - amount
cents = int(charge_amount * 100)
msg = "Charging %s %d cents ($%s + $%s fee = $%s%s) ... "
msg %= participant_id, cents, amount, fee, try_charge_amount, also_log
try:
customer = balanced.Account.find(balanced_account_uri)
customer.debit(cents, description=participant_id)
log(msg + "succeeded.")
except balanced.exc.HTTPError as err:
log(msg + "failed: %s" % err.message)
return charge_amount, fee, err.message
return charge_amount, fee, None
示例4: install_restarter_for_website
def install_restarter_for_website(website):
"""
"""
if website.changes_reload:
aspen.log("Aspen will restart when configuration scripts or "
"Python modules change.")
execution.install(website)
示例5: get_user_info
def get_user_info(db, username, osm_api_url):
"""Get the given user's information from the DB or failing that, openstreetmap.
:param username:
A unicode string representing a username in OpenStreetMap.
:param osm_api_url:
URL of OpenStreetMap API.
:returns:
A dictionary containing OpenStreetMap specific information for the user.
"""
typecheck(username, (unicode, PathPart))
rec = db.one("""
SELECT user_info FROM elsewhere
WHERE platform='openstreetmap'
AND user_info->'username' = %s
""", (username,))
if rec is not None:
user_info = rec
else:
osm_user = requests.get("%s/user/%s" % (osm_api_url, username))
if osm_user.status_code == 200:
log("User %s found in OpenStreetMap but not in gittip." % username)
user_info = None
elif osm_user.status_code == 404:
raise Response(404,
"OpenStreetMap identity '{0}' not found.".format(username))
else:
log("OpenStreetMap api responded with {0}: {1}".format(status, content),
level=logging.WARNING)
raise Response(502, "OpenStreetMap lookup failed with %d." % status)
return user_info
示例6: run
def run(self):
"""This is the starting point for payday.
This method runs every Thursday. It is structured such that it can be
run again safely (with a newly-instantiated Payday object) if it
crashes.
"""
log("Greetings, program! It's PAYDAY!!!!")
ts_start = self.start()
self.zero_out_pending()
def genparticipants(ts_start):
"""Closure generator to yield participants with tips and total.
We re-fetch participants each time, because the second time through
we want to use the total obligations they have for next week, and
if we pass a non-False ts_start to get_tips_and_total then we only
get unfulfilled tips from prior to that timestamp, which is none of
them by definition.
"""
for participant in self.get_participants():
tips, total = get_tips_and_total( participant['id']
, for_payday=ts_start
, db=self.db
)
typecheck(total, Decimal)
yield(participant, tips, total)
self.payin(ts_start, genparticipants(ts_start))
self.clear_pending_to_balance()
self.payout(ts_start, genparticipants(False))
self.end()
示例7: finish_payday
def finish_payday():
# Finish Payday.
# ==============
# Transfer pending into balance for all users, setting pending to NULL.
# Close out the paydays entry as well.
with db.get_connection() as conn:
cursor = conn.cursor()
cursor.execute("""\
UPDATE participants
SET balance = (balance + pending)
, pending = NULL
""")
cursor.execute("""\
UPDATE paydays
SET ts_end=now()
WHERE ts_end='1970-01-01T00:00:00+00'::timestamptz
RETURNING id
""")
assert_one_payday(cursor.fetchone())
conn.commit()
log("Finished payday.")
示例8: create_github_review_issue
def create_github_review_issue(self):
"""POST to GitHub, and return the URL of the new issue.
"""
api_url = "https://api.github.com/repos/{}/issues".format(self.review_repo)
data = json.dumps(
{
"title": self.name,
"body": "https://gratipay.com/{}/\n\n".format(self.slug)
+ "(This application will remain open for at least a week.)",
}
)
out = ""
try:
r = requests.post(api_url, auth=self.review_auth, data=data)
if r.status_code == 201:
out = r.json()["html_url"]
else:
log(r.status_code)
log(r.text)
err = str(r.status_code)
except:
err = "eep"
if not out:
out = "https://github.com/gratipay/team-review/issues#error-{}".format(err)
return out
示例9: payday
def payday():
"""This is the big one.
Settling the graph of Gittip balances is an abstract event called Payday.
On Payday, we want to use a participant's Gittip balance to settle their
tips due (pulling in more money via credit card as needed), but we only
want to use their balance at the start of Payday. Balance changes should be
atomic globally per-Payday.
This function runs every Friday. It is structured such that it can be run
again safely if it crashes.
"""
log("Greetings, program! It's PAYDAY!!!!")
participants, payday_start = initialize_payday()
# Drop to core.
# =============
# We are now locked for Payday. If the power goes out at this point then we
# will need to start over and reacquire the lock.
payday_loop(payday_start, participants)
finish_payday()
示例10: capture_card_hold
def capture_card_hold(db, participant, amount, hold):
"""Capture the previously created hold on the participant's credit card.
"""
typecheck( hold, balanced.CardHold
, amount, Decimal
)
username = participant.username
assert participant.id == int(hold.meta['participant_id'])
route = ExchangeRoute.from_address(participant, 'balanced-cc', hold.card_href)
assert isinstance(route, ExchangeRoute)
cents, amount_str, charge_amount, fee = _prep_hit(amount)
amount = charge_amount - fee # account for possible rounding
e_id = record_exchange(db, route, amount, fee, participant, 'pre')
meta = dict(participant_id=participant.id, exchange_id=e_id)
try:
hold.capture(amount=cents, description=username, meta=meta)
record_exchange_result(db, e_id, 'succeeded', None, participant)
except Exception as e:
error = repr_exception(e)
record_exchange_result(db, e_id, 'failed', error, participant)
raise
hold.meta['state'] = 'captured'
hold.save()
log("Captured " + amount_str + " on Balanced for " + username)
示例11: payday
def payday():
# Wire things up.
# ===============
env = wireup.env()
db = wireup.db(env)
wireup.billing(env)
# Lazily import the billing module.
# =================================
from liberapay.billing.exchanges import sync_with_mangopay
from liberapay.billing.payday import Payday
try:
sync_with_mangopay(db)
Payday.start().run()
except KeyboardInterrupt:
pass
except:
import aspen
import traceback
aspen.log(traceback.format_exc())
示例12: payday
def payday():
# Wire things up.
# ===============
# Manually override max db connections so that we only have one connection.
# Our db access is serialized right now anyway, and with only one
# connection it's easier to trust changes to statement_timeout. The point
# here is that we want to turn off statement_timeout for payday.
env = wireup.env()
env.database_maxconn = 1
db = wireup.db(env)
db.run("SET statement_timeout = 0")
wireup.billing(env)
wireup.nanswers(env)
# Lazily import the billing module.
# =================================
# This dodges a problem where db in billing is None if we import it from
# gittip before calling wireup.billing.
from gittip.billing.payday import Payday
try:
Payday(db).run()
except KeyboardInterrupt:
pass
except:
import aspen
import traceback
aspen.log(traceback.format_exc())
示例13: capture_card_hold
def capture_card_hold(db, participant, amount, hold):
"""Capture the previously created hold on the participant's credit card.
"""
typecheck( hold, braintree.Transaction
, amount, Decimal
)
username = participant.username
assert participant.id == int(hold.custom_fields['participant_id'])
route = ExchangeRoute.from_address(participant, 'braintree-cc', hold.credit_card['token'])
assert isinstance(route, ExchangeRoute)
cents, amount_str, charge_amount, fee = _prep_hit(amount)
amount = charge_amount - fee # account for possible rounding
e_id = record_exchange(db, route, amount, fee, participant, 'pre')
# TODO: Find a way to link transactions and corresponding exchanges
# meta = dict(participant_id=participant.id, exchange_id=e_id)
error = ''
try:
result = braintree.Transaction.submit_for_settlement(hold.id, str(cents/100.00))
assert result.is_success
if result.transaction.status != 'submitted_for_settlement':
error = result.transaction.status
except Exception as e:
error = repr_exception(e)
if error == '':
record_exchange_result(db, e_id, 'succeeded', None, participant)
log("Captured " + amount_str + " on Braintree for " + username)
else:
record_exchange_result(db, e_id, 'failed', error, participant)
raise Exception(error)
示例14: update_stats
def update_stats(self):
self.db.run("""\
WITH our_transfers AS (
SELECT *
FROM transfers
WHERE "timestamp" >= %(ts_start)s
)
, our_tips AS (
SELECT *
FROM our_transfers
WHERE context = 'tip'
)
, our_pachinkos AS (
SELECT *
FROM our_transfers
WHERE context = 'take'
)
, our_exchanges AS (
SELECT *
FROM exchanges
WHERE "timestamp" >= %(ts_start)s
)
, our_achs AS (
SELECT *
FROM our_exchanges
WHERE amount < 0
)
, our_charges AS (
SELECT *
FROM our_exchanges
WHERE amount > 0
)
UPDATE paydays
SET nactive = (
SELECT DISTINCT count(*) FROM (
SELECT tipper FROM our_transfers
UNION
SELECT tippee FROM our_transfers
) AS foo
)
, ntippers = (SELECT count(DISTINCT tipper) FROM our_transfers)
, ntips = (SELECT count(*) FROM our_tips)
, npachinko = (SELECT count(*) FROM our_pachinkos)
, pachinko_volume = (SELECT COALESCE(sum(amount), 0) FROM our_pachinkos)
, ntransfers = (SELECT count(*) FROM our_transfers)
, transfer_volume = (SELECT COALESCE(sum(amount), 0) FROM our_transfers)
, nachs = (SELECT count(*) FROM our_achs)
, ach_volume = (SELECT COALESCE(sum(amount), 0) FROM our_achs)
, ach_fees_volume = (SELECT COALESCE(sum(fee), 0) FROM our_achs)
, ncharges = (SELECT count(*) FROM our_charges)
, charge_volume = (
SELECT COALESCE(sum(amount + fee), 0)
FROM our_charges
)
, charge_fees_volume = (SELECT COALESCE(sum(fee), 0) FROM our_charges)
WHERE ts_end='1970-01-01T00:00:00+00'::timestamptz
""", {'ts_start': self.ts_start})
log("Updated payday stats.")
示例15: process_takes
def process_takes(cursor, ts_start):
log("Processing takes.")
cursor.run("""
UPDATE payday_teams SET available_today = LEAST(available, balance);
INSERT INTO payday_takes
SELECT team_id, participant_id, amount
FROM ( SELECT DISTINCT ON (team_id, participant_id)
team_id, participant_id, amount, ctime
FROM takes
WHERE mtime < %(ts_start)s
ORDER BY team_id, participant_id, mtime DESC
) t
WHERE t.amount > 0
AND t.team_id IN (SELECT id FROM payday_teams)
AND t.participant_id IN (SELECT id FROM payday_participants)
AND ( SELECT ppd.id
FROM payday_payments_done ppd
JOIN participants ON participants.id = t.participant_id
JOIN teams ON teams.id = t.team_id
WHERE participants.username = ppd.participant
AND teams.slug = ppd.team
AND direction = 'to-participant'
) IS NULL
ORDER BY t.team_id, t.amount ASC;
""", dict(ts_start=ts_start))