PyXMake Developer Guide 1.0
PyXMake
Loading...
Searching...
No Matches
docker.py
1# -*- coding: utf-8 -*-
2# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3# % PyXMake - Build environment for PyXMake %
4# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5"""
6Minimum working example for PyXMake.
7
8@note: Install Docker on any machine.
9Created on 29.10.2021
10
11@version: 1.0
12----------------------------------------------------------------------------------------------
13@requires:
14 - PyXMake
15
16@change:
17 -
18
19@author: garb_ma [DLR-FA,STM Braunschweig]
20----------------------------------------------------------------------------------------------
21"""
22import os, sys
23import argparse
24import subprocess
25
26try:
27 import PyXMake as _ #@UnusedImport
28except ImportError:
29 # Script is executed as a plug-in
30 __package = "PyCODAC"
31 sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
32 if __package in os.path.abspath(__file__): sys.path.insert(0,os.path.join(str(os.path.abspath(__file__)).split(__package)[0],__package,"Plugin"))
33finally:
34 from PyXMake.Tools import Utility #@UnresolvedImport
35
36def main(directory=False, feature=False):
37 """
38 Main function to execute the script.
39 Installs Docker on the current machine (Windows)
40 """
41 delimn = "="
42 if Utility.GetPlatform() in ["windows"]:
43 if not directory or not os.path.exists(directory): raise FileNotFoundError
44 if not feature or not feature in ["linux","windows","all"]: raise IOError
45 # Parse all installation arguments to install script (Powershell)
46 subprocess.check_call([Utility.GetExecutable("powershell", get_path=True)[-1],
47 os.path.join(Utility.GetPyXMakePath(),"Build","config","stm_docker.ps1"),
48 directory,delimn.join(["--package",feature])])
49 else:
50 import wget
51 # Download install script
52 wget.download("https://get.docker.com", 'get-docker.sh')
53 # Install Docker in its default location.
54 subprocess.check_call(["sudo","sh","get-docker.sh","&&","rm","-rf","get-docker.sh"])
55 raise NotImplementedError
56 pass
57
58if __name__ == "__main__":
59 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 # % Access command line inputs %
61 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 parser = argparse.ArgumentParser(description="Set up Docker in WSL2 on the current machine. Requires administrator privileges if Windows containers are desired.")
63 parser.add_argument("--directory", metavar="directory", nargs=1, help="Installation directory (absolute path). Defaults to user workspace.")
64 parser.add_argument("--feature", metavar="feature", nargs=1, help="Name of the package to install. Defaults to all.")
65
66 try:
67 _ = sys.argv[1]
68 args, _ = parser.parse_known_args()
69 # Extract command line option to identify the requested make operation
70 try: directory = args.directory[0]
71 except: directory = os.path.expanduser("~")
72 # Optional non-default package request
73 try: feature = args.feature[0]
74 except: feature = "linux"
75 except:
76 # This is the default build option
77 directory = os.path.expanduser("~");
78 feature = "linux" ;
79 finally:
80 # Run install script
81 main(directory, feature)
82 # Finish
83 print("==================================")
84 print("Finished")
85 print("==================================")
86 sys.exit()
Module containing basic functionalities defined for convenience.
Definition __init__.py:1
main(directory=False, feature=False)
Definition docker.py:36