mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: Port windows recycle bin code
This commit is contained in:
parent
cae30d8795
commit
85017dccc0
@ -11,7 +11,7 @@ from calibre.constants import config_dir, iswindows
|
|||||||
from calibre.utils.config_base import prefs, StringConfig, create_global_prefs
|
from calibre.utils.config_base import prefs, StringConfig, create_global_prefs
|
||||||
from calibre.utils.config import JSONConfig
|
from calibre.utils.config import JSONConfig
|
||||||
from calibre.utils.filenames import samefile
|
from calibre.utils.filenames import samefile
|
||||||
from polyglot.builtins import iteritems, raw_input, error_message
|
from polyglot.builtins import iteritems, raw_input, error_message, unicode_type
|
||||||
from polyglot.binary import as_hex_unicode
|
from polyglot.binary import as_hex_unicode
|
||||||
|
|
||||||
|
|
||||||
@ -306,7 +306,7 @@ class Importer(object):
|
|||||||
except Exception:
|
except Exception:
|
||||||
lpath = None
|
lpath = None
|
||||||
c = create_global_prefs(StringConfig(raw, 'calibre wide preferences'))
|
c = create_global_prefs(StringConfig(raw, 'calibre wide preferences'))
|
||||||
c.set('installation_uuid', str(uuid.uuid4()))
|
c.set('installation_uuid', unicode_type(uuid.uuid4()))
|
||||||
c.set('library_path', lpath)
|
c.set('library_path', lpath)
|
||||||
raw = c.src
|
raw = c.src
|
||||||
if not isinstance(raw, bytes):
|
if not isinstance(raw, bytes):
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||||
from __future__ import print_function
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
@ -35,8 +35,10 @@ if iswindows:
|
|||||||
raise RuntimeError('Failed to delete: %r with error code: %d' % (path, retcode))
|
raise RuntimeError('Failed to delete: %r with error code: %d' % (path, retcode))
|
||||||
|
|
||||||
def recycler_main():
|
def recycler_main():
|
||||||
|
stdin = getattr(sys.stdin, 'buffer', sys.stdin)
|
||||||
|
stdout = getattr(sys.stdout, 'buffer', sys.stdout)
|
||||||
while True:
|
while True:
|
||||||
path = eintr_retry_call(sys.stdin.readline)
|
path = eintr_retry_call(stdin.readline)
|
||||||
if not path:
|
if not path:
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
@ -46,16 +48,16 @@ if iswindows:
|
|||||||
try:
|
try:
|
||||||
recycle_path(path)
|
recycle_path(path)
|
||||||
except:
|
except:
|
||||||
eintr_retry_call(print, b'KO', file=sys.stdout)
|
eintr_retry_call(stdout.write, b'KO\n')
|
||||||
sys.stdout.flush()
|
stdout.flush()
|
||||||
try:
|
try:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc() # goes to stderr, which is the same as for parent process
|
traceback.print_exc() # goes to stderr, which is the same as for parent process
|
||||||
except Exception:
|
except Exception:
|
||||||
pass # Ignore failures to write the traceback, since GUI processes on windows have no stderr
|
pass # Ignore failures to write the traceback, since GUI processes on windows have no stderr
|
||||||
else:
|
else:
|
||||||
eintr_retry_call(print, b'OK', file=sys.stdout)
|
eintr_retry_call(stdout.write, b'OK\n')
|
||||||
sys.stdout.flush()
|
stdout.flush()
|
||||||
|
|
||||||
def delegate_recycle(path):
|
def delegate_recycle(path):
|
||||||
if '\n' in path:
|
if '\n' in path:
|
||||||
@ -149,4 +151,3 @@ def delete_tree(path, permanent=False):
|
|||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
delete_tree(path, permanent=True)
|
delete_tree(path, permanent=True)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user