PyXMake Developer Guide: D:/03_Workspaces/01_Eclipse/pyx_core/PyXMake/Build/__install__.py Source File

| PyXMake Developer Guide 1.0 PyXMake

__install__.py
1 # -*- coding: utf-8 -*-
2 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 # % Installation %
4 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 """
6 Fetch 3rd party dependencies for PyXMake from DLR's resource server.
7
8 @note: PyXMake 3rd party dependency installer
9 Created on 04.08.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 """
22
23 ## @package PyXMake.Build.__install__
24 # Fetch 3rd party dependencies for PyXMake from DLR's resource server.
25 ## @author
26 # Marc Garbade
27 ## @date
28 # 04.08.2020
29 ## @par Notes/Changes
30 # - Added documentation // mg 04.08.2020
31
32 import os
33 import urllib.request
34 import subprocess
35 import zipfile
36
37 from PyXMake import Build
38 from PyXMake.Tools import Utility
39
40 # Some immutable variables
41 __pyx_dependency = ["perl","latex","pandoc"]
42
43 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 # % Execute install script %
45 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 if __name__ == '__main__':
47
48 # Loop over all dependencies
49 for __package in __pyx_dependency:
50
51 # Resolve the correct name.
52 if __package.lower() == "perl":
53 package_name = "Perl"
54 elif __package.lower() == "latex":
55 package_name = "MikTeX"
56 elif __package.lower() == "pandoc":
57 package_name = "Pandoc"
58 else:
59 raise NotImplementedError
60
61 # Set some temporary variables for path manipulations.
62 __pyx_url_delimn = "/"; __pyx_point = "."; __pyx_space = " ";
63 __pyx_package_url = __pyx_url_delimn.join(["https:","","fa-jenkins2:8080","job","STM_Archive","lastSuccessfulBuild","artifact","Archive", __pyx_point.join([package_name, "zip"])])
64
65 # Download a ZIP archive and store its content temporarily in the user's download folder.
66 __pyx_zip_file = __pyx_package_url.rsplit(__pyx_url_delimn, 1)[-1].lower()
67 __pyx_package = os.path.join(Build.__path__[0],"bin",__pyx_zip_file.split(".")[0])
68 __pyx_source = __pyx_zip_file.split(".")[0]
69
70 try:
71 # Check if dependency can be executed on the current machine.
72 subprocess.check_call([__package.lower(), "--help"])
73 except OSError:
74 # Executable not found. Attempt installation from archive
75 if __debug__ and not os.path.exists(__pyx_package):
76
77 # Attempt remote installation from STM Archive.
78 print('==================================')
79 print('%s is required for the current process, but is' % __package.upper())
80 print('not found on your machine.')
81 print('Fetching portable installation from STM archive. ')
82 print('==================================')
83
84 # Download a ZIP archive and store its content temporarily in the user's download folder.
85 download_path = os.path.join(os.path.expanduser('~/Downloads'), __pyx_zip_file)
86 urllib.request.urlretrieve(__pyx_package_url, download_path)
87
88 # Extract archive into binary folder
89 with zipfile.ZipFile(download_path, 'r') as zip_folder:
90 zip_folder.extractall(__pyx_package)
91
92 # Print success message.
93 print('==================================')
94 print('Successfully installed %s' % __package.upper())
95 print('==================================')
96
97 # Remove temporary download path
98 os.remove(download_path)
99 finally:
100
101 # Package exists on the current machine or was installed.
102 if os.path.exists(__pyx_package):
103 pathlist = list([])
104 # Add portable PERL distribution to overall path
105 if os.path.exists(os.path.join(__pyx_package,__pyx_source,"site","bin")):
106 pathlist.extend([os.path.join(__pyx_package,__pyx_source,"site","bin"),os.path.join(__pyx_package,__pyx_source,"bin"),os.path.join(__pyx_package,"c","bin")])
107 # Add portable LATEX distribution (MikTeX) to overall path
108 elif os.path.exists(os.path.join(__pyx_package,"texmfs","install",__pyx_source,"bin","x64")):
109 pathlist.append(os.path.join(__pyx_package,"texmfs","install",__pyx_source,"bin","x64"))
110 # Add portable PANDOC distribution to overall path
111 else:
112 pathlist.append(__pyx_package)
113 # Modify the current path variable
114 os.environ["PATH"] += os.pathsep + os.pathsep.join(pathlist)
115
116 # Run command to check validity of the installation
117 assert Utility.Popen(__pyx_space.join([__package,"--help"]),0).returncode == 0
PyXMake.Tools
Module containing basic functionalities defined for convenience.
Definition: __init__.py:1