Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorCyril Bonté <cyril.bonte@free.fr>2014-06-05 02:57:49 +0400
committerCyril Bonté <cyril.bonte@free.fr>2014-06-06 23:30:27 +0400
commit70f779acfcbdd71a2bbaaea4b92e1dbb5b9ef277 (patch)
tree8dd63a720bc44472665449804d79330a45b0abb5 /misc
parent09c0246bf57de23a4968cabef9c5f34f1d5dba67 (diff)
disable cache when OrderedDict is not available
Fallback to a non cached dates when OrderedDict is not available. It can occur with python < 2.7 and Pypi OrderedDict is not installed.
Diffstat (limited to 'misc')
-rwxr-xr-xmisc/log-analytics/import_logs.py32
1 files changed, 20 insertions, 12 deletions
diff --git a/misc/log-analytics/import_logs.py b/misc/log-analytics/import_logs.py
index 56347900b2..d43b5e56be 100755
--- a/misc/log-analytics/import_logs.py
+++ b/misc/log-analytics/import_logs.py
@@ -50,7 +50,10 @@ except ImportError:
try:
from collections import OrderedDict
except ImportError:
- from ordereddict import OrderedDict
+ try:
+ from ordereddict import OrderedDict
+ except ImportError:
+ print >> sys.stderr, 'ordereddict (https://pypi.python.org/pypi/ordereddict) is required to enable dates caching.'
##
@@ -1595,7 +1598,10 @@ class Parser(object):
resolver.check_format(format)
hits = []
- cache_dates = OrderedDict()
+ try:
+ cache_dates = OrderedDict()
+ except NameError:
+ cache_dates = None
for lineno, line in enumerate(file):
try:
line = line.decode(config.options.encoding)
@@ -1675,13 +1681,14 @@ class Parser(object):
# Parse date.
# We parse it after calling check_methods as it's quite CPU hungry, and
# we want to avoid that cost for excluded hits.
- # To mitigate CPU usage, parsed dates are cached.
- try:
- timezone_key = format.get('timezone')
- except BaseFormatException:
- timezone_key = ''
- date_key = format.get('date') + '|' + timezone_key
- hit.date = cache_dates.get(date_key)
+ if cache_dates is not None:
+ # To mitigate CPU usage, parsed dates are cached.
+ try:
+ timezone_key = format.get('timezone')
+ except BaseFormatException:
+ timezone_key = ''
+ date_key = format.get('date') + '|' + timezone_key
+ hit.date = cache_dates.get(date_key)
if not hit.date:
date_string = format.get('date')
try:
@@ -1702,9 +1709,10 @@ class Parser(object):
if timezone:
hit.date -= datetime.timedelta(hours=timezone/100)
- if len(cache_dates) > 3600:
- cache_dates.popitem(False)
- cache_dates[date_key] = hit.date
+ if cache_dates is not None:
+ if len(cache_dates) > 3600:
+ cache_dates.popitem(False)
+ cache_dates[date_key] = hit.date
if config.options.replay_tracking:
# we need a query string and we only consider requests with piwik.php