PyXMake Developer Guide: src/PyXMake/VTL/stm_cara.py Source File

| PyXMake Developer Guide 1.0 PyXMake

Loading...
Searching...
No Matches
stm_cara.py
1# -*- coding: utf-8 -*-
2# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3# % PyXMake - Build environment for PyXMake %
4# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5"""
6Install latest STM software on DLR's HPC cluster (CARA).
7
8@note: Requires GitLab access
9Created on 21.07.2020
10
11@version: 1.0
12----------------------------------------------------------------------------------------------
13@requires:
14 -
15
16@change:
17 -
18
19@author: garb_ma [DLR-FA,STM Braunschweig]
20----------------------------------------------------------------------------------------------
21"""
22import os
23import sys
24import argparse
25import posixpath
26import getpass
27import tempfile
28
29try:
30 from urllib import quote_plus #@UnresolvedImport @UnusedImport
31except:
32 from urllib.parse import quote_plus #@Reimport
33
34try:
35 import PyXMake as _ #@UnusedImport
36except ImportError:
37 # Script is executed as a plug-in
38 sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
39finally:
40 from PyXMake.Build import Make
41 from PyXMake.Tools import Utility
42
43# Predefined script local variables
44__delimn = ":"
45__user = os.getenv("username")
46
47 def main(user, key="", password="", verbosity=0, **kwargs):
48 """
49 Main function to execute the script.
50 Install STM software in the user's workspace on CARA. Installs all packages.
51 """
52 # Check if GIT credentials differ from user credentials (using access token)
53 access = kwargs.get("auth",""); directory = kwargs.get("directory","")
54 if not access: access = __delimn.join([user, getpass.getpass()])
55 if access and __delimn in access:
56 access = __delimn.join([access.split(__delimn)[0],quote_plus(access.split(__delimn)[-1])]) + "@"
57 scratch = str(next(tempfile._get_candidate_names()))
58 # Create install command
59 command = "git clone --single-branch --recursive --branch pyx_service https://%sgitlab.dlr.de/fa_sw/stmlab/PyXMake.git %s; cd %s && \
60 chmod u+x stm_cara_software.sh && echo '\nrm -rf ../%s' >> stm_cara_software.sh && \
61 sbatch stm_cara_software.sh --internal=true --user='%s' --token='%s' --directory='%s' --package='%s' --refresh='%s'" % (access, scratch,
62 scratch, scratch, access.split(__delimn)[0], access.split(__delimn)[-1].replace("@",""),
63 directory or posixpath.join(Utility.AsDrive("home", posixpath.sep),user,"software"), kwargs.get("feature","all"), str(kwargs.get("refresh","false")))
64 # Replace part of command when interactive mode is requested.
65 if kwargs.get("interactive",False): command = command.replace("sbatch","srun")
66 # Establish SSH class
67 SSHBuild = Make.SSH("cara", [], verbose=verbosity)
68 # Set output paths to empty strings
69 SSHBuild.OutputPath("")
70 # Run a custom command
71 SSHBuild.Build(command, run="custom")
72 # Establish connection with key or password.
73 SSHBuild.Settings(user, key, password=password, host="cara.dlr.de", use_cache=False)
74 SSHBuild.create(tty=True, collect=False)
75
76if __name__ == "__main__":
77# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78# % Access command line inputs %
79# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 parser = argparse.ArgumentParser(description="Install supported STM software in the user's workspace on CARA.")
81 parser.add_argument("user", metavar="user", nargs=1, help="Current user for SSH connection")
82 parser.add_argument("password", metavar="password", nargs=1, help="Password of current user")
83 parser.add_argument("--access", metavar="access", nargs=1, help="Access token for GitLab in format <Token>:<Value>")
84 parser.add_argument("--directory", metavar="directory", nargs=1, help="Installation directory (absolute path). Defaults to user workspace.")
85 parser.add_argument("--feature", metavar="feature", nargs=1, help="Name of the package to install. Defaults to all.")
86 parser.add_argument("--refresh", metavar="refresh", nargs=1, help="Reinstall the given package if already present. Defaults to False.")
87 parser.add_argument("--interactive", metavar="interactive", type=Utility.GetBoolean, const=True, default=False, nargs='?', help="Select whether the installation runs interactively.")
88
89 try:
90 _ = sys.argv[1]
91 args, _ = parser.parse_known_args()
92 except:
93 pass
94
95 try:
96 # SSH connection information
97 user = args.user[0]; key = "";
98 password = args.password[0]
99 # Optional non-default GitLab credentials
100 try: access = args.access[0]
101 except: access = __delimn.join([user,password])
102 # Optional non-default installation directory
103 try: directory = args.directory[0]
104 except: directory = posixpath.join(Utility.AsDrive("home", posixpath.sep),user,"software")
105 # Optional non-default package request
106 try: feature = args.feature[0]
107 except: feature = "all"
108 # Optional refresh package request
109 try: refresh = args.refresh[0]
110 except: refresh = False
111 # Optional non-default package request
112 try: interactive = args.interactive[0]
113 except: interactive = False
114 except:
115 # Default settings. Applicable for most users.
116 user = __user; password = ""; access = ""; directory=""; feature="all"; refresh = False; interactive=False
117 key = os.path.join(Utility.AsDrive("C"),"Users",user,"Keys","Putty","id_rsa")
118 finally:
119 # Run install script
120 main(user, key, password, auth=access, directory=directory, feature=feature, interactive=interactive, refresh=refresh)
121 # Finish
122 print("==================================")
123 print("Finished")
124 print("==================================")
125 sys.exit()
PyXMake.Build.Make.SSH
Base class for all build events requiring a SSH connection.
PyXMake.Build
Module containing all relevant modules and scripts associated with the building process.
Definition __init__.py:1
PyXMake.Tools
Module containing basic functionalities defined for convenience.
Definition __init__.py:1
PyXMake.VTL.stm_cara.main
main(user, key="", password="", verbosity=0, **kwargs)
Definition stm_cara.py:47