Skip to content
Snippets Groups Projects
Commit b8350e0c authored by Damian Alvarez's avatar Damian Alvarez
Browse files

To make the contact injection logic a bit more robust

parent 14a7ac22
No related branches found
No related tags found
No related merge requests found
import grp
import os import os
import subprocess
from easybuild.tools.run import run_cmd from easybuild.tools.run import run_cmd
from easybuild.tools.config import build_option from easybuild.tools.config import build_option
...@@ -80,6 +80,46 @@ def installation_vetoer(ec): ...@@ -80,6 +80,46 @@ def installation_vetoer(ec):
print_msg(f"- {package}", stderr=True) print_msg(f"- {package}", stderr=True)
exit(1) exit(1)
def get_user_info():
# Query jutil to extract the contact information
jutil = subprocess.Popen([os.getenv('JUMO_USRCMD_EXEC'), 'person', 'show'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = jutil.communicate()
if not stderr:
return stdout.decode('utf-8').splitlines()[-1]
else:
print_warning(f'Could not query jutil: {stderr}')
exit(1)
def inject_site_contact(ec, site_contacts):
key = "site_contacts"
value = site_contacts
ec_dict = ec.asdict()
if key in ec_dict:
if ec_dict[key] is not None:
# Check current values if it is a list
if isinstance(ec_dict[key], list):
for contact in ec_dict[key]:
# Already in contact
if site_contacts in contact:
break
# We looped to the end and did not find the contact in this list
else:
# Do not add the generic one if there are other specific contacts
if 'sc@fz-juelich.de' not in site_contacts or len(ec_dict[key]) == 0:
ec.log.info("[parse hook] Injecting contact %s", value)
ec[key].append(site_contacts)
# Check current values if it is a string
else:
# Do not add the generic one if there are other specific contacts
if site_contacts not in ec_dict[key] and 'sc@fz-juelich.de' not in site_contacts:
ec.log.info("[parse hook] Injecting contact %s", value)
ec[key] = [ec_dict[key], site_contacts]
else:
ec.log.info("[parse hook] Injecting contact %s", value)
ec[key] = value
return ec
def parse_hook(ec, *args, **kwargs): def parse_hook(ec, *args, **kwargs):
"""Custom parse hook to manage installations intended for JSC systems.""" """Custom parse hook to manage installations intended for JSC systems."""
...@@ -166,13 +206,16 @@ family("mpi") ...@@ -166,13 +206,16 @@ family("mpi")
# Check where installations are going to go and add appropriate site contact # Check where installations are going to go and add appropriate site contact
# not sure of a fool-proof way to do this, let's just try a heuristic # not sure of a fool-proof way to do this, let's just try a heuristic
site_contacts = None site_contacts = None
if "stages" in install_path().lower(): # Non-user installation
users_groups = [grp.getgrgid(g).gr_name for g in os.getgroups()] if '/p/software' in install_path().lower() or '/gpfs/software' in install_path().lower():
if any(group in users_groups for group in ["swmanage", "software"]): if 'swmanage' in os.getenv('USER'):
site_contacts = "sc@fz-juelich.de" site_contacts = 'sc@fz-juelich.de'
if site_contacts is None: else:
site_contacts = get_user_info()
# Inject the user # Inject the user
site_contacts = os.getenv("USER") ec = inject_site_contact(ec, site_contacts)
# User installation
else:
# Tag the build as a user build # Tag the build as a user build
key = "modluafooter" key = "modluafooter"
value = 'add_property("build","user")' value = 'add_property("build","user")'
...@@ -182,14 +225,9 @@ family("mpi") ...@@ -182,14 +225,9 @@ family("mpi")
else: else:
ec[key] = value ec[key] = value
ec.log.info("[parse hook] Injecting user as Lmod build property") ec.log.info("[parse hook] Injecting user as Lmod build property")
if site_contacts: # Inject the user
key = "site_contacts" site_contacts = get_user_info()
value = site_contacts ec = inject_site_contact(ec, site_contacts)
if key in ec_dict:
if ec_dict[key] is not None and value not in ec_dict[key]:
value = ",".join([ec_dict[key], value])
ec[key] = value
ec.log.info("[parse hook] Injecting contact %s", value)
# If we are parsing we are not searching, in this case if the easyconfig is # If we are parsing we are not searching, in this case if the easyconfig is
# located in the search path, warn that it's dependencies will (most probably) # located in the search path, warn that it's dependencies will (most probably)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment