From 595e0af269defca53737ab8afc6b187ae637082c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 9 May 2008 21:08:22 -0700 Subject: [PATCH] Fix #644 --- src/calibre/__init__.py | 13 ++++++++++++- src/calibre/web/feeds/news.py | 8 +++++--- upload.py | 4 ++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py index dbcc36354c..0b5a042090 100644 --- a/src/calibre/__init__.py +++ b/src/calibre/__init__.py @@ -7,7 +7,7 @@ __author__ = "Kovid Goyal " __appname__ = 'calibre' import sys, os, logging, mechanize, locale, copy, cStringIO, re, subprocess, \ - textwrap, atexit, cPickle, codecs + textwrap, atexit, cPickle, codecs, time from gettext import GNUTranslations from math import floor from optparse import OptionParser as _OptionParser @@ -527,3 +527,14 @@ class LoggingInterface: def log_exception(self, msg, *args): self.___log(self.__logger.exception, msg, args, {}) + + +def strftime(fmt, t=time.localtime()): + ''' + A version of strtime that returns unicode strings. + ''' + result = time.strftime(fmt, t) + try: + return unicode(result, locale.getpreferredencoding(), 'replace') + except: + return unicode(result, 'utf-8', 'replace') diff --git a/src/calibre/web/feeds/news.py b/src/calibre/web/feeds/news.py index 1865a4b2e0..7bd3113af5 100644 --- a/src/calibre/web/feeds/news.py +++ b/src/calibre/web/feeds/news.py @@ -10,7 +10,7 @@ __docformat__ = "restructuredtext en" import logging, os, cStringIO, time, traceback, re, urlparse from collections import defaultdict -from calibre import browser, __appname__, iswindows, LoggingInterface +from calibre import browser, __appname__, iswindows, LoggingInterface, strftime from calibre.ebooks.BeautifulSoup import BeautifulSoup, NavigableString, CData, Tag from calibre.ebooks.metadata.opf import OPFCreator from calibre.ebooks.lrf import entity_to_unicode @@ -364,6 +364,8 @@ class BasicNewsRecipe(object, LoggingInterface): @param progress_reporter: A Callable that takes two arguments: progress (a number between 0 and 1) and a string message. The message should be optional. ''' LoggingInterface.__init__(self, logging.getLogger('feeds2disk')) + if not isinstance(self.title, unicode): + self.title = unicode(self.title, 'utf-8', 'replace') for attr in ('username', 'password', 'lrf', 'output_dir', 'verbose', 'debug', 'test'): setattr(self, attr, getattr(options, attr)) @@ -661,7 +663,7 @@ class BasicNewsRecipe(object, LoggingInterface): def create_opf(self, feeds, dir=None): if dir is None: dir = self.output_dir - mi = MetaInformation(self.title + time.strftime(self.timefmt), [__appname__]) + mi = MetaInformation(self.title + strftime(self.timefmt), [__appname__]) mi.publisher = __appname__ mi.author_sort = __appname__ opf_path = os.path.join(dir, 'index.opf') @@ -837,7 +839,7 @@ class CustomIndexRecipe(BasicNewsRecipe): raise NotImplementedError def create_opf(self): - mi = MetaInformation(self.title + time.strftime(self.timefmt), [__appname__]) + mi = MetaInformation(self.title + strftime(self.timefmt), [__appname__]) mi.publisher = __appname__ mi.author_sort = __appname__ mi = OPFCreator(self.output_dir, mi) diff --git a/upload.py b/upload.py index 99c963f852..6237cc0296 100644 --- a/upload.py +++ b/upload.py @@ -87,10 +87,10 @@ def upload_installers(): if exe and os.path.exists(exe): check_call('''ssh divok rm -f %s/calibre\*.exe'''%(DOWNLOADS,)) check_call('''scp %s divok:%s/'''%(exe, DOWNLOADS)) - check_call('''ssh divok rm -f %s/calibre\*.dmg'''%(DOWNLOADS,)) if dmg and os.path.exists(dmg): + check_call('''ssh divok rm -f %s/calibre\*.dmg'''%(DOWNLOADS,)) check_call('''scp %s divok:%s/'''%(dmg, DOWNLOADS)) - check_call('''ssh divok chmod a+r %s/\*'''%(DOWNLOADS,)) + check_call('''ssh divok chmod a+r %s/\*'''%(DOWNLOADS,)) def upload_docs(): check_call('''epydoc --config epydoc.conf''')