mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
squash squash...chitter...squash
This commit is contained in:
parent
4ea00e817a
commit
6b7af60e4b
@ -13,7 +13,7 @@
|
|||||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
''' E-book management software'''
|
''' E-book management software'''
|
||||||
__version__ = "0.3.91"
|
__version__ = "0.3.92"
|
||||||
__docformat__ = "epytext"
|
__docformat__ = "epytext"
|
||||||
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
||||||
__appname__ = 'libprs500'
|
__appname__ = 'libprs500'
|
||||||
|
@ -31,7 +31,7 @@ MIME_MAP = { \
|
|||||||
}
|
}
|
||||||
|
|
||||||
def sortable_title(title):
|
def sortable_title(title):
|
||||||
return re.sub('^\s*A\s+|^\s*The\s+|^\s*An\s+', '', ' An Crum').rstrip()
|
return re.sub('^\s*A\s+|^\s*The\s+|^\s*An\s+', '', title).rstrip()
|
||||||
|
|
||||||
class book_metadata_field(object):
|
class book_metadata_field(object):
|
||||||
""" Represents metadata stored as an attribute """
|
""" Represents metadata stored as an attribute """
|
||||||
@ -113,7 +113,7 @@ class Book(object):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
""" Return a utf-8 encoded string with title author and path information """
|
""" Return a utf-8 encoded string with title author and path information """
|
||||||
return self.title.encode('utf-8') + " by " + \
|
return self.title.encode('utf-8') + " by " + \
|
||||||
self.author.encode('utf-8') + " at " + self.path.encode('utf-8')
|
self.authors.encode('utf-8') + " at " + self.path.encode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
def fix_ids(media, cache):
|
def fix_ids(media, cache):
|
||||||
@ -203,6 +203,16 @@ class BookList(list):
|
|||||||
plitems.extend(pl.getElementsByTagName(self.prefix+'item'))
|
plitems.extend(pl.getElementsByTagName(self.prefix+'item'))
|
||||||
return plitems
|
return plitems
|
||||||
|
|
||||||
|
def purge_corrupted_files(self):
|
||||||
|
corrupted = self.root.getElementsByTagName(self.prefix+'corrupted')
|
||||||
|
paths = []
|
||||||
|
proot = self.proot if self.proot.endswith('/') else self.proot + '/'
|
||||||
|
for c in corrupted:
|
||||||
|
paths.append(proot + c.getAttribute('path'))
|
||||||
|
c.parentNode.removeChild(c)
|
||||||
|
c.unlink()
|
||||||
|
return paths
|
||||||
|
|
||||||
def purge_empty_playlists(self):
|
def purge_empty_playlists(self):
|
||||||
''' Remove all playlist entries that have no children. '''
|
''' Remove all playlist entries that have no children. '''
|
||||||
playlists = self.root.getElementsByTagName(self.prefix+'playlist')
|
playlists = self.root.getElementsByTagName(self.prefix+'playlist')
|
||||||
@ -250,12 +260,13 @@ class BookList(list):
|
|||||||
sourceid = str(self[0].sourceid) if len(self) else "1"
|
sourceid = str(self[0].sourceid) if len(self) else "1"
|
||||||
attrs = {
|
attrs = {
|
||||||
"title" : info["title"],
|
"title" : info["title"],
|
||||||
'titleSorter' : info['title'],
|
'titleSorter' : sortable_title(info['title']),
|
||||||
"author" : info["authors"] if info['authors'] else 'Unknown', \
|
"author" : info["authors"] if info['authors'] else 'Unknown', \
|
||||||
"page":"0", "part":"0", "scale":"0", \
|
"page":"0", "part":"0", "scale":"0", \
|
||||||
"sourceid":sourceid, "id":str(cid), "date":"", \
|
"sourceid":sourceid, "id":str(cid), "date":"", \
|
||||||
"mime":mime, "path":name, "size":str(size)
|
"mime":mime, "path":name, "size":str(size)
|
||||||
}
|
}
|
||||||
|
print name
|
||||||
for attr in attrs.keys():
|
for attr in attrs.keys():
|
||||||
node.setAttributeNode(self.document.createAttribute(attr))
|
node.setAttributeNode(self.document.createAttribute(attr))
|
||||||
node.setAttribute(attr, attrs[attr])
|
node.setAttribute(attr, attrs[attr])
|
||||||
|
@ -107,7 +107,8 @@ class PRS500(Device):
|
|||||||
FORMATS = ["lrf", "rtf", "pdf", "txt"]
|
FORMATS = ["lrf", "rtf", "pdf", "txt"]
|
||||||
# Height for thumbnails of books/images on the device
|
# Height for thumbnails of books/images on the device
|
||||||
THUMBNAIL_HEIGHT = 68
|
THUMBNAIL_HEIGHT = 68
|
||||||
|
# Directory on card to which books are copied
|
||||||
|
CARD_PATH_PREFIX = 'libprs500'
|
||||||
_packet_number = 0 #: Keep track of the packet number for packet tracing
|
_packet_number = 0 #: Keep track of the packet number for packet tracing
|
||||||
|
|
||||||
def log_packet(self, packet, header, stream=sys.stderr):
|
def log_packet(self, packet, header, stream=sys.stderr):
|
||||||
@ -800,7 +801,14 @@ class PRS500(Device):
|
|||||||
tfile = None
|
tfile = None
|
||||||
else:
|
else:
|
||||||
self.get_file(self.MEDIA_XML, tfile, end_session=False)
|
self.get_file(self.MEDIA_XML, tfile, end_session=False)
|
||||||
return BookList(root=root, sfile=tfile)
|
bl = BookList(root=root, sfile=tfile)
|
||||||
|
paths = bl.purge_corrupted_files()
|
||||||
|
for path in paths:
|
||||||
|
try:
|
||||||
|
self.del_file(path, end_session=False)
|
||||||
|
except PathError: # Incase this is a refetch without a sync in between
|
||||||
|
continue
|
||||||
|
return bl
|
||||||
|
|
||||||
@safe
|
@safe
|
||||||
def remove_books(self, paths, booklists, end_session=True):
|
def remove_books(self, paths, booklists, end_session=True):
|
||||||
@ -827,7 +835,7 @@ class PRS500(Device):
|
|||||||
@safe
|
@safe
|
||||||
def upload_books(self, files, names, on_card=False, end_session=True):
|
def upload_books(self, files, names, on_card=False, end_session=True):
|
||||||
card = self.card(end_session=False)
|
card = self.card(end_session=False)
|
||||||
prefix = card + '/libprs500/' if on_card else '/Data/media/books/'
|
prefix = card + '/' + self.CARD_PATH_PREFIX +'/' if on_card else '/Data/media/books/'
|
||||||
if on_card and not self._exists(prefix)[0]:
|
if on_card and not self._exists(prefix)[0]:
|
||||||
self.mkdir(prefix[:-1], False)
|
self.mkdir(prefix[:-1], False)
|
||||||
paths, ctimes = [], []
|
paths, ctimes = [], []
|
||||||
@ -862,8 +870,7 @@ class PRS500(Device):
|
|||||||
path = location[0]
|
path = location[0]
|
||||||
on_card = 1 if path[1] == ':' else 0
|
on_card = 1 if path[1] == ':' else 0
|
||||||
name = path.rpartition('/')[2]
|
name = path.rpartition('/')[2]
|
||||||
if not on_card:
|
name = (cls.CARD_PATH_PREFIX+'/' if on_card else 'books/') + name
|
||||||
name = 'books/' + name
|
|
||||||
booklists[on_card].add_book(info, name, *location[1:])
|
booklists[on_card].add_book(info, name, *location[1:])
|
||||||
fix_ids(*booklists)
|
fix_ids(*booklists)
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
## You should have received a copy of the GNU General Public License along
|
## You should have received a copy of the GNU General Public License along
|
||||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
from libprs500 import filename_to_utf8
|
||||||
''''''
|
''''''
|
||||||
|
|
||||||
import sys, os, subprocess
|
import sys, os, subprocess
|
||||||
@ -35,12 +36,18 @@ def generate_html(pathtopdf):
|
|||||||
raise ConversionError, 'Cannot read from ' + pathtopdf
|
raise ConversionError, 'Cannot read from ' + pathtopdf
|
||||||
pf = PersistentTemporaryFile('.html')
|
pf = PersistentTemporaryFile('.html')
|
||||||
pf.close()
|
pf.close()
|
||||||
cmd = PDFTOHTML + ' -noframes -p -nomerge "%s" "%s"'%(pathtopdf, pf.name)
|
# This is neccessary as pdftohtml doesn't always (linux) respect absolute paths
|
||||||
p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
|
cmd = PDFTOHTML + ' -noframes -p -nomerge "%s" "%s"'%(pathtopdf, os.path.basename(pf.name))
|
||||||
ret = p.wait()
|
cwd = os.getcwd()
|
||||||
if ret != 0:
|
try:
|
||||||
err = p.stderr.read()
|
os.chdir(os.path.dirname(pf.name))
|
||||||
raise ConversionError, err
|
p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
|
||||||
|
ret = p.wait()
|
||||||
|
if ret != 0:
|
||||||
|
err = p.stderr.read()
|
||||||
|
raise ConversionError, err
|
||||||
|
finally:
|
||||||
|
os.chdir(cwd)
|
||||||
return pf
|
return pf
|
||||||
|
|
||||||
def option_parser():
|
def option_parser():
|
||||||
@ -66,6 +73,8 @@ def main(args=sys.argv):
|
|||||||
else:
|
else:
|
||||||
options.output = os.path.abspath(options.output)
|
options.output = os.path.abspath(options.output)
|
||||||
options.pdftohtml = True
|
options.pdftohtml = True
|
||||||
|
if not options.title:
|
||||||
|
options.title = filename_to_utf8(os.path.splitext(os.path.basename(options.output))[0])
|
||||||
process_file(htmlfile.name, options)
|
process_file(htmlfile.name, options)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@ -415,7 +415,8 @@ class Main(QObject, Ui_MainWindow):
|
|||||||
self.status_bar.showMessage('Sending books to device.', 5000)
|
self.status_bar.showMessage('Sending books to device.', 5000)
|
||||||
if bad:
|
if bad:
|
||||||
bad = '\n'.join('<li>%s</li>'%(i,) for i in bad)
|
bad = '\n'.join('<li>%s</li>'%(i,) for i in bad)
|
||||||
d = warning_dialog(self.window, 'No suitable formats', 'Could not upload the following books to the device, as no suitable formats were found:<br><ul>%s</ul>'%(bad,))
|
d = warning_dialog(self.window, 'No suitable formats',
|
||||||
|
'Could not upload the following books to the device, as no suitable formats were found:<br><ul>%s</ul>'%(bad,))
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user