mirror of
https://github.com/JimmXinu/FanFicFare.git
synced 2026-05-02 03:48:40 +02:00
Working towards python 2.7 & 3 cross compatibility.
This commit is contained in:
parent
3f196cd135
commit
98b45e147d
8 changed files with 36 additions and 27 deletions
|
|
@ -189,9 +189,11 @@ __class_list = []
|
|||
__domain_map = {}
|
||||
|
||||
def imports():
|
||||
out = []
|
||||
for name, val in globals().items():
|
||||
if isinstance(val, types.ModuleType):
|
||||
yield val.__name__
|
||||
out.append(val.__name__)
|
||||
return out
|
||||
|
||||
for x in imports():
|
||||
if "fanficfare.adapters.adapter_" in x:
|
||||
|
|
|
|||
|
|
@ -71,7 +71,12 @@ from gziphttp import GZipProcessor
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
import adapters
|
||||
# It's all fault of David Beazley!
|
||||
try:
|
||||
from . import adapters
|
||||
except ImportError:
|
||||
import sys
|
||||
adapters = sys.modules["fanficfare.adapters"]
|
||||
|
||||
def re_compile(regex,line):
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -14,16 +14,16 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
## This could (should?) use a dynamic loader like adapters, but for
|
||||
## now, it's static, since there's so few of them.
|
||||
from __future__ import absolute_import
|
||||
|
||||
from ..exceptions import FailedToDownload
|
||||
|
||||
from writer_html import HTMLWriter
|
||||
from writer_txt import TextWriter
|
||||
from writer_epub import EpubWriter
|
||||
from writer_mobi import MobiWriter
|
||||
## This could (should?) use a dynamic loader like adapters, but for
|
||||
## now, it's static, since there's so few of them.
|
||||
from .writer_html import HTMLWriter
|
||||
from .writer_txt import TextWriter
|
||||
from .writer_epub import EpubWriter
|
||||
from .writer_mobi import MobiWriter
|
||||
|
||||
def getWriter(type,config,story):
|
||||
if type == "html":
|
||||
|
|
|
|||
|
|
@ -14,12 +14,13 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
from __future__ import absolute_import
|
||||
|
||||
import re
|
||||
import os.path
|
||||
import datetime
|
||||
import string
|
||||
import StringIO
|
||||
from six import StringIO
|
||||
import zipfile
|
||||
from zipfile import ZipFile, ZIP_DEFLATED
|
||||
import logging
|
||||
|
|
@ -41,10 +42,10 @@ class BaseStoryWriter(Configurable):
|
|||
|
||||
def __init__(self, configuration, adapter):
|
||||
Configurable.__init__(self, configuration)
|
||||
|
||||
|
||||
self.adapter = adapter
|
||||
self.story = adapter.getStoryMetadataOnly() # only cache the metadata initially.
|
||||
|
||||
|
||||
self.story.setMetadata('formatname',self.getFormatName())
|
||||
self.story.setMetadata('formatext',self.getFormatExt())
|
||||
|
||||
|
|
@ -59,12 +60,13 @@ class BaseStoryWriter(Configurable):
|
|||
|
||||
def getBaseFileName(self):
|
||||
return self.story.formatFileName(self.getConfig('output_filename'),self.getConfig('allow_unsafe_filename'))
|
||||
|
||||
|
||||
def getZipFileName(self):
|
||||
return self.story.formatFileName(self.getConfig('zip_filename'),self.getConfig('allow_unsafe_filename'))
|
||||
|
||||
def _write(self, out, text):
|
||||
out.write(text.encode('utf8'))
|
||||
# instead of text.encode('utf8')
|
||||
out.write(six.ensure_text(text))
|
||||
|
||||
def writeTitlePage(self, out, START, ENTRY, END, WIDE_ENTRY=None, NO_TITLE_ENTRY=None):
|
||||
"""
|
||||
|
|
@ -89,7 +91,7 @@ class BaseStoryWriter(Configurable):
|
|||
|
||||
if self.hasConfig("titlepage_no_title_entry"):
|
||||
NO_TITLE_ENTRY = string.Template(self.getConfig("titlepage_no_title_entry"))
|
||||
|
||||
|
||||
self._write(out,START.substitute(self.story.getAllMetadata()))
|
||||
|
||||
if WIDE_ENTRY==None:
|
||||
|
|
@ -120,7 +122,7 @@ class BaseStoryWriter(Configurable):
|
|||
# 'no title' option if there is one.
|
||||
if label == "" and NO_TITLE_ENTRY:
|
||||
TEMPLATE= NO_TITLE_ENTRY
|
||||
|
||||
|
||||
self._write(out,TEMPLATE.substitute({'label':label,
|
||||
'id':entry,
|
||||
'value':self.story.getMetadata(entry)}))
|
||||
|
|
@ -145,7 +147,7 @@ class BaseStoryWriter(Configurable):
|
|||
|
||||
if self.hasConfig("tocpage_end"):
|
||||
END = string.Template(self.getConfig("tocpage_end"))
|
||||
|
||||
|
||||
self._write(out,START.substitute(self.story.getAllMetadata()))
|
||||
|
||||
for index, chap in enumerate(self.story.getChapters(fortoc=True)):
|
||||
|
|
@ -170,7 +172,7 @@ class BaseStoryWriter(Configurable):
|
|||
condremoveentities=False)
|
||||
else:
|
||||
self.story.setMetadata("output_css",'')
|
||||
|
||||
|
||||
if not outstream:
|
||||
close=True
|
||||
logger.info("Save directly to file: %s" % outfilename)
|
||||
|
|
@ -191,7 +193,7 @@ class BaseStoryWriter(Configurable):
|
|||
if fileupdated > lastupdated:
|
||||
logger.warn("File(%s) Updated(%s) more recently than Story(%s) - Skipping" % (outfilename,fileupdated,lastupdated))
|
||||
return
|
||||
if not metaonly:
|
||||
if not metaonly:
|
||||
self.story = self.adapter.getStory() # get full story
|
||||
# now, just
|
||||
# before writing.
|
||||
|
|
@ -228,7 +230,7 @@ class BaseStoryWriter(Configurable):
|
|||
|
||||
def writeFile(self, filename, data):
|
||||
logger.debug("writeFile:%s"%filename)
|
||||
|
||||
|
||||
if self.getConfig('zip_output'):
|
||||
outputdirs = os.path.dirname(self.getBaseFileName())
|
||||
if outputdirs:
|
||||
|
|
@ -242,7 +244,7 @@ class BaseStoryWriter(Configurable):
|
|||
dir = os.path.dirname(filename)
|
||||
if not os.path.exists(dir):
|
||||
os.mkdir(dir) ## os.makedirs() doesn't work in 2.5.2?
|
||||
|
||||
|
||||
outstream = open(filename,"wb")
|
||||
outstream.write(data)
|
||||
outstream.close()
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
import logging
|
||||
import string
|
||||
import StringIO
|
||||
from six import StringIO
|
||||
import zipfile
|
||||
from zipfile import ZipFile, ZIP_STORED, ZIP_DEFLATED
|
||||
import urllib
|
||||
|
|
@ -29,7 +29,7 @@ from xml.dom.minidom import parse, parseString, getDOMImplementation
|
|||
|
||||
import bs4
|
||||
|
||||
from base_writer import *
|
||||
from .base_writer import *
|
||||
from ..htmlcleanup import stripHTML,removeEntities
|
||||
from ..story import commaGroups
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import string
|
|||
|
||||
import bs4
|
||||
|
||||
from base_writer import *
|
||||
from .base_writer import *
|
||||
|
||||
class HTMLWriter(BaseStoryWriter):
|
||||
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@
|
|||
|
||||
import logging
|
||||
import string
|
||||
import StringIO
|
||||
from six import StringIO
|
||||
|
||||
from base_writer import *
|
||||
from .base_writer import *
|
||||
from ..htmlcleanup import stripHTML
|
||||
from ..mobi import Converter
|
||||
from ..exceptions import FailedToWriteOutput
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import logging
|
|||
import string
|
||||
from textwrap import wrap
|
||||
|
||||
from base_writer import *
|
||||
from .base_writer import *
|
||||
|
||||
from html2text import html2text
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue