Skip to content

Commit 962d159

Browse files
check python
1 parent 370b69a commit 962d159

2 files changed

Lines changed: 60 additions & 18 deletions

File tree

kratos.gid/exec/launch.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"configurations": [
3+
{
4+
"id": "pip",
5+
"name": "Launch via pip",
6+
"runtimeExecutable": "python.exe"
7+
},
8+
{
9+
"id": "localpip",
10+
"name": "Launch via pip with local packages",
11+
"runtimeExecutable": "python.exe"
12+
},
13+
{
14+
"id": "local",
15+
"name": "Launch local compiled version",
16+
"kratos_path": "E:/Deploy_Kratos",
17+
"runtimeExecutable": "python.exe"
18+
},
19+
{
20+
"id": "docker",
21+
"image": ""
22+
}
23+
]
24+
}

kratos.gid/scripts/Utils.tcl

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
proc Kratos::Quicktest {example_app example_dim example_cmd} {
33
apps::setActiveApp Examples
44
::Examples::LaunchExample $example_app $example_dim $example_cmd
5-
}
5+
}
66

77
proc Kratos::ForceRun { } {
88
# validated by escolano@cimne.upc.edu
@@ -54,7 +54,7 @@ proc Kratos::CheckValidProjectName {modelname} {
5454
}
5555

5656
proc Kratos::PrintArray {a {pattern *}} {
57-
upvar 1 $a array
57+
upvar 1 $a array
5858
if {![array exists array]} {
5959
error "\"$a\" isn't an array"
6060
}
@@ -88,7 +88,7 @@ proc Kratos::WarnAboutMinimumRecommendedGiDVersion { } {
8888
if { [GidUtils::VersionCmp $kratos_private(CheckMinimumGiDVersion)] < 0 } {
8989
W "Warning: kratos interface requires GiD $kratos_private(CheckMinimumGiDVersion) or later."
9090
if { [GidUtils::VersionCmp 14.0.0] < 0 } {
91-
W "If you are still using a GiD version 13.1.7d or later, you can still use most of the features, but think about upgrading to GiD 14."
91+
W "If you are still using a GiD version 13.1.7d or later, you can still use most of the features, but think about upgrading to GiD 14."
9292
} {
9393
W "If you are using an official version of GiD 14, we recommend to use the latest developer version"
9494
}
@@ -97,11 +97,11 @@ proc Kratos::WarnAboutMinimumRecommendedGiDVersion { } {
9797
}
9898

9999
# Customlib libs and preferences
100-
proc Kratos::LoadProblemtypeLibraries {} {
100+
proc Kratos::LoadProblemtypeLibraries {} {
101101
package require customlib_extras
102102
package require customlib_native_groups
103103
variable kratos_private
104-
104+
105105
gid_groups_conds::SetProgramName $kratos_private(Name)
106106
gid_groups_conds::SetLibDir [file join $kratos_private(Path) exec]
107107
set spdfile [file join $kratos_private(Path) kratos_default.spd]
@@ -133,7 +133,7 @@ proc Kratos::GiveKratosDefaultsFile {} {
133133
proc Kratos::GetPreferencesFilePath { } {
134134
variable kratos_private
135135
# Where we store the user preferences :)
136-
136+
137137
# Get the GiD preferences dir
138138
set dir_name [file dirname [GiveGidDefaultsFile]]
139139

@@ -159,7 +159,7 @@ proc Kratos::RegisterEnvironment { } {
159159
dict set preferences $v $kratos_private($v)
160160
}
161161
}
162-
162+
163163
if {[llength [dict keys $preferences]] > 0} {
164164
set fp [open [Kratos::GetPreferencesFilePath] w]
165165
if {[catch {set data [puts $fp [write::tcl2json $preferences]]} ]} {W "Problems saving user prefecences"; W $data}
@@ -190,7 +190,7 @@ proc Kratos::LoadEnvironment { } {
190190

191191
# Init variables
192192
set data ""
193-
193+
194194
catch {
195195
# Try to open the preferences file
196196
set fp [open [Kratos::GetPreferencesFilePath] r]
@@ -199,7 +199,7 @@ proc Kratos::LoadEnvironment { } {
199199
# W $data
200200
# Close the file
201201
close $fp
202-
202+
203203
# Preferences are written in json format
204204
foreach {k v} [write::json2dict $data] {
205205
# W "$k $v"
@@ -212,18 +212,18 @@ proc Kratos::LoadEnvironment { } {
212212
# LOGS
213213

214214
proc Kratos::LogInitialData { } {
215-
215+
216216
# Get the exec version
217217
Kratos::GetExecVersion
218-
Kratos::GetProblemtypeGitTag
218+
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)
224224
dict set initial_data executable_version $Kratos::kratos_private(exec_version)
225225
dict set initial_data current_platform $::tcl_platform(platform)
226-
226+
227227
Kratos::Log [write::tcl2json $initial_data]
228228
}
229229

@@ -280,15 +280,15 @@ proc Kratos::GetProblemtypeGitTag {} {
280280
proc Kratos::GetMeshBasicData { } {
281281
set result [dict create]
282282
foreach element_type [GidUtils::GetElementTypes all] {
283-
set ne [GiD_Info Mesh NumElements $element_type]
283+
set ne [GiD_Info Mesh NumElements $element_type]
284284
if { $ne } {
285285
dict set result $element_type $ne
286286
}
287287
}
288-
289-
dict set result nodes [GiD_Info Mesh NumNodes]
288+
289+
dict set result nodes [GiD_Info Mesh NumNodes]
290290
dict set result is_quadratic [expr [GiD_Info Project Quadratic] && ![GiD_Cartesian get iscartesian] ]
291-
return $result
291+
return $result
292292
}
293293

294294
proc ? {question true_val false_val} {
@@ -310,14 +310,32 @@ proc Kratos::OpenCaseIn {program} {
310310
}
311311

312312
if { ![GidUtils::IsTkDisabled] } {
313-
proc xmlprograms::OpenBrowserForDirectory { baseframe variable} {
313+
proc xmlprograms::OpenBrowserForDirectory { baseframe variable} {
314314
set $variable [MessageBoxGetFilename directory write [_ "Select kratos debug compiled folder (kratos / bin / debug"]]
315315
return variable
316-
}
316+
}
317317
}
318318

319319
proc Kratos::IsDeveloperMode {} {
320320
set is_dev 0
321321
if {[info exists ::Kratos::kratos_private(DevMode)] && $::Kratos::kratos_private(DevMode) eq "dev"} {set is_dev 1}
322322
return $is_dev
323+
}
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
323341
}

0 commit comments

Comments
 (0)