Skip to content

Commit 9c6e490

Browse files
python install
1 parent 700e542 commit 9c6e490

3 files changed

Lines changed: 115 additions & 92 deletions

File tree

kratos.gid/kratos.tcl

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ if {[GidUtils::VersionCmp "14.0.1"] >=0 } {
2727
}
2828
}
2929
} {
30-
# GiD versions previous to 14 are no longer allowed
30+
# GiD versions previous to 15 are no longer allowed
3131
# As we dont register the event InitProblemtype, the rest of events are also unregistered
3232
# So no chance to open anything in GiD 13.x or earlier
33-
WarnWin "The minimum GiD Version for Kratos is 14 or later \nUpdate at gidhome.com"
33+
WarnWin "The minimum GiD Version for Kratos is 15 or later \nUpdate at gidhome.com"
3434
}
3535

3636
proc Kratos::Events { } {
3737
variable kratos_private
3838

3939
# Recommended GiD Version is the latest developer always
40-
if {[GidUtils::VersionCmp "14.1.4d"] <0 } {
40+
if {[GidUtils::VersionCmp "15.0.0"] <0 } {
4141
set dir [file dirname [info script]]
4242
uplevel #0 [list source [file join $kratos_private(Path) scripts DeprecatedEvents.tcl]]
4343
Kratos::ModifyPreferencesWindowOld
@@ -66,6 +66,7 @@ proc Kratos::RegisterGiDEvents { } {
6666
# Write - Calculation
6767
GiD_RegisterEvent GiD_Event_AfterWriteCalculationFile Kratos::Event_AfterWriteCalculationFile PROBLEMTYPE Kratos
6868
GiD_RegisterEvent GiD_Event_BeforeRunCalculation Kratos::Event_BeforeRunCalculation PROBLEMTYPE Kratos
69+
GiD_RegisterEvent GiD_Event_SelectGIDBatFile Kratos::Event_SelectGIDBatFile PROBLEMTYPE Kratos
6970

7071
# Postprocess
7172
GiD_RegisterEvent GiD_Event_InitGIDPostProcess Kratos::Event_InitGIDPostProcess PROBLEMTYPE Kratos
@@ -83,7 +84,7 @@ proc Kratos::RegisterGiDEvents { } {
8384

8485
# Preferences window
8586
GiD_RegisterPluginPreferencesProc Kratos::Event_ModifyPreferencesWindow
86-
if {[GidUtils::VersionCmp "15.0.0"] >=0 } {CreateWidgetsFromXml::ClearCachePreferences}
87+
CreateWidgetsFromXml::ClearCachePreferences
8788
}
8889

8990
proc Kratos::Event_InitProblemtype { dir } {
@@ -127,6 +128,8 @@ proc Kratos::Event_InitProblemtype { dir } {
127128
#open a window to allow the user select the app
128129
after 500 [list spdAux::CreateWindow]
129130
}
131+
132+
Kratos::CheckDependencies
130133
}
131134

132135
proc Kratos::InitGlobalVariables {dir} {
@@ -196,26 +199,26 @@ proc Kratos::LoadCommonScripts { } {
196199
}
197200

198201
# Writing common scripts
199-
foreach filename {Writing.tcl WriteHeadings.tcl WriteMaterials.tcl WriteNodes.tcl
200-
WriteElements.tcl WriteConditions.tcl WriteConditionsByGiDId.tcl WriteConditionsByUniqueId.tcl
201-
WriteProjectParameters.tcl WriteSubModelPart.tcl WriteProcess.tcl} {
202-
uplevel #0 [list source [file join $kratos_private(Path) scripts Writing $filename]]
202+
foreach filename {Writing WriteHeadings WriteMaterials WriteNodes
203+
WriteElements WriteConditions WriteConditionsByGiDId WriteConditionsByUniqueId
204+
WriteProjectParameters WriteSubModelPart WriteProcess} {
205+
uplevel #0 [list source [file join $kratos_private(Path) scripts Writing $filename.tcl]]
203206
}
204207
# Common scripts
205-
foreach filename {Utils.tcl Applications.tcl spdAuxiliar.tcl Menus.tcl Deprecated.tcl Logs.tcl} {
206-
uplevel #0 [list source [file join $kratos_private(Path) scripts $filename]]
208+
foreach filename {Utils Launch Applications spdAuxiliar Menus Deprecated Logs} {
209+
uplevel #0 [list source [file join $kratos_private(Path) scripts $filename.tcl]]
207210
}
208211
# Common controllers
209-
foreach filename {ApplicationMarketWindow.tcl ExamplesWindow.tcl CommonProcs.tcl PreferencesWindow.tcl TreeInjections.tcl MdpaImportMesh.tcl Drawer.tcl ImportFiles.tcl} {
210-
uplevel #0 [list source [file join $kratos_private(Path) scripts Controllers $filename]]
212+
foreach filename {ApplicationMarketWindow ExamplesWindow CommonProcs PreferencesWindow TreeInjections MdpaImportMesh Drawer ImportFiles} {
213+
uplevel #0 [list source [file join $kratos_private(Path) scripts Controllers $filename.tcl]]
211214
}
212215
# Model class
213-
foreach filename {Model.tcl Entity.tcl Parameter.tcl Topology.tcl Solver.tcl ConstitutiveLaw.tcl Condition.tcl Element.tcl Material.tcl SolutionStrategy.tcl Process.tcl} {
214-
uplevel #0 [list source [file join $kratos_private(Path) scripts Model $filename]]
216+
foreach filename {Model Entity Parameter Topology Solver ConstitutiveLaw Condition Element Material SolutionStrategy Process} {
217+
uplevel #0 [list source [file join $kratos_private(Path) scripts Model $filename.tcl]]
215218
}
216219
# Libs
217-
foreach filename {SimpleXMLViewer.tcl} {
218-
uplevel #0 [list source [file join $kratos_private(Path) libs $filename]]
220+
foreach filename {SimpleXMLViewer} {
221+
uplevel #0 [list source [file join $kratos_private(Path) libs $filename.tcl]]
219222
}
220223
}
221224

@@ -494,9 +497,12 @@ proc Kratos::Event_BeforeRunCalculation { batfilename basename dir problemtypedi
494497
set app_run_brake [apps::ExecuteOnCurrentApp BreakRunCalculation]
495498
if {[write::isBooleanTrue $app_run_brake]} {return "-cancel-"}
496499

500+
}
501+
502+
proc Kratos::Event_SelectGIDBatFile { dir basename } {
497503
if {[info exists Kratos::kratos_private(launch_configuration)]} {
498-
set launch_type $Kratos::kratos_private(launch_configuration)
499-
W $launch_type
504+
set launch_mode $Kratos::kratos_private(launch_configuration)
505+
return [Kratos::ExecuteLaunchByMode $launch_mode]
500506
}
501507
}
502508

kratos.gid/scripts/Launch.tcl

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
2+
proc Kratos::InstallAllPythonDependencies { } {
3+
4+
if { $::tcl_platform(platform) == "windows" } { set os win } {set os unix}
5+
6+
# Check if python is installed
7+
if {[pythonVersion] <= 0} {
8+
if {os eq "win"} {
9+
VisitWeb "https://www.microsoft.com/es-es/p/python-39/9p7qfqmjrfp7"
10+
} {
11+
exec "sudo apt-get install python3.9"
12+
}
13+
}
14+
15+
# Check if pip is installed
16+
17+
# Install pip packages
18+
}
19+
20+
proc Kratos::pythonVersion {{pythonExecutable "python"}} {
21+
# Tricky point: Python 2.7 writes version info to stderr!
22+
catch {
23+
set info [exec $pythonExecutable --version 2>@1]
24+
if {[regexp {^Python ([\d.]+)$} $info --> version]} {
25+
return $version
26+
}
27+
}
28+
return 0
29+
}
30+
31+
32+
proc Kratos::CheckDependencies { } {
33+
if {[pythonVersion] <= 0} {error "Python not installed on this system. Please install python 3 manually or click on menu Kratos > Install dependencies"}
34+
35+
}
36+
37+
proc Kratos::GetLaunchConfigurationFile { } {
38+
set new_dir [file join $::env(HOME) .kratos_multiphysics]
39+
set file [file join $new_dir launch_configuration.json]
40+
return [list $new_dir $file]
41+
}
42+
43+
proc Kratos::LoadLaunchModes { } {
44+
# Get location of launch config script
45+
lassign [Kratos::GetLaunchConfigurationFile] new_dir file
46+
47+
# If it does not exist, copy it from exec
48+
if {[file exists $new_dir] == 0} {file mkdir $new_dir}
49+
if {[file exists $file] == 0} {
50+
::GidUtils::SetWarnLine "Loading launch mode"
51+
set source [file join $::Kratos::kratos_private(Path) exec launch.json]
52+
file copy -force $source $file
53+
}
54+
55+
# Load configurations
56+
Kratos::LoadConfigurationFile $file
57+
}
58+
59+
proc Kratos::LoadConfigurationFile {config_file} {
60+
if {[file exists $config_file] == 0} { error "Configuration file not found: $config_file" }
61+
62+
set dic [Kratos::ReadJsonDict $config_file]
63+
set ::Kratos::kratos_private(configurations) [dict get $dic configurations]
64+
}
65+
66+
proc Kratos::SetDefaultLaunchMode { } {
67+
set curr_mode $Kratos::kratos_private(launch_configuration)
68+
set modes [list ]
69+
set first ""
70+
foreach mode $::Kratos::kratos_private(configurations) {
71+
set mode_name [dict get $mode name]
72+
lappend modes $mode_name
73+
if {$first eq ""} {set first $mode_name}
74+
}
75+
if {$curr_mode ni $modes} {set Kratos::kratos_private(launch_configuration) $first}
76+
}
77+
78+
proc Kratos::ExecuteLaunchByMode {launch_mode} {
79+
set bat_file ""
80+
if { $::tcl_platform(platform) == "windows" } { set os win } {set os unix}
81+
foreach mode $::Kratos::kratos_private(configurations) {
82+
set mode_name [dict get $mode name]
83+
if {$mode_name eq $launch_mode} {
84+
set bat [dict get $mode script]
85+
set bat_file [file join exec $bat.$os.bat]
86+
}
87+
}
88+
return $bat_file
89+
}

kratos.gid/scripts/Utils.tcl

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,14 @@ proc Kratos::LoadEnvironment { } {
214214
proc Kratos::LogInitialData { } {
215215

216216
# Get the exec version
217-
Kratos::GetExecVersion
217+
#Kratos::GetExecVersion
218218
Kratos::GetProblemtypeGitTag
219219

220220
set initial_data [dict create]
221221
dict set initial_data gid_version [GiD_Info gidversion]
222222
dict set initial_data problemtype_git_hash $Kratos::kratos_private(problemtype_git_hash)
223223
dict set initial_data problemtype_version $Kratos::kratos_private(Version)
224-
dict set initial_data executable_version $Kratos::kratos_private(exec_version)
224+
# dict set initial_data executable_version $Kratos::kratos_private(exec_version)
225225
dict set initial_data current_platform $::tcl_platform(platform)
226226

227227
Kratos::Log [write::tcl2json $initial_data]
@@ -321,75 +321,3 @@ proc Kratos::IsDeveloperMode {} {
321321
if {[info exists ::Kratos::kratos_private(DevMode)] && $::Kratos::kratos_private(DevMode) eq "dev"} {set is_dev 1}
322322
return $is_dev
323323
}
324-
325-
proc Kratos::InstallAllPythonDependencies { } {
326-
# Check if python is installed
327-
if {[pythonVersion] < 0} {error "Python not installed on this system. Please install python 3"}
328-
329-
# Check if pip is installed
330-
331-
# Install pip packages
332-
}
333-
334-
proc Kratos::pythonVersion {{pythonExecutable "python"}} {
335-
# Tricky point: Python 2.7 writes version info to stderr!
336-
set info [exec $pythonExecutable --version 2>@1]
337-
if {[regexp {^Python ([\d.]+)$} $info --> version]} {
338-
return $version
339-
}
340-
return 0
341-
}
342-
343-
proc Kratos::GetLaunchConfigurationFile { } {
344-
set new_dir [file join $::env(HOME) .kratos_multiphysics]
345-
set file [file join $new_dir launch_configuration.json]
346-
return [list $new_dir $file]
347-
}
348-
349-
proc Kratos::LoadLaunchModes { } {
350-
# Get location of launch config script
351-
lassign [Kratos::GetLaunchConfigurationFile] new_dir file
352-
353-
# If it does not exist, copy it from exec
354-
if {[file exists $new_dir] == 0} {file mkdir $new_dir}
355-
if {[file exists $file] == 0} {
356-
::GidUtils::SetWarnLine "Loading launch mode"
357-
set source [file join $::Kratos::kratos_private(Path) exec launch.json]
358-
file copy -force $source $file
359-
}
360-
361-
# Load configurations
362-
Kratos::LoadConfigurationFile $file
363-
}
364-
365-
proc Kratos::LoadConfigurationFile {config_file} {
366-
if {[file exists $config_file] == 0} { error "Configuration file not found: $config_file" }
367-
368-
set dic [Kratos::ReadJsonDict $config_file]
369-
set ::Kratos::kratos_private(configurations) [dict get $dic configurations]
370-
}
371-
372-
proc Kratos::SetDefaultLaunchMode { } {
373-
set curr_mode $Kratos::kratos_private(launch_configuration)
374-
set modes [list ]
375-
set first ""
376-
foreach mode $::Kratos::kratos_private(configurations) {
377-
set mode_name [dict get $mode name]
378-
lappend modes $mode_name
379-
if {$first eq ""} {set first $mode_name}
380-
}
381-
if {$curr_mode ni $modes} {set Kratos::kratos_private(launch_configuration) $first}
382-
}
383-
384-
proc Kratos::ExecuteLaunchByMode {launch_mode} {
385-
set bat_file ""
386-
if { $::tcl_platform(platform) == "windows" } { set os win } {set os unix}
387-
foreach mode $::Kratos::kratos_private(configurations) {
388-
set mode_name [dict get $mode name]
389-
if {$mode_name eq $launch_mode} {
390-
set bat [dict get $mode script]
391-
set bat_file [file join exec $bat.$os.bat]
392-
}
393-
}
394-
return $bat_file
395-
}

0 commit comments

Comments
 (0)