windows pathnames
This commit is contained in:
parent
5f1325c7aa
commit
5dead44107
5 changed files with 38 additions and 8 deletions
|
@ -657,7 +657,7 @@ class File(db.Model):
|
|||
|
||||
def fullpath(self):
|
||||
prefs = settings.preferences
|
||||
prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/')
|
||||
prefix = os.sep.join(os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/').split('/'))
|
||||
return os.path.join(prefix, self.path)
|
||||
|
||||
def make_readonly(self):
|
||||
|
@ -672,7 +672,7 @@ class File(db.Model):
|
|||
def format_underscores(string):
|
||||
return re.sub('^\.|\.$|:|/|\?|<|>', '_', string)
|
||||
prefs = settings.preferences
|
||||
prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/')
|
||||
prefix = os.sep.join(os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/').split('/'))
|
||||
j = self.item.json()
|
||||
|
||||
current_path = self.fullpath()
|
||||
|
|
|
@ -28,6 +28,9 @@ def get_ratio(data):
|
|||
except:
|
||||
return -1
|
||||
|
||||
def normpath(path):
|
||||
return '/'.join(os.path.normpath(path).split(os.sep))
|
||||
|
||||
def cover(path):
|
||||
logger.debug('cover %s', path)
|
||||
data = None
|
||||
|
@ -69,7 +72,7 @@ def cover(path):
|
|||
for e in manifest.getchildren():
|
||||
if e.attrib['id'] == cover_id:
|
||||
filename = unquote(e.attrib['href'])
|
||||
filename = os.path.normpath(os.path.join(os.path.dirname(opf[0]), filename))
|
||||
filename = normpath(os.path.join(os.path.dirname(opf[0]), filename))
|
||||
if filename in files:
|
||||
return use(filename)
|
||||
if manifest:
|
||||
|
@ -78,7 +81,7 @@ def cover(path):
|
|||
image_data = []
|
||||
for e in images:
|
||||
filename = unquote(e.attrib['href'])
|
||||
filename = os.path.normpath(os.path.join(os.path.dirname(opf[0]), filename))
|
||||
filename = normpath(os.path.join(os.path.dirname(opf[0]), filename))
|
||||
if filename in files:
|
||||
image_data.append(filename)
|
||||
if image_data:
|
||||
|
@ -87,14 +90,14 @@ def cover(path):
|
|||
for e in manifest.getchildren():
|
||||
if 'html' in e.attrib['media-type']:
|
||||
filename = unquote(e.attrib['href'])
|
||||
filename = os.path.normpath(os.path.join(os.path.dirname(opf[0]), filename))
|
||||
filename = normpath(os.path.join(os.path.dirname(opf[0]), filename))
|
||||
html = z.read(filename).decode('utf-8', 'ignore')
|
||||
img = re.compile('<img.*?src="(.*?)"').findall(html)
|
||||
#svg image
|
||||
img += re.compile('<image.*?href="(.*?)"').findall(html)
|
||||
if img:
|
||||
img = unquote(img[0])
|
||||
img = os.path.normpath(os.path.join(os.path.dirname(filename), img))
|
||||
img = normpath(os.path.join(os.path.dirname(filename), img))
|
||||
if img in files:
|
||||
return use(img)
|
||||
return data
|
||||
|
@ -152,7 +155,7 @@ def info(epub):
|
|||
for ref in guide.findall('{http://www.idpf.org/2007/opf}reference'):
|
||||
if ref.attrib.get('type') == 'toc':
|
||||
filename = unquote(ref.attrib['href']).split('#')[0]
|
||||
filename = os.path.normpath(os.path.join(os.path.dirname(opf[0]), filename))
|
||||
filename = normpath(os.path.join(os.path.dirname(opf[0]), filename))
|
||||
if filename in files:
|
||||
toc = z.read(filename)
|
||||
if toc:
|
||||
|
|
|
@ -14,7 +14,7 @@ from PyPDF2 import PdfFileReader
|
|||
import ox
|
||||
|
||||
import settings
|
||||
from utils import get_language, to_isbn13, find_isbns
|
||||
from utils import get_language, to_isbn13, find_isbns, get_short_path_name
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -51,6 +51,8 @@ def ql_cover(pdf):
|
|||
|
||||
def page(pdf, page):
|
||||
tmp = tempfile.mkdtemp()
|
||||
if sys.platform == 'win32':
|
||||
pdf = get_short_path_name(pdf)
|
||||
cmd = [
|
||||
'pdftocairo',
|
||||
pdf,
|
||||
|
|
|
@ -28,6 +28,7 @@ from Crypto.Util.asn1 import DerSequence
|
|||
|
||||
|
||||
from meta.utils import normalize_isbn, find_isbns, get_language, to_isbn13
|
||||
from win32utils import get_short_path_name
|
||||
|
||||
import logging
|
||||
logging.getLogger('PIL').setLevel(logging.ERROR)
|
||||
|
|
24
oml/win32utils.py
Normal file
24
oml/win32utils.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
import sys
|
||||
if sys.platform == 'win32':
|
||||
import ctypes
|
||||
from ctypes import wintypes
|
||||
_GetShortPathNameW = ctypes.windll.kernel32.GetShortPathNameW
|
||||
_GetShortPathNameW.argtypes = [wintypes.LPCWSTR, wintypes.LPWSTR, wintypes.DWORD]
|
||||
_GetShortPathNameW.restype = wintypes.DWORD
|
||||
|
||||
def get_short_path_name(long_name):
|
||||
"""
|
||||
Gets the short path name of a given long path.
|
||||
http://stackoverflow.com/a/23598461/200291
|
||||
"""
|
||||
output_buf_size = 0
|
||||
while True:
|
||||
output_buf = ctypes.create_unicode_buffer(output_buf_size)
|
||||
needed = _GetShortPathNameW(long_name, output_buf, output_buf_size)
|
||||
if output_buf_size >= needed:
|
||||
return output_buf.value
|
||||
else:
|
||||
output_buf_size = needed
|
||||
else:
|
||||
def get_short_path_name(long_name):
|
||||
return long_name
|
Loading…
Reference in a new issue