Skip to content

Commit 31a9122

Browse files
authored
Merge pull request #6855 from atsareg/dev-fccli
[8.0] Use default VO File Catalog in the CLI
2 parents b20d7ba + 63ec378 commit 31a9122

File tree

1 file changed

+52
-29
lines changed

1 file changed

+52
-29
lines changed

src/DIRAC/DataManagementSystem/scripts/dirac_dms_filecatalog_cli.py

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,52 +20,75 @@
2020
2121
FC:/>
2222
"""
23-
import sys
2423

2524
from DIRAC.Core.Base.Script import Script
2625

2726

2827
@Script()
2928
def main():
30-
fcType = "FileCatalog"
31-
Script.registerSwitch("f:", "file-catalog=", f" Catalog client type to use (default {fcType})")
29+
fcType = None
30+
catalog = None
31+
Script.registerSwitch("f:", "file-catalog=", f" Catalog to use (default - Catalog defined for the users' VO)")
3232
Script.parseCommandLine(ignoreErrors=False)
3333

34-
from DIRAC import gConfig, exit as dexit
35-
from DIRAC.Resources.Catalog.FileCatalogFactory import FileCatalogFactory
36-
37-
fcType = gConfig.getValue("/LocalSite/FileCatalog", "")
38-
39-
res = gConfig.getSections("/Resources/FileCatalogs", listOrdered=True)
40-
if not res["OK"]:
41-
dexit(1)
42-
fcList = res["Value"]
43-
if not fcType:
44-
if res["OK"]:
45-
fcType = res["Value"][0]
34+
from DIRAC import exit as dexit
4635

4736
for switch in Script.getUnprocessedSwitches():
4837
if switch[0].lower() == "f" or switch[0].lower() == "file-catalog":
4938
fcType = switch[1]
5039

5140
if not fcType:
52-
print("No file catalog given and defaults could not be obtained")
53-
sys.exit(1)
41+
# A particular catalog is not specified, try to instantiate the catalog container
42+
from DIRAC.Resources.Catalog.FileCatalog import FileCatalog
43+
44+
catalog = FileCatalog()
45+
if not catalog.valid:
46+
print("Failed to create the FileCatalog container. Try to use a specific catalog with -f option")
47+
dexit(-1)
48+
result = catalog.getMasterCatalogNames()
49+
if not result["OK"]:
50+
print("Failed to get the Master catalog name for the FileCatalog container")
51+
dexit(-1)
52+
masterCatalog = result["Value"][0]
53+
readCatalogs = [c[0] for c in catalog.getReadCatalogs()]
54+
writeCatalogs = [c[0] for c in catalog.getWriteCatalogs()]
55+
allCatalogs = list(set([masterCatalog] + readCatalogs + writeCatalogs))
56+
57+
if len(allCatalogs) == 1:
58+
# If we have a single catalog in the container, let's use this catalog directly
59+
fcType = allCatalogs[0]
60+
catalog = None
61+
else:
62+
print(
63+
"\nStarting FileCatalog container console. \n"
64+
"Note that you will access several catalogs at the same time:"
65+
)
66+
print(f" {masterCatalog} - Master")
67+
for cat in allCatalogs:
68+
if cat != masterCatalog:
69+
cTypes = ["Write"] if cat in writeCatalogs else []
70+
cTypes.extend(["Read"] if cat in readCatalogs else [])
71+
print(f" {cat} - {'-'.join(cTypes)}")
72+
print("If you want to work with a single catalog, specify it with the -f option\n")
73+
74+
if fcType:
75+
# We have to use a specific File Catalog, create it now
76+
from DIRAC.Resources.Catalog.FileCatalogFactory import FileCatalogFactory
77+
78+
result = FileCatalogFactory().createCatalog(fcType)
79+
if not result["OK"]:
80+
print(result["Message"])
81+
dexit(-1)
82+
catalog = result["Value"]
83+
print(f"Starting {fcType} console")
5484

5585
from DIRAC.DataManagementSystem.Client.FileCatalogClientCLI import FileCatalogClientCLI
5686

57-
result = FileCatalogFactory().createCatalog(fcType)
58-
if not result["OK"]:
59-
print(result["Message"])
60-
if fcList:
61-
print("Possible choices are:")
62-
for fc in fcList:
63-
print(" " * 5, fc)
64-
sys.exit(1)
65-
print(f"Starting {fcType} client")
66-
catalog = result["Value"]
67-
cli = FileCatalogClientCLI(catalog)
68-
cli.cmdloop()
87+
if catalog:
88+
cli = FileCatalogClientCLI(catalog)
89+
cli.cmdloop()
90+
else:
91+
print(f"Failed to access the catalog {fcType if fcType else 'container'}")
6992

7093

7194
if __name__ == "__main__":

0 commit comments

Comments
 (0)