本文整理汇总了Python中aspen.log函数的典型用法代码示例。如果您正苦于以下问题:Python log函数的具体用法?Python log怎么用?Python log使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了log函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:joeyespo,项目名称:aspen-python,代码行数:34,代码来源:website.py
示例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())
开发者ID:HolaChica,项目名称:gratipay.com,代码行数:25,代码来源:cli.py
示例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
开发者ID:booo,项目名称:www.gittip.com,代码行数:33,代码来源:payday.py
示例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)
开发者ID:BigBlueHat,项目名称:aspen-python,代码行数:7,代码来源:server.py
示例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
开发者ID:BastianBerndsen,项目名称:www.gittip.com,代码行数:34,代码来源:openstreetmap.py
示例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()
开发者ID:justinabrahms,项目名称:www.gittip.com,代码行数:35,代码来源:payday.py
示例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.")
开发者ID:mwhite,项目名称:www.gittip.com,代码行数:28,代码来源:billing.py
示例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
开发者ID:nishanthvijayan,项目名称:gratipay.com,代码行数:25,代码来源:team.py
示例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()
开发者ID:mwhite,项目名称:www.gittip.com,代码行数:26,代码来源:billing.py
示例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)
开发者ID:augmen,项目名称:gratipay.com,代码行数:30,代码来源:exchanges.py
示例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())
开发者ID:Changaco,项目名称:liberapay.com,代码行数:26,代码来源:cli.py
示例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())
开发者ID:Aaron1011,项目名称:www.gittip.com,代码行数:33,代码来源:cli.py
示例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)
开发者ID:PeterDaveHello,项目名称:gratipay.com,代码行数:35,代码来源:exchanges.py
示例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.")
开发者ID:beerm,项目名称:gratipay.com,代码行数:60,代码来源:payday.py
示例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))
开发者ID:cyberjacob,项目名称:www.gittip.com,代码行数:28,代码来源:payday.py
示例16: update_balances
def update_balances(cursor):
participants = cursor.all("""
UPDATE participants p
SET balance = (balance + p2.new_balance - p2.old_balance)
FROM payday_participants p2
WHERE p.id = p2.id
AND p2.new_balance <> p2.old_balance
RETURNING p.id
, p.username
, balance AS new_balance
, ( SELECT balance
FROM participants p3
WHERE p3.id = p.id
) AS cur_balance;
""")
# Check that balances aren't becoming (more) negative
for p in participants:
if p.new_balance < 0 and p.new_balance < p.cur_balance:
log(p)
raise NegativeBalance()
cursor.run("""
INSERT INTO transfers (timestamp, tipper, tippee, amount, context)
SELECT * FROM payday_transfers;
""")
log("Updated the balances of %i participants." % len(participants))
开发者ID:beerm,项目名称:gratipay.com,代码行数:27,代码来源:payday.py
示例17: check_one
def check_one(filename):
"""Given a filename, return None or restart.
"""
# The file may have been removed from the filesystem.
# ===================================================
if not os.path.isfile(filename):
if filename in mtimes:
aspen.log("file deleted: %s" % filename)
restart()
else:
# We haven't seen the file before. It has probably been loaded
# from a zip (egg) archive.
return
# Or not, in which case, check the modification time.
# ===================================================
mtime = os.stat(filename).st_mtime
if filename not in mtimes: # first time we've seen it
mtimes[filename] = mtime
if mtime > mtimes[filename]:
aspen.log("file changed: %s" % filename)
restart()
开发者ID:jarpineh,项目名称:aspen,代码行数:26,代码来源:restarter.py
示例18: 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.
"""
self.db.self_check()
_start = aspen.utils.utcnow()
log("Greetings, program! It's PAYDAY!!!!")
if self.stage < 1:
self.payin()
self.mark_stage_done()
if self.stage < 2:
self.payout()
self.mark_stage_done()
if self.stage < 3:
self.update_stats()
self.update_cached_amounts()
self.mark_stage_done()
self.end()
_end = aspen.utils.utcnow()
_delta = _end - _start
fmt_past = "Script ran for %%(age)s (%s)." % _delta
log(aspen.utils.to_age(_start, fmt_past=fmt_past))
开发者ID:beerm,项目名称:gratipay.com,代码行数:30,代码来源:payday.py
示例19: 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.
"""
_start = aspen.utils.utcnow()
log("Greetings, program! It's PAYDAY!!!!")
ts_start = self.start()
self.zero_out_pending(ts_start)
self.payin(ts_start, self.genparticipants(ts_start, ts_start))
self.move_pending_to_balance_for_teams()
self.pachinko(ts_start, self.genparticipants(ts_start, ts_start))
self.clear_pending_to_balance()
self.payout(ts_start, self.genparticipants(ts_start, False))
self.end()
_end = aspen.utils.utcnow()
_delta = _end - _start
fmt_past = "Script ran for {age} (%s)." % _delta
# XXX For some reason newer versions of aspen use old string
# formatting, so if/when we upgrade this will break. Why do we do that
# in aspen, anyway?
log(aspen.utils.to_age(_start, fmt_past=fmt_past))
开发者ID:DylanLacey,项目名称:www.gittip.com,代码行数:30,代码来源:payday.py
示例20: run
def run(self, log_dir='', keep_log=False):
"""This is the starting point for payday.
It is structured such that it can be run again safely (with a
newly-instantiated Payday object) if it crashes.
"""
self.db.self_check()
_start = aspen.utils.utcnow()
log("Greetings, program! It's PAYDAY!!!!")
self.shuffle(log_dir)
self.update_stats()
self.update_cached_amounts()
self.end()
self.notify_participants()
if not keep_log:
os.unlink(self.transfers_filename)
_end = aspen.utils.utcnow()
_delta = _end - _start
fmt_past = "Script ran for %%(age)s (%s)." % _delta
log(aspen.utils.to_age(_start, fmt_past=fmt_past))
开发者ID:aandis,项目名称:liberapay.com,代码行数:27,代码来源:payday.py
注:本文中的aspen.log函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论