Skip to content

Commit 4b04b95

Browse files
committed
fix: automated session init, removed dinit
1 parent 233dd62 commit 4b04b95

File tree

5 files changed

+34
-139
lines changed

5 files changed

+34
-139
lines changed

docs/source/UserGuide/commands.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ Commands Reference
77
This page is the work in progress.
88

99
The shorthand section contains short commands specifically developed for the interactive use of a DIRAC UI.
10-
To be able to use these commands, please check the :ref:`shorthand_cmd` section for an
11-
introduction and initial setup.
10+
For a complete list of these commands, please check the :ref:`shorthand_cmd` section. Please note that you will need to get a proxy using your usual dirac-proxy-init command before you are able to use the shorthand commands.
1211

1312
.. toctree::
1413
:maxdepth: 1

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ console_scripts =
241241
dfind = DIRAC.Interfaces.scripts.dfind:main
242242
dget = DIRAC.Interfaces.scripts.dget:main
243243
dgetenv = DIRAC.Interfaces.scripts.dgetenv:main
244-
dinit = DIRAC.Interfaces.scripts.dinit:main
245244
dkill = DIRAC.Interfaces.scripts.dkill:main
246245
dlogging = DIRAC.Interfaces.scripts.dlogging:main
247246
dls = DIRAC.Interfaces.scripts.dls:main

src/DIRAC/Interfaces/Utilities/DCommands.py

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -292,24 +292,44 @@ def sessionFilename(cls, pid):
292292
return cls.sessionFilePrefix() + ".%d" % (pid,)
293293

294294
def __init__(self, profileName=None, config=None, sessionDir=None, pid=None):
295-
self.origin = config or DConfig()
295+
if not config:
296+
config = DConfig()
297+
298+
if not profileName:
299+
proxyPath = _getProxyLocation()
300+
if not proxyPath:
301+
gLogger.error("No proxy found")
302+
return None
303+
304+
retVal = _getProxyInfo(proxyPath)
305+
if not retVal["OK"]:
306+
raise Exception(retVal["Message"])
307+
proxyInfo = retVal["Value"]
308+
groupName = proxyInfo.get("group")
309+
sections = config.sections()
310+
for s in sections:
311+
if config.has(s, "group_name") and config.get(s, "group_name")["Value"] == groupName:
312+
profileName = s
313+
break
314+
if not profileName:
315+
if not groupName:
316+
raise Exception("cannot guess profile defaults without a DIRAC group in Proxy")
317+
profileName = "__guessed_profile__"
318+
userName = proxyInfo.get("username")
319+
gLogger.warn(f"No config section found for {groupName}, using default profile.")
320+
guessConfigFromCS(config, profileName, userName, groupName)
321+
322+
self.origin = config
296323
modified = self.origin.fillMinimal()
297324
if modified:
298325
self.origin.write()
299326

300327
self.pid = pid
301328
if not self.pid:
302-
if "DCOMMANDS_PPID" in os.environ:
303-
self.pid = int(os.environ["DCOMMANDS_PPID"])
304-
else:
305-
self.pid = os.getppid()
329+
self.pid = os.getppid()
306330

307331
if not sessionDir:
308-
var = "DCOMMANDS_SESSION_DIR"
309-
if var in os.environ:
310-
sessionDir = os.environ[var]
311-
else:
312-
sessionDir = self.origin.configDir
332+
sessionDir = self.origin.configDir
313333

314334
super().__init__(sessionDir, self.sessionFilename(self.pid))
315335

@@ -575,43 +595,10 @@ def guessConfigFromCS(config, section, userName, groupName):
575595
config.set(section, "default_se", defaultSESite)
576596

577597

578-
def sessionFromProxy(config=DConfig(), sessionDir=None):
579-
proxyPath = _getProxyLocation()
580-
if not proxyPath:
581-
gLogger.error("No proxy found")
582-
return None
583-
584-
retVal = _getProxyInfo(proxyPath)
585-
if not retVal["OK"]:
586-
raise Exception(retVal["Message"])
587-
588-
pi = retVal["Value"]
589-
try:
590-
groupName = pi["group"]
591-
except KeyError:
592-
groupName = None
593-
594-
sections = config.sections()
595-
match = None
596-
597-
for s in sections:
598-
if config.has(s, "group_name") and config.get(s, "group_name")["Value"] == groupName:
599-
match = s
600-
break
601-
602-
if not match:
603-
if not groupName:
604-
raise Exception("cannot guess profile defaults without a DIRAC group in Proxy")
605-
606-
match = "__guessed_profile__"
607-
userName = pi["username"]
608-
guessConfigFromCS(config, match, userName, groupName)
609-
610-
session = DSession(match, config, sessionDir=sessionDir)
611-
598+
def sessionFromProxy(config=None, sessionDir=None):
599+
session = DSession(None, config, sessionDir=sessionDir)
612600
# force copy of config profile options to environment
613601
session.copyProfile()
614-
615602
return session
616603

617604

src/DIRAC/Interfaces/Utilities/DConfigCache.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ def cacheFilePrefix(cls):
2121
def __init__(self, forceRefresh=False):
2222
self.newConfig = True
2323
self.configCacheLifetime = 600.0 # ten minutes
24-
25-
if "DCOMMANDS_PPID" in os.environ:
26-
self.pid = int(os.environ["DCOMMANDS_PPID"])
27-
else:
28-
self.pid = os.getppid()
29-
24+
self.pid = os.getppid()
3025
self.configCacheName = os.path.join(self.cacheDir, self.cacheFilePrefix() + ".%d.%d" % (os.getuid(), self.pid))
3126

3227
if not forceRefresh:

src/DIRAC/Interfaces/scripts/dinit.py

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)