Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Larry Price
gmsh
Commits
c2dee215
Commit
c2dee215
authored
10 years ago
by
Francois Henrotte
Browse files
Options
Downloads
Patches
Plain Diff
improved path checking in py metamodels, solution file archiving on demand when saving the database
parent
01cca733
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Fltk/onelabGroup.cpp
+22
-23
22 additions, 23 deletions
Fltk/onelabGroup.cpp
contrib/onelab/python/onelab.py
+32
-36
32 additions, 36 deletions
contrib/onelab/python/onelab.py
with
54 additions
and
59 deletions
Fltk/onelabGroup.cpp
+
22
−
23
View file @
c2dee215
...
@@ -656,8 +656,8 @@ static void archiveOutputFiles(const std::string &fileName)
...
@@ -656,8 +656,8 @@ static void archiveOutputFiles(const std::string &fileName)
std
::
string
stamp
;
std
::
string
stamp
;
std
::
vector
<
onelab
::
string
>
ps
;
std
::
vector
<
onelab
::
string
>
ps
;
onelab
::
server
::
instance
()
->
get
(
ps
,
"0Metamodel/9Tag"
);
onelab
::
server
::
instance
()
->
get
(
ps
,
"0Metamodel/9Tag"
);
if
(
ps
.
size
())
if
(
ps
.
size
()
&&
ps
[
0
].
getValue
().
size
()
)
stamp
.
assign
(
timeStamp
()
+
ps
[
0
].
getValue
());
stamp
.
assign
(
timeStamp
()
+
"_"
+
ps
[
0
].
getValue
());
else
else
stamp
.
assign
(
timeStamp
());
stamp
.
assign
(
timeStamp
());
...
@@ -700,9 +700,12 @@ static void archiveOutputFiles(const std::string &fileName)
...
@@ -700,9 +700,12 @@ static void archiveOutputFiles(const std::string &fileName)
static
void
archiveSolutionFiles
(
const
std
::
string
&
fileName
)
static
void
archiveSolutionFiles
(
const
std
::
string
&
fileName
)
{
{
// extract tag from db
Nam
e
// extract tag from db
fileName, use fileName as tag otherwis
e
std
::
vector
<
std
::
string
>
split
=
SplitFileName
(
fileName
);
std
::
vector
<
std
::
string
>
split
=
SplitFileName
(
fileName
);
std
::
string
tag
=
split
[
1
].
substr
(
6
);
// cut off 'onelab'
std
::
string
dir
=
split
[
0
]
+
"archive/"
;
std
::
string
tag
=
split
[
1
];
if
(
!
tag
.
compare
(
0
,
6
,
"onelab"
))
tag
.
assign
(
tag
.
substr
(
6
));
// cut off 'onelab' if present
// add tag to all solution files in the db, and rename them on disk
// add tag to all solution files in the db, and rename them on disk
std
::
vector
<
onelab
::
string
>
strings
;
std
::
vector
<
onelab
::
string
>
strings
;
...
@@ -713,8 +716,8 @@ static void archiveSolutionFiles(const std::string &fileName)
...
@@ -713,8 +716,8 @@ static void archiveSolutionFiles(const std::string &fileName)
for
(
unsigned
int
j
=
0
;
j
<
names
.
size
();
j
++
){
for
(
unsigned
int
j
=
0
;
j
<
names
.
size
();
j
++
){
std
::
vector
<
std
::
string
>
split
=
SplitFileName
(
names
[
j
]);
std
::
vector
<
std
::
string
>
split
=
SplitFileName
(
names
[
j
]);
std
::
string
old
=
names
[
j
];
std
::
string
old
=
names
[
j
];
CreateSingleDir
(
split
[
0
]
+
"archive/"
);
CreateSingleDir
(
dir
);
names
[
j
]
=
split
[
0
]
+
"archive/"
+
split
[
1
]
+
tag
+
split
[
2
];
names
[
j
]
=
dir
+
split
[
1
]
+
tag
+
split
[
2
];
Msg
::
Info
(
"Renaming '%s' into '%s'"
,
old
.
c_str
(),
names
[
j
].
c_str
());
Msg
::
Info
(
"Renaming '%s' into '%s'"
,
old
.
c_str
(),
names
[
j
].
c_str
());
rename
(
old
.
c_str
(),
names
[
j
].
c_str
());
rename
(
old
.
c_str
(),
names
[
j
].
c_str
());
}
}
...
@@ -839,17 +842,15 @@ void onelab_cb(Fl_Widget *w, void *data)
...
@@ -839,17 +842,15 @@ void onelab_cb(Fl_Widget *w, void *data)
// add user defined tag, if any
// add user defined tag, if any
std
::
vector
<
onelab
::
string
>
ps
;
std
::
vector
<
onelab
::
string
>
ps
;
onelab
::
server
::
instance
()
->
get
(
ps
,
"0Metamodel/9Tag"
);
onelab
::
server
::
instance
()
->
get
(
ps
,
"0Metamodel/9Tag"
);
if
(
ps
.
size
()){
if
(
ps
.
size
()
&&
ps
[
0
].
getValue
().
size
()){
fileName
.
assign
(
"onelab"
+
ps
[
0
].
getValue
()
+
".db"
);
fileName
.
assign
(
"onelab_"
+
ps
[
0
].
getValue
()
+
".db"
);
//ps[0].setValue("");
//onelab::server::instance()->set(ps[0]);
}
}
// s
witch to "run
" mode"
// s
ave db in "restore
" mode"
std
::
vector
<
onelab
::
number
>
pn
;
std
::
vector
<
onelab
::
number
>
pn
;
onelab
::
server
::
instance
()
->
get
(
pn
,
"0Metamodel/9Use restored solution"
);
onelab
::
server
::
instance
()
->
get
(
pn
,
"0Metamodel/9Use restored solution"
);
if
(
pn
.
size
()){
if
(
pn
.
size
()){
pn
[
0
].
setValue
(
0
);
pn
[
0
].
setValue
(
1
);
pn
[
0
].
setVisible
(
1
);
pn
[
0
].
setVisible
(
1
);
onelab
::
server
::
instance
()
->
set
(
pn
[
0
]);
onelab
::
server
::
instance
()
->
set
(
pn
[
0
]);
}
}
...
@@ -861,7 +862,15 @@ void onelab_cb(Fl_Widget *w, void *data)
...
@@ -861,7 +862,15 @@ void onelab_cb(Fl_Widget *w, void *data)
saveDb
(
fileChooserGetName
(
1
));
saveDb
(
fileChooserGetName
(
1
));
}
}
return
;
// switch back to normal "run" mode"
onelab
::
server
::
instance
()
->
get
(
pn
,
"0Metamodel/9Use restored solution"
);
if
(
pn
.
size
()){
pn
[
0
].
setValue
(
0
);
pn
[
0
].
setVisible
(
0
);
onelab
::
server
::
instance
()
->
set
(
pn
[
0
]);
}
action
=
"check"
;
//return;
}
}
if
(
FlGui
::
instance
()
->
onelab
->
isBusy
()){
if
(
FlGui
::
instance
()
->
onelab
->
isBusy
()){
...
@@ -873,16 +882,6 @@ void onelab_cb(Fl_Widget *w, void *data)
...
@@ -873,16 +882,6 @@ void onelab_cb(Fl_Widget *w, void *data)
std
::
string
db
=
SplitFileName
(
GModel
::
current
()
->
getFileName
())[
0
]
+
"onelab.db"
;
std
::
string
db
=
SplitFileName
(
GModel
::
current
()
->
getFileName
())[
0
]
+
"onelab.db"
;
if
(
fileChooser
(
FILE_CHOOSER_SINGLE
,
"Load"
,
"*.db"
,
db
.
c_str
()))
if
(
fileChooser
(
FILE_CHOOSER_SINGLE
,
"Load"
,
"*.db"
,
db
.
c_str
()))
loadDb
(
fileChooserGetName
(
1
));
loadDb
(
fileChooserGetName
(
1
));
// switch to "restore" mode"
// (the metamodel will use archived solution files)
std
::
vector
<
onelab
::
number
>
pn
;
onelab
::
server
::
instance
()
->
get
(
pn
,
"0Metamodel/9Use restored solution"
);
if
(
pn
.
size
()){
pn
[
0
].
setValue
(
1
);
pn
[
0
].
setVisible
(
1
);
onelab
::
server
::
instance
()
->
set
(
pn
[
0
]);
}
action
=
"check"
;
action
=
"check"
;
}
}
...
...
This diff is collapsed.
Click to expand it.
contrib/onelab/python/onelab.py
+
32
−
36
View file @
c2dee215
...
@@ -36,42 +36,22 @@ def file_exist(filename):
...
@@ -36,42 +36,22 @@ def file_exist(filename):
return
True
return
True
except
IOError
:
except
IOError
:
return
False
return
False
def
path
(
ref
,
inp
=
''
):
def
path
(
dirname
,
inp
):
# ref is a reference file name (not a directory)
# dirname is a directory, can be empty if model called in cmd line
# inp is an optional file or subdirectory name
# inp is an aptional file or subdirectory name
# return the path to 'inp' in the same directory as 'ref'
# returns the path to 'inp' in the same directory as 'ref'
dirname
=
os
.
path
.
dirname
(
ref
)
if
not
inp
:
if
not
inp
:
if
dirname
:
return
dirname
return
dirname
else
:
return
'
.
'
if
inp
[
0
]
==
'
/
'
or
inp
[
0
]
==
'
\\
'
or
(
len
(
inp
)
>
2
and
inp
[
1
]
==
'
\:
'
):
if
inp
[
0
]
==
'
/
'
or
inp
[
0
]
==
'
\\
'
or
(
len
(
inp
)
>
2
and
inp
[
1
]
==
'
\:
'
):
return
inp
# do nothing, inp is an absolute path
return
inp
# do nothing, inp is an absolute path
if
inp
[
0
]
==
'
.
'
:
inp
=
inp
[
2
:]
# cut off heading './' or '.\'
if
dirname
:
if
dirname
:
return
dirname
+
os
.
sep
+
inp
# append inp to the path of the reference file
return
dirname
+
os
.
sep
+
inp
# append inp to the path of the reference file
else
:
else
:
return
inp
return
inp
class
pth
:
def
path
(
self
,
ref
,
inp
=
''
):
p
=
path
(
ref
,
inp
)
if
not
os
.
path
.
exists
(
p
):
self
.
errors
+=
1
self
.
msg
+=
p
+
'
'
return
p
def
status
(
self
):
return
'
%d path errors: %s
'
%
(
self
.
errors
,
self
.
msg
)
def
copy
(
self
,
here
,
there
):
os
.
system
(
'
cp
'
+
here
+
'
'
+
there
)
def
__init__
(
self
)
:
self
.
errors
=
0
self
.
msg
=
''
class
_parameter
()
:
class
_parameter
()
:
_membersbase
=
[
_membersbase
=
[
(
'
name
'
,
'
string
'
),
(
'
label
'
,
'
string
'
,
''
),
(
'
help
'
,
'
string
'
,
''
),
(
'
name
'
,
'
string
'
),
(
'
label
'
,
'
string
'
,
''
),
(
'
help
'
,
'
string
'
,
''
),
...
@@ -364,7 +344,7 @@ class client :
...
@@ -364,7 +344,7 @@ class client :
if
msg
==
"
true
"
:
if
msg
==
"
true
"
:
return
True
return
True
return
False
return
False
def
isChanged
(
self
,
name
)
:
def
isChanged
(
self
,
name
)
:
if
not
self
.
socket
:
if
not
self
.
socket
:
return
return
...
@@ -410,10 +390,11 @@ class client :
...
@@ -410,10 +390,11 @@ class client :
def
run
(
self
,
name
,
command
,
arguments
=
''
):
def
run
(
self
,
name
,
command
,
arguments
=
''
):
self
.
runSubClient
(
name
,
command
,
arguments
)
self
.
runSubClient
(
name
,
command
,
arguments
)
def
__init__
(
self
):
def
__init__
(
self
,
ref
=
''
):
self
.
socket
=
None
self
.
socket
=
None
self
.
name
=
""
self
.
name
=
""
self
.
addr
=
""
self
.
addr
=
""
self
.
wdir
=
os
.
path
.
dirname
(
ref
)
self
.
_numSubClients
=
0
self
.
_numSubClients
=
0
for
i
,
v
in
enumerate
(
sys
.
argv
)
:
for
i
,
v
in
enumerate
(
sys
.
argv
)
:
if
v
==
'
-onelab
'
:
if
v
==
'
-onelab
'
:
...
@@ -424,7 +405,6 @@ class client :
...
@@ -424,7 +405,6 @@ class client :
self
.
action
=
"
compute
"
# default (subclients have no client.Action defined)
self
.
action
=
"
compute
"
# default (subclients have no client.Action defined)
self
.
action
=
self
.
getString
(
self
.
name
+
'
/Action
'
,
False
)
self
.
action
=
self
.
getString
(
self
.
name
+
'
/Action
'
,
False
)
self
.
setNumber
(
'
IsPyMetamodel
'
,
value
=
1
,
visible
=
0
)
self
.
setNumber
(
'
IsPyMetamodel
'
,
value
=
1
,
visible
=
0
)
#self.defineNumber('0Metamodel/Loop',value=0,visible=0)
self
.
loop
=
self
.
getNumber
(
'
0Metamodel/Loop
'
,
warn_if_not_found
=
False
)
self
.
loop
=
self
.
getNumber
(
'
0Metamodel/Loop
'
,
warn_if_not_found
=
False
)
self
.
batch
=
self
.
getNumber
(
'
0Metamodel/Batch
'
,
warn_if_not_found
=
False
)
self
.
batch
=
self
.
getNumber
(
'
0Metamodel/Batch
'
,
warn_if_not_found
=
False
)
self
.
sendInfo
(
"
Performing OneLab
'"
+
self
.
action
+
"'"
)
self
.
sendInfo
(
"
Performing OneLab
'"
+
self
.
action
+
"'"
)
...
@@ -472,7 +452,24 @@ class client :
...
@@ -472,7 +452,24 @@ class client :
for
line
in
iter
(
call
.
stderr
.
readline
,
b
''
):
for
line
in
iter
(
call
.
stderr
.
readline
,
b
''
):
self
.
_send
(
self
.
_GMSH_ERROR
,
line
.
rstrip
().
encode
(
'
utf-8
'
))
self
.
_send
(
self
.
_GMSH_ERROR
,
line
.
rstrip
().
encode
(
'
utf-8
'
))
sys
.
exit
(
1
)
sys
.
exit
(
1
)
def
path
(
self
,
inp
=
''
)
:
return
path
(
self
.
wdir
,
inp
)
def
exists
(
self
,
p
)
:
if
not
os
.
path
.
exists
(
p
):
self
.
sendError
(
'
path error: %s
'
%
(
p
))
exit
(
0
)
return
True
def
cpath
(
self
,
inp
=
''
)
:
p
=
path
(
self
.
wdir
,
inp
)
self
.
exists
(
p
)
return
p
def
copy
(
self
,
here
,
there
):
os
.
system
(
'
cp
'
+
here
+
'
'
+
there
)
def
upload
(
self
,
here
,
there
,
remote
=
''
)
:
def
upload
(
self
,
here
,
there
,
remote
=
''
)
:
if
not
here
or
not
there
:
if
not
here
or
not
there
:
return
return
...
@@ -510,8 +507,9 @@ class client :
...
@@ -510,8 +507,9 @@ class client :
if
self
.
getNumber
(
'
0Metamodel/9Use restored solution
'
)
:
if
self
.
getNumber
(
'
0Metamodel/9Use restored solution
'
)
:
return
self
.
getStringChoices
(
'
0Metamodel/9Solution files
'
)
return
self
.
getStringChoices
(
'
0Metamodel/9Solution files
'
)
else
:
else
:
self
.
setNumber
(
'
0Metamodel/9Use restored solution
'
,
visible
=
0
)
self
.
setString
(
'
0Metamodel/9Solution files
'
,
value
=
list
[
0
],
self
.
setString
(
'
0Metamodel/9Solution files
'
,
value
=
list
[
0
],
choices
=
list
,
readOnly
=
1
)
choices
=
list
,
readOnly
=
1
)
return
list
return
list
def
restoreSolution
(
self
)
:
def
restoreSolution
(
self
)
:
...
@@ -521,11 +519,9 @@ class client :
...
@@ -521,11 +519,9 @@ class client :
if
list
:
if
list
:
self
.
setString
(
'
0Metamodel/9Output files
'
,
value
=
list
[
0
],
self
.
setString
(
'
0Metamodel/9Output files
'
,
value
=
list
[
0
],
choices
=
list
,
visible
=
1
)
choices
=
list
,
visible
=
1
)
# self.setString(self.name+'/9Output files', value=list[0],
# choices=list, visible=1)
# tool to extract the (i, j)th element in an array file
# tool to extract the (i, j)th element in an array file
from
rlcompleter
import
readline
#
from rlcompleter import readline
def
extract
(
filename
,
i
,
j
):
def
extract
(
filename
,
i
,
j
):
input
=
open
(
filename
,
'
r
'
)
input
=
open
(
filename
,
'
r
'
)
all_lines
=
input
.
readlines
()
all_lines
=
input
.
readlines
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment