Browse Source

HUE-8426 [backend] fix hue CLI commands don't work after Django upgrade

Testing done: Just running
./build/env/bin/hue import_ldap_group
./build/env/bin/hue import_ldap_user
./build/env/bin/hue sync_ldap_users_and_groups
./build/env/bin/hue useradmin_sync_with_unix
./build/env/bin/hue config_override
./build/env/bin/hue config_upgrade
./build/env/bin/hue create_user_directories

(cherry picked from commit 00d849ddd9e55311214acff35f0e291d93b4654f)
Prakash Ranade 7 years ago
parent
commit
acd53a8700

+ 11 - 15
apps/useradmin/src/useradmin/management/commands/import_ldap_group.py

@@ -33,27 +33,23 @@ class Command(BaseCommand):
   group with the LDAP server. If --import-members is specified, it will import
   all unimported users.
   """
-
-  option_list = BaseCommand.option_list + (
-      make_option("--dn", help=_t("Whether or not the user should be imported by "
+  def add_arguments(self, parser):
+    parser.add_argument("--dn", help=_t("Whether or not the user should be imported by "
                                "distinguished name."),
                           action="store_true",
-                          default=False),
-      make_option("--import-members", help=_t("Import users from the group."),
+                          default=False)
+    parser.add_argument("--import-members", help=_t("Import users from the group."),
                                       action="store_true",
-                                      default=False),
-      make_option("--import-members-recursive", help=_t("Import users from the group, but also do so recursively."),
+                                      default=False)
+    parser.add_argument("--import-members-recursive", help=_t("Import users from the group, but also do so recursively."),
                                                 action="store_true",
-                                                default=False),
-      make_option("--sync-users", help=_t("Sync users in the group."),
+                                                default=False)
+    parser.add_argument("--sync-users", help=_t("Sync users in the group."),
                                   action="store_true",
-                                  default=False),
-      make_option("--server", help=_t("Server to connect to."),
+                                  default=False)
+    parser.add_argument("--server", help=_t("Server to connect to."),
                               action="store",
-                              default=None),
-   )
-
-  args = "group-name"
+                              default=None)
 
   def handle(self, group=None, **options):
     if group is None:

+ 7 - 11
apps/useradmin/src/useradmin/management/commands/import_ldap_user.py

@@ -30,21 +30,17 @@ class Command(BaseCommand):
 
   If a user has been previously imported, this will sync their user information.
   """
-
-  option_list = BaseCommand.option_list + (
-      make_option("--dn", help=_t("Whether or not the user should be imported by "
+  def add_arguments(self, parser):
+      parser.add_argument("--dn", help=_t("Whether or not the user should be imported by "
                                "distinguished name."),
                           action="store_true",
-                          default=False),
-      make_option("--sync-groups", help=_t("Sync groups of the users."),
+                          default=False)
+      parser.add_argument("--sync-groups", help=_t("Sync groups of the users."),
                                    action="store_true",
-                                   default=False),
-      make_option("--server", help=_t("Server to connect to."),
+                                   default=False)
+      parser.add_argument("--server", help=_t("Server to connect to."),
                               action="store",
-                              default=None),
-  )
-
-  args = "username"
+                              default=None)
 
   def handle(self, user=None, **options):
     if user is None:

+ 3 - 5
apps/useradmin/src/useradmin/management/commands/sync_ldap_users_and_groups.py

@@ -32,12 +32,10 @@ class Command(BaseCommand):
   user information and group memberships will be updated based on the LDAP
   server's current state.
   """
-
-  option_list = BaseCommand.option_list + (
-      make_option("--server", help=_t("Server to connect to."),
+  def add_arguments(self, parser):
+    parser.add_argument("--server", help=_t("Server to connect to."),
                               action="store",
-                              default=None),
-   )
+                              default=None)
 
   def handle(self, **options):
     server = options['server']

+ 6 - 8
apps/useradmin/src/useradmin/management/commands/useradmin_sync_with_unix.py

@@ -26,14 +26,12 @@ class Command(BaseCommand):
   """
   Handler for syncing the Hue database with Unix users and groups
   """
-
-  option_list = BaseCommand.option_list + (
-      make_option("--min-uid", help=_("Minimum UID to import (Inclusive)."), default=500),
-      make_option("--max-uid", help=_("Maximum UID to import (Exclusive)."), default=65334),
-      make_option("--min-gid", help=_("Minimum GID to import (Inclusive)."), default=500),
-      make_option("--max-gid", help=_("Maximum GID to import (Exclusive)."), default=65334),
-      make_option("--check-shell", help=_("Whether or not to check that the user's shell is not /bin/false."), default=True)
-  )
+  def add_arguments(self, parser):
+    parser.add_argument("--min-uid", help=_("Minimum UID to import (Inclusive)."), default=500)
+    parser.add_argument("--max-uid", help=_("Maximum UID to import (Exclusive)."), default=65334)
+    parser.add_argument("--min-gid", help=_("Minimum GID to import (Inclusive)."), default=500)
+    parser.add_argument("--max-gid", help=_("Maximum GID to import (Exclusive)."), default=65334)
+    parser.add_argument("--check-shell", help=_("Whether or not to check that the user's shell is not /bin/false."), default=True)
 
   def handle(self, *args, **options):
     # Typically, system users are under 500 or 1000, depending on OS, and there

+ 7 - 11
desktop/core/src/desktop/management/commands/config_override.py

@@ -38,19 +38,15 @@ class Command(BaseCommand):
   e.g. hue override_config --inline_override="{\"desktop\":{\"cherrypy_server_threads\":50}}"
   to override [desktop] cherrypy_server_threads entry
   """
+  def add_arguments(self, parser):
+    parser.add_argument('-c', '--config_path', default=DEFAULT_HUE_CONFIG_PATH, action='store', dest='config_path',
+                  help='Absolute hue.ini file path where config should be written or merged to')
 
-  args = ''
+    parser.add_argument('-o', '--override_path', dest='override_path', action='store',
+                  help='Absolute file path of a local JSON file to be merged with hue.ini')
 
-  option_list = BaseCommand.option_list + (
-      make_option('-c', '--config_path', default=DEFAULT_HUE_CONFIG_PATH, action='store', dest='config_path',
-                  help='Absolute hue.ini file path where config should be written or merged to'),
-
-      make_option('-o', '--override_path', dest='override_path', action='store',
-                  help='Absolute file path of a local JSON file to be merged with hue.ini'),
-
-      make_option('-i', '--inline_override', dest='inline_override', action='store',
-                  help='A JSON dictionary to be merged with hue.ini'),
-  )
+    parser.add_argument('-i', '--inline_override', dest='inline_override', action='store',
+                  help='A JSON dictionary to be merged with hue.ini')
 
   def handle(self, *args, **options):
 

+ 2 - 5
desktop/core/src/desktop/management/commands/config_upgrade.py

@@ -34,12 +34,9 @@ from django.utils.translation import ugettext as _
 LOG = logging.getLogger(__name__)
 
 class Command(BaseCommand):
-  args = ''
   help = _('Upgrades the Hue configuration with a mapping file.')
-
-  option_list = BaseCommand.option_list + (
-      make_option('--mapping_file', help=_('Location of the mapping file.')),
-  )
+  def add_arguments(self, parser):
+    parser.add_argument('--mapping_file', help=_('Location of the mapping file.'))
 
   """Upgrades a configuration."""
   def handle(self, *args, **options):

+ 2 - 5
desktop/core/src/desktop/management/commands/create_user_directories.py

@@ -39,12 +39,9 @@ class Command(BaseCommand):
 
   If --username is specified, it will only perform the operation for the specific user.
   """
-
   help = _("Creates home and Trash directories for users as needed, or specific user if username is provided.")
-
-  option_list = BaseCommand.option_list + (
-    make_option('--username', help=_("Username of user to create directories for."), action='store', default=None),
-  )
+  def add_arguments(self, parser):
+    parser.add_argument('--username', help=_("Username of user to create directories for."), action='store', default=None)
 
   def handle(self, *args, **options):
     users = User.objects.all()