Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #89 from TaykYoku/integration_fix-1
Browse files Browse the repository at this point in the history
[Integration] use DIRAC.Core.Base.Script
  • Loading branch information
TaykYoku authored Jun 11, 2022
2 parents 1d67f5e + aa51c22 commit ebe3b4a
Show file tree
Hide file tree
Showing 30 changed files with 216 additions and 549 deletions.
4 changes: 0 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from setuptools import setup

# This is required to allow editable pip installs while using the declarative configuration (setup.cfg)
Expand Down
6 changes: 3 additions & 3 deletions src/COMDIRAC/Interfaces/Utilities/DCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def listFormatJSON(summaries, headers=None, sortKeys=None):
return json.dumps(l)


class ArrayFormatter(object):
class ArrayFormatter:
fmts = {"csv": listFormatCSV, "pretty": listFormatPretty, "json": listFormatJSON}

def __init__(self, outputFormat):
Expand Down Expand Up @@ -140,7 +140,7 @@ def dictFormat(self, dict_, headers=None, sort=None):
# -------------------------------


class DConfig(object):
class DConfig:
def __init__(self, configDir=None, configFilename="dcommands.conf"):
try:
self.config = ConfigParser(allow_no_value=True)
Expand Down Expand Up @@ -700,7 +700,7 @@ def createCatalog():
return FileCatalog()


class DCatalog(object):
class DCatalog:
"""
DIRAC File Catalog helper
"""
Expand Down
7 changes: 3 additions & 4 deletions src/COMDIRAC/Interfaces/Utilities/DConfigCache.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import os
import re
import stat
import time
import re

import pickle

from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
from DIRAC.Core.Base.Script import Script
from DIRAC.ConfigurationSystem.Client.ConfigurationData import gConfigurationData


Expand All @@ -26,7 +25,7 @@ def proxy_lcg_protocols_if_missing():
)


class ConfigCache(object):
class ConfigCache:
@classmethod
def cacheFilePrefix(cls):
return "DSession.configCache"
Expand Down
29 changes: 9 additions & 20 deletions src/COMDIRAC/Interfaces/scripts/dcd.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
#! /usr/bin/env python

"""
Change current DIRAC File Catalog working directory
Examples:
$ dcd /dirac/user
$ dcd
"""
from COMDIRAC.Interfaces import critical
from COMDIRAC.Interfaces import DSession
from COMDIRAC.Interfaces import DCatalog
from COMDIRAC.Interfaces import pathFromArgument
from COMDIRAC.Interfaces import ConfigCache

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


@Script()
def main():
Script.setUsageMessage(
"\n".join(
[
__doc__.split("\n")[1],
"Usage:",
" %s [Path]" % Script.scriptName,
"Arguments:",
" Path: path to new working directory (defaults to home directory)",
"",
"Examples:",
" $ dcd /dirac/user",
" $ dcd",
]
)
Script.registerArgument(
"Path: path to new working directory (defaults to home directory)",
mandatory=False,
)

configCache = ConfigCache()
Expand All @@ -36,14 +28,11 @@ def main():

args = Script.getPositionalArgs()

import DIRAC

session = DSession()

if len(args) > 1:
print("Error: too many arguments provided\n%s:" % Script.scriptName)
Script.showHelp()
DIRAC.exit(-1)
Script.showHelp(exitCode=-1)

if len(args):
arg = pathFromArgument(session, args[0])
Expand Down
42 changes: 10 additions & 32 deletions src/COMDIRAC/Interfaces/scripts/dchgrp.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#! /usr/bin/env python
########################################################################
# $HeadURL$
########################################################################

"""
Change file owner's group
Examples:
$ dchown atsareg ././some_lfn_file
$ dchown -R pgay ./
"""
from COMDIRAC.Interfaces import ConfigCache
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
from DIRAC.Core.Base.Script import Script
from DIRAC import S_OK


class Params(object):
class Params:
def __init__(self):
self.recursive = False

Expand All @@ -27,46 +27,24 @@ def getRecursive(self):
def main():
params = Params()

Script.setUsageMessage(
"\n".join(
[
__doc__.split("\n")[1],
"Usage:",
" %s [options] group Path..." % Script.scriptName,
"Arguments:",
" group: new group name",
" Path: path to file",
"",
"Examples:",
" $ dchown atsareg ././some_lfn_file",
" $ dchown -R pgay ./",
]
)
)
Script.registerArgument(" group: new group name")
Script.registerArgument(["Path: path to file"])
Script.registerSwitch("R", "recursive", "recursive", params.setRecursive)

configCache = ConfigCache()
Script.parseCommandLine(ignoreErrors=True)
configCache.cacheConfig()

args = Script.getPositionalArgs()
group, paths = Script.getPositionalArgs(group=True)

import DIRAC
from DIRAC import gLogger
from COMDIRAC.Interfaces import DSession
from COMDIRAC.Interfaces import pathFromArgument

session = DSession()

if len(args) < 2:
print("Error: not enough arguments provided\n%s:" % Script.scriptName)
Script.showHelp()
DIRAC.exit(-1)

group = args[0]

lfns = []
for path in args[1:]:
for path in paths:
lfns.append(pathFromArgument(session, path))

from DIRAC.Resources.Catalog.FileCatalog import FileCatalog
Expand Down
38 changes: 10 additions & 28 deletions src/COMDIRAC/Interfaces/scripts/dchmod.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#! /usr/bin/env python
"""
Change file mode bits
Examples:
$ dchmod 755 ././some_lfn_file
$ dchmod -R 700 ./
"""
from COMDIRAC.Interfaces import ConfigCache
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
from DIRAC.Core.Base.Script import Script
from DIRAC import S_OK


class Params(object):
class Params:
def __init__(self):
self.recursive = False

Expand All @@ -23,46 +27,24 @@ def getRecursive(self):
def main():
params = Params()

Script.setUsageMessage(
"\n".join(
[
__doc__.split("\n")[1],
"Usage:",
" %s [options] mode Path..." % Script.scriptName,
"Arguments:",
" mode: octal mode bits",
" Path: path to file",
"",
"Examples:",
" $ dchmod 755 ././some_lfn_file",
" $ dchmod -R 700 ./",
]
)
)
Script.registerArgument(" mode: octal mode bits")
Script.registerArgument(["Path: path to file"])
Script.registerSwitch("R", "recursive", "recursive", params.setRecursive)

configCache = ConfigCache()
Script.parseCommandLine(ignoreErrors=True)
configCache.cacheConfig()

args = Script.getPositionalArgs()
mode, paths = Script.getPositionalArgs(group=True)

import DIRAC
from DIRAC import gLogger
from COMDIRAC.Interfaces import DSession
from COMDIRAC.Interfaces import pathFromArgument

session = DSession()

if len(args) < 2:
print("Error: not enough arguments provided\n%s:" % Script.scriptName)
Script.showHelp()
DIRAC.exit(-1)

mode = args[0]

lfns = []
for path in args[1:]:
for path in paths:
lfns.append(pathFromArgument(session, path))

from DIRAC.Resources.Catalog.FileCatalog import FileCatalog
Expand Down
38 changes: 10 additions & 28 deletions src/COMDIRAC/Interfaces/scripts/dchown.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#! /usr/bin/env python
"""
Change file owner
Examples:
$ dchown atsareg ././some_lfn_file
$ dchown -R pgay ./
"""
from COMDIRAC.Interfaces import ConfigCache
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
from DIRAC.Core.Base.Script import Script
from DIRAC import S_OK


class Params(object):
class Params:
def __init__(self):
self.recursive = False

Expand All @@ -23,46 +27,24 @@ def getRecursive(self):
def main():
params = Params()

Script.setUsageMessage(
"\n".join(
[
__doc__.split("\n")[1],
"Usage:",
" %s [options] owner Path..." % Script.scriptName,
"Arguments:",
" owner: new owner name",
" Path: path to file",
"",
"Examples:",
" $ dchown atsareg ././some_lfn_file",
" $ dchown -R pgay ./",
]
)
)
Script.registerArgument(" owner: new owner name")
Script.registerArgument(["Path: path to file"])
Script.registerSwitch("R", "recursive", "recursive", params.setRecursive)

configCache = ConfigCache()
Script.parseCommandLine(ignoreErrors=True)
configCache.cacheConfig()

args = Script.getPositionalArgs()
owner, paths = Script.getPositionalArgs(group=True)

import DIRAC
from DIRAC import gLogger
from COMDIRAC.Interfaces import DSession
from COMDIRAC.Interfaces import pathFromArgument

session = DSession()

if len(args) < 2:
print("Error: not enough arguments provided\n%s:" % Script.scriptName)
Script.showHelp()
DIRAC.exit(-1)

owner = args[0]

lfns = []
for path in args[1:]:
for path in paths:
lfns.append(pathFromArgument(session, path))

from DIRAC.Resources.Catalog.FileCatalog import FileCatalog
Expand Down
32 changes: 11 additions & 21 deletions src/COMDIRAC/Interfaces/scripts/dconfig.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#! /usr/bin/env python

"""
configure DCommands
"""
import DIRAC
from DIRAC import S_OK
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
from DIRAC.Core.Base.Script import Script

from COMDIRAC.Interfaces import (
DConfig,
Expand All @@ -16,7 +15,7 @@
from COMDIRAC.Interfaces import getDNFromProxy


class Params(object):
class Params:
def __init__(self):
self.minimal = False
self.guessProfile = False
Expand All @@ -40,22 +39,13 @@ def getGuessProfiles(self):
def main():
params = Params()

Script.setUsageMessage(
"\n".join(
[
__doc__.split("\n")[1],
"Usage:",
" %s [options] [section[.option[=value]]]..." % Script.scriptName,
"Arguments:",
" without argument: display whole configuration content",
"++ OR ++",
" section: display all options in section",
"++ OR ++",
" section.option: display option",
"++ OR ++",
" section.option=value: set option value",
]
)
Script.registerArgument(
[
"section[.option[=value]]: section: display all options in section\n"
" section.option: display option\n"
" section.option=value: set option value"
],
mandatory=False,
)
Script.registerSwitch(
"m", "minimal", "verify and fill minimal configuration", params.setMinimal
Expand All @@ -77,12 +67,12 @@ def main():
Script.enableCS()
result = getDNFromProxy()
if not result["OK"]:
print("ERROR: %s" % result["Message"])
print("ERROR:", result["Message"])
DIRAC.exit(2)
dn = result["Value"]
result = guessProfilesFromCS(dn)
if not result["OK"]:
print("ERROR: %s" % result["Message"])
print("ERROR:", result["Message"])
DIRAC.exit(2)
profiles = result["Value"]

Expand Down
Loading

0 comments on commit ebe3b4a

Please sign in to comment.