mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-17 03:12:27 +12:00
Add data status to objects
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
parent
25e0d700a4
commit
3516242500
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
# --!-- coding: utf8 --!--
|
||||
|
||||
from manuskript.data.abstractData import DataStatus
|
||||
from manuskript.data.characters import Characters, Character
|
||||
from manuskript.data.color import Color
|
||||
from manuskript.data.goal import Goal
|
||||
|
|
33
manuskript/data/abstractData.py
Normal file
33
manuskript/data/abstractData.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env python
|
||||
# --!-- coding: utf8 --!--
|
||||
|
||||
from enum import Enum, unique
|
||||
|
||||
|
||||
@unique
|
||||
class DataStatus(Enum):
|
||||
UNDEFINED = 0
|
||||
CHANGED = 1
|
||||
LOADING = 2
|
||||
LOADED = 3
|
||||
SAVING = 4
|
||||
SAVED = 5
|
||||
|
||||
|
||||
class AbstractData:
|
||||
|
||||
def __init__(self, path):
|
||||
self.dataPath = path
|
||||
self.dataStatus = DataStatus.UNDEFINED
|
||||
|
||||
def complete(self, statusCompletion: bool = True):
|
||||
if self.dataStatus == DataStatus.LOADING:
|
||||
self.dataStatus = DataStatus.LOADED if statusCompletion else DataStatus.UNDEFINED
|
||||
elif self.dataStatus == DataStatus.SAVING:
|
||||
self.dataStatus = DataStatus.SAVED
|
||||
|
||||
def load(self):
|
||||
self.dataStatus = DataStatus.LOADING
|
||||
|
||||
def save(self):
|
||||
self.dataStatus = DataStatus.SAVING
|
|
@ -5,6 +5,7 @@ import os
|
|||
|
||||
from collections import OrderedDict
|
||||
|
||||
from manuskript.data.abstractData import AbstractData
|
||||
from manuskript.data.color import Color
|
||||
from manuskript.data.importance import Importance
|
||||
from manuskript.data.links import LinkAction, Links
|
||||
|
@ -13,10 +14,11 @@ from manuskript.io.mmdFile import MmdFile
|
|||
from manuskript.util import safeFilename
|
||||
|
||||
|
||||
class Character:
|
||||
class Character(AbstractData):
|
||||
|
||||
def __init__(self, path, characters):
|
||||
self.file = MmdFile(path, 21)
|
||||
AbstractData.__init__(self, path)
|
||||
self.file = MmdFile(self.dataPath, 21)
|
||||
self.characters = characters
|
||||
self.links = Links()
|
||||
|
||||
|
@ -50,6 +52,8 @@ class Character:
|
|||
return defaultValue
|
||||
|
||||
def load(self):
|
||||
AbstractData.load(self)
|
||||
|
||||
metadata, _ = self.file.loadMMD(True)
|
||||
|
||||
ID = Character.loadAttribute(metadata, "ID")
|
||||
|
@ -79,8 +83,11 @@ class Character:
|
|||
self.details[key] = value
|
||||
|
||||
self.links.call(LinkAction.RELOAD, self.UID, self)
|
||||
self.complete()
|
||||
|
||||
def save(self):
|
||||
AbstractData.save(self)
|
||||
|
||||
metadata = OrderedDict()
|
||||
|
||||
metadata["Name"] = self.name
|
||||
|
@ -102,12 +109,13 @@ class Character:
|
|||
metadata[key] = value
|
||||
|
||||
self.file.save((metadata, None))
|
||||
self.complete()
|
||||
|
||||
|
||||
class Characters:
|
||||
class Characters(AbstractData):
|
||||
|
||||
def __init__(self, path):
|
||||
self.dir_path = os.path.join(path, "characters")
|
||||
AbstractData.__init__(self, os.path.join(path, "characters"))
|
||||
self.host = UniqueIDHost()
|
||||
self.data = dict()
|
||||
|
||||
|
@ -121,7 +129,7 @@ class Characters:
|
|||
UID = self.host.newID()
|
||||
filename = safeFilename("%s-%s" % (str(UID), name), "txt")
|
||||
|
||||
path = os.path.join(self.dir_path, filename)
|
||||
path = os.path.join(self.dataPath, filename)
|
||||
|
||||
if os.path.exists(filename):
|
||||
return None
|
||||
|
@ -143,12 +151,14 @@ class Characters:
|
|||
|
||||
def load(self):
|
||||
self.data.clear()
|
||||
AbstractData.load(self)
|
||||
|
||||
if not os.path.isdir(self.dir_path):
|
||||
if not os.path.isdir(self.dataPath):
|
||||
self.complete(False)
|
||||
return
|
||||
|
||||
for filename in os.listdir(self.dir_path):
|
||||
path = os.path.join(self.dir_path, filename)
|
||||
for filename in os.listdir(self.dataPath):
|
||||
path = os.path.join(self.dataPath, filename)
|
||||
|
||||
if not os.path.isfile(path):
|
||||
continue
|
||||
|
@ -162,10 +172,16 @@ class Characters:
|
|||
|
||||
self.data[character.UID.value] = character
|
||||
|
||||
self.complete()
|
||||
|
||||
def save(self):
|
||||
AbstractData.save(self)
|
||||
|
||||
if not self.data:
|
||||
return
|
||||
|
||||
os.makedirs(self.dir_path, exist_ok=True)
|
||||
os.makedirs(self.dataPath, exist_ok=True)
|
||||
for character in self.data.values():
|
||||
character.save()
|
||||
|
||||
self.complete(False)
|
||||
|
|
|
@ -3,13 +3,15 @@
|
|||
|
||||
import os
|
||||
|
||||
from manuskript.data.abstractData import AbstractData
|
||||
from manuskript.io.mmdFile import MmdFile
|
||||
|
||||
|
||||
class Info:
|
||||
class Info(AbstractData):
|
||||
|
||||
def __init__(self, path):
|
||||
self.file = MmdFile(os.path.join(path, "infos.txt"), 16)
|
||||
AbstractData.__init__(self, os.path.join(path, "infos.txt"))
|
||||
self.file = MmdFile(self.dataPath, 16)
|
||||
|
||||
self.title = None
|
||||
self.subtitle = None
|
||||
|
@ -21,6 +23,8 @@ class Info:
|
|||
self.email = None
|
||||
|
||||
def load(self):
|
||||
AbstractData.load(self)
|
||||
|
||||
try:
|
||||
metadata, _ = self.file.loadMMD(True)
|
||||
except FileNotFoundError:
|
||||
|
@ -34,8 +38,10 @@ class Info:
|
|||
self.license = metadata.get("License", None)
|
||||
self.author = metadata.get("Author", None)
|
||||
self.email = metadata.get("Email", None)
|
||||
self.complete()
|
||||
|
||||
def save(self):
|
||||
AbstractData.save(self)
|
||||
metadata = dict()
|
||||
|
||||
metadata["Title"] = self.title
|
||||
|
@ -48,3 +54,4 @@ class Info:
|
|||
metadata["Email"] = self.email
|
||||
|
||||
self.file.save((metadata, None))
|
||||
self.complete()
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
import collections
|
||||
import os
|
||||
|
||||
from manuskript.data.abstractData import AbstractData
|
||||
from manuskript.data.color import Color
|
||||
from manuskript.io.mmdFile import MmdFile
|
||||
|
||||
|
@ -27,10 +28,11 @@ class Label:
|
|||
self.host.save()
|
||||
|
||||
|
||||
class LabelHost:
|
||||
class LabelHost(AbstractData):
|
||||
|
||||
def __init__(self, path):
|
||||
self.file = MmdFile(os.path.join(path, "labels.txt"), 21)
|
||||
AbstractData.__init__(self, os.path.join(path, "labels.txt"))
|
||||
self.file = MmdFile(self.dataPath, 21)
|
||||
self.labels = collections.OrderedDict()
|
||||
|
||||
def addLabel(self, name: str = None, color: Color = None) -> Label:
|
||||
|
@ -86,11 +88,13 @@ class LabelHost:
|
|||
return self.labels.values().__iter__()
|
||||
|
||||
def load(self):
|
||||
self.labels.clear()
|
||||
AbstractData.load(self)
|
||||
|
||||
try:
|
||||
metadata, _ = self.file.loadMMD(True)
|
||||
self.labels.clear()
|
||||
except FileNotFoundError:
|
||||
self.labels.clear()
|
||||
self.complete(False)
|
||||
return
|
||||
|
||||
for (name, value) in metadata.items():
|
||||
|
@ -99,10 +103,14 @@ class LabelHost:
|
|||
|
||||
self.addLabel(name, Color.parse(value))
|
||||
|
||||
self.complete()
|
||||
|
||||
def save(self):
|
||||
AbstractData.save(self)
|
||||
metadata = collections.OrderedDict()
|
||||
|
||||
for (name, label) in self.labels.items():
|
||||
metadata[name] = label.color
|
||||
|
||||
self.file.save((metadata, None))
|
||||
self.complete()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
# --!-- coding: utf8 --!--
|
||||
|
||||
from collections.abc import Callable
|
||||
from enum import Enum, unique
|
||||
|
||||
|
|
|
@ -4,12 +4,13 @@
|
|||
import os
|
||||
|
||||
from collections import OrderedDict
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from enum import Enum, unique
|
||||
|
||||
from manuskript.data.abstractData import AbstractData, DataStatus
|
||||
from manuskript.data.goal import Goal
|
||||
from manuskript.data.labels import LabelHost, Label
|
||||
from manuskript.data.plots import Plots
|
||||
from manuskript.data.status import StatusHost, Status
|
||||
from manuskript.data.status import StatusHost
|
||||
from manuskript.data.unique_id import UniqueIDHost
|
||||
from manuskript.io.mmdFile import MmdFile
|
||||
from manuskript.util import CounterKind, countText, safeInt
|
||||
|
@ -22,10 +23,11 @@ class OutlineState(Enum):
|
|||
COMPLETE = 2
|
||||
|
||||
|
||||
class OutlineItem:
|
||||
class OutlineItem(AbstractData):
|
||||
|
||||
def __init__(self, path, outline):
|
||||
self.file = MmdFile(path)
|
||||
AbstractData.__init__(self, path)
|
||||
self.file = MmdFile(self.dataPath)
|
||||
self.outline = outline
|
||||
self.state = OutlineState.UNDEFINED
|
||||
|
||||
|
@ -108,11 +110,19 @@ class OutlineItem:
|
|||
def goalCount(self) -> int:
|
||||
return 0 if self.goal is None else self.goal.value
|
||||
|
||||
def complete(self, statusCompletion: bool = True, optimized: bool = True):
|
||||
AbstractData.complete(self, statusCompletion)
|
||||
|
||||
if self.dataStatus != DataStatus.LOADED:
|
||||
return
|
||||
|
||||
self.state = OutlineState.OPTIMIZED if optimized else OutlineState.COMPLETE
|
||||
|
||||
def load(self, optimized: bool = True):
|
||||
raise IOError('Loading undefined!')
|
||||
AbstractData.load(self)
|
||||
|
||||
def save(self):
|
||||
raise IOError('Saving undefined!')
|
||||
AbstractData.save(self)
|
||||
|
||||
|
||||
class OutlineText(OutlineItem):
|
||||
|
@ -137,31 +147,35 @@ class OutlineText(OutlineItem):
|
|||
return self.cache[counterKind.name]
|
||||
|
||||
def load(self, optimized: bool = True):
|
||||
OutlineItem.load(self)
|
||||
|
||||
metadata, body = self.file.loadMMD(optimized)
|
||||
OutlineItem.loadMetadata(self, metadata)
|
||||
|
||||
if not optimized:
|
||||
self.text = body
|
||||
self.state = OutlineState.COMPLETE
|
||||
elif self.state == OutlineState.UNDEFINED:
|
||||
self.state = OutlineState.OPTIMIZED
|
||||
|
||||
self.complete(optimized=optimized)
|
||||
|
||||
def save(self):
|
||||
if self.state == OutlineState.OPTIMIZED:
|
||||
self.outline.host.removeID(self.UID)
|
||||
self.load(False)
|
||||
|
||||
OutlineItem.save(self)
|
||||
|
||||
metadata = OutlineItem.saveMetadata(self)
|
||||
self.file.save((metadata, self.text))
|
||||
self.complete()
|
||||
|
||||
|
||||
class OutlineFolder(OutlineItem):
|
||||
|
||||
def __init__(self, path, outline):
|
||||
self.dir_path = path
|
||||
self.items = list()
|
||||
OutlineItem.__init__(self, os.path.join(path, "folder.txt"), outline)
|
||||
|
||||
OutlineItem.__init__(self, os.path.join(self.dir_path, "folder.txt"), outline)
|
||||
self.folderPath = path
|
||||
self.items = list()
|
||||
|
||||
def __iter__(self):
|
||||
return self.items.__iter__()
|
||||
|
@ -173,12 +187,12 @@ class OutlineFolder(OutlineItem):
|
|||
def loadItems(cls, outline, folder, recursive: bool = True):
|
||||
folder.items.clear()
|
||||
|
||||
names = os.listdir(folder.dir_path)
|
||||
names = os.listdir(folder.folderPath)
|
||||
names.remove("folder.txt")
|
||||
names.sort()
|
||||
|
||||
for name in names:
|
||||
path = os.path.join(folder.dir_path, name)
|
||||
path = os.path.join(folder.folderPath, name)
|
||||
|
||||
if os.path.isdir(path):
|
||||
item = OutlineFolder(path, outline)
|
||||
|
@ -213,17 +227,15 @@ class OutlineFolder(OutlineItem):
|
|||
return count
|
||||
|
||||
def load(self, optimized: bool = True):
|
||||
OutlineItem.load(self)
|
||||
|
||||
metadata, _ = self.file.loadMMD(True)
|
||||
OutlineItem.loadMetadata(self, metadata)
|
||||
|
||||
if optimized:
|
||||
self.state = OutlineState.OPTIMIZED
|
||||
else:
|
||||
for item in self.items:
|
||||
if item.state != OutlineState.COMPLETE:
|
||||
return
|
||||
if not optimized:
|
||||
optimized = any(item.state != OutlineState.COMPLETE for item in self.items)
|
||||
|
||||
self.state = OutlineState.COMPLETE
|
||||
self.complete(optimized=optimized)
|
||||
|
||||
@classmethod
|
||||
def saveItems(cls, folder, recursive: bool = True):
|
||||
|
@ -236,14 +248,18 @@ class OutlineFolder(OutlineItem):
|
|||
|
||||
def save(self):
|
||||
self.type = "folder"
|
||||
|
||||
OutlineItem.save(self)
|
||||
|
||||
metadata = OutlineItem.saveMetadata(self)
|
||||
self.file.save((metadata, "\n"))
|
||||
self.complete()
|
||||
|
||||
|
||||
class Outline:
|
||||
class Outline(AbstractData):
|
||||
|
||||
def __init__(self, path, plots: Plots, labels: LabelHost, statuses: StatusHost):
|
||||
self.dir_path = os.path.join(path, "outline")
|
||||
AbstractData.__init__(self, os.path.join(path, "outline"))
|
||||
self.host = UniqueIDHost()
|
||||
self.plots = plots
|
||||
self.labels = labels
|
||||
|
@ -299,11 +315,13 @@ class Outline:
|
|||
self.items.clear()
|
||||
self.cache.clear()
|
||||
|
||||
names = os.listdir(self.dir_path)
|
||||
AbstractData.load(self)
|
||||
|
||||
names = os.listdir(self.dataPath)
|
||||
names.sort()
|
||||
|
||||
for name in names:
|
||||
path = os.path.join(self.dir_path, name)
|
||||
path = os.path.join(self.dataPath, name)
|
||||
|
||||
if os.path.isdir(path):
|
||||
item = OutlineFolder(path, self)
|
||||
|
@ -320,9 +338,20 @@ class Outline:
|
|||
for item in filter(lambda outlineItem: type(outlineItem) is OutlineFolder, self.items):
|
||||
OutlineFolder.loadItems(self, item, True)
|
||||
|
||||
self.complete()
|
||||
|
||||
def save(self):
|
||||
AbstractData.save(self)
|
||||
|
||||
if not self.items:
|
||||
self.complete()
|
||||
return
|
||||
|
||||
os.makedirs(self.dataPath, exist_ok=True)
|
||||
for item in self.items:
|
||||
item.save()
|
||||
|
||||
for item in filter(lambda outlineItem: type(outlineItem) is OutlineFolder, self.items):
|
||||
OutlineFolder.saveItems(item, True)
|
||||
|
||||
self.complete()
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
import os
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from manuskript.data.abstractData import AbstractData
|
||||
from manuskript.data.characters import Characters, Character
|
||||
from manuskript.data.importance import Importance
|
||||
from manuskript.data.links import LinkAction, Links
|
||||
|
@ -102,10 +104,11 @@ class PlotLine:
|
|||
self.plots.save()
|
||||
|
||||
|
||||
class Plots:
|
||||
class Plots(AbstractData):
|
||||
|
||||
def __init__(self, path, characters: Characters):
|
||||
self.file = XmlFile(os.path.join(path, "plots.xml"))
|
||||
AbstractData.__init__(self, os.path.join(path, "plots.xml"))
|
||||
self.file = XmlFile(self.dataPath)
|
||||
self.host = UniqueIDHost()
|
||||
self.characters = characters
|
||||
self.lines = dict()
|
||||
|
@ -171,19 +174,22 @@ class Plots:
|
|||
|
||||
@classmethod
|
||||
def loadPlots(cls, plots, root: etree.Element):
|
||||
plots.host.reset()
|
||||
plots.lines.clear()
|
||||
|
||||
for element in root.findall("plot"):
|
||||
cls.loadPlotLine(plots, element)
|
||||
|
||||
def load(self):
|
||||
self.host.reset()
|
||||
self.lines.clear()
|
||||
|
||||
AbstractData.load(self)
|
||||
|
||||
try:
|
||||
tree = self.file.load()
|
||||
Plots.loadPlots(self, tree.getroot())
|
||||
|
||||
self.complete()
|
||||
except FileNotFoundError:
|
||||
self.host.reset()
|
||||
self.lines.clear()
|
||||
self.complete(False)
|
||||
|
||||
@classmethod
|
||||
def saveElementAttribute(cls, element: etree.Element, name: str, value):
|
||||
|
@ -230,5 +236,8 @@ class Plots:
|
|||
return root
|
||||
|
||||
def save(self):
|
||||
AbstractData.save(self)
|
||||
|
||||
tree = etree.ElementTree(Plots.savePlots(self))
|
||||
self.file.save(tree)
|
||||
self.complete()
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
import os
|
||||
|
||||
from zipfile import BadZipFile
|
||||
|
||||
from manuskript.data.abstractData import AbstractData
|
||||
from manuskript.data.version import Version, CURRENT_MSK_VERSION
|
||||
from manuskript.data.info import Info
|
||||
from manuskript.data.summary import Summary
|
||||
|
@ -19,22 +21,23 @@ from manuskript.io.mskFile import MskFile
|
|||
from manuskript.util import profileTime
|
||||
|
||||
|
||||
class Project:
|
||||
class Project(AbstractData):
|
||||
|
||||
def __init__(self, path):
|
||||
self.file = MskFile(path)
|
||||
AbstractData.__init__(self, path)
|
||||
self.file = MskFile(self.dataPath)
|
||||
|
||||
self.version = Version(self.file.dir_path)
|
||||
self.info = Info(self.file.dir_path)
|
||||
self.summary = Summary(self.file.dir_path)
|
||||
self.labels = LabelHost(self.file.dir_path)
|
||||
self.statuses = StatusHost(self.file.dir_path)
|
||||
self.settings = Settings(self.file.dir_path)
|
||||
self.characters = Characters(self.file.dir_path)
|
||||
self.plots = Plots(self.file.dir_path, self.characters)
|
||||
self.world = World(self.file.dir_path)
|
||||
self.outline = Outline(self.file.dir_path, self.plots, self.labels, self.statuses)
|
||||
self.revisions = Revisions(self.file.dir_path)
|
||||
self.version = Version(self.file.directoryPath)
|
||||
self.info = Info(self.file.directoryPath)
|
||||
self.summary = Summary(self.file.directoryPath)
|
||||
self.labels = LabelHost(self.file.directoryPath)
|
||||
self.statuses = StatusHost(self.file.directoryPath)
|
||||
self.settings = Settings(self.file.directoryPath)
|
||||
self.characters = Characters(self.file.directoryPath)
|
||||
self.plots = Plots(self.file.directoryPath, self.characters)
|
||||
self.world = World(self.file.directoryPath)
|
||||
self.outline = Outline(self.file.directoryPath, self.plots, self.labels, self.statuses)
|
||||
self.revisions = Revisions(self.file.directoryPath)
|
||||
|
||||
def __del__(self):
|
||||
del self.file
|
||||
|
@ -58,9 +61,12 @@ class Project:
|
|||
self.version.value = CURRENT_MSK_VERSION
|
||||
|
||||
def load(self):
|
||||
AbstractData.load(self)
|
||||
|
||||
try:
|
||||
self.file.load()
|
||||
except BadZipFile or FileNotFoundError:
|
||||
self.complete(False)
|
||||
return
|
||||
|
||||
profileTime(self.version.load)
|
||||
|
@ -76,8 +82,10 @@ class Project:
|
|||
profileTime(self.revisions.load)
|
||||
|
||||
self.file.setZipFile(self.settings.isEnabled("saveToZip"))
|
||||
self.complete()
|
||||
|
||||
def save(self):
|
||||
AbstractData.save(self)
|
||||
saveToZip = self.settings.isEnabled("saveToZip")
|
||||
|
||||
self.file.setZipFile(saveToZip)
|
||||
|
@ -96,3 +104,4 @@ class Project:
|
|||
#self.revisions.save()
|
||||
|
||||
self.file.save(saveToZip)
|
||||
self.complete()
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
import os
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from manuskript.data.abstractData import AbstractData
|
||||
from manuskript.io.xmlFile import XmlFile
|
||||
|
||||
|
||||
|
@ -34,10 +36,11 @@ class RevisionOutline:
|
|||
self.revisions.load()
|
||||
|
||||
|
||||
class Revisions:
|
||||
class Revisions(AbstractData):
|
||||
|
||||
def __init__(self, path):
|
||||
self.file = XmlFile(os.path.join(path, "revisions.xml"))
|
||||
AbstractData.__init__(self, os.path.join(path, "revisions.xml"))
|
||||
self.file = XmlFile(self.dataPath)
|
||||
self.outline = dict()
|
||||
|
||||
def __iter__(self):
|
||||
|
@ -78,10 +81,22 @@ class Revisions:
|
|||
cls.loadRevisionOutline(revisions, child, element)
|
||||
|
||||
def load(self):
|
||||
self.outline.clear()
|
||||
|
||||
AbstractData.load(self)
|
||||
|
||||
try:
|
||||
tree = self.file.load()
|
||||
self.outline.clear()
|
||||
|
||||
Revisions.loadRevisionOutline(self, tree.getroot(), None)
|
||||
|
||||
self.complete()
|
||||
except FileNotFoundError:
|
||||
self.outline.clear()
|
||||
self.complete(False)
|
||||
|
||||
def save(self):
|
||||
AbstractData.save(self)
|
||||
|
||||
# TODO
|
||||
|
||||
self.complete()
|
||||
|
|
|
@ -3,13 +3,15 @@
|
|||
|
||||
import os
|
||||
|
||||
from manuskript.data.abstractData import AbstractData
|
||||
from manuskript.io.jsonFile import JsonFile
|
||||
|
||||
|
||||
class Settings:
|
||||
class Settings(AbstractData):
|
||||
|
||||
def __init__(self, path, initDefault: bool = True):
|
||||
self.file = JsonFile(os.path.join(path, "settings.txt"))
|
||||
AbstractData.__init__(self, os.path.join(path, "settings.txt"))
|
||||
self.file = JsonFile(self.dataPath)
|
||||
self.properties = dict()
|
||||
|
||||
if initDefault:
|
||||
|
@ -134,10 +136,17 @@ class Settings:
|
|||
}
|
||||
|
||||
def load(self):
|
||||
AbstractData.load(self)
|
||||
|
||||
try:
|
||||
self.properties = self.file.load()
|
||||
except FileNotFoundError:
|
||||
Settings.loadDefaultSettings(self)
|
||||
|
||||
self.complete()
|
||||
|
||||
def save(self):
|
||||
AbstractData.save(self)
|
||||
|
||||
self.file.save(self.properties)
|
||||
self.complete()
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
import collections
|
||||
import os
|
||||
|
||||
from manuskript.data.abstractData import AbstractData
|
||||
from manuskript.io.textFile import TextFile
|
||||
|
||||
|
||||
|
@ -25,10 +26,11 @@ class Status:
|
|||
self.host.save()
|
||||
|
||||
|
||||
class StatusHost:
|
||||
class StatusHost(AbstractData):
|
||||
|
||||
def __init__(self, path):
|
||||
self.file = TextFile(os.path.join(path, "status.txt"))
|
||||
AbstractData.__init__(self, os.path.join(path, "status.txt"))
|
||||
self.file = TextFile(self.dataPath)
|
||||
self.statuses = collections.OrderedDict()
|
||||
|
||||
def addStatus(self, name: str = None) -> Status:
|
||||
|
@ -84,22 +86,32 @@ class StatusHost:
|
|||
return self.statuses.values().__iter__()
|
||||
|
||||
def load(self):
|
||||
self.statuses.clear()
|
||||
|
||||
AbstractData.load(self)
|
||||
|
||||
try:
|
||||
text = self.file.load()
|
||||
self.statuses.clear()
|
||||
except FileNotFoundError:
|
||||
self.statuses.clear()
|
||||
self.complete(False)
|
||||
return
|
||||
|
||||
if (len(text) <= 1) or (text[len(text) - 1] != "\n"):
|
||||
self.complete(False)
|
||||
return
|
||||
|
||||
text = text[:-1]
|
||||
if len(text) <= 0:
|
||||
self.complete(False)
|
||||
return
|
||||
|
||||
for name in text.split("\n"):
|
||||
self.addStatus(name)
|
||||
|
||||
self.complete()
|
||||
|
||||
def save(self):
|
||||
AbstractData.save(self)
|
||||
|
||||
self.file.save("\n".join(self.statuses.keys()) + "\n")
|
||||
self.complete()
|
||||
|
|
|
@ -3,13 +3,15 @@
|
|||
|
||||
import os
|
||||
|
||||
from manuskript.data.abstractData import AbstractData
|
||||
from manuskript.io.mmdFile import MmdFile
|
||||
|
||||
|
||||
class Summary:
|
||||
class Summary(AbstractData):
|
||||
|
||||
def __init__(self, path):
|
||||
self.file = MmdFile(os.path.join(path, "summary.txt"), 13)
|
||||
AbstractData.__init__(self, os.path.join(path, "summary.txt"))
|
||||
self.file = MmdFile(self.dataPath, 13)
|
||||
|
||||
self.situation = None
|
||||
self.sentence = None
|
||||
|
@ -18,6 +20,8 @@ class Summary:
|
|||
self.full = None
|
||||
|
||||
def load(self):
|
||||
AbstractData.load(self)
|
||||
|
||||
try:
|
||||
metadata, _ = self.file.loadMMD(True)
|
||||
except FileNotFoundError:
|
||||
|
@ -28,8 +32,10 @@ class Summary:
|
|||
self.paragraph = metadata.get("Paragraph", None)
|
||||
self.page = metadata.get("Page", None)
|
||||
self.full = metadata.get("Full", None)
|
||||
self.complete()
|
||||
|
||||
def save(self):
|
||||
AbstractData.save(self)
|
||||
metadata = dict()
|
||||
|
||||
metadata["Situation"] = self.situation
|
||||
|
@ -39,3 +45,4 @@ class Summary:
|
|||
metadata["Full"] = self.full
|
||||
|
||||
self.file.save((metadata, None))
|
||||
self.complete()
|
||||
|
|
|
@ -3,16 +3,18 @@
|
|||
|
||||
import os
|
||||
|
||||
from manuskript.data.abstractData import AbstractData
|
||||
from manuskript.io.textFile import TextFile
|
||||
|
||||
LEGACY_MSK_VERSION = 0
|
||||
CURRENT_MSK_VERSION = 1
|
||||
|
||||
|
||||
class Version:
|
||||
class Version(AbstractData):
|
||||
|
||||
def __init__(self, path):
|
||||
self.file = TextFile(os.path.join(path, "MANUSKRIPT"))
|
||||
AbstractData.__init__(self, os.path.join(path, "MANUSKRIPT"))
|
||||
self.file = TextFile(self.dataPath)
|
||||
self.legacy_file = TextFile(os.path.join(path, "VERSION"))
|
||||
|
||||
self.value = LEGACY_MSK_VERSION
|
||||
|
@ -24,10 +26,17 @@ class Version:
|
|||
return LEGACY_MSK_VERSION
|
||||
|
||||
def load(self):
|
||||
AbstractData.load(self)
|
||||
|
||||
try:
|
||||
self.value = int(self.file.load())
|
||||
except FileNotFoundError or ValueError:
|
||||
self.value = self.loadLegacy()
|
||||
|
||||
self.complete()
|
||||
|
||||
def save(self):
|
||||
AbstractData.save(self)
|
||||
|
||||
self.file.save(str(self.value))
|
||||
self.complete()
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
import os
|
||||
|
||||
from manuskript.data.abstractData import AbstractData
|
||||
from manuskript.data.unique_id import UniqueIDHost, UniqueID
|
||||
from manuskript.io.opmlFile import OpmlFile, OpmlOutlineItem
|
||||
|
||||
|
@ -35,10 +36,11 @@ class WorldItem:
|
|||
self.world.load()
|
||||
|
||||
|
||||
class World:
|
||||
class World(AbstractData):
|
||||
|
||||
def __init__(self, path):
|
||||
self.file = OpmlFile(os.path.join(path, "world.opml"))
|
||||
AbstractData.__init__(self, os.path.join(path, "world.opml"))
|
||||
self.file = OpmlFile(self.dataPath)
|
||||
self.host = UniqueIDHost()
|
||||
self.items = dict()
|
||||
self.top = list()
|
||||
|
@ -100,12 +102,14 @@ class World:
|
|||
return item
|
||||
|
||||
def load(self):
|
||||
self.items.clear()
|
||||
self.top.clear()
|
||||
|
||||
AbstractData.load(self)
|
||||
|
||||
try:
|
||||
outlines = self.file.load()
|
||||
|
||||
self.items.clear()
|
||||
self.top.clear()
|
||||
|
||||
for outline in outlines:
|
||||
item = World.loadWorldItem(self, outline)
|
||||
|
||||
|
@ -113,9 +117,10 @@ class World:
|
|||
continue
|
||||
|
||||
self.top.append(item)
|
||||
|
||||
self.complete()
|
||||
except FileNotFoundError:
|
||||
self.items.clear()
|
||||
self.top.clear()
|
||||
self.complete(False)
|
||||
|
||||
@classmethod
|
||||
def saveWorldItem(cls, item: WorldItem):
|
||||
|
@ -133,9 +138,11 @@ class World:
|
|||
return outline
|
||||
|
||||
def save(self):
|
||||
AbstractData.save(self)
|
||||
outlines = list()
|
||||
|
||||
for item in self.top:
|
||||
outlines.append(World.saveWorldItem(item))
|
||||
|
||||
self.file.save(outlines)
|
||||
self.complete()
|
||||
|
|
|
@ -16,23 +16,23 @@ class MskFile(TextFile, ZipFile):
|
|||
def __init__(self, path):
|
||||
try:
|
||||
_ZipFile(path)
|
||||
dir_path = None
|
||||
directoryPath = None
|
||||
except BadZipFile:
|
||||
dir_path = os.path.splitext(path)[0]
|
||||
directoryPath = os.path.splitext(path)[0]
|
||||
|
||||
if not os.path.isdir(dir_path):
|
||||
dir_path = None
|
||||
if not os.path.isdir(directoryPath):
|
||||
directoryPath = None
|
||||
|
||||
self.zipFile = dir_path is None
|
||||
self.zipFile = directoryPath is None
|
||||
self.version = str(LEGACY_MSK_VERSION)
|
||||
|
||||
ZipFile.__init__(self, path, dir_path)
|
||||
ZipFile.__init__(self, path, directoryPath)
|
||||
|
||||
def __del__(self):
|
||||
ZipFile.__del__(self)
|
||||
|
||||
if self.isZipFile() and (self.tmp is None) and not (self.dir_path is None):
|
||||
shutil.rmtree(self.dir_path)
|
||||
if self.isZipFile() and (self.tmp is None) and not (self.directoryPath is None):
|
||||
shutil.rmtree(self.directoryPath)
|
||||
|
||||
def isZipFile(self) -> bool:
|
||||
return self.zipFile
|
||||
|
@ -42,10 +42,10 @@ class MskFile(TextFile, ZipFile):
|
|||
return
|
||||
|
||||
if not zipFile:
|
||||
self.dir_path = os.path.splitext(self.path)[0]
|
||||
self.directoryPath = os.path.splitext(self.path)[0]
|
||||
|
||||
if not os.path.isdir(self.dir_path):
|
||||
os.mkdir(self.dir_path)
|
||||
if not os.path.isdir(self.directoryPath):
|
||||
os.mkdir(self.directoryPath)
|
||||
|
||||
ZipFile.load(self)
|
||||
|
||||
|
@ -78,7 +78,7 @@ class MskFile(TextFile, ZipFile):
|
|||
TextFile.save(self, self.version)
|
||||
|
||||
def remove(self):
|
||||
if os.path.isdir(self.dir_path):
|
||||
shutil.rmtree(self.dir_path)
|
||||
if os.path.isdir(self.directoryPath):
|
||||
shutil.rmtree(self.directoryPath)
|
||||
|
||||
ZipFile.remove(self)
|
||||
|
|
|
@ -11,30 +11,30 @@ from manuskript.io.abstractFile import AbstractFile
|
|||
|
||||
class ZipFile(AbstractFile):
|
||||
|
||||
def __init__(self, path, dir_path=None):
|
||||
def __init__(self, path, directoryPath=None):
|
||||
AbstractFile.__init__(self, path)
|
||||
|
||||
if dir_path is None:
|
||||
if directoryPath is None:
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
dir_path = self.tmp.name
|
||||
directoryPath = self.tmp.name
|
||||
else:
|
||||
self.tmp = None
|
||||
|
||||
self.dir_path = dir_path
|
||||
self.directoryPath = directoryPath
|
||||
|
||||
def __del__(self):
|
||||
if not (self.tmp is None):
|
||||
self.tmp.cleanup()
|
||||
|
||||
def load(self):
|
||||
if self.dir_path is None:
|
||||
if self.directoryPath is None:
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.dir_path = self.tmp.name
|
||||
self.directoryPath = self.tmp.name
|
||||
|
||||
with _ZipFile(self.path) as archive:
|
||||
archive.extractall(self.dir_path)
|
||||
archive.extractall(self.directoryPath)
|
||||
|
||||
return self.dir_path
|
||||
return self.directoryPath
|
||||
|
||||
def save(self, content=None):
|
||||
if not (content is None):
|
||||
|
@ -42,14 +42,14 @@ class ZipFile(AbstractFile):
|
|||
self.tmp.cleanup()
|
||||
|
||||
self.tmp = None
|
||||
self.dir_path = content
|
||||
elif self.dir_path is None:
|
||||
self.directoryPath = content
|
||||
elif self.directoryPath is None:
|
||||
if self.tmp is None:
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
|
||||
self.dir_path = self.tmp.name
|
||||
self.directoryPath = self.tmp.name
|
||||
|
||||
shutil.make_archive(self.path, 'zip', self.dir_path)
|
||||
shutil.make_archive(self.path, 'zip', self.directoryPath)
|
||||
shutil.move(self.path + ".zip", self.path)
|
||||
|
||||
def remove(self):
|
||||
|
|
Loading…
Reference in a new issue