mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Mutex for console_print to ensure output is not mixed
This commit is contained in:
parent
e8cb8d45fe
commit
15b0d5dcc9
@ -2,16 +2,27 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPLv3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPLv3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
import hashlib, random, zipfile, shutil, sys, cPickle
|
|
||||||
|
import cPickle
|
||||||
|
import hashlib
|
||||||
|
import random
|
||||||
|
import shutil
|
||||||
|
import sys
|
||||||
|
import zipfile
|
||||||
from json import load as load_json_file
|
from json import load as load_json_file
|
||||||
|
from threading import Lock
|
||||||
|
|
||||||
from calibre import as_unicode
|
from calibre import as_unicode
|
||||||
from calibre.customize.ui import available_input_formats
|
from calibre.customize.ui import available_input_formats
|
||||||
from calibre.db.view import sanitize_sort_field_name
|
from calibre.db.view import sanitize_sort_field_name
|
||||||
from calibre.srv.ajax import search_result
|
from calibre.srv.ajax import search_result
|
||||||
from calibre.srv.errors import HTTPNotFound, HTTPBadRequest, BookNotFound, HTTPForbidden
|
from calibre.srv.errors import (
|
||||||
from calibre.srv.metadata import book_as_json, categories_as_json, icon_map, categories_settings
|
BookNotFound, HTTPBadRequest, HTTPForbidden, HTTPNotFound
|
||||||
|
)
|
||||||
|
from calibre.srv.metadata import (
|
||||||
|
book_as_json, categories_as_json, categories_settings, icon_map
|
||||||
|
)
|
||||||
from calibre.srv.routes import endpoint, json
|
from calibre.srv.routes import endpoint, json
|
||||||
from calibre.srv.utils import get_library_data, get_use_roman
|
from calibre.srv.utils import get_library_data, get_use_roman
|
||||||
from calibre.utils.config import prefs, tweaks
|
from calibre.utils.config import prefs, tweaks
|
||||||
@ -49,12 +60,16 @@ def allow_console_print(ctx, rd):
|
|||||||
return 'y' if getattr(rd.opts, 'allow_console_print', False) else 'n'
|
return 'y' if getattr(rd.opts, 'allow_console_print', False) else 'n'
|
||||||
|
|
||||||
|
|
||||||
|
print_lock = Lock()
|
||||||
|
|
||||||
|
|
||||||
@endpoint('/console-print', methods=('POST', ))
|
@endpoint('/console-print', methods=('POST', ))
|
||||||
def console_print(ctx, rd):
|
def console_print(ctx, rd):
|
||||||
if not getattr(rd.opts, 'allow_console_print', False):
|
if not getattr(rd.opts, 'allow_console_print', False):
|
||||||
raise HTTPForbidden('console printing is not allowed')
|
raise HTTPForbidden('console printing is not allowed')
|
||||||
print(rd.remote_addr, end=' ')
|
with print_lock:
|
||||||
shutil.copyfileobj(rd.request_body_file, sys.stdout)
|
print(rd.remote_addr, end=' ')
|
||||||
|
shutil.copyfileobj(rd.request_body_file, sys.stdout)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user