@@ -14,7 +14,7 @@ v1 = addVariable!(dfg, :a, ContinuousScalar, labels = [:POSE], solvable=0)
14
14
saveDFG(dfg, "/tmp/saveDFG")
15
15
```
16
16
"""
17
- function saveDFG (dfg:: G , folder:: String ) where G <: AbstractDFG
17
+ function saveDFG (dfg:: AbstractDFG , folder:: String ; compress :: Symbol = :gzip )
18
18
variables = getVariables (dfg)
19
19
factors = getFactors (dfg)
20
20
varFolder = " $folder /variables"
@@ -43,6 +43,19 @@ function saveDFG(dfg::G, folder::String) where G <: AbstractDFG
43
43
JSON2. write (io, fPacked)
44
44
close (io)
45
45
end
46
+
47
+ # compress newly saved folder, skip if not supported format
48
+ ! (compress in [:gzip ]) && return
49
+ savepath = folder[end ] == ' /' ? folder[1 : end - 1 ] : folder
50
+ savedir = dirname (savepath)
51
+ savename = splitpath (string (savepath))[end ]
52
+ @assert savename != " "
53
+ # temporarily change working directory to get correct zipped path
54
+ here = Base. pwd ()
55
+ Base. cd (savedir)
56
+ run (` tar -zcf $savepath .tar.gz $savename ` )
57
+ Base. rm (savename, recursive= true )
58
+ Base. cd (here)
46
59
end
47
60
48
61
"""
@@ -56,12 +69,25 @@ using DistributedFactorGraphs, IncrementalInference
56
69
# Create a DFG - can make one directly, e.g. GraphsDFG{NoSolverParams}() or use IIF:
57
70
dfg = initfg()
58
71
# Load the graph
59
- loadDFG("/tmp/savedgraph", IncrementalInference, dfg)
72
+ loadDFG("/tmp/savedgraph.tar.gz", IncrementalInference, dfg)
73
+ loadDFG("/tmp/savedgraph", IncrementalInference, dfg) # alternative
60
74
# Use the DFG as you do normally.
61
75
ls(dfg)
62
76
```
63
77
"""
64
- function loadDFG (folder:: String , iifModule, dfgLoadInto:: G ) where G <: AbstractDFG
78
+ function loadDFG (dst:: String , iifModule, dfgLoadInto:: G ) where G <: AbstractDFG
79
+ # check if zipped dst first
80
+ folder = dst
81
+ sdist = split (dst, ' .' )
82
+ if sdist[end ] == " gz" && sdist[end - 1 ] == " tar"
83
+ caesardir = joinpath (" /tmp" ," caesar" ," random" )
84
+ Base. mkpath (caesardir)
85
+ folder = joinpath (caesardir, splitpath (string (sdist[end - 2 ]))[end ] )
86
+ @info " loadDF detected a gzip tarball -- unpacking via $folder now..."
87
+ Base. rm (folder, recursive= true , force= true )
88
+ # unzip the tar file
89
+ run (` tar -zxf $dst -C $caesardir ` )
90
+ end
65
91
variables = DFGVariable[]
66
92
factors = DFGFactor[]
67
93
varFolder = " $folder /variables"
0 commit comments