mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-21 05:12:27 +12:00
Saving 2.0 works.
This commit is contained in:
parent
b26de717a9
commit
fa386896db
|
@ -13,7 +13,7 @@ import manuskript.load_save.version_1 as v1
|
||||||
def saveProject(version=None):
|
def saveProject(version=None):
|
||||||
|
|
||||||
# While debugging, we don't save the project
|
# While debugging, we don't save the project
|
||||||
return
|
# return
|
||||||
|
|
||||||
if version == 0:
|
if version == 0:
|
||||||
v0.saveProject()
|
v0.saveProject()
|
||||||
|
|
|
@ -47,18 +47,9 @@ characterMap = OrderedDict([
|
||||||
(Character.summaryFull, "Full Summary"),
|
(Character.summaryFull, "Full Summary"),
|
||||||
(Character.notes, "Notes"),
|
(Character.notes, "Notes"),
|
||||||
])
|
])
|
||||||
# characterMap = {
|
|
||||||
# Character.name: "Name",
|
# If true, logs infos while saving and loading.
|
||||||
# Character.ID: "ID",
|
LOG = False
|
||||||
# Character.importance: "Importance",
|
|
||||||
# Character.motivation: "Motivation",
|
|
||||||
# Character.goal: "Goal",
|
|
||||||
# Character.conflict: "Conflict",
|
|
||||||
# Character.summarySentence: "Phrase Summary",
|
|
||||||
# Character.summaryPara: "Paragraph Summary",
|
|
||||||
# Character.summaryFull: "Full Summary",
|
|
||||||
# Character.notes: "Notes",
|
|
||||||
# }
|
|
||||||
|
|
||||||
def formatMetaData(name, value, tabLength=10):
|
def formatMetaData(name, value, tabLength=10):
|
||||||
|
|
||||||
|
@ -99,7 +90,8 @@ def slugify(name):
|
||||||
|
|
||||||
|
|
||||||
def log(*args):
|
def log(*args):
|
||||||
print(" ".join(str(a) for a in args))
|
if LOG:
|
||||||
|
print(" ".join(str(a) for a in args))
|
||||||
|
|
||||||
|
|
||||||
def saveProject(zip=None):
|
def saveProject(zip=None):
|
||||||
|
@ -327,6 +319,10 @@ def saveProject(zip=None):
|
||||||
# Debug
|
# Debug
|
||||||
log("\nSaving to folder", folder)
|
log("\nSaving to folder", folder)
|
||||||
|
|
||||||
|
# If cache is empty (meaning we haven't loaded from disk), we wipe folder, just to be sure.
|
||||||
|
if not cache:
|
||||||
|
shutil.rmtree(os.path.join(dir, folder))
|
||||||
|
|
||||||
# Moving files that have been renamed
|
# Moving files that have been renamed
|
||||||
for old, new in moves:
|
for old, new in moves:
|
||||||
|
|
||||||
|
@ -358,7 +354,7 @@ def saveProject(zip=None):
|
||||||
|
|
||||||
# Check if content is in cache, and write if necessary
|
# Check if content is in cache, and write if necessary
|
||||||
if path not in cache or cache[path] != content:
|
if path not in cache or cache[path] != content:
|
||||||
log("* Writing file", path)
|
log("* Writing file {} ({})".format(path, "not in cache" if path not in cache else "different"))
|
||||||
mode = "w" + ("b" if type(content) == bytes else "")
|
mode = "w" + ("b" if type(content) == bytes else "")
|
||||||
with open(filename, mode) as f:
|
with open(filename, mode) as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
@ -372,6 +368,10 @@ def saveProject(zip=None):
|
||||||
if os.path.isdir(filename):
|
if os.path.isdir(filename):
|
||||||
shutil.rmtree(filename)
|
shutil.rmtree(filename)
|
||||||
|
|
||||||
|
elif path == "VERSION":
|
||||||
|
# If loading from zip, but saving to path, file VERSION is not needed.
|
||||||
|
continue
|
||||||
|
|
||||||
else: # elif os.path.exists(filename)
|
else: # elif os.path.exists(filename)
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
|
|
||||||
|
@ -442,12 +442,12 @@ def addPlotItem(root, mdl, parent=QModelIndex()):
|
||||||
|
|
||||||
index = mdl.index(x, y, parent)
|
index = mdl.index(x, y, parent)
|
||||||
val = mdl.data(index)
|
val = mdl.data(index)
|
||||||
|
#
|
||||||
if not val:
|
# if not val:
|
||||||
continue
|
# continue
|
||||||
|
|
||||||
for w in Plot:
|
for w in Plot:
|
||||||
if y == w.value:
|
if y == w.value and val:
|
||||||
outline.attrib[w.name] = val
|
outline.attrib[w.name] = val
|
||||||
|
|
||||||
# List characters as attrib
|
# List characters as attrib
|
||||||
|
@ -459,7 +459,8 @@ def addPlotItem(root, mdl, parent=QModelIndex()):
|
||||||
cIndex = mdl.index(cX, cY, index)
|
cIndex = mdl.index(cX, cY, index)
|
||||||
characters.append(mdl.data(cIndex))
|
characters.append(mdl.data(cIndex))
|
||||||
outline.attrib[Plot.characters.name] = ",".join(characters)
|
outline.attrib[Plot.characters.name] = ",".join(characters)
|
||||||
else:
|
|
||||||
|
elif Plot.characters.name in outline.attrib:
|
||||||
outline.attrib.pop(Plot.characters.name)
|
outline.attrib.pop(Plot.characters.name)
|
||||||
|
|
||||||
# List resolution steps as sub items
|
# List resolution steps as sub items
|
||||||
|
@ -475,7 +476,8 @@ def addPlotItem(root, mdl, parent=QModelIndex()):
|
||||||
if cY == w.value:
|
if cY == w.value:
|
||||||
step.attrib[w.name] = val
|
step.attrib[w.name] = val
|
||||||
|
|
||||||
outline.attrib.pop(Plot.steps.name)
|
elif Plot.steps.name in outline.attrib:
|
||||||
|
outline.attrib.pop(Plot.steps.name)
|
||||||
|
|
||||||
return root
|
return root
|
||||||
|
|
||||||
|
@ -621,12 +623,13 @@ def loadProject(project, zip=None):
|
||||||
with open(os.path.join(dirpath, f), mode) as fo:
|
with open(os.path.join(dirpath, f), mode) as fo:
|
||||||
files[os.path.join(p, f)] = fo.read()
|
files[os.path.join(p, f)] = fo.read()
|
||||||
|
|
||||||
|
# Saves to cache (only if we loaded from disk and not zip)
|
||||||
|
global cache
|
||||||
|
cache = files
|
||||||
|
|
||||||
# Sort files by keys
|
# Sort files by keys
|
||||||
files = OrderedDict(sorted(files.items()))
|
files = OrderedDict(sorted(files.items()))
|
||||||
|
|
||||||
# Saves to cache
|
|
||||||
cache = files
|
|
||||||
|
|
||||||
####################################################################################################################
|
####################################################################################################################
|
||||||
# Settings
|
# Settings
|
||||||
|
|
||||||
|
@ -764,6 +767,7 @@ def loadProject(project, zip=None):
|
||||||
for f in [f for f in files if "characters" in f]:
|
for f in [f for f in files if "characters" in f]:
|
||||||
md, body = parseMMDFile(files[f])
|
md, body = parseMMDFile(files[f])
|
||||||
c = mdl.addCharacter()
|
c = mdl.addCharacter()
|
||||||
|
c.lastPath = f
|
||||||
|
|
||||||
color = False
|
color = False
|
||||||
for desc, val in md:
|
for desc, val in md:
|
||||||
|
@ -804,13 +808,15 @@ def loadProject(project, zip=None):
|
||||||
|
|
||||||
last = ""
|
last = ""
|
||||||
parent = outline
|
parent = outline
|
||||||
|
parentLastPath = "outline"
|
||||||
for i in split:
|
for i in split:
|
||||||
if last:
|
if last:
|
||||||
parent = parent[last]
|
parent = parent[last]
|
||||||
|
parentLastPath = os.path.join(parentLastPath, last)
|
||||||
last = i
|
last = i
|
||||||
|
|
||||||
if not i in parent:
|
if not i in parent:
|
||||||
# If not last item, then it is folder
|
# If not last item, then it is a folder
|
||||||
if i != split[-1]:
|
if i != split[-1]:
|
||||||
parent[i] = OrderedDict()
|
parent[i] = OrderedDict()
|
||||||
|
|
||||||
|
@ -818,6 +824,11 @@ def loadProject(project, zip=None):
|
||||||
else:
|
else:
|
||||||
parent[i] = files[f]
|
parent[i] = files[f]
|
||||||
|
|
||||||
|
# We store f to add it later as lastPath
|
||||||
|
parent[i + ":lastPath"] = os.path.join(parentLastPath, i)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# We now just have to recursively add items.
|
# We now just have to recursively add items.
|
||||||
addTextItems(mdl, outline)
|
addTextItems(mdl, outline)
|
||||||
|
|
||||||
|
@ -850,14 +861,19 @@ def addTextItems(mdl, odict, parent=None):
|
||||||
# Adds folder
|
# Adds folder
|
||||||
log("{}* Adds {} to {} (folder)".format(" " * parent.level(), k, parent.title()))
|
log("{}* Adds {} to {} (folder)".format(" " * parent.level(), k, parent.title()))
|
||||||
item = outlineFromMMD(odict[k]["folder.txt"], parent=parent)
|
item = outlineFromMMD(odict[k]["folder.txt"], parent=parent)
|
||||||
|
item._lastPath = odict[k + ":lastPath"]
|
||||||
|
|
||||||
# Read content
|
# Read content
|
||||||
addTextItems(mdl, odict[k], parent=item)
|
addTextItems(mdl, odict[k], parent=item)
|
||||||
|
|
||||||
# In case it is not
|
# k is not a folder
|
||||||
elif k != "folder.txt":
|
elif type(odict[k]) == str and k != "folder.txt" and not ":lastPath" in k:
|
||||||
log("{}* Adds {} to {} (file)".format(" " * parent.level(), k, parent.title()))
|
log("{}* Adds {} to {} (file)".format(" " * parent.level(), k, parent.title()))
|
||||||
item = outlineFromMMD(odict[k], parent=parent)
|
item = outlineFromMMD(odict[k], parent=parent)
|
||||||
|
item._lastPath = odict[k + ":lastPath"]
|
||||||
|
|
||||||
|
elif not ":lastPath" in k and k != "folder.txt":
|
||||||
|
print("* Strange things in file {}".format(k))
|
||||||
|
|
||||||
|
|
||||||
def outlineFromMMD(text, parent):
|
def outlineFromMMD(text, parent):
|
||||||
|
|
Loading…
Reference in a new issue