Skip to content

Commit

Permalink
ok got it to dump only new items
Browse files Browse the repository at this point in the history
  • Loading branch information
doutriaux1 committed Nov 5, 2015
1 parent a839478 commit cfe05ae
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 44 deletions.
20 changes: 0 additions & 20 deletions Packages/vcs/Lib/Canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@
from xmldocs import plot_keywords_doc, graphics_method_core, axesconvert, xaxisconvert, \
plot_1D_input, plot_2D_input, plot_output, plot_2_1D_input, \
plot_2_1D_options
# Flag to set if the initial attributes file has aready been read in
called_initial_attributes_flg = 0
gui_canvas_closed = 0
canvas_closed = 0
import vcsaddons
Expand Down Expand Up @@ -883,7 +881,6 @@ def __init__(self, gui=0, mode=1, pause_time=0,
if found is False:
os.environ["PATH"] = os.environ["PATH"] + \
":" + os.path.join(sys.prefix, "bin")
global called_initial_attributes_flg
global gui_canvas_closed
global canvas_closed

Expand Down Expand Up @@ -961,23 +958,6 @@ def __init__(self, gui=0, mode=1, pause_time=0,
# to make sure that the initial attributes file is called only once for normalization #
# purposes.... #
##########################################################################
if called_initial_attributes_flg == 0:
pth = vcs.__path__[0].split(os.path.sep)
pth = pth[:-4] # Maybe need to make sure on none framework config
pth = ['/'] + pth + ['share', 'vcs', 'initial.attributes']
try:
vcs.scriptrun(os.path.join(*pth))
except:
pass
self._dotdir, self._dotdirenv = vcs.getdotdirectory()
user_init = os.path.join(
os.environ['HOME'],
self._dotdir,
'initial.attributes')
if os.path.exists(user_init):
vcs.scriptrun(user_init)
else:
shutil.copy2(os.path.join(*pth), user_init)

called_initial_attributes_flg = 1
self.canvas_template_editor = None
Expand Down
7 changes: 3 additions & 4 deletions Packages/vcs/Lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

_default_time_units = 'days since 2000'


##########################################################################
# #
# Set up the User's directory if necessary. Copy files from #
Expand All @@ -59,14 +58,14 @@


elements = collections.OrderedDict()
elements["list"] = {}
elements["projection"] = {}
elements["texttable"] = {}
elements["textorientation"] = {}
elements["textcombined"] = {}
elements["line"] = {}
elements["marker"] = {}
elements["fillarea"] = {}
elements["list"] = {}
elements["font"] = {}
elements["fontNumber"] = {}
elements["boxfill"] = {}
Expand Down Expand Up @@ -217,10 +216,10 @@
for k in elts.keys(): # let's save which elements should be saved and untouched
_protected_elements[typ].add(k)

self._dotdir, self._dotdirenv = vcs.getdotdirectory()
_dotdir, _dotdirenv = vcs.getdotdirectory()
user_init = os.path.join(
os.environ['HOME'],
self._dotdir,
_dotdir,
'initial.attributes')
if os.path.exists(user_init):
vcs.scriptrun(user_init)
Expand Down
42 changes: 22 additions & 20 deletions Packages/vcs/Lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import vcsaddons
import cdms2
import genutil
import copy

indent = 1
sort_keys = True
Expand Down Expand Up @@ -103,7 +104,7 @@ def dumpToJson(obj, fileout, skipped=[
f.close()
for etype in associated.keys():
for asso in associated[etype]:
if asso is not None:
if asso is not None and asso not in vcs._protected_elements[etype]:
dumpToJson(
vcs.elements[etype][asso],
fileout,
Expand Down Expand Up @@ -521,38 +522,39 @@ def scriptrun_scr(*args):
os.remove(temporary_file_name)
fin.close()


def saveinitialfile():
_dotdir, _dotdirenv = vcs.getdotdirectory()
fnm = os.path.join(os.environ['HOME'], _dotdir, 'initial.attributes')
if os.path.exists(fnm):
os.remove(fnm)
items = vcs.elements.keys()
for k in ["projection", "marker", "texttable",
"textorientation", "line", "list"]:
items.remove(k)
items.insert(0, k)
for k in items:
if k in ["font", "fontNumber"]:
Skip={}
for k in vcs.elements.keys():
Skip[k] = []
for e in vcs.elements[k].keys():
if e in vcs._protected_elements[k] or e[:2]=="__": # temporary elt
Skip[k].append(e)
for k in vcs.elements.keys():
if k in ["display", "font", "fontNumber"]:
continue
elif k == "list":
D = {}
D["L"] = vcs.elements["list"]
f = open(fnm + ".json", "w")
json.dump(D, f)
f.close()
D2 = {}
D2["L"] = {}
for l in vcs.elements["list"].keys():
if not l in Skip["list"]:
D2["L"][l]=vcs.elements["list"][l]
if len(D2["L"].keys())!=0:
f = open(fnm + ".json", "w")
json.dump(D2, f)
f.close()
continue
e = vcs.elements[k]
for nm, g in e.iteritems():
if nm != "default" and not nm[:2] == "__" \
and nm not in ["default_scatter_",
"default_xvsy_", "default_xyvsy_",
"default_yxvsx_"]: # skip defaults and temp ones
if not nm in Skip[k]:
try:
g.script(fnm)
except Exception as err:
warnings.warn(
"Could not save graphic method %s named %si: %s" %
"Could not save graphic method %s named %s: %s" %
(k, nm, err))
# extension .json has been auto-added, removing it in this specific case
os.rename(fnm + ".json", fnm)
Expand Down Expand Up @@ -596,7 +598,7 @@ def scriptrun(script):
f = open(script)
jsn = json.load(f)
keys = []
for k in ["Tt", "To", "Tl", "Tm"]: # always read these first
for k in ["Tt", "To", "Tl", "Tm", "Proj"]: # always read these first
if k in jsn.keys():
keys.append(k)
for k in jsn.keys():
Expand Down

0 comments on commit cfe05ae

Please sign in to comment.