Skip to content

[v7r3] register args (optional)#5061

Merged
atsareg merged 12 commits into
DIRACGrid:integrationfrom
TaykYoku:v7r3_args
May 19, 2021
Merged

[v7r3] register args (optional)#5061
atsareg merged 12 commits into
DIRACGrid:integrationfrom
TaykYoku:v7r3_args

Conversation

@TaykYoku

@TaykYoku TaykYoku commented Mar 25, 2021

Copy link
Copy Markdown
Contributor

Example:

"""My script

Usage:
  dirac-myscript [options] ... Status <DN|ID> Element [Element]

Arguments:
  Status:          element status ['done', 'fail']
  DN:               user DN
  ID:                 user ID
  Element:       list of elements [default: 'no elements'] (optional)
"""
from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript

@DIRACScript()
def main():
  Script.parseCommandLine()
  args = Script.getPositionalArguments()
  
  # Check if all mandatory arguments is present and the value of the first argument corresponds to the specified value
  if len(args) < 2 or (args[0] not in ['done', 'fail']):
     Script.showHelp()

  status = args[0]

  # detection of a controversial argument
  if args[1].startswith('/'):
    dn = args[1]
    id = None
  else:
     id = args[1]
     dn = None
  
  # identifying an optional argument with default value
  elements = 'no elements'
  if len(args) > 2:
    elements = args[1:]

Can be converted to

"""My script"""
from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript

@DIRACScript()
def main():
  # it is important to add a colon after the name of the argument in the description
  Script.registerArgument(' Status: element status', values=['done', 'fail'])
  Script.registerArgument(('DN:  user DN', 'ID: user ID'))
  Script.registerArgument(['Element: list of elements'], default='no elements', mandatory=False)

  Script.parseCommandLine()
  status, second, elements = Script.getPositionalArguments(group=True)

  # detection of a controversial argument
  if second.startswith('/'):
    dn = second
    id = None
  else:
     id = second
     dn = None

The help output should be the same.

BEGINRELEASENOTES
Fragment from #5035:

  • Added the ability to register positional arguments and add it to help message.
  • Docs

*Core
NEW: provide some docs and add registerArgument method to register arguments in Script
FIX: align Script with changes in LocalConfiguration

*Configuration
NEW: add registerCmdArg to register arguments and group argument to group returned arguments
NEW: add Test_LocalConfiguration

*docs
FIX: rename exapmle scripts, docs

ENDRELEASENOTES

@TaykYoku TaykYoku marked this pull request as ready for review March 25, 2021 16:07
@fstagni

fstagni commented Apr 7, 2021

Copy link
Copy Markdown
Contributor

Looks OK to me.

@andresailer

Copy link
Copy Markdown
Contributor

Don't you want to add the use of Script.registerArgument to the two example scripts (ping_info, great_script)?
Also maybe move the example conversion out of the release notes?

Comment thread src/DIRAC/Core/Utilities/DIRACScript.py Outdated
Comment thread src/DIRAC/ConfigurationSystem/Client/test/Test_LocalConfiguration.py Outdated
Comment thread src/DIRAC/ConfigurationSystem/Client/LocalConfiguration.py Outdated
@chrisburr

Copy link
Copy Markdown
Member

The docs are failing with the matplotlib thing, a rebasing on integration will fix it

@TaykYoku

TaykYoku commented Apr 9, 2021

Copy link
Copy Markdown
Contributor Author

Don't you want to add the use of Script.registerArgument to the two example scripts (ping_info, great_script)?

I added documentation to the appropriate methods in LocalConfiguration and updated the dirac-my-great-script script with examples of registration of various arguments.
Do we really need two examples of scripts? are they any different or should I add to dirac-ping-info the same as to the dirac-my-great-script script?

@fstagni

fstagni commented Apr 16, 2021

Copy link
Copy Markdown
Contributor

Can you rebase? Then we should hopefully see the tests not failing...?

@TaykYoku

Copy link
Copy Markdown
Contributor Author

PilotWrapper failed with:

2021-04-16 13:21:46 UTC dirac-install [NOTICE]  Installing DIRAC OS ...
2021-04-16 13:21:46 UTC dirac-install [DEBUG] Using DIRACOS tarball URL from configuration key Installations/DIRAC/DIRACOS
2021-04-16 13:21:46 UTC dirac-install [NOTICE]  Retrieving https://diracos.web.cern.ch/diracos/releases/diracos-master.tar.gz
2021-04-16 13:21:46 UTC dirac-install [DEBUG] Retrieving remote file "https://diracos.web.cern.ch/diracos/releases/diracos-master.tar.gz"
Error: -16 13:26:51 UTC dirac-install [ERROR] Cannot download diracos-master.tar.gz: Timeout

I have the same problem when testing locally via docker

@fstagni

fstagni commented Apr 16, 2021

Copy link
Copy Markdown
Contributor

PilotWrapper failed with:

2021-04-16 13:21:46 UTC dirac-install [NOTICE]  Installing DIRAC OS ...
2021-04-16 13:21:46 UTC dirac-install [DEBUG] Using DIRACOS tarball URL from configuration key Installations/DIRAC/DIRACOS
2021-04-16 13:21:46 UTC dirac-install [NOTICE]  Retrieving https://diracos.web.cern.ch/diracos/releases/diracos-master.tar.gz
2021-04-16 13:21:46 UTC dirac-install [DEBUG] Retrieving remote file "https://diracos.web.cern.ch/diracos/releases/diracos-master.tar.gz"
Error: -16 13:26:51 UTC dirac-install [ERROR] Cannot download diracos-master.tar.gz: Timeout

I have the same problem when testing locally via docker

That's happening frequently these days. Just restart...

@atsareg atsareg merged commit dfe38c8 into DIRACGrid:integration May 19, 2021
@TaykYoku TaykYoku deleted the v7r3_args branch June 4, 2021 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants