|
20 | 20 |
|
21 | 21 | FC:/>
|
22 | 22 | """
|
23 |
| -import sys |
24 | 23 |
|
25 | 24 | from DIRAC.Core.Base.Script import Script
|
26 | 25 |
|
27 | 26 |
|
28 | 27 | @Script()
|
29 | 28 | def main():
|
30 |
| - fcType = "FileCatalog" |
| 29 | + fcType = None |
| 30 | + catalog = None |
31 | 31 | Script.registerSwitch("f:", "file-catalog=", f" Catalog client type to use (default {fcType})")
|
32 | 32 | Script.parseCommandLine(ignoreErrors=False)
|
33 | 33 |
|
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 |
46 | 35 |
|
47 | 36 | for switch in Script.getUnprocessedSwitches():
|
48 | 37 | if switch[0].lower() == "f" or switch[0].lower() == "file-catalog":
|
49 | 38 | fcType = switch[1]
|
50 | 39 |
|
51 | 40 | 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("Starting FileCatalog container client:") |
| 63 | + print(f" {masterCatalog} - Master") |
| 64 | + for cat in allCatalogs: |
| 65 | + if cat != masterCatalog: |
| 66 | + cTypes = ["Write"] if cat in writeCatalogs else [] |
| 67 | + cTypes.extend(["Read"] if cat in readCatalogs else []) |
| 68 | + print(f" {cat} - {'-'.join(cTypes)}") |
| 69 | + print("") |
| 70 | + |
| 71 | + if fcType: |
| 72 | + from DIRAC.Resources.Catalog.FileCatalogFactory import FileCatalogFactory |
| 73 | + |
| 74 | + result = FileCatalogFactory().createCatalog(fcType) |
| 75 | + if not result["OK"]: |
| 76 | + print(result["Message"]) |
| 77 | + dexit(-1) |
| 78 | + catalog = result["Value"] |
| 79 | + print(f"Starting {fcType} client") |
54 | 80 |
|
55 | 81 | from DIRAC.DataManagementSystem.Client.FileCatalogClientCLI import FileCatalogClientCLI
|
56 | 82 |
|
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 | 83 | cli = FileCatalogClientCLI(catalog)
|
68 | 84 | cli.cmdloop()
|
69 | 85 |
|
|
0 commit comments