Pull from trunk

This commit is contained in:
Kovid Goyal 2010-09-22 20:25:37 -06:00
commit 22b96a0dda
5 changed files with 26 additions and 28 deletions

View File

@ -456,9 +456,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
parent = os.path.dirname(spath)
if len(os.listdir(parent)) == 0:
self.rmtree(parent, permanent=True)
'''
This is commented out as it can lead to book file loss if the second
rename fails. This makes it not worthwhile, IMO.
curpath = self.library_path
c1, c2 = current_path.split('/'), path.split('/')
@ -474,24 +471,12 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
# handles files in the directories, so no need to do them here.
for oldseg, newseg in zip(c1, c2):
if oldseg.lower() == newseg.lower() and oldseg != newseg:
while True:
# need a temp name in the current segment for renames
tempname = os.path.join(curpath, 'TEMP.%f'%time.time())
if not os.path.exists(tempname):
break
try:
os.rename(os.path.join(curpath, oldseg), tempname)
except (IOError, OSError):
# Windows (at least) sometimes refuses to do the rename
# probably because a file such a cover is open in the
# hierarchy. Just go on -- nothing is hurt beyond the
# case of the filesystem not matching the case in
# name stored by calibre
print 'rename of library component failed'
else:
os.rename(tempname, os.path.join(curpath, newseg))
os.rename(os.path.join(curpath, oldseg),
os.path.join(curpath, newseg))
except:
break # Fail silently since nothing catastrophic has happened
curpath = os.path.join(curpath, newseg)
'''
def add_listener(self, listener):
'''

View File

@ -21,7 +21,7 @@ class Worker(object):
Platform independent object for launching child processes. All processes
have the environment variable :envvar:`CALIBRE_WORKER` set.
Useful attributes: ``is_alive``, ``returncode``
Useful attributes: ``is_alive``, ``returncode``, ``pid``
Useful methods: ``kill``
To launch child simply call the Worker object. By default, the child's
@ -94,6 +94,11 @@ class Worker(object):
self.child.poll()
return self.child.returncode
@property
def pid(self):
if not hasattr(self, 'child'): return None
return getattr(self.child, 'pid', None)
def kill(self):
try:
if self.is_alive:

View File

@ -5,12 +5,16 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import sys
import sys, os
from calibre import prints as prints_
from calibre import prints as prints_, preferred_encoding, isbytestring
from calibre.utils.config import Config, ConfigProxy, JSONConfig
from calibre.utils.ipc.launch import Worker
from calibre.constants import __appname__, __version__, iswindows
from calibre.gui2 import error_dialog
preferred_encoding, isbytestring, __appname__, __version__, error_dialog, \
iswindows
def console_config():
desc='Settings to control the calibre console'
@ -28,5 +32,11 @@ def prints(*args, **kwargs):
prints_(*args, **kwargs)
class Process(Worker):
pass
@property
def env(self):
env = dict(os.environ)
env.update(self._env)
return env

View File

@ -14,11 +14,10 @@ from PyQt4.Qt import QTextEdit, Qt, QTextFrameFormat, pyqtSignal, \
from pygments.lexers import PythonLexer, PythonTracebackLexer
from pygments.styles import get_all_styles
from calibre.constants import __appname__, __version__
from calibre.utils.pyconsole.formatter import Formatter
from calibre.utils.pyconsole.repl import Interpreter, DummyFile
from calibre.utils.pyconsole import prints, prefs
from calibre.gui2 import error_dialog
from calibre.utils.pyconsole import prints, prefs, __appname__, \
__version__, error_dialog
class EditBlock(object): # {{{

View File

@ -11,8 +11,7 @@ from functools import partial
from PyQt4.Qt import QDialog, QToolBar, QStatusBar, QLabel, QFont, Qt, \
QApplication, QIcon, QVBoxLayout, QAction
from calibre.constants import __appname__, __version__
from calibre.utils.pyconsole import dynamic
from calibre.utils.pyconsole import dynamic, __appname__, __version__
from calibre.utils.pyconsole.console import Console
class MainWindow(QDialog):