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):
'application/vnd.oasis.opendocument.text')
res = proxy.run_setmetadata("t.odt", odt_data, {"Title": "test"})
self.assertEqual(res[0], 200)
response_code, response_dict, response_message = \
response_code, response_dict, _ = \
proxy.run_convert("t.odt", res[1]['data'])
self.assertEqual(response_code, 200)
self.assertEqual(response_dict['meta']['Title'], "test")
......
......@@ -56,7 +56,7 @@ class Handler(object):
# XXX This implementation could use ffmpeg -i pipe:0, but
# XXX seems super unreliable currently and it generates currupted files in
# 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,
dir=self.input.directory_name)
command = ["ffmpeg",
......
......@@ -49,7 +49,7 @@ class Handler(object):
def convert(self, destination_format=None, **kw):
"""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,
dir=self.base_folder_url)
command = ["convert", self.file.getUrl(), output_url]
......@@ -80,7 +80,7 @@ class Handler(object):
std = std.strip()
if re.search("^[a-zA-Z]", std):
if std.count(":") > 1:
key, value = re.compile(".*\:\ ").split(std)
key, value = re.compile(r".*\:\ ").split(std)
else:
key, value = std.split(":")
metadata_dict[key] = value.strip()
......
......@@ -44,15 +44,17 @@ class Application(object):
def start(self, init=True):
"""Start Application"""
logger.debug("Process Started %s, Port %s. Pid %s" % (self.name,
logger.debug(
"Process Started %s, Port %s. Pid %s",
self.name,
self.getAddress()[-1],
self.pid()))
self.pid())
def stop(self):
"""Stop the process"""
if hasattr(self, 'process') and self.status():
process_pid = self.process.pid
logger.debug("Stop Pid - %s" % process_pid)
logger.debug("Stop Pid - %s", process_pid)
try:
self.process.terminate()
waitStopDaemon(self, self.timeout)
......
......@@ -60,8 +60,10 @@ class OpenOffice(Application):
def _testOpenOffice(self, host, port):
"""Test if OpenOffice was started correctly"""
logger.debug("Test OpenOffice %s - Pid %s" % (self.getAddress()[-1],
self.pid()))
logger.debug(
"Test OpenOffice %s - Pid %s",
self.getAddress()[-1],
self.pid())
python = join(self.office_binary_path, "python")
args = [exists(python) and python or "python3",
pkg_resources.resource_filename("cloudooo",
......@@ -70,14 +72,14 @@ class OpenOffice(Application):
"--hostname=%s" % host,
"--port=%s" % port,
"--uno_path=%s" % self.uno_path]
logger.debug("Testing Openoffice Instance %s" % port)
logger.debug("Testing Openoffice Instance %s", port)
try:
subprocess.check_output(args, stderr=subprocess.STDOUT, close_fds=True)
except subprocess.CalledProcessError as e:
logger.warning(e.output)
return False
else:
logger.debug("Instance %s works" % port)
logger.debug("Instance %s works", port)
return True
def _cleanRequest(self):
......@@ -174,7 +176,7 @@ class OpenOffice(Application):
def release(self):
"""Unlock Instance."""
logger.debug("OpenOffice %s, %s unlocked" % self.getAddress())
logger.debug("OpenOffice %s, %s unlocked", *self.getAddress())
self._lock.release()
openoffice = OpenOffice()
......@@ -250,9 +250,9 @@ class OOGranulator(object):
text = ''.join(paragraph.itertext())
if TEXT_ATTRIB_STYLENAME not in paragraph.attrib.keys():
logger.error("Unable to find %s attribute at paragraph %s " % \
(TEXT_ATTRIB_STYLENAME, paragraph_id))
if TEXT_ATTRIB_STYLENAME not in paragraph.attrib:
logger.error("Unable to find %s attribute at paragraph %s ",
TEXT_ATTRIB_STYLENAME, paragraph_id)
return None
p_class = paragraph.attrib[TEXT_ATTRIB_STYLENAME]
......
......@@ -165,7 +165,7 @@ class Handler(object):
filter_list.append((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,
filter_list=filter_list,
mimetype_by_filter_type=mimemapper._mimetype_by_filter_type))
......@@ -177,7 +177,7 @@ class Handler(object):
"""
if not self.enable_scripting and kw.get('script'):
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
if destination_format:
kw['destination_format'] = destination_format
......
......@@ -55,8 +55,8 @@ class MonitorRequest(Monitor, Thread):
while self.status_flag:
if self.openoffice.request > self.request_limit:
self.openoffice.acquire()
logger.debug("Openoffice: %s, %s will be restarted" % \
self.openoffice.getAddress())
logger.debug("Openoffice: %s, %s will be restarted",
*self.openoffice.getAddress())
self.openoffice.restart()
self.openoffice.release()
sleep(self.interval)
......
......@@ -66,7 +66,7 @@ class MonitorSpleepingTime(Monitor, Thread):
current_time = time()
if self.openoffice.status() and\
(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.openoffice.acquire()
self.openoffice.stop()
......
......@@ -47,11 +47,11 @@ class MonitorTimeout(Monitor, Process):
"""Start the process"""
port = self.openoffice.getAddress()[-1]
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
sleep(self.interval)
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()
def terminate(self):
......
......@@ -70,8 +70,6 @@ class TestUnoMimeMapper(HandlerTestCase):
stderr=PIPE).communicate()
self.assertEqual(stderr, '')
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.assertEqual(type_dict.get('writer8').get('Name'), 'writer8')
self.assertNotEqual(filter_dict.get('writer8'), None)
......@@ -91,8 +89,6 @@ class TestUnoMimeMapper(HandlerTestCase):
stderr=PIPE).communicate()
self.assertEqual(stderr, '')
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.assertEqual(type_dict.get('writer8').get('Name'), 'writer8')
self.assertNotEqual(filter_dict.get('writer8'), None)
......@@ -119,7 +115,7 @@ class TestUnoMimeMapper(HandlerTestCase):
stdout=PIPE,
stderr=PIPE).communicate()
self.assertEqual(stdout, '')
self.assertTrue(stderr.endswith(error_msg), stderr)
self.assertIn(error_msg, stderr)
openoffice.start()
......@@ -52,7 +52,7 @@ class Handler(object):
def convert(self, destination_format=None, **kw):
""" Convert a pdf document """
# 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,
dir=self.document.directory_name)
command = ["pdftotext", self.document.getUrl(), output_url]
......@@ -78,7 +78,7 @@ class Handler(object):
stderr=PIPE,
close_fds=True,
env=self.environment).communicate()
info_list = filter(None, stdout.split("\n"))
info_list = [_f for _f in stdout.split("\n") if _f]
metadata = {}
for info in iter(info_list):
info = info.split(":")
......
......@@ -66,7 +66,7 @@ class Handler(object):
def convert(self, destination_format=None, **kw):
"""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)
command = self.makeWkhtmltopdfCommandList(
self.convertPathToUrl(self.file.getUrl()),
......
......@@ -183,7 +183,7 @@ class Handler(object):
def convert(self, destination_format=None, **kw):
""" Convert the inputed file to output as format that were informed """
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
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