pySIMSalabim 1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pySIMsalabim/__init__.py +21 -0
- pySIMsalabim/aux_funcs/SCLC_funcs.py +561 -0
- pySIMsalabim/aux_funcs/__init__.py +0 -0
- pySIMsalabim/aux_funcs/addons.py +55 -0
- pySIMsalabim/experiments/CV.py +918 -0
- pySIMsalabim/experiments/EQE.py +461 -0
- pySIMsalabim/experiments/JV_steady_state.py +259 -0
- pySIMsalabim/experiments/__init__.py +0 -0
- pySIMsalabim/experiments/hysteresis.py +753 -0
- pySIMsalabim/experiments/impedance.py +848 -0
- pySIMsalabim/experiments/imps.py +630 -0
- pySIMsalabim/install/__init__.py +20 -0
- pySIMsalabim/install/compile_simsalabim.py +76 -0
- pySIMsalabim/install/get_SIMsalabim.py +505 -0
- pySIMsalabim/install/get_gnu_parallel.py +107 -0
- pySIMsalabim/plots/__init__.py +0 -0
- pySIMsalabim/plots/band_diagram.py +209 -0
- pySIMsalabim/plots/plot_def.py +19 -0
- pySIMsalabim/plots/plot_functions.py +240 -0
- pySIMsalabim/tests/__init__.py +0 -0
- pySIMsalabim/tests/test_CV.py +91 -0
- pySIMsalabim/tests/test_EQE.py +97 -0
- pySIMsalabim/tests/test_IMPS.py +92 -0
- pySIMsalabim/tests/test_JV.py +88 -0
- pySIMsalabim/tests/test_hyst.py +92 -0
- pySIMsalabim/tests/test_impedance.py +89 -0
- pySIMsalabim/utils/__init__.py +25 -0
- pySIMsalabim/utils/clean_up.py +96 -0
- pySIMsalabim/utils/device_parameters.py +720 -0
- pySIMsalabim/utils/general.py +521 -0
- pySIMsalabim/utils/parallel_sim.py +654 -0
- pySIMsalabim/utils/utils.py +129 -0
- pySIMsalabim-1.dist-info/LICENSE +674 -0
- pySIMsalabim-1.dist-info/METADATA +159 -0
- pySIMsalabim-1.dist-info/RECORD +37 -0
- pySIMsalabim-1.dist-info/WHEEL +5 -0
- pySIMsalabim-1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Compile program with fpc"""
|
|
2
|
+
# Description:
|
|
3
|
+
# ------------
|
|
4
|
+
# Compile program using fpc
|
|
5
|
+
|
|
6
|
+
######### Package Imports ###################################################################
|
|
7
|
+
|
|
8
|
+
import os,subprocess
|
|
9
|
+
|
|
10
|
+
######### Function Definitions ##############################################################
|
|
11
|
+
|
|
12
|
+
def fpc_prog(prog_name,path2prog,show_term_output=True,force_fpc=True,verbose=True):
|
|
13
|
+
"""Compile program using fpc
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
prog_name : str
|
|
18
|
+
Program name (e.g. 'SimSS', 'zimt', 'SIMsalabim)
|
|
19
|
+
path2prog : str
|
|
20
|
+
String of the absolute path to the program
|
|
21
|
+
show_term_output : bool, optional
|
|
22
|
+
show terminal output from the compilation, by default True
|
|
23
|
+
force_fpc : bool, optional
|
|
24
|
+
force recompile with fpc even if compiled program already exists, by default True
|
|
25
|
+
verbose : bool, optional
|
|
26
|
+
print output of the compilation, by default True
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
is_windows = (os.name == 'nt') # Check if we are on Windows
|
|
30
|
+
path2prog = str(path2prog) # Convert to string
|
|
31
|
+
# Check if the program is already compiled
|
|
32
|
+
if (os.path.isfile(os.path.join(path2prog,prog_name+'.exe')) and is_windows) or (os.path.isfile(os.path.join(path2prog,prog_name)) and not is_windows):
|
|
33
|
+
if force_fpc:
|
|
34
|
+
if show_term_output == True:
|
|
35
|
+
output_direct = None
|
|
36
|
+
else:
|
|
37
|
+
output_direct = subprocess.DEVNULL
|
|
38
|
+
try:
|
|
39
|
+
subprocess.check_call(['fpc', prog_name.lower()+'.pas'], encoding='utf8', stdout=output_direct, cwd=path2prog, shell=is_windows)
|
|
40
|
+
except subprocess.CalledProcessError:
|
|
41
|
+
print('Error compiling '+prog_name+' in '+path2prog)
|
|
42
|
+
raise ChildProcessError
|
|
43
|
+
if verbose:
|
|
44
|
+
print('\n'+prog_name+' already existed but was recompiled'+'\n')
|
|
45
|
+
else:
|
|
46
|
+
if verbose:
|
|
47
|
+
print('\n'+prog_name+' already compiled')
|
|
48
|
+
|
|
49
|
+
else: # Compile the program
|
|
50
|
+
if show_term_output == True:
|
|
51
|
+
output_direct = None
|
|
52
|
+
else:
|
|
53
|
+
output_direct = subprocess.DEVNULL
|
|
54
|
+
try:
|
|
55
|
+
subprocess.check_call(['fpc', prog_name.lower()+'.pas'], encoding='utf8', stdout=output_direct, cwd=path2prog, shell=is_windows)
|
|
56
|
+
if verbose:
|
|
57
|
+
print('\n'+prog_name+' was not compiled so we did it!'+'\n')
|
|
58
|
+
except subprocess.CalledProcessError:
|
|
59
|
+
print('Error compiling '+prog_name+' in '+path2prog)
|
|
60
|
+
raise ChildProcessError
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if __name__ == '__main__':
|
|
66
|
+
|
|
67
|
+
print('I am not doing anything, please import me in your script'+'\n')
|
|
68
|
+
|
|
69
|
+
# System = platform.system() # Operating system
|
|
70
|
+
# is_windows = (System == 'Windows') # Check if we are on Windows
|
|
71
|
+
# if is_windows:
|
|
72
|
+
# fpc_prog('SimSS', 'c:/Users/lecor/Desktop/GitHub/SIMsalabim/SimSS')
|
|
73
|
+
# fpc_prog('zimt', 'c:/Users/lecor/Desktop/GitHub/SIMsalabim/ZimT')
|
|
74
|
+
# else:
|
|
75
|
+
# fpc_prog('SimSS', '/mnt/c/Users/lecor/Desktop/GitHub/SIMsalabim/SimSS')
|
|
76
|
+
# fpc_prog('zimt', '/mnt/c/Users/lecor/Desktop/GitHub/SIMsalabim/ZimT')
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import sys, os, subprocess, shutil, json, requests, zipfile, io
|
|
2
|
+
from packaging import version
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from getpass import getpass
|
|
5
|
+
|
|
6
|
+
######### Parameter Definitions ###################################################################
|
|
7
|
+
cwd = Path.cwd()
|
|
8
|
+
folder_name = 'kostergroup-SIMsalabim-'
|
|
9
|
+
min_fpc_version = '3.2.0'
|
|
10
|
+
|
|
11
|
+
######### Function Definitions ####################################################################
|
|
12
|
+
def cmd_yes_no_question(question, default = "yes"):
|
|
13
|
+
"""_summary_
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
question : str
|
|
18
|
+
question to ask the user
|
|
19
|
+
default : str, optional
|
|
20
|
+
default answer, by default "yes"
|
|
21
|
+
|
|
22
|
+
Returns
|
|
23
|
+
-------
|
|
24
|
+
bool
|
|
25
|
+
whether the default answer is valid or not
|
|
26
|
+
|
|
27
|
+
Raises
|
|
28
|
+
------
|
|
29
|
+
ValueError
|
|
30
|
+
If the default answer is not valid
|
|
31
|
+
"""
|
|
32
|
+
# valid answers (yes/no)
|
|
33
|
+
valid = {'yes' : True, 'y': True, 'ye': True, 'no': False, 'n': False}
|
|
34
|
+
# Set the default answer.
|
|
35
|
+
if default is None:
|
|
36
|
+
prompt = " [y/n] "
|
|
37
|
+
elif default == 'yes':
|
|
38
|
+
prompt = " [Y/n] "
|
|
39
|
+
elif default == 'no':
|
|
40
|
+
prompt = " [y/N] "
|
|
41
|
+
else:
|
|
42
|
+
raise ValueError(f"Invalid default answer: {default}\n")
|
|
43
|
+
|
|
44
|
+
while True:
|
|
45
|
+
# Capture user input
|
|
46
|
+
sys.stdout.write(question + prompt)
|
|
47
|
+
choice = input()
|
|
48
|
+
# convert the input to lowercase
|
|
49
|
+
choice = choice.lower()
|
|
50
|
+
if default is not None and choice == "":
|
|
51
|
+
# Use default value
|
|
52
|
+
return valid[default]
|
|
53
|
+
elif choice in valid:
|
|
54
|
+
# Use user input
|
|
55
|
+
return valid[choice]
|
|
56
|
+
else:
|
|
57
|
+
# Incorrect input
|
|
58
|
+
sys.stdout.write('Please respond with "y" or "n"\n')
|
|
59
|
+
|
|
60
|
+
def clear_current_working_directory(cwd, folder_name='kostergroup-SIMsalabim-'):
|
|
61
|
+
"""_summary_
|
|
62
|
+
|
|
63
|
+
Parameters
|
|
64
|
+
----------
|
|
65
|
+
cwd : string
|
|
66
|
+
Current working directory
|
|
67
|
+
folder_name : string, optional
|
|
68
|
+
Name of the folder to download, by default 'kostergroup-SIMsalabim-'
|
|
69
|
+
|
|
70
|
+
Returns
|
|
71
|
+
-------
|
|
72
|
+
bool
|
|
73
|
+
Whether the folder was removed or not
|
|
74
|
+
|
|
75
|
+
"""
|
|
76
|
+
# Clear the current working directory
|
|
77
|
+
for dirpath, dirnames, files in os.walk(cwd):
|
|
78
|
+
for dirname in dirnames:
|
|
79
|
+
if dirname.startswith(folder_name):
|
|
80
|
+
result = cmd_yes_no_question(f"Are you sure you want to overwrite the {dirname} folder?")
|
|
81
|
+
if result == True:
|
|
82
|
+
shutil.rmtree(os.path.join(cwd,dirname))
|
|
83
|
+
print(f"Found and removed a folder named {dirname}")
|
|
84
|
+
return True
|
|
85
|
+
elif result is False:
|
|
86
|
+
print(f"Not allowed to write into folder {dirname}")
|
|
87
|
+
return False
|
|
88
|
+
else:
|
|
89
|
+
# print(f"No folder found named SIMsalabim, continue.")
|
|
90
|
+
return True
|
|
91
|
+
|
|
92
|
+
def get_SIMsalabim_source(cwd, folder_name='kostergroup-SIMsalabim-',verbose=False):
|
|
93
|
+
""" Get the latest release from the Kostergroup Github
|
|
94
|
+
|
|
95
|
+
Parameters
|
|
96
|
+
----------
|
|
97
|
+
cwd : string
|
|
98
|
+
Current working directory
|
|
99
|
+
folder_name : string, optional
|
|
100
|
+
Name of the folder to download, by default 'kostergroup-SIMsalabim-'
|
|
101
|
+
verbose : bool, optional
|
|
102
|
+
Print verbose output, by default False
|
|
103
|
+
|
|
104
|
+
Returns
|
|
105
|
+
-------
|
|
106
|
+
int
|
|
107
|
+
|
|
108
|
+
0 : Success
|
|
109
|
+
2 : Failed
|
|
110
|
+
3 : Failed
|
|
111
|
+
|
|
112
|
+
"""
|
|
113
|
+
if verbose:
|
|
114
|
+
print("Getting the latest release from the Kostergroup Github")
|
|
115
|
+
# Get the SIMsalabim source code.
|
|
116
|
+
if os.path.exists(os.path.join(cwd, 'SIMsalabim')):
|
|
117
|
+
# Pop out dialog box to confirm overwriting
|
|
118
|
+
result = cmd_yes_no_question("Are you sure you want to overwrite the 'SIMsalabim' folder?")
|
|
119
|
+
if result == True:
|
|
120
|
+
# Remove folder
|
|
121
|
+
shutil.rmtree(os.path.join(cwd, 'SIMsalabim'))
|
|
122
|
+
|
|
123
|
+
# # Get the files from the latest release
|
|
124
|
+
url = 'https://api.github.com/repos/kostergroup/SIMsalabim/zipball'
|
|
125
|
+
response = requests.get(url)
|
|
126
|
+
|
|
127
|
+
# Open the zip file
|
|
128
|
+
z = zipfile.ZipFile(io.BytesIO(response.content))
|
|
129
|
+
|
|
130
|
+
# Extract all the files
|
|
131
|
+
z.extractall(path=cwd)
|
|
132
|
+
|
|
133
|
+
for dirpath, dirnames, files in os.walk(cwd):
|
|
134
|
+
for dirname in dirnames:
|
|
135
|
+
if dirname.startswith(folder_name):
|
|
136
|
+
# Rename folder
|
|
137
|
+
shutil.move(os.path.join(cwd, dirname), os.path.join(cwd, 'SIMsalabim'))
|
|
138
|
+
print("\nGot the latest release of SIMsalabim")
|
|
139
|
+
return 0
|
|
140
|
+
else:
|
|
141
|
+
print('We keep the current SIMsalabim version')
|
|
142
|
+
return 0
|
|
143
|
+
else:
|
|
144
|
+
# # Get the files from the latest release
|
|
145
|
+
url = 'https://api.github.com/repos/kostergroup/SIMsalabim/zipball'
|
|
146
|
+
response = requests.get(url)
|
|
147
|
+
|
|
148
|
+
# Open the zip file
|
|
149
|
+
z = zipfile.ZipFile(io.BytesIO(response.content))
|
|
150
|
+
|
|
151
|
+
# Extract all the files
|
|
152
|
+
z.extractall(path=cwd)
|
|
153
|
+
|
|
154
|
+
for dirpath, dirnames, files in os.walk(cwd):
|
|
155
|
+
for dirname in dirnames:
|
|
156
|
+
if dirname.startswith(folder_name):
|
|
157
|
+
# print(f"Found a folder named {dirname}")
|
|
158
|
+
# Rename folder
|
|
159
|
+
shutil.move(os.path.join(cwd, dirname), os.path.join(cwd, 'SIMsalabim'))
|
|
160
|
+
print("\nGot the latest release of SIMsalabim")
|
|
161
|
+
return 0
|
|
162
|
+
|
|
163
|
+
def get_SIMsalabim_assets(cwd,folder_name='kostergroup-SIMsalabim-',verbose=False):
|
|
164
|
+
""" Get the latest compiled binaries from the Kostergroup Github
|
|
165
|
+
|
|
166
|
+
Parameters
|
|
167
|
+
----------
|
|
168
|
+
cwd : string
|
|
169
|
+
Current working directory
|
|
170
|
+
folder_name : string, optional
|
|
171
|
+
Name of the folder to download, by default 'kostergroup-SIMsalabim-'
|
|
172
|
+
verbose : bool, optional
|
|
173
|
+
Print verbose output, by default False
|
|
174
|
+
|
|
175
|
+
Returns
|
|
176
|
+
-------
|
|
177
|
+
int
|
|
178
|
+
|
|
179
|
+
0 : Success
|
|
180
|
+
1 : Success
|
|
181
|
+
2 : Failed
|
|
182
|
+
3 : Failed
|
|
183
|
+
|
|
184
|
+
"""
|
|
185
|
+
|
|
186
|
+
if verbose:
|
|
187
|
+
print("Getting the latest compiled binaries from the Kostergroup Github")
|
|
188
|
+
# Get the assets from the latest release
|
|
189
|
+
url = "https://api.github.com/repos/kostergroup/SIMsalabim/releases/latest"
|
|
190
|
+
response = requests.get(url)
|
|
191
|
+
data = json.loads(response.text)
|
|
192
|
+
|
|
193
|
+
for asset in data["assets"]:
|
|
194
|
+
download_url = asset["browser_download_url"]
|
|
195
|
+
filename = asset["name"]
|
|
196
|
+
response = requests.get(download_url)
|
|
197
|
+
open(os.path.join(cwd,filename), "wb").write(response.content)
|
|
198
|
+
|
|
199
|
+
for dirpath, dirnames, files in os.walk(cwd):
|
|
200
|
+
|
|
201
|
+
for filename in files:
|
|
202
|
+
if filename.startswith('simss') and os.path.exists(os.path.join(cwd, filename)):
|
|
203
|
+
print(f"Found a folder named {filename}")
|
|
204
|
+
# Rename folder
|
|
205
|
+
shutil.move(os.path.join(cwd, filename), os.path.join(cwd, 'SIMsalabim','SimSS',filename))
|
|
206
|
+
elif filename.startswith('zimt') and os.path.exists(os.path.join(cwd, filename)):
|
|
207
|
+
print(f"Found a folder named {filename}")
|
|
208
|
+
# Rename folder
|
|
209
|
+
shutil.move(os.path.join(cwd, filename), os.path.join(cwd, 'SIMsalabim','ZimT',filename))
|
|
210
|
+
else:
|
|
211
|
+
pass
|
|
212
|
+
return 1
|
|
213
|
+
|
|
214
|
+
def use_SIMsalabim_source(cwd, folder_name='kostergroup-SIMsalabim-'):
|
|
215
|
+
""" Use the SIMsalabim source code
|
|
216
|
+
|
|
217
|
+
Parameters
|
|
218
|
+
----------
|
|
219
|
+
cwd : string
|
|
220
|
+
Current working directory
|
|
221
|
+
folder_name : string, optional
|
|
222
|
+
Name of the folder to download, by default 'kostergroup-SIMsalabim-'
|
|
223
|
+
|
|
224
|
+
Returns
|
|
225
|
+
-------
|
|
226
|
+
int
|
|
227
|
+
|
|
228
|
+
0 : Success
|
|
229
|
+
2 : Failed
|
|
230
|
+
3 : Failed
|
|
231
|
+
|
|
232
|
+
"""
|
|
233
|
+
# Clear the working directory. TEMP disabled
|
|
234
|
+
# result = clear_current_working_directory(cwd, folder_name)
|
|
235
|
+
result = True
|
|
236
|
+
if result == True:
|
|
237
|
+
result_get = get_SIMsalabim_source(cwd, folder_name)
|
|
238
|
+
return result_get
|
|
239
|
+
elif result == False:
|
|
240
|
+
print('Script terminated manually')
|
|
241
|
+
return 3
|
|
242
|
+
else:
|
|
243
|
+
print('Failed')
|
|
244
|
+
return 2
|
|
245
|
+
|
|
246
|
+
def install_SIMsalabim(cwd, folder_name='kostergroup-SIMsalabim-',verbose=False):
|
|
247
|
+
"""Install SIMsalabim in the current working directory
|
|
248
|
+
|
|
249
|
+
Parameters
|
|
250
|
+
----------
|
|
251
|
+
cwd : string
|
|
252
|
+
Current working directory
|
|
253
|
+
folder_name : string, optional
|
|
254
|
+
Name of the folder to download, by default 'kostergroup-SIMsalabim-'
|
|
255
|
+
verbose : bool, optional
|
|
256
|
+
Print verbose output, by default False
|
|
257
|
+
|
|
258
|
+
Returns
|
|
259
|
+
-------
|
|
260
|
+
int
|
|
261
|
+
|
|
262
|
+
0 : Success
|
|
263
|
+
1 : Success
|
|
264
|
+
2 : Failed
|
|
265
|
+
3 : Failed
|
|
266
|
+
|
|
267
|
+
"""
|
|
268
|
+
|
|
269
|
+
# Check if fpc installed
|
|
270
|
+
if verbose:
|
|
271
|
+
print("Checking for Free Pascal Compiler (fpc) package")
|
|
272
|
+
if shutil.which("fpc") is not None:
|
|
273
|
+
# fpc is installed, check the version and print to stdout.
|
|
274
|
+
result = subprocess.run(["fpc", "-iV"], stdout=subprocess.PIPE, text=True)
|
|
275
|
+
fpc_version = result.stdout
|
|
276
|
+
|
|
277
|
+
# remove possible newline character
|
|
278
|
+
if '\n' in fpc_version:
|
|
279
|
+
fpc_version = fpc_version.strip('\n')
|
|
280
|
+
|
|
281
|
+
# fpc version must be larger than min_fpc_version
|
|
282
|
+
if version.parse(fpc_version) > version.parse(min_fpc_version):
|
|
283
|
+
if verbose:
|
|
284
|
+
print(f'Free Pascal Compiler (fpc) is installed with version >= {min_fpc_version}\n')
|
|
285
|
+
result_fpc = use_SIMsalabim_source(cwd, folder_name)
|
|
286
|
+
# sys.exit(result_fpc)
|
|
287
|
+
|
|
288
|
+
# Compile the programs
|
|
289
|
+
# compile simss with fpc in os.path.join(path2prog,'SimSS')
|
|
290
|
+
os.chdir(os.path.join(cwd,'SIMsalabim','SimSS'))
|
|
291
|
+
os.system('fpc simss.pas')
|
|
292
|
+
os.chdir(cwd)
|
|
293
|
+
|
|
294
|
+
# compile zimt with fpc in os.path.join(path2prog,'ZimT')
|
|
295
|
+
cwd = os.getcwd() # Get current working directory
|
|
296
|
+
os.chdir(os.path.join(cwd,'SIMsalabim','ZimT'))
|
|
297
|
+
os.system('fpc zimt.pas')
|
|
298
|
+
os.chdir(cwd)
|
|
299
|
+
|
|
300
|
+
if verbose:
|
|
301
|
+
print('SIMsalabim programs have been compiled successfully!')
|
|
302
|
+
|
|
303
|
+
else:
|
|
304
|
+
# fpc version requirement not met
|
|
305
|
+
print(f'Installed Free Pascal Compiler (fpc) version is {fpc_version}, but must be at least 3.2.0\n')
|
|
306
|
+
result = cmd_yes_no_question("Do you want to continue with the pre-compiled binaries (y) or abort and update the Free Pascal Compiler (n) (recommended)", 'no')
|
|
307
|
+
if result is True:
|
|
308
|
+
# download assets
|
|
309
|
+
print("\ndownload assets")
|
|
310
|
+
result_assets = get_SIMsalabim_assets(cwd, verbose)
|
|
311
|
+
sys.exit(result_assets)
|
|
312
|
+
elif result is False:
|
|
313
|
+
# return and exit
|
|
314
|
+
sys.exit(3)
|
|
315
|
+
else:
|
|
316
|
+
# fpc is not installed.
|
|
317
|
+
print("Free Pascal Compiler is not installed.\n")
|
|
318
|
+
result = cmd_yes_no_question("Do you want to continue with the pre-compiled binaries (y) or abort and install the Free Pascal Compiler (n) (recommended)", 'no')
|
|
319
|
+
if result is True:
|
|
320
|
+
# download assets
|
|
321
|
+
print("\ndownload assets")
|
|
322
|
+
result_assets = get_SIMsalabim_assets(cwd, verbose)
|
|
323
|
+
sys.exit(result_assets)
|
|
324
|
+
elif result is False:
|
|
325
|
+
# return and exit
|
|
326
|
+
sys.exit(3)
|
|
327
|
+
|
|
328
|
+
def install_fpc_Linux():
|
|
329
|
+
""" Install Free Pascal Compiler on Linux
|
|
330
|
+
"""
|
|
331
|
+
# check if system is Linux
|
|
332
|
+
if os.name != 'posix':
|
|
333
|
+
print('This function is only available on Linux systems')
|
|
334
|
+
sys.exit()
|
|
335
|
+
|
|
336
|
+
# check if apt-get is available
|
|
337
|
+
if shutil.which("apt-get") is None:
|
|
338
|
+
print('apt-get is not available on this system')
|
|
339
|
+
sys.exit()
|
|
340
|
+
|
|
341
|
+
# Install Free Pascal Compiler
|
|
342
|
+
password = getpass('Sudo password:')
|
|
343
|
+
# run the command sudo apt-get install fp-compiler and enter the password and print the output
|
|
344
|
+
os.system('echo {} | sudo -S apt-get install fp-compiler'.format(password))
|
|
345
|
+
|
|
346
|
+
# def install_parallel_Linux():
|
|
347
|
+
# """ Install GNU Parallel on Linux
|
|
348
|
+
# """
|
|
349
|
+
# # check if system is Linux
|
|
350
|
+
# if os.name != 'posix':
|
|
351
|
+
# print('This function is only available on Linux systems')
|
|
352
|
+
# sys.exit()
|
|
353
|
+
|
|
354
|
+
# # check if apt-get is available
|
|
355
|
+
# if shutil.which("apt-get") is None:
|
|
356
|
+
# print('apt-get is not available on this system')
|
|
357
|
+
# sys.exit()
|
|
358
|
+
|
|
359
|
+
# # Install GNU Parallel
|
|
360
|
+
# password = getpass('Sudo password:')
|
|
361
|
+
# # run the command sudo apt-get install parallel and enter the password and print the output
|
|
362
|
+
# os.system('echo {} | sudo -S apt-get install parallel'.format(password))
|
|
363
|
+
|
|
364
|
+
# def fpc_prog(cwd,prog_name):
|
|
365
|
+
# """_summary_
|
|
366
|
+
|
|
367
|
+
# Parameters
|
|
368
|
+
# ----------
|
|
369
|
+
# cwd : string
|
|
370
|
+
# Current working directory
|
|
371
|
+
# prog_name : string
|
|
372
|
+
# Name of the program to compile
|
|
373
|
+
|
|
374
|
+
# """
|
|
375
|
+
# # Check if fpc installed
|
|
376
|
+
# if verbose:
|
|
377
|
+
# print("Checking for Free Pascal Compiler (fpc) package")
|
|
378
|
+
# if shutil.which("fpc") is not None:
|
|
379
|
+
# # fpc is installed, check the version and print to stdout.
|
|
380
|
+
# result = subprocess.run(["fpc", "-iV"], stdout=subprocess.PIPE, text=True)
|
|
381
|
+
# fpc_version = result.stdout
|
|
382
|
+
|
|
383
|
+
# # remove possible newline character
|
|
384
|
+
# if '\n' in fpc_version:
|
|
385
|
+
# fpc_version = fpc_version.strip('\n')
|
|
386
|
+
|
|
387
|
+
# # fpc version must be larger than min_fpc_version
|
|
388
|
+
# if version.parse(fpc_version) > version.parse(min_fpc_version):
|
|
389
|
+
# if verbose:
|
|
390
|
+
# print(f'Free Pascal Compiler (fpc) is installed with version >= {min_fpc_version}\n')
|
|
391
|
+
# # Compile the programs
|
|
392
|
+
# os.chdir(os.path.join(cwd,prog_name))
|
|
393
|
+
# os.system(f'fpc {prog_name}.pas')
|
|
394
|
+
# os.chdir(cwd)
|
|
395
|
+
# else:
|
|
396
|
+
# # fpc version requirement not met
|
|
397
|
+
# print(f'Installed Free Pascal Compiler (fpc) version is {fpc_version}, but must be at least 3.2.0\n')
|
|
398
|
+
# result = cmd_yes_no_question("Do you want to continue with the pre-compiled binaries (y) or abort and update the Free Pascal Compiler (n) (recommended)", 'no')
|
|
399
|
+
# if result is True:
|
|
400
|
+
# # download assets
|
|
401
|
+
# print("\ndownload assets")
|
|
402
|
+
# result_assets = get_SIMsalabim_assets(cwd, verbose)
|
|
403
|
+
# sys.exit(result_assets)
|
|
404
|
+
# elif result is False:
|
|
405
|
+
# # return and exit
|
|
406
|
+
# sys.exit(3)
|
|
407
|
+
# else:
|
|
408
|
+
# # fpc is not installed.
|
|
409
|
+
# print("Free Pascal Compiler is not installed.\n")
|
|
410
|
+
|
|
411
|
+
# sys.exit(3)
|
|
412
|
+
|
|
413
|
+
def fpc_prog(cwd,prog_name,show_term_output=True,force_fpc=True,verbose=True):
|
|
414
|
+
"""Compile program using fpc
|
|
415
|
+
|
|
416
|
+
Parameters
|
|
417
|
+
----------
|
|
418
|
+
cwd : string
|
|
419
|
+
String of the absolute path to the program
|
|
420
|
+
prog_name : string
|
|
421
|
+
Name of the program to compile
|
|
422
|
+
show_term_output : bool, optional
|
|
423
|
+
show terminal output from the compilation, by default True
|
|
424
|
+
force_fpc : bool, optional
|
|
425
|
+
force recompile with fpc even if compiled program already exists, by default True
|
|
426
|
+
verbose : bool, optional
|
|
427
|
+
print output of the compilation, by default True
|
|
428
|
+
"""
|
|
429
|
+
|
|
430
|
+
is_windows = (os.name == 'nt') # Check if we are on Windows
|
|
431
|
+
cwd = str(cwd) # Convert to string
|
|
432
|
+
|
|
433
|
+
# check if
|
|
434
|
+
compiled = False
|
|
435
|
+
while not compiled:
|
|
436
|
+
if shutil.which("fpc") is not None:
|
|
437
|
+
# fpc is installed, check the version and print to stdout.
|
|
438
|
+
result = subprocess.run(["fpc", "-iV"], stdout=subprocess.PIPE, text=True)
|
|
439
|
+
fpc_version = result.stdout
|
|
440
|
+
|
|
441
|
+
# remove possible newline character
|
|
442
|
+
if '\n' in fpc_version:
|
|
443
|
+
fpc_version = fpc_version.strip('\n')
|
|
444
|
+
|
|
445
|
+
# fpc version must be larger than min_fpc_version
|
|
446
|
+
if version.parse(fpc_version) >= version.parse(min_fpc_version):
|
|
447
|
+
if verbose:
|
|
448
|
+
print(f'Free Pascal Compiler (fpc) is installed with version >= {min_fpc_version}\n')
|
|
449
|
+
# Check if the program is already compiled
|
|
450
|
+
if (os.path.isfile(os.path.join(cwd,prog_name+'.exe')) and is_windows) or (os.path.isfile(os.path.join(cwd,prog_name)) and not is_windows):
|
|
451
|
+
if force_fpc:
|
|
452
|
+
if show_term_output == True:
|
|
453
|
+
output_direct = None
|
|
454
|
+
else:
|
|
455
|
+
output_direct = subprocess.DEVNULL
|
|
456
|
+
try:
|
|
457
|
+
subprocess.check_call(['fpc', prog_name.lower()+'.pas'], encoding='utf8', stdout=output_direct, cwd=cwd, shell=is_windows)
|
|
458
|
+
except subprocess.CalledProcessError:
|
|
459
|
+
print('Error compiling '+prog_name+' in '+cwd)
|
|
460
|
+
raise ChildProcessError
|
|
461
|
+
if verbose:
|
|
462
|
+
print('\n'+prog_name+' already existed but was recompiled'+'\n')
|
|
463
|
+
else:
|
|
464
|
+
if verbose:
|
|
465
|
+
print('\n'+prog_name+' already compiled')
|
|
466
|
+
|
|
467
|
+
else: # Compile the program
|
|
468
|
+
if show_term_output == True:
|
|
469
|
+
output_direct = None
|
|
470
|
+
else:
|
|
471
|
+
output_direct = subprocess.DEVNULL
|
|
472
|
+
try:
|
|
473
|
+
subprocess.check_call(['fpc', prog_name.lower()+'.pas'], encoding='utf8', stdout=output_direct, cwd=cwd, shell=is_windows)
|
|
474
|
+
if verbose:
|
|
475
|
+
print('\n'+prog_name+' was not compiled so we did it!'+'\n')
|
|
476
|
+
except subprocess.CalledProcessError:
|
|
477
|
+
print('Error compiling '+prog_name+' in '+cwd)
|
|
478
|
+
raise ChildProcessError
|
|
479
|
+
compiled = True
|
|
480
|
+
else:
|
|
481
|
+
# fpc version requirement not met
|
|
482
|
+
print(f'Installed Free Pascal Compiler (fpc) version is {fpc_version}, but must be at least 3.2.0\n')
|
|
483
|
+
print('Please update the Free Pascal Compiler to the latest version')
|
|
484
|
+
sys.exit(3)
|
|
485
|
+
else:
|
|
486
|
+
# fpc is not installed.
|
|
487
|
+
print("Free Pascal Compiler is not installed.\n")
|
|
488
|
+
result = cmd_yes_no_question("Do you want to continue and install the Free Pascal Compiler (only works on Linux) (y) or abort (n) (recommended)", 'no')
|
|
489
|
+
if result is True:
|
|
490
|
+
# install fpc
|
|
491
|
+
install_fpc_Linux()
|
|
492
|
+
# sys.exit(0)
|
|
493
|
+
elif result is False:
|
|
494
|
+
# return and exit
|
|
495
|
+
sys.exit(3)
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
######### Script ##################################################################################
|
|
502
|
+
if __name__ == "__main__":
|
|
503
|
+
|
|
504
|
+
install_SIMsalabim(cwd,verbose=True)
|
|
505
|
+
sys.exit(0)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
""" install GNU parallel"""
|
|
2
|
+
# Description:
|
|
3
|
+
# ------------
|
|
4
|
+
# This script contains a function to download SIMsalabim from GitHub and compile it
|
|
5
|
+
|
|
6
|
+
######### Package Imports ####################################################################
|
|
7
|
+
|
|
8
|
+
import os,shutil,sys, getpass
|
|
9
|
+
|
|
10
|
+
######### Function Definitions ################################################################
|
|
11
|
+
|
|
12
|
+
# def install_parallel_Linux():
|
|
13
|
+
# """ Install GNU Parallel on Linux
|
|
14
|
+
# """
|
|
15
|
+
# # check if system is Linux
|
|
16
|
+
# if os.name != 'posix':
|
|
17
|
+
# print('This function is only available on Linux systems')
|
|
18
|
+
# sys.exit()
|
|
19
|
+
|
|
20
|
+
# # check if apt-get is available
|
|
21
|
+
# if shutil.which("apt-get") is None:
|
|
22
|
+
# print('apt-get is not available on this system')
|
|
23
|
+
# sys.exit()
|
|
24
|
+
|
|
25
|
+
# # Install GNU Parallel
|
|
26
|
+
# password = getpass('Sudo password:')
|
|
27
|
+
# # run the command sudo apt-get install parallel and enter the password and print the output
|
|
28
|
+
# os.system('echo {} | sudo -S apt-get install parallel'.format(password))
|
|
29
|
+
|
|
30
|
+
def install_GNU_parallel_Linux(verbose=True):
|
|
31
|
+
"""Download GNU parallel if on Linux and install it if possible (requires sudo)
|
|
32
|
+
|
|
33
|
+
Parameters
|
|
34
|
+
----------
|
|
35
|
+
verbose : bool, optional
|
|
36
|
+
Print the download progress, by default False
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
Returns
|
|
40
|
+
-------
|
|
41
|
+
None
|
|
42
|
+
|
|
43
|
+
Raises
|
|
44
|
+
------
|
|
45
|
+
Exception
|
|
46
|
+
If GNU parallel could not be installed
|
|
47
|
+
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
if os.name == 'posix': # Check if we are on Linux
|
|
51
|
+
# check if GNU parallel is installed
|
|
52
|
+
if shutil.which('parallel') == None:
|
|
53
|
+
# Download GNU parallel
|
|
54
|
+
# Requires sudo so we ask if the user has sudo rights
|
|
55
|
+
overwrite = None
|
|
56
|
+
overwrite = input(f'A sudo password is required to install GNU parallel, do you have sudo rights? (y/n): ')
|
|
57
|
+
while overwrite.lower() not in ['y','n','yes','no']:
|
|
58
|
+
print('Please enter y or n')
|
|
59
|
+
overwrite = input(f'A sudo password is required to install GNU parallel, do you have sudo rights? (y/n): ')
|
|
60
|
+
if overwrite.lower() == 'n' or overwrite.lower() =='no':
|
|
61
|
+
raise Exception('GNU parallel could not be installed')
|
|
62
|
+
|
|
63
|
+
# try first with sudo apt-get install parallel
|
|
64
|
+
try:
|
|
65
|
+
# check if apt-get is available
|
|
66
|
+
if shutil.which("apt-get") is None:
|
|
67
|
+
print('apt-get is not available on this system')
|
|
68
|
+
sys.exit()
|
|
69
|
+
# Install GNU Parallel
|
|
70
|
+
password = getpass('Sudo password:')
|
|
71
|
+
# run the command sudo apt-get install parallel and enter the password and print the output
|
|
72
|
+
os.system('echo {} | sudo -S apt-get install parallel'.format(password))
|
|
73
|
+
# os.system('sudo apt-get install parallel')
|
|
74
|
+
if verbose:
|
|
75
|
+
print('GNU parallel was installed with apt-get install parallel')
|
|
76
|
+
except:
|
|
77
|
+
# if that doesn't work, download GNU parallel from git
|
|
78
|
+
try:
|
|
79
|
+
password = getpass('Sudo password:')
|
|
80
|
+
os.system('wget http://ftp.gnu.org/gnu/parallel/parallel-latest.tar.bz2')
|
|
81
|
+
os.system('echo {} | sudo -S tar -xjf parallel-latest.tar.bz2'.format(password))
|
|
82
|
+
os.system('cd parallel-*/')
|
|
83
|
+
os.system('echo {} | sudo -S ./configure && make'.format(password))
|
|
84
|
+
os.system('echo {} | sudo -S sudo make install'.format(password))
|
|
85
|
+
os.system('rm -rf parallel-*/')
|
|
86
|
+
os.system('rm parallel-latest.tar.bz2')
|
|
87
|
+
if verbose:
|
|
88
|
+
print('GNU parallel was downloaded from git and installed')
|
|
89
|
+
except:
|
|
90
|
+
print('GNU parallel could not be installed')
|
|
91
|
+
raise Exception('GNU parallel could not be installed')
|
|
92
|
+
else:
|
|
93
|
+
if verbose:
|
|
94
|
+
print('GNU parallel is already installed')
|
|
95
|
+
else:
|
|
96
|
+
if verbose:
|
|
97
|
+
print('GNU parallel is not installed because you are not on Linux')
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
if __name__ == '__main__':
|
|
102
|
+
|
|
103
|
+
install_GNU_parallel_Linux(verbose=True)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
File without changes
|