From 199d760d2b3f6dd62acdec483a2b60291cba2990 Mon Sep 17 00:00:00 2001 From: Chris Burr Date: Thu, 4 Feb 2021 10:38:44 +0100 Subject: [PATCH 1/3] Revert scripts to before Python 3 incompatible merge --- .../scripts/dirac_admin_add_site.py | 26 ++++----- .../scripts/dirac_admin_sort_cs_sites.py | 1 - .../Core/scripts/dirac_deploy_scripts.py | 55 ++++--------------- .../Core/scripts/dirac_install_extension.py | 29 +++++----- src/DIRAC/Core/scripts/dirac_platform.py | 32 ----------- src/DIRAC/Core/scripts/dirac_version.py | 26 +-------- .../scripts/dirac_admin_proxy_upload.py | 10 ---- .../scripts/dirac_proxy_destroy.py | 5 +- .../scripts/dirac_proxy_init.py | 12 +--- 9 files changed, 42 insertions(+), 154 deletions(-) mode change 100644 => 100755 src/DIRAC/Core/scripts/dirac_version.py diff --git a/src/DIRAC/ConfigurationSystem/scripts/dirac_admin_add_site.py b/src/DIRAC/ConfigurationSystem/scripts/dirac_admin_add_site.py index 0a4f00d8307..d6e7ed85fc5 100755 --- a/src/DIRAC/ConfigurationSystem/scripts/dirac_admin_add_site.py +++ b/src/DIRAC/ConfigurationSystem/scripts/dirac_admin_add_site.py @@ -7,20 +7,6 @@ Add a new DIRAC SiteName to DIRAC Configuration, including one or more CEs. If site is already in the CS with another name, error message will be produced. If site is already in the CS with the right name, only new CEs will be added. - -Usage: - - dirac-admin-add-site [option|cfgfile] ... DIRACSiteName GridSiteName CE [CE] ... - -Arguments: - - DIRACSiteName: Name of the site for DIRAC in the form GRID.LOCATION.COUNTRY (ie:LCG.CERN.ch) - GridSiteName: Name of the site in the Grid (ie: CERN-PROD) - CE: Name of the CE to be included in the site (ie: ce111.cern.ch) - -Example: - - $ dirac-admin-add-site LCG.IN2P3.fr IN2P3-Site """ from __future__ import absolute_import from __future__ import division @@ -36,7 +22,17 @@ @DIRACScript() def main(): - Script.setUsageMessage(__doc__) + Script.setUsageMessage( + '\n'.join( + [ + __doc__.split('\n')[1], + 'Usage:', + ' %s [option|cfgfile] ... DIRACSiteName GridSiteName CE [CE] ...' % + Script.scriptName, + 'Arguments:', + ' DIRACSiteName: Name of the site for DIRAC in the form GRID.LOCATION.COUNTRY (ie:LCG.CERN.ch)', + ' GridSiteName: Name of the site in the Grid (ie: CERN-PROD)', + ' CE: Name of the CE to be included in the site (ie: ce111.cern.ch)'])) Script.parseCommandLine(ignoreErrors=True) args = Script.getPositionalArgs() diff --git a/src/DIRAC/ConfigurationSystem/scripts/dirac_admin_sort_cs_sites.py b/src/DIRAC/ConfigurationSystem/scripts/dirac_admin_sort_cs_sites.py index 6393e90da2e..113c766fc48 100755 --- a/src/DIRAC/ConfigurationSystem/scripts/dirac_admin_sort_cs_sites.py +++ b/src/DIRAC/ConfigurationSystem/scripts/dirac_admin_sort_cs_sites.py @@ -21,7 +21,6 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function - __RCSID__ = "$Id$" from DIRAC import gLogger, exit as DIRACExit diff --git a/src/DIRAC/Core/scripts/dirac_deploy_scripts.py b/src/DIRAC/Core/scripts/dirac_deploy_scripts.py index 0c1af6cf6d8..c3cd66e8f55 100755 --- a/src/DIRAC/Core/scripts/dirac_deploy_scripts.py +++ b/src/DIRAC/Core/scripts/dirac_deploy_scripts.py @@ -1,52 +1,22 @@ #!/usr/bin/env python """ -Deploy all scripts and extensions. -This script is not meant to be called by users (it's automatically called by dirac-install). - -Usage:: - - dirac-deploy-scripts (|)* ... - -Arguments:: - python path: you can specify the folder where your python installation should be fetched from +Deploy all scripts and extensions +Options: + * --symlink: this will create symlinks instead of wrappers + * : you can specify the folder where your python installation should be fetched from to replace the shebang - -Example:: - - $ dirac-deploy-scripts """ from __future__ import print_function from __future__ import absolute_import from __future__ import division - __RCSID__ = "$Id$" +import getopt import os +import shutil +import stat import re import sys -import stat -import getopt -import shutil - -cmdOpts = (('', 'symlink', 'this will create symlinks instead of wrappers'), - ('', 'module=', 'module in which to look for the scripts'), - ('h', 'help', 'help doc string')) - - -def usage(err=''): - """ Usage printout - - :param str err: will print something like "option -a not recognized" - """ - if err: - print(err) - print(__doc__) - print('Options::\n\n') - for cmdOpt in cmdOpts: - print(" %s %s : %s" % (cmdOpt[0].ljust(3), cmdOpt[1].ljust(20), cmdOpt[2])) - - sys.exit(2 if err else 0) - DEBUG = False @@ -76,15 +46,12 @@ def usage(err=''): module = None try: - opts, args = getopt.getopt(sys.argv[1:], - "".join([opt[0] for opt in cmdOpts]), - [opt[1] for opt in cmdOpts]) + opts, args = getopt.getopt(sys.argv[1:], "", ["symlink", "module="]) except getopt.GetoptError as err: - # print help information and exit - usage(str(err)) + # print help information and exit: + print(str(err)) # will print something like "option -a not recognized" + sys.exit(2) for o, a in opts: - if o in ('-h', '--help'): - usage() if o == "--symlink": useSymlinks = True elif o == "--module": diff --git a/src/DIRAC/Core/scripts/dirac_install_extension.py b/src/DIRAC/Core/scripts/dirac_install_extension.py index fd550ef1e6d..c767b01346e 100644 --- a/src/DIRAC/Core/scripts/dirac_install_extension.py +++ b/src/DIRAC/Core/scripts/dirac_install_extension.py @@ -1,36 +1,37 @@ #!/usr/bin/env python -""" -Allows to add a specified extension to an already existing DIRAC installation. -The extension can come from another project than the one installed. -No new version directory is created. The command is based on the main DIRAC installer dirac-install.py. - -Usage:: +""" dirac-install-extension command allows to add a specified extension +to an already existing DIRAC installation. No new version directory is created. +The command is based on the main DIRAC installer dirac-install.py. - dirac-install-extension (|)* +The valid options are: + -l - the project in which the extension is developed + -r - the project release version + -e - the extension name. Several -e options can be given """ from __future__ import unicode_literals, absolute_import, division, print_function import os import sys -import six -import time -import getopt import importlib +import getopt +import time +import six cmdOpts = (('r:', 'release=', 'Release version to install'), ('l:', 'project=', 'Project to install'), - ('e:', 'extensions=', 'Extensions to install (comma separated). Several -e options can be given'), - ('M:', 'defaultsURL=', 'Where to retrieve the global defaults from'), + ('e:', 'extensions=', 'Extensions to install (comma separated)'), ('h', 'help', 'help doc string')) def usage(): """ Usage printout """ - print(__doc__) - print('Options::\n\n') + print("\nThe command allows to add a specified extension to an already existing DIRAC installation.\n" + "The extension can come from another project than the one installed.") + print("\nUsage:\n\n %s " % os.path.basename(sys.argv[0])) + print("\nOptions:") for cmdOpt in cmdOpts: print(" %s %s : %s" % (cmdOpt[0].ljust(3), cmdOpt[1].ljust(20), cmdOpt[2])) diff --git a/src/DIRAC/Core/scripts/dirac_platform.py b/src/DIRAC/Core/scripts/dirac_platform.py index f9c1ef20fae..f134cb03d44 100755 --- a/src/DIRAC/Core/scripts/dirac_platform.py +++ b/src/DIRAC/Core/scripts/dirac_platform.py @@ -3,44 +3,12 @@ # File : dirac-platform # Author : Adria Casajus ######################################################################## -""" -The *dirac-platform* script determines the "platform" of a certain node. -The platform is a string used to identify the minimal characteristics of the node, -enough to determine which version of DIRAC can be installed. -Invoked at any installation, so by the *dirac-install* script, and by the pilots. - -On a RHEL 6 node, for example, the determined dirac platform is "Linux_x86_64_glibc-2.5" - -Usage:: - - dirac-platform [option|cfgfile] - -Example:: - - $ dirac-platform - Linux_x86_64_glibc-2.5 - -""" from __future__ import print_function from __future__ import absolute_import from __future__ import division - __RCSID__ = "$Id$" -import sys -import getopt - -cmdOpt = ('h', 'help', 'help doc string') - -optList, args = getopt.getopt(sys.argv[1:], cmdOpt[0], cmdOpt[1]) -for opt, value in optList: - if opt in ('-h', '--help'): - print(__doc__) - print('Options::\n\n') - print(" %s %s : %s" % (cmdOpt[0].ljust(3), cmdOpt[1].ljust(20), cmdOpt[2])) - sys.exit(0) - try: from DIRAC.Core.Utilities.Platform import getPlatformString except Exception: diff --git a/src/DIRAC/Core/scripts/dirac_version.py b/src/DIRAC/Core/scripts/dirac_version.py old mode 100644 new mode 100755 index 5f2fde81414..6cd1072a1b4 --- a/src/DIRAC/Core/scripts/dirac_version.py +++ b/src/DIRAC/Core/scripts/dirac_version.py @@ -4,36 +4,12 @@ # Author : Ricardo Graciani ######################################################################## """ -Print version of current DIRAC installation - -Usage:: - - dirac-version [option] - -Example:: - - $ dirac-version - + print version of current DIRAC installation """ from __future__ import print_function from __future__ import absolute_import from __future__ import division -__RCSID__ = "$Id$" - -import sys -import getopt - -cmdOpt = ('h', 'help', 'help doc string') - -optList, args = getopt.getopt(sys.argv[1:], cmdOpt[0], cmdOpt[1]) -for opt, value in optList: - if opt in ('-h', '--help'): - print(__doc__) - print('Options::\n\n') - print(" %s %s : %s" % (cmdOpt[0].ljust(3), cmdOpt[1].ljust(20), cmdOpt[2])) - sys.exit(0) - import DIRAC from DIRAC.Core.Utilities.DIRACScript import DIRACScript diff --git a/src/DIRAC/FrameworkSystem/scripts/dirac_admin_proxy_upload.py b/src/DIRAC/FrameworkSystem/scripts/dirac_admin_proxy_upload.py index 3492c8c95b3..832cf7cc9f8 100755 --- a/src/DIRAC/FrameworkSystem/scripts/dirac_admin_proxy_upload.py +++ b/src/DIRAC/FrameworkSystem/scripts/dirac_admin_proxy_upload.py @@ -3,26 +3,16 @@ # File : dirac-admin-proxy-upload.py # Author : Adrian Casajus ######################################################################## -""" -Usage: - dirac-admin-proxy-upload.py (|)* - -Example:: - - $ dirac-admin-proxy-upload -""" from __future__ import print_function from __future__ import absolute_import from __future__ import division - import sys from DIRAC.Core.Base import Script from DIRAC.Core.Utilities.DIRACScript import DIRACScript from DIRAC.FrameworkSystem.Client.ProxyUpload import CLIParams, uploadProxy __RCSID__ = "$Id$" -Script.setUsageMessage(__doc__) @DIRACScript() diff --git a/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_destroy.py b/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_destroy.py index bd51bfedceb..8b109a63cbb 100755 --- a/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_destroy.py +++ b/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_destroy.py @@ -11,12 +11,13 @@ import DIRAC from DIRAC import gLogger, S_OK +from DIRAC.Core.Security import Locations from DIRAC.Core.Base import Script from DIRAC.Core.Utilities.DIRACScript import DIRACScript -from DIRAC.Core.Security import Locations, ProxyInfo from DIRAC.Core.DISET.RPCClient import RPCClient from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager +from DIRAC.Core.Security import ProxyInfo from DIRAC.ConfigurationSystem.Client.Helpers import Registry __RCSID__ = "$Id$" @@ -59,7 +60,7 @@ def registerCLISwitches(self): """ add options to dirac option parser """ - Script.setUsageMessage(__doc__) + Script.setUsageMessage("Script to delete a dirac proxy. Default: delete local proxy only.") Script.registerSwitch( "a", "all", diff --git a/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_init.py b/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_init.py index 2718a555a57..693ad998b7b 100755 --- a/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_init.py +++ b/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_init.py @@ -3,16 +3,6 @@ # File : dirac-proxy-init.py # Author : Adrian Casajus ######################################################################## -""" -Usage: - - dirac-proxy-init.py (|)* - -Example: - - $ dirac-proxy-init -g dirac_user -t --rfc - Enter Certificate password: -""" from __future__ import division from __future__ import absolute_import from __future__ import print_function @@ -34,7 +24,7 @@ from DIRAC.FrameworkSystem.Client.BundleDeliveryClient import BundleDeliveryClient __RCSID__ = "$Id$" -Script.setUsageMessage(__doc__) + class Params(ProxyGeneration.CLIParams): From 9f5e751e93a365eec060646f0b5cc1bfab234509 Mon Sep 17 00:00:00 2001 From: Chris Burr Date: Thu, 4 Feb 2021 11:03:03 +0100 Subject: [PATCH 2/3] Revert test changes for dirac-info -v --- tests/System/transformationSystem.sh | 2 +- tests/System/transformation_replication.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/System/transformationSystem.sh b/tests/System/transformationSystem.sh index 7afeb24f4f6..956e4c2c676 100755 --- a/tests/System/transformationSystem.sh +++ b/tests/System/transformationSystem.sh @@ -34,7 +34,7 @@ stamptime=$(date +%Y%m%d_%H%M%S) stime=$(date +"%H%M%S") tdate=$(date +"20%y-%m-%d") ttime=$(date +"%R") -version=$(dirac-info -v) +version=$(dirac-version) if [[ -d "TransformationSystemTest" ]]; then echo "Removing TransformationSystemTest" diff --git a/tests/System/transformation_replication.sh b/tests/System/transformation_replication.sh index 2e7f7d2519c..4987038a205 100755 --- a/tests/System/transformation_replication.sh +++ b/tests/System/transformation_replication.sh @@ -35,7 +35,7 @@ echo " " #Values to be used stime=$(date +"%H%M%S") tdate=$(date +"20%y-%m-%d") -version=$(dirac-info -v) +version=$(dirac-version) if [[ -d "TransformationSystemTest" ]]; then echo "Removing TransformationSystemTest" From c28b0c9cb6360ffbed5a8c4a40479f7e355d3ef8 Mon Sep 17 00:00:00 2001 From: Chris Burr Date: Mon, 8 Feb 2021 12:24:59 +0100 Subject: [PATCH 3/3] Reapply changes to dirac_deploy_scripts.py to fix tests --- .../Core/scripts/dirac_deploy_scripts.py | 55 +++++++++++++++---- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/src/DIRAC/Core/scripts/dirac_deploy_scripts.py b/src/DIRAC/Core/scripts/dirac_deploy_scripts.py index c3cd66e8f55..0c1af6cf6d8 100755 --- a/src/DIRAC/Core/scripts/dirac_deploy_scripts.py +++ b/src/DIRAC/Core/scripts/dirac_deploy_scripts.py @@ -1,22 +1,52 @@ #!/usr/bin/env python """ -Deploy all scripts and extensions -Options: - * --symlink: this will create symlinks instead of wrappers - * : you can specify the folder where your python installation should be fetched from +Deploy all scripts and extensions. +This script is not meant to be called by users (it's automatically called by dirac-install). + +Usage:: + + dirac-deploy-scripts (|)* ... + +Arguments:: + python path: you can specify the folder where your python installation should be fetched from to replace the shebang + +Example:: + + $ dirac-deploy-scripts """ from __future__ import print_function from __future__ import absolute_import from __future__ import division + __RCSID__ = "$Id$" -import getopt import os -import shutil -import stat import re import sys +import stat +import getopt +import shutil + +cmdOpts = (('', 'symlink', 'this will create symlinks instead of wrappers'), + ('', 'module=', 'module in which to look for the scripts'), + ('h', 'help', 'help doc string')) + + +def usage(err=''): + """ Usage printout + + :param str err: will print something like "option -a not recognized" + """ + if err: + print(err) + print(__doc__) + print('Options::\n\n') + for cmdOpt in cmdOpts: + print(" %s %s : %s" % (cmdOpt[0].ljust(3), cmdOpt[1].ljust(20), cmdOpt[2])) + + sys.exit(2 if err else 0) + DEBUG = False @@ -46,12 +76,15 @@ module = None try: - opts, args = getopt.getopt(sys.argv[1:], "", ["symlink", "module="]) + opts, args = getopt.getopt(sys.argv[1:], + "".join([opt[0] for opt in cmdOpts]), + [opt[1] for opt in cmdOpts]) except getopt.GetoptError as err: - # print help information and exit: - print(str(err)) # will print something like "option -a not recognized" - sys.exit(2) + # print help information and exit + usage(str(err)) for o, a in opts: + if o in ('-h', '--help'): + usage() if o == "--symlink": useSymlinks = True elif o == "--module":