Added remove function for file types

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
TheJackiMonster 2021-05-14 19:46:39 +02:00
parent ee881bdb17
commit 9078079241
No known key found for this signature in database
GPG key ID: D850A5F772E880F9
7 changed files with 43 additions and 2 deletions

View file

@ -1,6 +1,8 @@
#!/usr/bin/env python
# --!-- coding: utf8 --!--
import os
from zipfile import BadZipFile
from manuskript.data.info import Info
from manuskript.data.summary import Summary
@ -34,6 +36,15 @@ class Project:
def __del__(self):
del self.file
def getName(self):
parts = os.path.split(self.file.path)
name = parts[-1]
if name.endswith('.msk'):
name = name[:-4]
return name
def load(self):
try:
self.file.load()

View file

@ -12,3 +12,6 @@ class AbstractFile:
def save(self, content):
raise IOError('Saving undefined!')
def remove(self):
raise IOError('Removing undefined!')

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python
# --!-- coding: utf8 --!--
import os
import re
from manuskript.io.abstractFile import AbstractFile
@ -77,3 +77,7 @@ class MmdFile(AbstractFile):
if not (body is None):
file.write("\n" + body)
def remove(self):
if os.path.exists(self.path):
os.remove(self.path)

View file

@ -61,3 +61,9 @@ class MskFile(TextFile, ZipFile):
ZipFile.save(self)
else:
TextFile.save(self, "1")
def remove(self):
if os.path.isdir(self.dir_path):
shutil.rmtree(self.dir_path)
ZipFile.remove(self)

View file

@ -1,6 +1,8 @@
#!/usr/bin/env python
# --!-- coding: utf8 --!--
import os
from manuskript.io.abstractFile import AbstractFile
@ -13,3 +15,7 @@ class TextFile(AbstractFile):
def save(self, content):
with open(self.path, 'wt', encoding='utf-8') as file:
file.write(content)
def remove(self):
if os.path.exists(self.path):
os.remove(self.path)

View file

@ -1,6 +1,8 @@
#!/usr/bin/env python
# --!-- coding: utf8 --!--
import os
from lxml import etree
from manuskript.io.abstractFile import AbstractFile
@ -14,3 +16,7 @@ class XmlFile(AbstractFile):
def save(self, content):
with open(self.path, 'wb') as file:
content.write(file, encoding="utf-8", xml_declaration=True, pretty_print=True)
def remove(self):
if os.path.exists(self.path):
os.remove(self.path)

View file

@ -1,8 +1,9 @@
#!/usr/bin/env python
# --!-- coding: utf8 --!--
import tempfile
import os
import shutil
import tempfile
from zipfile import ZipFile as _ZipFile
from manuskript.io.abstractFile import AbstractFile
@ -49,3 +50,7 @@ class ZipFile(AbstractFile):
shutil.make_archive(self.path, 'zip', self.dir_path)
shutil.move(self.path + ".zip", self.path)
def remove(self):
if os.path.exists(self.path):
os.remove(self.path)