From 46fc259cdf3923f473130519e25c240836170df9 Mon Sep 17 00:00:00 2001
From: Cyril Bay <cbay@excellency.fr>
Date: Fri, 6 Apr 2012 13:35:54 +0000
Subject: [PATCH] Refs #703 Added --exclude-path and --exclude-path-from.

git-svn-id: http://dev.piwik.org/svn/trunk@6167 59fd770c-687e-43c8-a1e3-f5a4ff64c105
---
 misc/log-analytics/import_logs.py | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/misc/log-analytics/import_logs.py b/misc/log-analytics/import_logs.py
index 8d4cc8f3b9..b35d0becad 100755
--- a/misc/log-analytics/import_logs.py
+++ b/misc/log-analytics/import_logs.py
@@ -213,6 +213,14 @@ class Configuration(object):
             help="Accepted hostname (requests with other hostnames will be excluded). "
 	         "Can be specified multiple times"
         )
+        option_parser.add_option(
+            '--exclude-path', dest='excluded_paths', action='append', default=[],
+            help="Paths to exclude. Can be specified multiple times"
+        )
+        option_parser.add_option(
+            '--exclude-path-from', dest='exclude_path_from',
+            help="Each line from this file is a path to exclude"
+        )
         option_parser.add_option(
             '--useragent-exclude', dest='excluded_useragents',
             action='append', default=[],
@@ -297,8 +305,14 @@ class Configuration(object):
 
         self.options.excluded_useragents = [s.lower() for s in self.options.excluded_useragents]
 
+        if self.options.exclude_path_from:
+            paths = [path.strip() for path in open(self.options.exclude_path_from).readlines()]
+            self.options.excluded_paths.extend(path for path in paths if len(path) > 0)
+        if self.options.excluded_paths:
+            logging.debug('Excluded paths: %s', ' '.join(self.options.excluded_paths))
+
         if self.options.hostnames:
-            logging.debug('Accepted hostnames: %s', ', '.join(options.hostnames))
+            logging.debug('Accepted hostnames: %s', ', '.join(self.options.hostnames))
         else:
             logging.debug('Accepted hostnames: all')
 
@@ -1009,6 +1023,12 @@ class Parser(object):
                 return False
         return True
 
+    def check_path(self, hit):
+        for excluded_path in config.options.excluded_paths:
+            if fnmatch.fnmatch(hit.path, excluded_path):
+                return False
+        return True
+
 
     @staticmethod
     def detect_format(line):
-- 
GitLab