Commit a77f5599 authored by Jérome Perrin's avatar Jérome Perrin

*: cleanups

lazy loging and other obvious changes
parent ad60ba5b
...@@ -33,7 +33,7 @@ class CloudoooTestCase(unittest.TestCase): ...@@ -33,7 +33,7 @@ class CloudoooTestCase(unittest.TestCase):
'application/vnd.oasis.opendocument.text') 'application/vnd.oasis.opendocument.text')
res = proxy.run_setmetadata("t.odt", odt_data, {"Title": "test"}) res = proxy.run_setmetadata("t.odt", odt_data, {"Title": "test"})
self.assertEqual(res[0], 200) self.assertEqual(res[0], 200)
response_code, response_dict, response_message = \ response_code, response_dict, _ = \
proxy.run_convert("t.odt", res[1]['data']) proxy.run_convert("t.odt", res[1]['data'])
self.assertEqual(response_code, 200) self.assertEqual(response_code, 200)
self.assertEqual(response_dict['meta']['Title'], "test") self.assertEqual(response_dict['meta']['Title'], "test")
......
...@@ -56,7 +56,7 @@ class Handler(object): ...@@ -56,7 +56,7 @@ class Handler(object):
# XXX This implementation could use ffmpeg -i pipe:0, but # XXX This implementation could use ffmpeg -i pipe:0, but
# XXX seems super unreliable currently and it generates currupted files in # XXX seems super unreliable currently and it generates currupted files in
# the end # the end
logger.debug("FfmpegConvert: %s > %s" % (self.input.source_format, destination_format)) logger.debug("FfmpegConvert: %s > %s", self.input.source_format, destination_format)
output_url = mktemp(suffix=".%s" % destination_format, output_url = mktemp(suffix=".%s" % destination_format,
dir=self.input.directory_name) dir=self.input.directory_name)
command = ["ffmpeg", command = ["ffmpeg",
......
...@@ -49,7 +49,7 @@ class Handler(object): ...@@ -49,7 +49,7 @@ class Handler(object):
def convert(self, destination_format=None, **kw): def convert(self, destination_format=None, **kw):
"""Convert a image""" """Convert a image"""
logger.debug("ImageMagickConvert: %s > %s" % (self.file.source_format, destination_format)) logger.debug("ImageMagickConvert: %s > %s", self.file.source_format, destination_format)
output_url = mktemp(suffix='.%s' % destination_format, output_url = mktemp(suffix='.%s' % destination_format,
dir=self.base_folder_url) dir=self.base_folder_url)
command = ["convert", self.file.getUrl(), output_url] command = ["convert", self.file.getUrl(), output_url]
...@@ -80,7 +80,7 @@ class Handler(object): ...@@ -80,7 +80,7 @@ class Handler(object):
std = std.strip() std = std.strip()
if re.search("^[a-zA-Z]", std): if re.search("^[a-zA-Z]", std):
if std.count(":") > 1: if std.count(":") > 1:
key, value = re.compile(".*\:\ ").split(std) key, value = re.compile(r".*\:\ ").split(std)
else: else:
key, value = std.split(":") key, value = std.split(":")
metadata_dict[key] = value.strip() metadata_dict[key] = value.strip()
......
...@@ -44,15 +44,17 @@ class Application(object): ...@@ -44,15 +44,17 @@ class Application(object):
def start(self, init=True): def start(self, init=True):
"""Start Application""" """Start Application"""
logger.debug("Process Started %s, Port %s. Pid %s" % (self.name, logger.debug(
self.getAddress()[-1], "Process Started %s, Port %s. Pid %s",
self.pid())) self.name,
self.getAddress()[-1],
self.pid())
def stop(self): def stop(self):
"""Stop the process""" """Stop the process"""
if hasattr(self, 'process') and self.status(): if hasattr(self, 'process') and self.status():
process_pid = self.process.pid process_pid = self.process.pid
logger.debug("Stop Pid - %s" % process_pid) logger.debug("Stop Pid - %s", process_pid)
try: try:
self.process.terminate() self.process.terminate()
waitStopDaemon(self, self.timeout) waitStopDaemon(self, self.timeout)
......
...@@ -60,8 +60,10 @@ class OpenOffice(Application): ...@@ -60,8 +60,10 @@ class OpenOffice(Application):
def _testOpenOffice(self, host, port): def _testOpenOffice(self, host, port):
"""Test if OpenOffice was started correctly""" """Test if OpenOffice was started correctly"""
logger.debug("Test OpenOffice %s - Pid %s" % (self.getAddress()[-1], logger.debug(
self.pid())) "Test OpenOffice %s - Pid %s",
self.getAddress()[-1],
self.pid())
python = join(self.office_binary_path, "python") python = join(self.office_binary_path, "python")
args = [exists(python) and python or "python3", args = [exists(python) and python or "python3",
pkg_resources.resource_filename("cloudooo", pkg_resources.resource_filename("cloudooo",
...@@ -70,14 +72,14 @@ class OpenOffice(Application): ...@@ -70,14 +72,14 @@ class OpenOffice(Application):
"--hostname=%s" % host, "--hostname=%s" % host,
"--port=%s" % port, "--port=%s" % port,
"--uno_path=%s" % self.uno_path] "--uno_path=%s" % self.uno_path]
logger.debug("Testing Openoffice Instance %s" % port) logger.debug("Testing Openoffice Instance %s", port)
try: try:
subprocess.check_output(args, stderr=subprocess.STDOUT, close_fds=True) subprocess.check_output(args, stderr=subprocess.STDOUT, close_fds=True)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
logger.warning(e.output) logger.warning(e.output)
return False return False
else: else:
logger.debug("Instance %s works" % port) logger.debug("Instance %s works", port)
return True return True
def _cleanRequest(self): def _cleanRequest(self):
...@@ -174,7 +176,7 @@ class OpenOffice(Application): ...@@ -174,7 +176,7 @@ class OpenOffice(Application):
def release(self): def release(self):
"""Unlock Instance.""" """Unlock Instance."""
logger.debug("OpenOffice %s, %s unlocked" % self.getAddress()) logger.debug("OpenOffice %s, %s unlocked", *self.getAddress())
self._lock.release() self._lock.release()
openoffice = OpenOffice() openoffice = OpenOffice()
...@@ -250,9 +250,9 @@ class OOGranulator(object): ...@@ -250,9 +250,9 @@ class OOGranulator(object):
text = ''.join(paragraph.itertext()) text = ''.join(paragraph.itertext())
if TEXT_ATTRIB_STYLENAME not in paragraph.attrib.keys(): if TEXT_ATTRIB_STYLENAME not in paragraph.attrib:
logger.error("Unable to find %s attribute at paragraph %s " % \ logger.error("Unable to find %s attribute at paragraph %s ",
(TEXT_ATTRIB_STYLENAME, paragraph_id)) TEXT_ATTRIB_STYLENAME, paragraph_id)
return None return None
p_class = paragraph.attrib[TEXT_ATTRIB_STYLENAME] p_class = paragraph.attrib[TEXT_ATTRIB_STYLENAME]
......
...@@ -165,7 +165,7 @@ class Handler(object): ...@@ -165,7 +165,7 @@ class Handler(object):
filter_list.append((destination_extension, filter_list.append((destination_extension,
service_type, service_type,
mimemapper.getFilterName(destination_extension, service_type))) mimemapper.getFilterName(destination_extension, service_type)))
logger.debug("Filter List: %r" % filter_list) logger.debug("Filter List: %r", filter_list)
return json.dumps(dict(doc_type_list_by_extension=mimemapper._doc_type_list_by_extension, return json.dumps(dict(doc_type_list_by_extension=mimemapper._doc_type_list_by_extension,
filter_list=filter_list, filter_list=filter_list,
mimetype_by_filter_type=mimemapper._mimetype_by_filter_type)) mimetype_by_filter_type=mimemapper._mimetype_by_filter_type))
...@@ -177,7 +177,7 @@ class Handler(object): ...@@ -177,7 +177,7 @@ class Handler(object):
""" """
if not self.enable_scripting and kw.get('script'): if not self.enable_scripting and kw.get('script'):
raise Exception("ooo: scripting is disabled") raise Exception("ooo: scripting is disabled")
logger.debug("OooConvert: %s > %s" % (self.source_format, destination_format)) logger.debug("OooConvert: %s > %s", self.source_format, destination_format)
kw['source_format'] = self.source_format kw['source_format'] = self.source_format
if destination_format: if destination_format:
kw['destination_format'] = destination_format kw['destination_format'] = destination_format
......
...@@ -55,8 +55,8 @@ class MonitorRequest(Monitor, Thread): ...@@ -55,8 +55,8 @@ class MonitorRequest(Monitor, Thread):
while self.status_flag: while self.status_flag:
if self.openoffice.request > self.request_limit: if self.openoffice.request > self.request_limit:
self.openoffice.acquire() self.openoffice.acquire()
logger.debug("Openoffice: %s, %s will be restarted" % \ logger.debug("Openoffice: %s, %s will be restarted",
self.openoffice.getAddress()) *self.openoffice.getAddress())
self.openoffice.restart() self.openoffice.restart()
self.openoffice.release() self.openoffice.release()
sleep(self.interval) sleep(self.interval)
......
...@@ -66,8 +66,8 @@ class MonitorSpleepingTime(Monitor, Thread): ...@@ -66,8 +66,8 @@ class MonitorSpleepingTime(Monitor, Thread):
current_time = time() current_time = time()
if self.openoffice.status() and\ if self.openoffice.status() and\
(self._touched_at + self.sleeping_time) <= current_time: (self._touched_at + self.sleeping_time) <= current_time:
logger.debug("Stopping OpenOffice after sleeping time of %is" %\ logger.debug("Stopping OpenOffice after sleeping time of %is",
self.sleeping_time) self.sleeping_time)
self.openoffice.acquire() self.openoffice.acquire()
self.openoffice.stop() self.openoffice.stop()
self.openoffice.release() self.openoffice.release()
......
...@@ -47,14 +47,14 @@ class MonitorTimeout(Monitor, Process): ...@@ -47,14 +47,14 @@ class MonitorTimeout(Monitor, Process):
"""Start the process""" """Start the process"""
port = self.openoffice.getAddress()[-1] port = self.openoffice.getAddress()[-1]
pid = self.openoffice.pid() pid = self.openoffice.pid()
logger.debug("Monitoring OpenOffice: Port %s, Pid: %s" % (port, pid)) logger.debug("Monitoring OpenOffice: port %s pid %s timeout: %s", port, pid, self.interval)
self.status_flag = True self.status_flag = True
sleep(self.interval) sleep(self.interval)
if self.openoffice.isLocked(): if self.openoffice.isLocked():
logger.debug("Stop OpenOffice - Port %s - Pid %s" % (port, pid)) logger.debug("Stoping OpenOffice: port %s pid %s", port, pid)
self.openoffice.stop() self.openoffice.stop()
def terminate(self): def terminate(self):
"""Stop the process""" """Stop the process"""
Monitor.terminate(self) Monitor.terminate(self)
Process.terminate(self) Process.terminate(self)
\ No newline at end of file
...@@ -70,8 +70,6 @@ class TestUnoMimeMapper(HandlerTestCase): ...@@ -70,8 +70,6 @@ class TestUnoMimeMapper(HandlerTestCase):
stderr=PIPE).communicate() stderr=PIPE).communicate()
self.assertEqual(stderr, '') self.assertEqual(stderr, '')
filter_dict, type_dict = json.loads(stdout) filter_dict, type_dict = json.loads(stdout)
self.assertTrue('filter_dict' in locals())
self.assertTrue('type_dict' in locals())
self.assertNotEqual(filter_dict.get('writer8'), None) self.assertNotEqual(filter_dict.get('writer8'), None)
self.assertEqual(type_dict.get('writer8').get('Name'), 'writer8') self.assertEqual(type_dict.get('writer8').get('Name'), 'writer8')
self.assertNotEqual(filter_dict.get('writer8'), None) self.assertNotEqual(filter_dict.get('writer8'), None)
...@@ -91,8 +89,6 @@ class TestUnoMimeMapper(HandlerTestCase): ...@@ -91,8 +89,6 @@ class TestUnoMimeMapper(HandlerTestCase):
stderr=PIPE).communicate() stderr=PIPE).communicate()
self.assertEqual(stderr, '') self.assertEqual(stderr, '')
filter_dict, type_dict = json.loads(stdout) filter_dict, type_dict = json.loads(stdout)
self.assertTrue('filter_dict' in locals())
self.assertTrue('type_dict' in locals())
self.assertNotEqual(filter_dict.get('writer8'), None) self.assertNotEqual(filter_dict.get('writer8'), None)
self.assertEqual(type_dict.get('writer8').get('Name'), 'writer8') self.assertEqual(type_dict.get('writer8').get('Name'), 'writer8')
self.assertNotEqual(filter_dict.get('writer8'), None) self.assertNotEqual(filter_dict.get('writer8'), None)
...@@ -119,7 +115,7 @@ class TestUnoMimeMapper(HandlerTestCase): ...@@ -119,7 +115,7 @@ class TestUnoMimeMapper(HandlerTestCase):
stdout=PIPE, stdout=PIPE,
stderr=PIPE).communicate() stderr=PIPE).communicate()
self.assertEqual(stdout, '') self.assertEqual(stdout, '')
self.assertTrue(stderr.endswith(error_msg), stderr) self.assertIn(error_msg, stderr)
openoffice.start() openoffice.start()
...@@ -52,7 +52,7 @@ class Handler(object): ...@@ -52,7 +52,7 @@ class Handler(object):
def convert(self, destination_format=None, **kw): def convert(self, destination_format=None, **kw):
""" Convert a pdf document """ """ Convert a pdf document """
# TODO: use pyPdf # TODO: use pyPdf
logger.debug("PDFConvert: %s > %s" % (self.document.source_format, destination_format)) logger.debug("PDFConvert: %s > %s", self.document.source_format, destination_format)
output_url = mktemp(suffix=".%s" % destination_format, output_url = mktemp(suffix=".%s" % destination_format,
dir=self.document.directory_name) dir=self.document.directory_name)
command = ["pdftotext", self.document.getUrl(), output_url] command = ["pdftotext", self.document.getUrl(), output_url]
...@@ -78,7 +78,7 @@ class Handler(object): ...@@ -78,7 +78,7 @@ class Handler(object):
stderr=PIPE, stderr=PIPE,
close_fds=True, close_fds=True,
env=self.environment).communicate() env=self.environment).communicate()
info_list = filter(None, stdout.split("\n")) info_list = [_f for _f in stdout.split("\n") if _f]
metadata = {} metadata = {}
for info in iter(info_list): for info in iter(info_list):
info = info.split(":") info = info.split(":")
......
...@@ -66,7 +66,7 @@ class Handler(object): ...@@ -66,7 +66,7 @@ class Handler(object):
def convert(self, destination_format=None, **kw): def convert(self, destination_format=None, **kw):
"""Convert a image""" """Convert a image"""
logger.debug("wkhtmltopdf convert: %s > %s" % (self.file.source_format, destination_format)) logger.debug("wkhtmltopdf convert: %s > %s", self.file.source_format, destination_format)
output_path = self.makeTempFile(destination_format) output_path = self.makeTempFile(destination_format)
command = self.makeWkhtmltopdfCommandList( command = self.makeWkhtmltopdfCommandList(
self.convertPathToUrl(self.file.getUrl()), self.convertPathToUrl(self.file.getUrl()),
......
...@@ -183,7 +183,7 @@ class Handler(object): ...@@ -183,7 +183,7 @@ class Handler(object):
def convert(self, destination_format=None, **kw): def convert(self, destination_format=None, **kw):
""" Convert the inputed file to output as format that were informed """ """ Convert the inputed file to output as format that were informed """
source_format = self.file.source_format source_format = self.file.source_format
logger.debug("x2t convert: %s > %s" % (source_format, destination_format)) logger.debug("x2t convert: %s > %s", source_format, destination_format)
# init vars and xml configuration file # init vars and xml configuration file
in_format = format_code_map[source_format] in_format = format_code_map[source_format]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment