2013-04-23 18:51:17 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2013-04-11 20:06:03 +02:00
|
|
|
from django.conf import settings
|
2013-04-01 21:57:48 +02:00
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
|
|
|
|
def update_stat(name, value):
|
|
|
|
try:
|
2013-04-11 20:06:03 +02:00
|
|
|
os.mkdir(settings.STATS_DIR)
|
2013-04-01 21:57:48 +02:00
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
2013-04-11 20:06:03 +02:00
|
|
|
base_filename = os.path.join(settings.STATS_DIR, name)
|
2013-04-01 21:57:48 +02:00
|
|
|
tmp_filename = base_filename + ".new"
|
|
|
|
|
|
|
|
try:
|
|
|
|
with file(tmp_filename, "w") as stat_file:
|
|
|
|
stat_file.write("%s\n" % (str(value),))
|
|
|
|
|
|
|
|
os.rename(tmp_filename, base_filename)
|
|
|
|
except (OSError, IOError) as e:
|
|
|
|
logging.info("Could not update statistic '%s': %s" % (name, e))
|