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) parent = os.path.dirname(spath)
if len(os.listdir(parent)) == 0: if len(os.listdir(parent)) == 0:
self.rmtree(parent, permanent=True) 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 curpath = self.library_path
c1, c2 = current_path.split('/'), path.split('/') 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. # handles files in the directories, so no need to do them here.
for oldseg, newseg in zip(c1, c2): for oldseg, newseg in zip(c1, c2):
if oldseg.lower() == newseg.lower() and oldseg != newseg: 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: try:
os.rename(os.path.join(curpath, oldseg), tempname) os.rename(os.path.join(curpath, oldseg),
except (IOError, OSError): os.path.join(curpath, newseg))
# Windows (at least) sometimes refuses to do the rename except:
# probably because a file such a cover is open in the break # Fail silently since nothing catastrophic has happened
# 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))
curpath = os.path.join(curpath, newseg) curpath = os.path.join(curpath, newseg)
'''
def add_listener(self, listener): def add_listener(self, listener):
''' '''

View File

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

View File

@ -5,12 +5,16 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __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.config import Config, ConfigProxy, JSONConfig
from calibre.utils.ipc.launch import Worker 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(): def console_config():
desc='Settings to control the calibre console' desc='Settings to control the calibre console'
@ -28,5 +32,11 @@ def prints(*args, **kwargs):
prints_(*args, **kwargs) prints_(*args, **kwargs)
class Process(Worker): 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.lexers import PythonLexer, PythonTracebackLexer
from pygments.styles import get_all_styles from pygments.styles import get_all_styles
from calibre.constants import __appname__, __version__
from calibre.utils.pyconsole.formatter import Formatter from calibre.utils.pyconsole.formatter import Formatter
from calibre.utils.pyconsole.repl import Interpreter, DummyFile from calibre.utils.pyconsole.repl import Interpreter, DummyFile
from calibre.utils.pyconsole import prints, prefs from calibre.utils.pyconsole import prints, prefs, __appname__, \
from calibre.gui2 import error_dialog __version__, error_dialog
class EditBlock(object): # {{{ class EditBlock(object): # {{{

View File

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