Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7be0176
fix
TaykYoku Mar 14, 2021
c72fc40
fix
TaykYoku Mar 14, 2021
408c82f
fix py3 scripts
TaykYoku Mar 14, 2021
5b331d0
fix
TaykYoku Mar 14, 2021
b7e5474
fix pylint
TaykYoku Mar 15, 2021
afb4f4e
fix pylint
TaykYoku Mar 15, 2021
8b701d7
fix pylint
TaykYoku Mar 15, 2021
9bc0b31
fix pylint
TaykYoku Mar 15, 2021
64d1712
fix pylint
TaykYoku Mar 15, 2021
f88dcfd
fix pylint
TaykYoku Mar 15, 2021
a107f2d
fix pylint
TaykYoku Mar 15, 2021
33d4897
fix pylint
TaykYoku Mar 15, 2021
ffe46c1
fix pylint
TaykYoku Mar 15, 2021
aed3b6b
fix dirac info
TaykYoku Mar 15, 2021
89fbea7
merge #5024
TaykYoku Mar 17, 2021
d1f506c
fix
TaykYoku Mar 17, 2021
de43cbd
fix pylint
TaykYoku Mar 17, 2021
679f5de
fix pylint
TaykYoku Mar 17, 2021
941d351
fix pylint, warnings
TaykYoku Mar 17, 2021
44ca305
remove unuse
TaykYoku Mar 17, 2021
165476b
fix pylints
TaykYoku Mar 17, 2021
297d1f2
fix assertRaisesRegexp
TaykYoku Mar 17, 2021
8cc1748
fix
TaykYoku Mar 17, 2021
4f25c5f
fix
TaykYoku Mar 18, 2021
6849649
fix bugs
TaykYoku Mar 18, 2021
f20c350
fix dirac-my-great-script
TaykYoku Mar 19, 2021
19299a7
fix examples
TaykYoku Mar 19, 2021
044995a
fix dirac_my_great_script
TaykYoku Mar 19, 2021
416b7f9
docs
TaykYoku Jul 9, 2021
2e4365b
align with rebased code
TaykYoku Jul 9, 2021
3571d7d
rebase
TaykYoku Jul 10, 2021
0e3e6e8
fix pylint
TaykYoku Jul 10, 2021
db4c949
script initialize
TaykYoku Jul 10, 2021
b316082
fix
TaykYoku Jul 11, 2021
453f4f5
dont pass instance to main, optimize
TaykYoku Jul 11, 2021
95b7411
fix pylint
TaykYoku Jul 11, 2021
0252ca6
fix DIRACScript
TaykYoku Jul 12, 2021
ca7da53
Update docs/source/DeveloperGuide/AddingNewComponents/DevelopingComma…
TaykYoku Jul 13, 2021
6a130d2
use with open, and use one style of decorator
TaykYoku Jul 15, 2021
f9ac44e
fix pylint
TaykYoku Jul 15, 2021
e9dd2f0
Update src/DIRAC/DataManagementSystem/scripts/dirac_dms_change_replic…
TaykYoku Jul 19, 2021
a83ac0a
Update src/DIRAC/DataManagementSystem/scripts/dirac_dms_move_replica_…
TaykYoku Jul 19, 2021
a8325bf
Update src/DIRAC/Interfaces/scripts/dirac_admin_reset_job.py
TaykYoku Jul 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/AdministratorGuide/Tutorials/dmsWithTs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ script that creates a removal transformation:

# set up the DIRAC configuration, parse command line arguments
from DIRAC import gLogger, S_OK, S_ERROR
from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
Script.parseCommandLine()

from DIRAC.TransformationSystem.Client.Transformation import Transformation
Expand Down
2 changes: 1 addition & 1 deletion docs/source/AdministratorGuide/Tutorials/installWMS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Create a Python script to generate and submit a simple job. Copy paste the follo
#!/bin/env python
# Magic lines necessary to activate the DIRAC Configuration System
# to discover all the required services
from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
Script.parseCommandLine(ignoreErrors=True)
from DIRAC.Interfaces.API.Job import Job
from DIRAC.Interfaces.API.Dirac import Dirac
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
__RCSID__ = '$Id$'

from DIRAC import S_OK, S_ERROR, gLogger, exit as DIRACExit
from DIRAC.Core.Utilities.DIRACScript import DIRACScript
from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script


class Params(object):
Expand All @@ -29,6 +28,13 @@ def __init__(self):
""" C'or """
self.raw = False
self.pingsToDo = 1
# Defined all switches that can be used while calling the script from the command line interface.
self.switches = [
('', 'text=', 'Text to be printed'),
('u', 'upper', 'Print text on upper case'),
('r', 'showRaw', 'Show raw result from the query', self.setRawResult),
('p:', 'numPings=', 'Number of pings to do (by default 1)', self.setNumOfPingsToDo)
]

def setRawResult(self, _):
""" ShowRaw option callback function, no option argument.
Expand All @@ -52,26 +58,6 @@ def setNumOfPingsToDo(self, value):
return S_OK()


def registerSwitches():
"""
Registers all switches that can be used while calling the script from the command line interface.
"""

# Some of the switches have associated a callback, defined on Params class.
cliParams = Params()

switches = [
('', 'text=', 'Text to be printed'),
('u', 'upper', 'Print text on upper case'),
('r', 'showRaw', 'Show raw result from the query', cliParams.setRawResult),
('p:', 'numPings=', 'Number of pings to do (by default 1)', cliParams.setNumOfPingsToDo)
]

# Register switches
for switch in switches:
Script.registerSwitch(*switch)


def registerArguments():
"""
Registers a positional arguments that can be used while calling the script from the command line interface.
Expand Down Expand Up @@ -112,14 +98,15 @@ def parseSwitchesAndPositionalArguments():


# IMPORTANT: Make sure to add the console-scripts entry to setup.cfg as well!
@DIRACScript()
@Script()
def main():
"""
This is the script main method, which will hold all the logic.
"""
params = Params()

# Script initialization
registerSwitches()
Script.registerSwitches(params.switches)
registerArguments()
switchDict, repType, user, services = parseSwitchesAndPositionalArguments()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
__RCSID__ = "$Id$"

import sys
from DIRAC import exit as DIRACExit
from DIRAC import S_OK, S_ERROR, gLogger
from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript

from DIRAC import S_OK, S_ERROR, gLogger, exit as DIRACExit
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script


# Define a simple class to hold the script parameters
Expand All @@ -38,7 +37,7 @@ def setNumOfPingsToDo(self, value):
return S_OK()


@DIRACScript()
@Script()
def main():
# Instantiate the params class
cliParams = Params()
Expand All @@ -49,7 +48,7 @@ def main():
Script.registerArgument(['System: system names'])

# Parse the command line and initialize DIRAC
Script.parseCommandLine(ignoreErrors=False)
switches, servicesList = Script.parseCommandLine(ignoreErrors=False)

# Get the list of services
servicesList = Script.getPositionalArgs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Developing Commands

.. warning::
This instructions here demonstrate how to support both the legacy (Python 2) and future (Python3) installations of DIRAC.
If only having Python 3 support is acceptable, the requirement for scripts to be in the the *scripts* directory of their parent system will be removed and the only requirement will be for the function to be decorated with the ``@DIRACScript()`` decorator.
If only having Python 3 support is acceptable, the requirement for scripts to be in the the *scripts* directory of their parent system will be removed and the only requirement will be for the function to be decorated with the ``@Script()`` decorator.
Comment thread
fstagni marked this conversation as resolved.
Comment thread
fstagni marked this conversation as resolved.

Commands are one of the main interface tools for the users. Commands are also called *scripts* in DIRAC lingo.

Expand Down Expand Up @@ -37,16 +37,16 @@ which will set the interpreter directive to the python on the environment.

**2.** The next is the documentation line which is describing the command. This same documentation line will be used also the command help information available with the *-h* command switch.

**3.** The majority of the code should be contained with a function, often called ``main`` though this is not required. This function should be wrapped with the ``@DIRACScript()`` decorator to allow the DIRAC plugin mechanism to override the script with the function from the highest priority extension.
**3.** The majority of the code should be contained with a function, often called ``main`` though this is not required. This function should be wrapped with the ``@Script()`` decorator to allow the DIRAC plugin mechanism to override the script with the function from the highest priority extension.

.. code-block:: python

#Import the required DIRAC modules
from DIRAC.Core.Utilities.DIRACScript import DIRACScript
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
from DIRAC.Interfaces.API.DIRAC import DIRAC
from DIRAC import gLogger

@DIRACScript()
@Script()
def main():
# Do stuff

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Remember to start the script with:
#!/usr/bin/env python
""" Some doc: what does this script should do?
"""
from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
Script.parseCommandLine()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import time
from DIRAC import S_OK, S_ERROR
from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
from DIRAC.Core.DISET.MessageClient import MessageClient

Script.parseCommandLine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ with `setEvenOdd`, and then execute this function to test it.
:linenos:

from DIRAC import gLogger, S_OK, S_ERROR
from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
Script.parseCommandLine()

from DIRAC.TransformationSystem.Client.Transformation import Transformation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Creating a DIRAC Job using API
The API allows creating DIRAC jobs using the Job object, specifying job requirements.::

# setup DIRAC
from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
Script.parseCommandLine(ignoreErrors=False)

from DIRAC.Interfaces.API.Job import Job
Expand Down Expand Up @@ -63,7 +63,7 @@ Job Monitoring
Once you have submitted your jobs to the Grid, a little script can be used to monitor the job status::

# setup DIRAC
from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
Script.parseCommandLine(ignoreErrors=False)

from DIRAC.Interfaces.API.Dirac import Dirac
Expand All @@ -88,7 +88,7 @@ Job Output
When the status of the job is done, the outputs can be retrieved using also a simple script::

# setup DIRAC
from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
Script.parseCommandLine(ignoreErrors=False)

from DIRAC.Interfaces.API.Dirac import Dirac
Expand Down
2 changes: 1 addition & 1 deletion src/DIRAC/AccountingSystem/Client/ReportCLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Once ready it could be used with a script as simple as:


from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script

Script.localCfg.addDefaultEntry("LogLevel", "info")
Script.parseCommandLine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
########################################################################
"""
Decode Accounting plot URLs

Usage:
dirac-accounting-decode-fileid [options] ... URL ...

Arguments:
URL: encoded URL of a DIRAC Accounting plot
"""
from __future__ import absolute_import
from __future__ import division
Expand All @@ -24,16 +18,15 @@
from six.moves.urllib import parse as urlparse

from DIRAC import gLogger
from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script


@DIRACScript()
@Script()
def main():
from DIRAC.Core.Utilities.Plotting.FileCoding import extractRequestFromFileId
Script.parseCommandLine()
Script.registerArgument(["URL: encoded URL of a DIRAC Accounting plot"])

fileIds = Script.getPositionalArgs()
_, fileIds = Script.parseCommandLine()

for fileId in fileIds:
# Try to find if it's a url
Expand All @@ -53,4 +46,4 @@ def main():


if __name__ == "__main__":
main()
main()
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
########################################################################
"""
Command line administrative interface to DIRAC Accounting DataStore Service

Usage:
dirac-admin-accounting-cli [options] ...
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

__RCSID__ = "$Id$"

from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script


@DIRACScript()
@Script()
def main():
Script.localCfg.addDefaultEntry("LogLevel", "info")
Script.parseCommandLine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

import six

from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
from DIRAC import gLogger, exit as DIRACExit
from DIRAC.ConfigurationSystem.Client.Utilities import getGridCEs, getSiteUpdates
from DIRAC.Core.Utilities.Subprocess import systemCall
Expand Down Expand Up @@ -256,7 +255,7 @@ def handler(signum, frame):
DIRACExit(-1)


@DIRACScript()
@Script()
def main():
signal.signal(signal.SIGTERM, handler)
signal.signal(signal.SIGINT, handler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,29 @@
########################################################################
"""
Adds or modify a shifter, in the operations section of the CS

Usage:
dirac-admin-add-shifter [options] ... ShifterRole UserName DIRACGroup ...

Arguments:
ShifterRole: Name of the shifter role, e.g. DataManager
UserName: A user name, as registered in Registry section
DIRACGroup: DIRAC Group, e.g. diracAdmin (the user has to have this role)
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

__RCSID__ = "$Id$"

from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
from DIRAC.ConfigurationSystem.Client.CSAPI import CSAPI
from DIRAC import exit as DIRACExit, gLogger


@DIRACScript()
@Script()
def main():
# Registering arguments will automatically add their description to the help menu
Script.registerArgument("ShifterRole: Name of the shifter role, e.g. DataManager")
Script.registerArgument("UserName: A user name, as registered in Registry section")
Script.registerArgument("DIRACGroup: DIRAC Group, e.g. diracAdmin (the user has to have this role)")
Script.parseCommandLine(ignoreErrors=True)
args = Script.getPositionalArgs()

csAPI = CSAPI()

if len(args) < 3:
Script.showHelp(exitCode=1)

shifterRole = args[0]
userName = args[1]
diracGroup = args[2]

shifterRole, userName, diracGroup = Script.getPositionalArgs(group=True)
res = csAPI.addShifter({shifterRole: {'User': userName, 'Group': diracGroup}})
if not res['OK']:
gLogger.error("Could not add shifter", ": " + res['Message'])
Expand Down
28 changes: 10 additions & 18 deletions src/DIRAC/ConfigurationSystem/scripts/dirac_admin_add_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,34 @@
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 [options] ... 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
$ dirac-admin-add-site LCG.IN2P3.fr IN2P3-Site ce01.in2p3.fr
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

__RCSID__ = "$Id$"

import six

from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.DIRACScript import DIRACScript
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
from DIRAC import exit as DIRACExit, gLogger
from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getDIRACSiteName
from DIRAC.ConfigurationSystem.Client.CSAPI import CSAPI


@DIRACScript()
@Script()
def main():
# Registering arguments will automatically add their description to the help menu
Script.registerArgument("DIRACSiteName: Name of the site for DIRAC in the form GRID.LOCATION.COUNTRY "
"(ie: LCG.CERN.ch)")
Script.registerArgument("GridSiteName: Name of the site in the Grid (ie: CERN-PROD)")
Script.registerArgument(["CE: Name of the CE to be included in the site (ie: ce111.cern.ch)"])
Script.parseCommandLine(ignoreErrors=True)
args = Script.getPositionalArgs()

if len(args) < 3:
Script.showHelp(exitCode=1)
diracSiteName, gridSiteName, ces = Script.getPositionalArgs(group=True)

diracSiteName = args[0]
gridSiteName = args[1]
ces = args[2:]
try:
diracGridType, place, country = diracSiteName.split('.')
except ValueError:
Expand Down
Loading