Skip to content

Commit e90208c

Browse files
committed
Mask and MaxLength conditions
1 parent a61c4f2 commit e90208c

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

isc/py/data/Context.cls

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Method PopulateModules() As %Status
6161
}
6262

6363
/// Get variables and their values.
64-
Method PopulateVariables() As %Status
64+
Method PopulateVariables(maxLength As %Integer = {$$$MaxStringLength}, mask As %String = "*") As %Status
6565
{
6666
#dim sc As %Status = $$$OK
6767

@@ -73,9 +73,13 @@ Method PopulateVariables() As %Status
7373
set iterator = variables.%GetIterator()
7474
while iterator.%GetNext(.key, .variable) {
7575
#dim varObj As isc.py.data.Varable
76-
set sc = ##class(isc.py.data.Variable).SaveVariable(variable, .varObj)
77-
quit:$$$ISERR(sc)
78-
do ..Variables.Insert(varObj)
76+
kill varObj
77+
if ##class(isc.py.util.Matcher).MatchOr(variable, mask) {
78+
set sc = ##class(isc.py.data.Variable).SaveVariable(variable, maxLength, .varObj)
79+
quit:$$$ISERR(sc)
80+
do:$isObject($g(varObj)) ..Variables.Insert(varObj)
81+
}
82+
7983
}
8084

8185
quit sc
@@ -98,8 +102,8 @@ Method Init()
98102

99103
/// Save Python context on disk
100104
/// context - resulting context
101-
/// maxLength - maximum length of saved variable. If veriable serialization is longer than that, it would be ignored. Overrides mask. Set to 0 to get them all.
102-
/// mask - commaseparated list of variables to save. Special symbols * and ? are recognized.
105+
/// maxLength - maximum length of saved variable. If veriable serialization is longer than that, it would be ignored. Set to 0 to get them all.
106+
/// mask - comma separated list of variables to save. Special symbols * and ? are recognized. Set to * to get them all.
103107
/// set sc=##class(isc.py.data.Context).SaveContext()
104108
ClassMethod SaveContext(Output context As isc.py.data.Context, maxLength As %Integer = {$$$MaxStringLength}, mask As %String = "*", verbose As %Boolean = {$$$NO}) As %Status
105109
{
@@ -109,7 +113,7 @@ ClassMethod SaveContext(Output context As isc.py.data.Context, maxLength As %Int
109113
//do obj.PopulateHistory()
110114
set sc = context.PopulateModules()
111115
quit:$$$ISERR(sc) sc
112-
set sc = context.PopulateVariables()
116+
set sc = context.PopulateVariables(maxLength, mask)
113117
quit:$$$ISERR(sc) sc
114118
do:verbose context.Display()
115119

isc/py/data/Variable.cls

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ Property Pickle As %Stream.GlobalCharacter;
2020
Property JSON As %Stream.GlobalCharacter;
2121

2222
/// Save variable on disk.
23+
/// Do not save if length > maxLength
2324
/// zw ##class(isc.py.data.Variable).SaveVariable()
24-
ClassMethod SaveVariable(variable As %String = "", Output obj As isc.py.data.Variable) As %Status
25+
ClassMethod SaveVariable(variable As %String = "", maxLength As %Integer = {$$$MaxStringLength}, Output obj As isc.py.data.Variable) As %Status
2526
{
2627
#include Ensemble
2728
kill obj
@@ -30,8 +31,8 @@ ClassMethod SaveVariable(variable As %String = "", Output obj As isc.py.data.Var
3031
//$$$TRACE(variable)
3132

3233
set sc = ##class(isc.py.Main).GetVariableInfo(variable, ##class(isc.py.Callout).#SerializationRepr, .defined, .type, .length)
33-
quit:$$$ISERR(sc) sc
34-
quit:'defined $$$ERROR($$$GeneralError, "Variable '" _ variable _ "' is not defined")
34+
quit:(($$$ISERR(sc)) || ((maxLength>0) && (length>maxLength))) sc
35+
quit:'defined $$$ERROR($$$GeneralError, "Variable '" _ variable _ "' is not defined")
3536

3637
#dim repr, pickle, json As %Stream.GlobalCharacter
3738

isc/py/ens/Operation.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Method SaveContext(request As isc.py.msg.SaveRequest, Output response As Ens.Str
5757
{
5858
#dim sc As %Status = $$$OK
5959
#dim context As isc.py.data.Context
60-
set sc = ##class(isc.py.data.Context).SaveContext(.context)
60+
set sc = ##class(isc.py.data.Context).SaveContext(.context, request.MaxLength, request.Mask)
6161
quit:$$$ISERR(sc) sc
6262

6363
set context.Name = request.Name

isc/py/msg/SaveRequest.cls

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22
Class isc.py.msg.SaveRequest Extends Ens.Request
33
{
44

5-
/// TODO Only variables that satisfy Mask are saved.
6-
/// Wildcards * and ? are accepted, masks are commaseparated.
5+
/// Comma-separated list of variables to save.
6+
/// Only variables that satisfy Mask are saved.
7+
/// Wildcards * and ? are accepted.
8+
/// Example: "Data*,Figure?"
79
Property Mask As %VarString [ InitialExpression = "*" ];
810

11+
/// Maximum length of saved variable.
12+
/// If veriable serialization is longer than that, it would be ignored.
13+
/// Set to 0 to get them all.
14+
Property MaxLength As %Integer [ InitialExpression = {$$$MaxStringLength} ];
15+
916
/// Short name for the context.
1017
Property Name As %String;
1118

@@ -25,6 +32,9 @@ Storage Default
2532
<Value name="3">
2633
<Value>Description</Value>
2734
</Value>
35+
<Value name="4">
36+
<Value>MaxLength</Value>
37+
</Value>
2838
</Data>
2939
<DefaultData>SaveRequestDefaultData</DefaultData>
3040
<Type>%Library.CacheStorage</Type>

0 commit comments

Comments
 (0)