...
 
Commits (7)
......@@ -85,9 +85,9 @@ class Application(object):
process = Process(pid)
try:
for connection in process.get_connections():
for connection in process.connections():
if connection.status == 'LISTEN' and \
connection.local_address[1] == self.port:
connection.laddr[1] == self.port:
return True
except AccessDenied:
return False
......
......@@ -28,7 +28,7 @@
import pkg_resources
import psutil
from psutil import error
from psutil import AccessDenied
from os.path import exists, join
from subprocess import Popen, PIPE
from threading import Lock
......@@ -117,12 +117,12 @@ class OpenOffice(Application):
def _releaseOpenOfficePort(self):
for process in psutil.process_iter():
try:
if process.exe == join(self.office_binary_path, self._bin_soffice):
for connection in process.get_connections():
if process.exe() == join(self.office_binary_path, self._bin_soffice):
for connection in process.connections():
if connection.status == "LISTEN" and \
connection.local_address[1] == self.port:
connection.laddr[1] == self.port:
process.terminate()
except error.AccessDenied, e:
except AccessDenied, e:
pass
except TypeError, e:
# exception to prevent one psutil issue with zombie processes
......
......@@ -119,10 +119,17 @@ class MimeMapper(object):
"--hostname=%s" % hostname,
"--port=%s" % port]
process = Popen(command, stdout=PIPE, stderr=STDOUT, close_fds=True)
stdout, stderr = process.communicate()
if process.returncode:
import time
for _ in range(20):
process = Popen(command, stdout=PIPE, stderr=STDOUT, close_fds=True)
stdout, stderr = process.communicate()
if process.returncode == 0:
break
time.sleep(2)
else:
raise ValueError(stdout)
filter_dict, type_dict = json.loads(stdout)
ooo_disable_filter_name_list = kw.get("ooo_disable_filter_name_list") or [] + [
......
......@@ -52,7 +52,7 @@ class MonitorMemory(Monitor, Process):
if not hasattr(self, 'process') or \
self.process.pid != int(self.openoffice.pid()):
self.create_process()
return self.process.get_memory_info().rss / (1024 * 1024)
return self.process.memory_info().rss / (1024 * 1024)
except TypeError:
logger.debug("OpenOffice is stopped")
return 0
......
This diff is collapsed.
......@@ -73,7 +73,7 @@ class Manager(object):
self.handler_dict = self.kw.pop("handler_dict")
def convertFile(self, file, source_format, destination_format, zip=False,
refresh=False):
refresh=False, conversion_kw={}):
"""Returns the converted file in the given format.
Keywords arguments:
file -- File as string in base64
......@@ -84,7 +84,21 @@ class Manager(object):
"""
self.kw['zip'] = zip
self.kw['refresh'] = refresh
handler_class = getHandlerClass(source_format,
# XXX Force the use of wkhtmltopdf handler if converting from html to pdf
# with conversion parameters.
# This is a hack that quickly enables the use of wkhtmltopdf without
# conflicting with other "html to pdf" conversion method
# (i.e. using the ooo handler) that does not use such a parameter.
# This hack should be removed after defining and implementing a way to
# use the conversion_kw in a possible interoperable way between all
# "html to pdf" handlers.
if (conversion_kw and
source_format in ("html", "text/html") and
destination_format in ("pdf", "application/pdf")):
from cloudooo.handler.wkhtmltopdf.handler import Handler as WkhtmltopdfHandler
handler_class = WkhtmltopdfHandler
else:
handler_class = getHandlerClass(source_format,
destination_format,
self.mimetype_registry,
self.handler_dict)
......@@ -92,7 +106,7 @@ class Manager(object):
decodestring(file),
source_format,
**self.kw)
decode_data = handler.convert(destination_format)
decode_data = handler.convert(destination_format, **conversion_kw)
return encodestring(decode_data)
def updateFileMetadata(self, file, source_format, metadata_dict):
......
......@@ -17,7 +17,7 @@ from signal import SIGQUIT
def wait_use_port(pid, timeout_limit=30):
process = psutil.Process(pid)
for n in range(timeout_limit):
if len(process.get_connections()) > 0:
if len(process.connections()) > 0:
return True
sleep(1)
return False
......
......@@ -14,7 +14,7 @@ install_requires = [
'PasteDeploy',
'PasteScript',
'WSGIUtils',
'psutil>=0.2.0',
'psutil>=3.0.0',
'lxml',
'python-magic',
'argparse',
......