From dbbe3fd6f404bdc7b0ad6408176240249c570a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Mon, 1 Jan 2018 15:38:49 +0100 Subject: [PATCH 3/3] misc: update management commands to new arg parsing (#20933) --- .../authentic2/management/commands/import-wcs-roles.py | 6 +++--- hobo/agent/common/management/commands/hobo_deploy.py | 13 ++++++------- hobo/agent/common/management/commands/hobo_notify.py | 13 +++++++------ hobo/environment/management/commands/cook.py | 15 +++++++-------- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/hobo/agent/authentic2/management/commands/import-wcs-roles.py b/hobo/agent/authentic2/management/commands/import-wcs-roles.py index 37ccf9d..2ba2e64 100644 --- a/hobo/agent/authentic2/management/commands/import-wcs-roles.py +++ b/hobo/agent/authentic2/management/commands/import-wcs-roles.py @@ -156,13 +156,13 @@ class WcsRoleImporter(object): class Command(BaseCommand): - option_list = BaseCommand.option_list + ( - make_option('--delete', action='store_true', dest='delete'), - ) help = "Import W.C.S. roles" requires_system_checks = False + def add_arguments(self, parser): + parser.add_argument('--delete', action="store_true", dest='delete') + def handle(self, *args, **options): # traverse list of tenants for tenant in TenantMiddleware.get_tenants(): diff --git a/hobo/agent/common/management/commands/hobo_deploy.py b/hobo/agent/common/management/commands/hobo_deploy.py index e3eb9b7..fe280cf 100644 --- a/hobo/agent/common/management/commands/hobo_deploy.py +++ b/hobo/agent/common/management/commands/hobo_deploy.py @@ -1,5 +1,4 @@ import json -from optparse import make_option import os import requests import subprocess @@ -32,15 +31,15 @@ def replace_file(path, content): class Command(BaseCommand): - args = ['base_url', 'json_filename'] early_secondary_exit = True me = None - option_list = BaseCommand.option_list + ( - make_option('--ignore-timestamp', dest='ignore_timestamp', - action="store_true", default=False), - make_option('--redeploy', action="store_true", default=False), - ) + def add_arguments(self, parser): + parser.add_argument('base_url', metavar='BASE_URL', type=str) + parser.add_argument('json_filename', metavar='JSON_FILENAME', type=str) + parser.add_argument('--ignore-timestamp', dest='ignore_timestamp', + action="store_true", default=False) + parser.add_argument('--redeploy', action="store_true", default=False) def handle(self, base_url=None, json_filename=None, ignore_timestamp=None, redeploy=None, *args, **kwargs): diff --git a/hobo/agent/common/management/commands/hobo_notify.py b/hobo/agent/common/management/commands/hobo_notify.py index b642db7..b5630c1 100644 --- a/hobo/agent/common/management/commands/hobo_notify.py +++ b/hobo/agent/common/management/commands/hobo_notify.py @@ -34,18 +34,19 @@ class TryAgain(Exception): pass class Command(BaseCommand): - args = ['...'] + def add_arguments(self, parser): + parser.add_argument('notification', metavar='NOTIFICATION', type=str) @classmethod - def load_notification(cls, args): - if args[0] == '-': + def load_notification(cls, notification): + if notification == '-': # get environment definition from stdin return json.load(sys.stdin) else: - return json.load(file(args[0])) + return json.load(file(notification)) - def handle(self, *args, **kwargs): - notification = self.load_notification(args) + def handle(self, notification, **kwargs): + notification = self.load_notification(notification) for tenant in TenantMiddleware.get_tenants(): if not os.path.exists(os.path.join(tenant.get_directory(), 'hobo.json')): continue diff --git a/hobo/environment/management/commands/cook.py b/hobo/environment/management/commands/cook.py index da72ec9..d143a2d 100644 --- a/hobo/environment/management/commands/cook.py +++ b/hobo/environment/management/commands/cook.py @@ -20,7 +20,6 @@ import sys import time import os import urlparse -from optparse import make_option from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType @@ -46,19 +45,19 @@ def get_domain(url): class Command(BaseCommand): - args = ['...'] must_notify = False verbosity = 1 - option_list = BaseCommand.option_list + ( - make_option('--timeout', type='int', action='store', default=120, - help='set the timeout for the wait_operationals method'), - ) + def add_arguments(self, parser): + parser.add_argument('recipe', metavar='RECIPE', type=str) + parser.add_argument( + '--timeout', type=int, action='store', default=120, + help='set the timeout for the wait_operationals method') - def handle(self, recipe_json, *args, **kwargs): + def handle(self, recipe, *args, **kwargs): self.verbosity = kwargs.get('verbosity') self.timeout = kwargs.get('timeout') - self.run_cook(recipe_json) + self.run_cook(recipe) if self.verbosity: print 'All steps executed successfully. Your environment should now be ready.' -- 2.15.1