Commit 903e7b7f authored by Nicolas Delaby's avatar Nicolas Delaby

Rename All IHandler Class with name "Handler" as it make them easier to imports

dynamically.
As they all belong to a different namespace they can not collide with each other.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@43966 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7c3f182a
...@@ -33,8 +33,8 @@ from subprocess import Popen, PIPE ...@@ -33,8 +33,8 @@ from subprocess import Popen, PIPE
from tempfile import mktemp from tempfile import mktemp
class FFMPEGHandler(object): class Handler(object):
"""FFMPEGHandler is used to handler inputed video files""" """FFMPEG Handler is used to handler inputed video files"""
implements(IHandler) implements(IHandler)
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
############################################################################## ##############################################################################
from magic import Magic from magic import Magic
from cloudooo.handler.ffmpeg.handler import FFMPEGHandler from cloudooo.handler.ffmpeg.handler import Handler
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
...@@ -36,11 +36,11 @@ class TestAllSupportedFormat(HandlerTestCase): ...@@ -36,11 +36,11 @@ class TestAllSupportedFormat(HandlerTestCase):
def afterSetUp(self): def afterSetUp(self):
self.data = open("./data/test.ogv").read() self.data = open("./data/test.ogv").read()
self.kw = dict(env=dict(PATH=self.env_path)) self.kw = dict(env=dict(PATH=self.env_path))
self.input = FFMPEGHandler(self.tmp_url, self.data, "ogv", **self.kw) self.input = Handler(self.tmp_url, self.data, "ogv", **self.kw)
self.file_detector = Magic(mime=True) self.file_detector = Magic(mime=True)
def afterFormat(self, data): def afterFormat(self, data):
ogv_file = FFMPEGHandler(self.tmp_url, data, "avi", **self.kw) ogv_file = Handler(self.tmp_url, data, "avi", **self.kw)
ogv_data = ogv_file.convert("ogv") ogv_data = ogv_file.convert("ogv")
ogv_mimetype = self.file_detector.from_buffer(ogv_data) ogv_mimetype = self.file_detector.from_buffer(ogv_data)
return ogv_mimetype return ogv_mimetype
......
...@@ -27,16 +27,16 @@ ...@@ -27,16 +27,16 @@
############################################################################## ##############################################################################
import magic import magic
from cloudooo.handler.ffmpeg.handler import FFMPEGHandler from cloudooo.handler.ffmpeg.handler import Handler
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
class TestFFMPEGHandler(HandlerTestCase): class TestHandler(HandlerTestCase):
def afterSetUp(self): def afterSetUp(self):
self.data = open("./data/test.ogv").read() self.data = open("./data/test.ogv").read()
kw = dict(env=dict(PATH=self.env_path)) kw = dict(env=dict(PATH=self.env_path))
self.input = FFMPEGHandler(self.tmp_url, self.data, "ogv", **kw) self.input = Handler(self.tmp_url, self.data, "ogv", **kw)
def testConvertVideo(self): def testConvertVideo(self):
"""Test coversion of video to another format""" """Test coversion of video to another format"""
...@@ -55,4 +55,4 @@ class TestFFMPEGHandler(HandlerTestCase): ...@@ -55,4 +55,4 @@ class TestFFMPEGHandler(HandlerTestCase):
def test_suite(): def test_suite():
return make_suite(TestFFMPEGHandler) return make_suite(TestHandler)
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
import unittest import unittest
from cloudooo.interfaces.handler import IHandler from cloudooo.interfaces.handler import IHandler
from cloudooo.handler.ffmpeg.handler import FFMPEGHandler from cloudooo.handler.ffmpeg.handler import Handler
from cloudooo.handler.tests.handlerTestCase import make_suite from cloudooo.handler.tests.handlerTestCase import make_suite
...@@ -37,8 +37,8 @@ class TestInterface(unittest.TestCase): ...@@ -37,8 +37,8 @@ class TestInterface(unittest.TestCase):
def testIHandler(self): def testIHandler(self):
"""Test if Handlers implements IHandler""" """Test if Handlers implements IHandler"""
# XXX this might verify FFMPEGHandler methods too # XXX this might verify Handler methods too
self.assertTrue(IHandler.implementedBy(FFMPEGHandler)) self.assertTrue(IHandler.implementedBy(Handler))
def test_suite(): def test_suite():
......
...@@ -34,8 +34,8 @@ from subprocess import Popen, PIPE ...@@ -34,8 +34,8 @@ from subprocess import Popen, PIPE
from tempfile import mktemp from tempfile import mktemp
class ImageMagickHandler(object): class Handler(object):
"""ImageMagicHandler is used to handler images.""" """ImageMagic Handler is used to handler images."""
implements(IHandler) implements(IHandler)
......
...@@ -28,11 +28,11 @@ ...@@ -28,11 +28,11 @@
import magic import magic
from cloudooo.handler.imagemagick.handler import ImageMagickHandler from cloudooo.handler.imagemagick.handler import Handler
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
class TestImageMagickHandler(HandlerTestCase): class TestHandler(HandlerTestCase):
def afterSetUp(self): def afterSetUp(self):
self.kw = dict(env=dict(PATH=self.env_path)) self.kw = dict(env=dict(PATH=self.env_path))
...@@ -40,7 +40,7 @@ class TestImageMagickHandler(HandlerTestCase): ...@@ -40,7 +40,7 @@ class TestImageMagickHandler(HandlerTestCase):
def testConvertPNGtoJPG(self): def testConvertPNGtoJPG(self):
"""Test conversion of png to jpg""" """Test conversion of png to jpg"""
png_file = open("data/test.png").read() png_file = open("data/test.png").read()
handler = ImageMagickHandler(self.tmp_url, png_file, "png", **self.kw) handler = Handler(self.tmp_url, png_file, "png", **self.kw)
jpg_file = handler.convert("jpg") jpg_file = handler.convert("jpg")
mime = magic.Magic(mime=True) mime = magic.Magic(mime=True)
jpg_mimetype = mime.from_buffer(jpg_file) jpg_mimetype = mime.from_buffer(jpg_file)
...@@ -49,7 +49,7 @@ class TestImageMagickHandler(HandlerTestCase): ...@@ -49,7 +49,7 @@ class TestImageMagickHandler(HandlerTestCase):
def testgetMetadataFromImage(self): def testgetMetadataFromImage(self):
"""Test if metadata is extracted from image correctly""" """Test if metadata is extracted from image correctly"""
png_file = open("data/test.png").read() png_file = open("data/test.png").read()
handler = ImageMagickHandler(self.tmp_url, png_file, "png", **self.kw) handler = Handler(self.tmp_url, png_file, "png", **self.kw)
metadata = handler.getMetadata() metadata = handler.getMetadata()
self.assertEquals(metadata.get("Compression"), "Zip") self.assertEquals(metadata.get("Compression"), "Zip")
self.assertEquals(metadata.get("Colorspace"), "RGB") self.assertEquals(metadata.get("Colorspace"), "RGB")
...@@ -57,9 +57,9 @@ class TestImageMagickHandler(HandlerTestCase): ...@@ -57,9 +57,9 @@ class TestImageMagickHandler(HandlerTestCase):
def testsetMetadata(self): def testsetMetadata(self):
""" Test if metadata are inserted correclty """ """ Test if metadata are inserted correclty """
handler = ImageMagickHandler(self.tmp_url, "", "png", **self.kw) handler = Handler(self.tmp_url, "", "png", **self.kw)
self.assertRaises(NotImplementedError, handler.setMetadata) self.assertRaises(NotImplementedError, handler.setMetadata)
def test_suite(): def test_suite():
return make_suite(TestImageMagickHandler) return make_suite(TestHandler)
...@@ -43,8 +43,8 @@ from cloudooo.utils.utils import logger ...@@ -43,8 +43,8 @@ from cloudooo.utils.utils import logger
from psutil import pid_exists from psutil import pid_exists
class OOHandler(object): class Handler(object):
"""OOHandler is used to access the one Document and OpenOffice. """OOO Handler is used to access the one Document and OpenOffice.
For each Document inputed is created on instance of this class to manipulate For each Document inputed is created on instance of this class to manipulate
the document. This Document must be able to create and remove a temporary the document. This Document must be able to create and remove a temporary
document at FS, load and export. document at FS, load and export.
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
import unittest import unittest
from cloudooo.handler.ooo.document import FileSystemDocument, OdfDocument from cloudooo.handler.ooo.document import FileSystemDocument, OdfDocument
from cloudooo.handler.ooo.handler import OOHandler from cloudooo.handler.ooo.handler import Handler
from cloudooo.handler.ooo.application.openoffice import OpenOffice from cloudooo.handler.ooo.application.openoffice import OpenOffice
from cloudooo.manager import Manager from cloudooo.manager import Manager
from cloudooo.handler.ooo.mimemapper import MimeMapper from cloudooo.handler.ooo.mimemapper import MimeMapper
...@@ -142,7 +142,7 @@ class TestInterface(unittest.TestCase): ...@@ -142,7 +142,7 @@ class TestInterface(unittest.TestCase):
def testIHandler(self): def testIHandler(self):
"""Test if Handlers implements IHandler""" """Test if Handlers implements IHandler"""
self.assertTrue(IHandler.implementedBy(OOHandler)) self.assertTrue(IHandler.implementedBy(Handler))
method_list = ['convert', 'getMetadata', 'setMetadata'] method_list = ['convert', 'getMetadata', 'setMetadata']
for method in method_list: for method in method_list:
self.assertTrue(method in IHandler.names(), self.assertTrue(method in IHandler.names(),
......
...@@ -30,7 +30,7 @@ import magic ...@@ -30,7 +30,7 @@ import magic
from os import path from os import path
from base64 import encodestring, decodestring from base64 import encodestring, decodestring
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
from cloudooo.handler.ooo.handler import OOHandler from cloudooo.handler.ooo.handler import Handler
from cloudooo.handler.ooo.application.openoffice import openoffice from cloudooo.handler.ooo.application.openoffice import openoffice
import os import os
from lxml import etree from lxml import etree
...@@ -39,8 +39,8 @@ from zipfile import ZipFile ...@@ -39,8 +39,8 @@ from zipfile import ZipFile
OPENOFFICE = True OPENOFFICE = True
class TestOOHandler(HandlerTestCase): class TestHandler(HandlerTestCase):
"""Test OOHandler and manipulation of OOo Instance""" """Test OOO Handler and manipulation of OOo Instance"""
_file_path_list = [] _file_path_list = []
...@@ -69,7 +69,7 @@ class TestOOHandler(HandlerTestCase): ...@@ -69,7 +69,7 @@ class TestOOHandler(HandlerTestCase):
def testConvertOdtToDoc(self): def testConvertOdtToDoc(self):
"""Test convert ODT to DOC""" """Test convert ODT to DOC"""
data = encodestring(open("data/test.odt").read()) data = encodestring(open("data/test.odt").read())
handler = OOHandler(self.tmp_url, handler = Handler(self.tmp_url,
decodestring(data), decodestring(data),
'odt') 'odt')
doc_exported = handler.convert("doc") doc_exported = handler.convert("doc")
...@@ -78,7 +78,7 @@ class TestOOHandler(HandlerTestCase): ...@@ -78,7 +78,7 @@ class TestOOHandler(HandlerTestCase):
def testConvertDocToOdt(self): def testConvertDocToOdt(self):
"""Test convert DOC to ODT""" """Test convert DOC to ODT"""
data = encodestring(open("data/test.doc").read()) data = encodestring(open("data/test.doc").read())
handler = OOHandler(self.tmp_url, handler = Handler(self.tmp_url,
decodestring(data), decodestring(data),
'doc') 'doc')
doc_exported = handler.convert("odt") doc_exported = handler.convert("odt")
...@@ -88,7 +88,7 @@ class TestOOHandler(HandlerTestCase): ...@@ -88,7 +88,7 @@ class TestOOHandler(HandlerTestCase):
def testGetMetadata(self): def testGetMetadata(self):
"""Test getMetadata""" """Test getMetadata"""
data = encodestring(open("data/test.odt").read()) data = encodestring(open("data/test.odt").read())
handler = OOHandler(self.tmp_url, handler = Handler(self.tmp_url,
decodestring(data), decodestring(data),
'odt') 'odt')
metadata = handler.getMetadata() metadata = handler.getMetadata()
...@@ -101,20 +101,20 @@ class TestOOHandler(HandlerTestCase): ...@@ -101,20 +101,20 @@ class TestOOHandler(HandlerTestCase):
def testSetMetadata(self): def testSetMetadata(self):
"""Test setMetadata""" """Test setMetadata"""
data = encodestring(open("data/test.odt").read()) data = encodestring(open("data/test.odt").read())
handler = OOHandler(self.tmp_url, handler = Handler(self.tmp_url,
decodestring(data), decodestring(data),
'odt') 'odt')
new_data = handler.setMetadata({"Title": "cloudooo Test -"}) new_data = handler.setMetadata({"Title": "cloudooo Test -"})
new_handler = OOHandler(self.tmp_url, new_handler = Handler(self.tmp_url,
new_data, new_data,
'odt') 'odt')
metadata = new_handler.getMetadata() metadata = new_handler.getMetadata()
self.assertEquals(metadata.get('Title'), "cloudooo Test -") self.assertEquals(metadata.get('Title'), "cloudooo Test -")
handler = OOHandler(self.tmp_url, handler = Handler(self.tmp_url,
decodestring(data), decodestring(data),
'odt') 'odt')
new_data = handler.setMetadata({"Title": "Namie's working record"}) new_data = handler.setMetadata({"Title": "Namie's working record"})
new_handler = OOHandler(self.tmp_url, new_handler = Handler(self.tmp_url,
new_data, new_data,
'odt') 'odt')
metadata = new_handler.getMetadata() metadata = new_handler.getMetadata()
...@@ -124,7 +124,7 @@ class TestOOHandler(HandlerTestCase): ...@@ -124,7 +124,7 @@ class TestOOHandler(HandlerTestCase):
"""Test convert with openoffice stopped""" """Test convert with openoffice stopped"""
openoffice.stop() openoffice.stop()
data = encodestring(open("data/test.doc").read()) data = encodestring(open("data/test.doc").read())
handler = OOHandler(self.tmp_url, handler = Handler(self.tmp_url,
decodestring(data), decodestring(data),
'doc') 'doc')
doc_exported = handler.convert("odt") doc_exported = handler.convert("odt")
...@@ -135,7 +135,7 @@ class TestOOHandler(HandlerTestCase): ...@@ -135,7 +135,7 @@ class TestOOHandler(HandlerTestCase):
"""Test getMetadata with openoffice stopped""" """Test getMetadata with openoffice stopped"""
openoffice.stop() openoffice.stop()
data = encodestring(open("data/test.odt").read()) data = encodestring(open("data/test.odt").read())
handler = OOHandler(self.tmp_url, handler = Handler(self.tmp_url,
decodestring(data), decodestring(data),
'odt') 'odt')
metadata = handler.getMetadata() metadata = handler.getMetadata()
...@@ -147,11 +147,11 @@ class TestOOHandler(HandlerTestCase): ...@@ -147,11 +147,11 @@ class TestOOHandler(HandlerTestCase):
"""Test setMetadata with openoffice stopped""" """Test setMetadata with openoffice stopped"""
openoffice.stop() openoffice.stop()
data = encodestring(open("data/test.doc").read()) data = encodestring(open("data/test.doc").read())
handler = OOHandler(self.tmp_url, handler = Handler(self.tmp_url,
decodestring(data), decodestring(data),
'doc') 'doc')
new_data = handler.setMetadata({"Title": "cloudooo Test -"}) new_data = handler.setMetadata({"Title": "cloudooo Test -"})
new_handler = OOHandler(self.tmp_url, new_handler = Handler(self.tmp_url,
new_data, new_data,
'doc') 'doc')
metadata = new_handler.getMetadata() metadata = new_handler.getMetadata()
...@@ -161,7 +161,7 @@ class TestOOHandler(HandlerTestCase): ...@@ -161,7 +161,7 @@ class TestOOHandler(HandlerTestCase):
"""Test refresh argument""" """Test refresh argument"""
# Check when refreshing is disabled # Check when refreshing is disabled
data = encodestring(open("data/test_fields.odt").read()) data = encodestring(open("data/test_fields.odt").read())
handler = OOHandler(self.tmp_url, handler = Handler(self.tmp_url,
decodestring(data), decodestring(data),
'odt', 'odt',
refresh=False) refresh=False)
...@@ -175,7 +175,7 @@ class TestOOHandler(HandlerTestCase): ...@@ -175,7 +175,7 @@ class TestOOHandler(HandlerTestCase):
# Check when refreshing is enabled # Check when refreshing is enabled
data = encodestring(open("data/test_fields.odt").read()) data = encodestring(open("data/test_fields.odt").read())
handler = OOHandler(self.tmp_url, handler = Handler(self.tmp_url,
decodestring(data), decodestring(data),
'odt', 'odt',
refresh=True) refresh=True)
...@@ -189,4 +189,4 @@ class TestOOHandler(HandlerTestCase): ...@@ -189,4 +189,4 @@ class TestOOHandler(HandlerTestCase):
def test_suite(): def test_suite():
return make_suite(TestOOHandler) return make_suite(TestHandler)
...@@ -33,8 +33,8 @@ from subprocess import Popen, PIPE ...@@ -33,8 +33,8 @@ from subprocess import Popen, PIPE
from tempfile import mktemp from tempfile import mktemp
class PDFHandler(object): class Handler(object):
"""PDFHandler is used to handler inputed pdf document.""" """PDF Handler is used to handler inputed pdf document."""
implements(IHandler) implements(IHandler)
......
...@@ -27,12 +27,12 @@ ...@@ -27,12 +27,12 @@
############################################################################## ##############################################################################
from cloudooo.handler.pdf.handler import PDFHandler from cloudooo.handler.pdf.handler import Handler
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
from types import DictType from types import DictType
class TestPDFHandler(HandlerTestCase): class TestHandler(HandlerTestCase):
def afterSetUp(self): def afterSetUp(self):
self.kw = dict(env=dict(PATH=self.env_path)) self.kw = dict(env=dict(PATH=self.env_path))
...@@ -40,14 +40,14 @@ class TestPDFHandler(HandlerTestCase): ...@@ -40,14 +40,14 @@ class TestPDFHandler(HandlerTestCase):
def testConvertPDFtoText(self): def testConvertPDFtoText(self):
"""Test conversion of pdf to txt""" """Test conversion of pdf to txt"""
pdf_document = open("data/test.pdf").read() pdf_document = open("data/test.pdf").read()
handler = PDFHandler(self.tmp_url, pdf_document, "pdf", **self.kw) handler = Handler(self.tmp_url, pdf_document, "pdf", **self.kw)
txt_document = handler.convert("txt") txt_document = handler.convert("txt")
self.assertTrue(txt_document.startswith("UNG Docs Architecture")) self.assertTrue(txt_document.startswith("UNG Docs Architecture"))
def testgetMetadata(self): def testgetMetadata(self):
"""Test if the metadata are extracted correctly""" """Test if the metadata are extracted correctly"""
pdf_document = open("data/test.pdf").read() pdf_document = open("data/test.pdf").read()
handler = PDFHandler(self.tmp_url, pdf_document, "pdf", **self.kw) handler = Handler(self.tmp_url, pdf_document, "pdf", **self.kw)
metadata = handler.getMetadata() metadata = handler.getMetadata()
self.assertEquals(type(metadata), DictType) self.assertEquals(type(metadata), DictType)
self.assertNotEquals(metadata, {}) self.assertNotEquals(metadata, {})
...@@ -56,14 +56,14 @@ class TestPDFHandler(HandlerTestCase): ...@@ -56,14 +56,14 @@ class TestPDFHandler(HandlerTestCase):
def testsetMetadata(self): def testsetMetadata(self):
"""Test if the metadata is inserted correctly""" """Test if the metadata is inserted correctly"""
pdf_document = open("data/test.pdf").read() pdf_document = open("data/test.pdf").read()
handler = PDFHandler(self.tmp_url, pdf_document, "pdf", **self.kw) handler = Handler(self.tmp_url, pdf_document, "pdf", **self.kw)
metadata_dict = {"title": "Set Metadata Test", "creator": "gabriel\'@"} metadata_dict = {"title": "Set Metadata Test", "creator": "gabriel\'@"}
new_document = handler.setMetadata(metadata_dict) new_document = handler.setMetadata(metadata_dict)
handler = PDFHandler(self.tmp_url, new_document, "pdf", **self.kw) handler = Handler(self.tmp_url, new_document, "pdf", **self.kw)
metadata = handler.getMetadata() metadata = handler.getMetadata()
self.assertEquals(metadata["title"], 'Set Metadata Test') self.assertEquals(metadata["title"], 'Set Metadata Test')
self.assertEquals(metadata['creator'], 'gabriel\'@') self.assertEquals(metadata['creator'], 'gabriel\'@')
def test_suite(): def test_suite():
return make_suite(TestPDFHandler) return make_suite(TestHandler)
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