manuskript/manuskript/exporter/basic.py

114 lines
2.3 KiB
Python
Raw Normal View History

2015-07-01 23:14:03 +12:00
#!/usr/bin/env python
2016-02-07 00:34:22 +13:00
# --!-- coding: utf8 --!--
2016-04-02 06:01:27 +13:00
import shutil
2016-02-07 00:34:22 +13:00
import subprocess
2016-04-02 06:01:27 +13:00
from PyQt5.QtWidgets import QWidget
2016-04-05 06:00:19 +12:00
from manuskript.models.outlineModel import outlineItem
2016-04-02 06:01:27 +13:00
class basicExporter:
name = ""
description = ""
exportTo = []
cmd = ""
2015-07-01 23:14:03 +12:00
def __init__(self):
pass
2016-02-07 00:34:22 +13:00
2016-04-02 06:01:27 +13:00
@classmethod
def getFormatByName(cls, name):
for f in cls.exportTo:
if f.name == name:
return f
return None
@classmethod
def isValid(cls):
return cls.path() != None
@classmethod
def version(cls):
return ""
@classmethod
def path(cls):
return shutil.which(cls.cmd)
@classmethod
def run(cls, args):
r = subprocess.check_output([cls.cmd] + args) # timeout=.2
return r.decode("utf-8")
# Example of how to run a command
#
# cmdl = ['txt2tags', '-t', target, '--enc=utf-8', '--no-headers', '-o', '-', '-']
#
# cmd = subprocess.Popen(('echo', text), stdout=subprocess.PIPE)
# try:
# output = subprocess.check_output(cmdl, stdin=cmd.stdout, stderr=subprocess.STDOUT) # , cwd="/tmp"
# except subprocess.CalledProcessError as e:
# print("Error!")
# return text
# cmd.wait()
#
# return output.decode("utf-8")
class basicFormat:
implemented = False
2016-04-08 00:27:51 +12:00
InvalidBecause = ""
2016-04-02 06:01:27 +13:00
requires = {
"Settings": False,
2016-04-06 03:21:07 +12:00
"Preview": False,
2016-04-02 06:01:27 +13:00
}
2016-02-07 00:34:22 +13:00
2016-04-02 06:01:27 +13:00
def __init__(self, name, description=""):
self.name = name
self.description = description
2016-02-07 00:34:22 +13:00
2016-04-02 06:01:27 +13:00
@classmethod
2016-04-05 06:00:19 +12:00
def settingsWidget(cls):
return QWidget()
@classmethod
2016-04-06 03:21:07 +12:00
def previewWidget(cls):
2016-04-02 06:01:27 +13:00
return QWidget()
2016-02-07 00:34:22 +13:00
2016-04-02 06:01:27 +13:00
@classmethod
2016-04-06 03:21:07 +12:00
def preview(cls, settingsWidget, previewWidget):
pass
2016-04-08 22:02:50 +12:00
@classmethod
def export(cls, settingsWidget):
pass
@classmethod
def shortcodes(cls):
return [
("\n", "\\n")
]
@classmethod
def escapes(cls, text):
for A, B in cls.shortcodes():
text = text.replace(A, B)
return text
@classmethod
def descapes(cls, text):
"""How do we call that?"""
for A, B in cls.shortcodes():
text = text.replace(B, A)
return text
2016-04-08 00:27:51 +12:00
@classmethod
def isValid(cls):
return True