Ejegg has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/373924 )

Change subject: Update option parsing for Django 1.10+
......................................................................

Update option parsing for Django 1.10+

Django now uses standard argparse, see
https://docs.djangoproject.com/en/1.11/howto/custom-management-commands/

Preserve back-compat by wrapping the old code in a hasattr check

Change-Id: I9ab1ea04c1bab9805a5ca10d25e2675e5561036b
---
M fundraiser/analytics/management/commands/AggregateBannerImpressions.py
M fundraiser/analytics/management/commands/LoadBannerImpressions.py
M fundraiser/analytics/management/commands/LoadBannerImpressions2Aggregate.py
M fundraiser/analytics/management/commands/LoadLPImpressions.py
4 files changed, 263 insertions(+), 111 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/tools/DjangoBannerStats 
refs/changes/24/373924/1

diff --git 
a/fundraiser/analytics/management/commands/AggregateBannerImpressions.py 
b/fundraiser/analytics/management/commands/AggregateBannerImpressions.py
index c05459d..b5f71be 100644
--- a/fundraiser/analytics/management/commands/AggregateBannerImpressions.py
+++ b/fundraiser/analytics/management/commands/AggregateBannerImpressions.py
@@ -15,38 +15,41 @@
 
     logger = logging.getLogger("fundraiser.analytics.load_banners")
 
-    option_list = BaseCommand.option_list + (
-        make_option('', '--verbose',
-            dest='verbose',
-            action='store_true',
-            default=False,
-            help='Provides more verbose output.'),
-        make_option('', '--debug',
-            dest='debug',
-            action='store_true',
-            default=False,
-            help='Do not save. Parse only.'),
-        make_option('', '--newest',
-            dest='newest',
-            action='store_true',
-            default=False,
-            help='Do not save. Parse only.'),
-        make_option('', '--top',
-            dest='top',
-            action='store_true',
-            default=False,
-            help='Only separate out top languages and projects'),
-        make_option('', '--batch',
-            dest='batch',
-            type='int',
-            default=1000,
-            help='Batch size to be used for query operations.'),
-        make_option('', '--rounds',
-            dest='rounds',
-            type='int',
-            default=1,
-            help='Number of rounds of the batch size to be run.'),
-        )
+    if hasattr(BaseCommand, 'option_list'):
+        # DEPRECATED, removed in Django 1.10
+        # replaced by add_arguments below
+        option_list = BaseCommand.option_list + (
+            make_option('', '--verbose',
+                dest='verbose',
+                action='store_true',
+                default=False,
+                help='Provides more verbose output.'),
+            make_option('', '--debug',
+                dest='debug',
+                action='store_true',
+                default=False,
+                help='Do not save. Parse only.'),
+            make_option('', '--newest',
+                dest='newest',
+                action='store_true',
+                default=False,
+                help='Do not save. Parse only.'),
+            make_option('', '--top',
+                dest='top',
+                action='store_true',
+                default=False,
+                help='Only separate out top languages and projects'),
+            make_option('', '--batch',
+                dest='batch',
+                type='int',
+                default=1000,
+                help='Batch size to be used for query operations.'),
+            make_option('', '--rounds',
+                dest='rounds',
+                type='int',
+                default=1,
+                help='Number of rounds of the batch size to be run.'),
+            )
 
     help = ''
 
@@ -63,6 +66,45 @@
     ]
 
 
+    def add_arguments(self, parser):
+        parser.add_argument(
+            '--verbose',
+            dest='verbose',
+            action='store_true',
+            default=False,
+            help='Provides more verbose output.')
+        parser.add_argument(
+            '--debug',
+            dest='debug',
+            action='store_true',
+            default=False,
+            help='Do not save. Parse only.')
+        parser.add_argument(
+            '--newest',
+            dest='newest',
+            action='store_true',
+            default=False,
+            help='Do not save. Parse only.')
+        parser.add_argument(
+            '--top',
+            dest='top',
+            action='store_true',
+            default=False,
+            help='Only separate out top languages and projects')
+        parser.add_argument(
+            '--batch',
+            dest='batch',
+            type='int',
+            default=1000,
+            help='Batch size to be used for query operations.')
+        parser.add_argument(
+            '--rounds',
+            dest='rounds',
+            type='int',
+            default=1,
+            help='Number of rounds of the batch size to be run.')
+
+
     def handle(self, *args, **options):
         starttime = datetime.now()
         self.debug = options.get('debug')
diff --git a/fundraiser/analytics/management/commands/LoadBannerImpressions.py 
b/fundraiser/analytics/management/commands/LoadBannerImpressions.py
index 9badc60..68851d7 100644
--- a/fundraiser/analytics/management/commands/LoadBannerImpressions.py
+++ b/fundraiser/analytics/management/commands/LoadBannerImpressions.py
@@ -22,32 +22,35 @@
 
     logger = logging.getLogger("fundraiser.analytics.load_banners")
 
-    option_list = BaseCommand.option_list + (
-        make_option('-f', '--file',
-            dest='filename',
-            default=None,
-            help='Specify the input file'),
-        make_option('', '--verbose',
-            dest='verbose',
-            action='store_true',
-            default=False,
-            help='Provides more verbose output.'),
-        make_option('', '--debug',
-            dest='debug',
-            action='store_true',
-            default=False,
-            help='Do not save the impressions. Parse only.'),
-        make_option('', '--recent',
-            dest='recent',
-            action='store_true',
-            default=False,
-            help='Process recent logs.'),
-        make_option('', '--hidden',
-            dest='hidden',
-            action='store_true',
-            default=False,
-            help='Parse records for hidden logs.'),
-        )
+    if hasattr(BaseCommand, 'option_list'):
+        # DEPRECATED, removed in Django 1.10
+        # replaced by add_arguments below
+        option_list = BaseCommand.option_list + (
+            make_option('-f', '--file',
+                dest='filename',
+                default=None,
+                help='Specify the input file'),
+            make_option('', '--verbose',
+                dest='verbose',
+                action='store_true',
+                default=False,
+                help='Provides more verbose output.'),
+            make_option('', '--debug',
+                dest='debug',
+                action='store_true',
+                default=False,
+                help='Do not save the impressions. Parse only.'),
+            make_option('', '--recent',
+                dest='recent',
+                action='store_true',
+                default=False,
+                help='Process recent logs.'),
+            make_option('', '--hidden',
+                dest='hidden',
+                action='store_true',
+                default=False,
+                help='Parse records for hidden logs.'),
+            )
 
     help = 'Parses the specified squid log file and stores the impression in 
the database.'
 
@@ -66,6 +69,39 @@
         "languages" : {},
     }
 
+
+    def add_arguments(self, parser):
+        parser.add_argument(
+            '-f',
+            '--file',
+            dest='filename',
+            default=None,
+            help='Specify the input file')
+        parser.add_argument(
+            '--verbose',
+            dest='verbose',
+            action='store_true',
+            default=False,
+            help='Provides more verbose output.')
+        parser.add_argument(
+            '--debug',
+            dest='debug',
+            action='store_true',
+            default=False,
+            help='Do not save the impressions. Parse only.')
+        parser.add_argument(
+            '--recent',
+            dest='recent',
+            action='store_true',
+            default=False,
+            help='Process recent logs.')
+        parser.add_argument(
+            '--hidden',
+            dest='hidden',
+            action='store_true',
+            default=False,
+            help='Parse records for hidden logs.')
+
     def handle(self, *args, **options):
         try:
             starttime = datetime.now()
diff --git 
a/fundraiser/analytics/management/commands/LoadBannerImpressions2Aggregate.py 
b/fundraiser/analytics/management/commands/LoadBannerImpressions2Aggregate.py
index 6538913..6e5c644 100644
--- 
a/fundraiser/analytics/management/commands/LoadBannerImpressions2Aggregate.py
+++ 
b/fundraiser/analytics/management/commands/LoadBannerImpressions2Aggregate.py
@@ -24,32 +24,35 @@
 
     logger = logging.getLogger("fundraiser.analytics.load_banners")
 
-    option_list = BaseCommand.option_list + (
-        make_option('-f', '--file',
-            dest='filename',
-            default=None,
-            help='Specify the input file'),
-        make_option('', '--verbose',
-            dest='verbose',
-            action='store_true',
-            default=False,
-            help='Provides more verbose output.'),
-        make_option('', '--top',
-            dest='top',
-            action='store_true',
-            default=False,
-            help='Only separate out top languages and projects'),
-        make_option('', '--debug',
-            dest='debug',
-            action='store_true',
-            default=False,
-            help='Do not save the impressions. Parse only.'),
-        make_option('', '--recent',
-            dest='recent',
-            action='store_true',
-            default=False,
-            help='Process recent logs.'),
-        )
+    if hasattr(BaseCommand, 'option_list'):
+        # DEPRECATED, removed in Django 1.10
+        # replaced by add_arguments below
+        option_list = BaseCommand.option_list + (
+            make_option('-f', '--file',
+                dest='filename',
+                default=None,
+                help='Specify the input file'),
+            make_option('', '--verbose',
+                dest='verbose',
+                action='store_true',
+                default=False,
+                help='Provides more verbose output.'),
+            make_option('', '--top',
+                dest='top',
+                action='store_true',
+                default=False,
+                help='Only separate out top languages and projects'),
+            make_option('', '--debug',
+                dest='debug',
+                action='store_true',
+                default=False,
+                help='Do not save the impressions. Parse only.'),
+            make_option('', '--recent',
+                dest='recent',
+                action='store_true',
+                default=False,
+                help='Process recent logs.'),
+            )
 
     help = 'Parses the specified squid log file and stores the impression in 
the database.'
 
@@ -62,6 +65,40 @@
         "pl", "cs", "ar", "el", "ko", "tr", "ms", "uk"
     ]
 
+
+    def add_arguments(self, parser):
+        parser.add_argument(
+            '-f',
+            '--file',
+            dest='filename',
+            default=None,
+            help='Specify the input file')
+        parser.add_argument(
+            '--verbose',
+            dest='verbose',
+            action='store_true',
+            default=False,
+            help='Provides more verbose output.')
+        parser.add_argument(
+            '--top',
+            dest='top',
+            action='store_true',
+            default=False,
+            help='Only separate out top languages and projects')
+        parser.add_argument(
+            '--debug',
+            dest='debug',
+            action='store_true',
+            default=False,
+            help='Do not save the impressions. Parse only.')
+        parser.add_argument(
+            '--recent',
+            dest='recent',
+            action='store_true',
+            default=False,
+            help='Process recent logs.')
+
+
     def handle(self, *args, **options):
 #        gc.set_debug(gc.DEBUG_LEAK)
 
diff --git a/fundraiser/analytics/management/commands/LoadLPImpressions.py 
b/fundraiser/analytics/management/commands/LoadLPImpressions.py
index 6c3b920..700a6a2 100644
--- a/fundraiser/analytics/management/commands/LoadLPImpressions.py
+++ b/fundraiser/analytics/management/commands/LoadLPImpressions.py
@@ -23,34 +23,37 @@
 
     logger = logging.getLogger("fundraiser.analytics.load_lps")
 
-    option_list = BaseCommand.option_list + (
-        make_option('-f', '--file',
-            dest='filename',
-            default=None,
-            help='Specify the input file'),
-        make_option('', '--verbose',
-            dest='verbose',
-            action='store_true',
-            default=False,
-            help='Provides more verbose output.'),
-        make_option('', '--debug',
-            dest='debug',
-            action='store_true',
-            default=False,
-            help='Do not save the impressions. Parse only.'),
-        make_option('', '--recent',
-            dest='recent',
-            action='store_true',
-            default=False,
-            help='Process recent logs.'),
-        make_option('', '--alt',
-            dest='alt',
-            action='store_true',
-            default=False,
-            help="Save to alternate tables.  Allows for reprocessing and then 
a table rename."
-                "NOTE: This requires the associated SquidLog records to be 
removed."
+    if hasattr(BaseCommand, 'option_list'):
+        # DEPRECATED, removed in Django 1.10
+        # replaced by add_arguments below
+        option_list = BaseCommand.option_list + (
+            make_option('-f', '--file',
+                dest='filename',
+                default=None,
+                help='Specify the input file'),
+            make_option('', '--verbose',
+                dest='verbose',
+                action='store_true',
+                default=False,
+                help='Provides more verbose output.'),
+            make_option('', '--debug',
+                dest='debug',
+                action='store_true',
+                default=False,
+                help='Do not save the impressions. Parse only.'),
+            make_option('', '--recent',
+                dest='recent',
+                action='store_true',
+                default=False,
+                help='Process recent logs.'),
+            make_option('', '--alt',
+                dest='alt',
+                action='store_true',
+                default=False,
+                help="Save to alternate tables.  Allows for reprocessing and 
then a table rename."
+                    "NOTE: This requires the associated SquidLog records to be 
removed."
+            )
         )
-    )
     help = 'Parses the specified squid log file and stores the impression in 
the database.'
 
     impression_sql = "INSERT INTO `landingpageimpression_raw%s` (timestamp, 
squid_id, squid_sequence, utm_source, utm_campaign, utm_key, utm_medium, 
landingpage, project_id, language_id, country_id) VALUES %s"
@@ -68,6 +71,40 @@
         "languages" : {},
     }
 
+
+    def add_arguments(self, parser):
+        parser.add_argument(
+            '-f',
+            '--file',
+            dest='filename',
+            default=None,
+            help='Specify the input file')
+        parser.add_argument(
+            '--verbose',
+            dest='verbose',
+            action='store_true',
+            default=False,
+            help='Provides more verbose output.')
+        parser.add_argument(
+            '--debug',
+            dest='debug',
+            action='store_true',
+            default=False,
+            help='Do not save the impressions. Parse only.')
+        parser.add_argument(
+            '--recent',
+            dest='recent',
+            action='store_true',
+            default=False,
+            help='Process recent logs.')
+        parser.add_argument(
+            '--alt',
+            dest='alt',
+            action='store_true',
+            default=False,
+            help="Save to alternate tables.  Allows for reprocessing and then 
a table rename."
+                "NOTE: This requires the associated SquidLog records to be 
removed.")
+
     def handle(self, *args, **options):
         try:
             starttime = datetime.now()

-- 
To view, visit https://gerrit.wikimedia.org/r/373924
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9ab1ea04c1bab9805a5ca10d25e2675e5561036b
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/tools/DjangoBannerStats
Gerrit-Branch: master
Gerrit-Owner: Ejegg <ej...@ejegg.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to