Commit 51958577 authored by Gabriel Monnerat's avatar Gabriel Monnerat

split utils.py and add folder for this file

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@41958 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4d5cce43
......@@ -32,7 +32,7 @@ from signal import signal, SIGHUP
from handler.ooo.application.openoffice import openoffice
from handler.ooo.application.xvfb import xvfb
from wsgixmlrpcapplication import WSGIXMLRPCApplication
from handler.ooo.utils import convertStringToBool, configureLogger
from utils.utils import convertStringToBool, configureLogger
from os import path, mkdir
from handler.ooo.mimemapper import mimemapper
......
......@@ -28,7 +28,8 @@
from zope.interface import implements
from cloudooo.interfaces.application import IApplication
from cloudooo.handler.ooo.utils import logger, socketStatus, waitStopDaemon
from cloudooo.utils.utils import logger
from cloudooo.handler.ooo.utils.utils import socketStatus, waitStopDaemon
from psutil import pid_exists, Process
......
......@@ -36,9 +36,10 @@ from zope.interface import implements
from application import Application
from xvfb import xvfb
from cloudooo.interfaces.lockable import ILockable
from cloudooo.handler.ooo.utils import logger, waitStartDaemon, \
from cloudooo.utils.utils import logger, convertStringToBool
from cloudooo.handler.ooo.utils.utils import waitStartDaemon, \
removeDirectory, waitStopDaemon, \
convertStringToBool, socketStatus
socketStatus
class OpenOffice(Application):
......@@ -114,10 +115,10 @@ class OpenOffice(Application):
connection_list[0].local_address[1] == self.port:
process.terminate()
except psutil.error.AccessDenied, e:
logger.error(e)
logger.debug(e)
except TypeError, e:
# exception to prevent one psutil issue with svn processes
logger.error(e)
logger.debug(e)
except NotImplementedError, e:
logger.error("lsof isn't installed on this machine: " + str(e))
......
......@@ -27,7 +27,8 @@
##############################################################################
from subprocess import Popen, PIPE
from cloudooo.handler.ooo.utils import logger, waitStartDaemon, remove_file
from cloudooo.utils.utils import logger
from cloudooo.handler.ooo.utils.utils import waitStartDaemon, remove_file
from zope.interface import implements
from application import Application
from cloudooo.interfaces.application import IApplication
......@@ -55,7 +56,6 @@ class Xvfb(Application):
def start(self):
"""Method to start Virtual Frame Buffer."""
self.command = ["Xvfb", "-ac", ":%s" % self.display_id, \
# "-nolisten", "tcp",
"-screen", self.virtual_screen, "800x600x16", \
"-fbdir", self.path_run_dir]
self.process = Popen(" ".join(self.command),
......
......@@ -31,7 +31,7 @@ from zipfile import ZipFile
from StringIO import StringIO
from lxml import etree
from os import path
from cloudooo.handler.ooo.utils import logger
from cloudooo.utils.utils import logger
from cloudooo.handler.ooo.document import OdfDocument
from cloudooo.interfaces.granulate import ITableGranulator, \
IImageGranulator, \
......
......@@ -39,7 +39,7 @@ from cloudooo.interfaces.handler import IHandler
from cloudooo.handler.ooo.mimemapper import mimemapper
from cloudooo.handler.ooo.document import FileSystemDocument
from cloudooo.handler.ooo.monitor.timeout import MonitorTimeout
from cloudooo.handler.ooo.utils import logger
from cloudooo.utils.utils import logger
from psutil import pid_exists
......
......@@ -34,7 +34,7 @@ from filter import Filter
from os import environ, path
from cloudooo.interfaces.mimemapper import IMimemapper
from types import InstanceType
from utils import getCleanPythonEnvironment
from cloudooo.utils.utils import getCleanPythonEnvironment
import json
......
......@@ -29,7 +29,7 @@
from monitor import Monitor
from multiprocessing import Process
import psutil
from cloudooo.handler.ooo.utils import logger
from cloudooo.utils.utils import logger
from time import sleep
......
......@@ -28,7 +28,7 @@
from monitor import Monitor
from threading import Thread
from cloudooo.handler.ooo.utils import logger
from cloudooo.utils.utils import logger
from time import sleep
......
......@@ -29,7 +29,7 @@
from monitor import Monitor
from multiprocessing import Process
from time import sleep
from cloudooo.handler.ooo.utils import logger
from cloudooo.utils.utils import logger
class MonitorTimeout(Monitor, Process):
......
......@@ -29,7 +29,6 @@
import sys
from multiprocessing import Process
from os import listdir
from cloudooo.utils import usage
from xmlrpclib import ServerProxy
from os.path import join
from getopt import getopt, GetoptError
......@@ -133,13 +132,13 @@ def main():
opt_list, arg_list = getopt(sys.argv[1:], "hc:n:f:s:l:", ["help"])
except GetoptError, msg:
msg = msg.msg + help_msg
usage(sys.stderr, msg)
print >> sys.stderr, msg
sys.exit(2)
kw = {}
for opt, arg in opt_list:
if opt in ('-h', '--help'):
usage(sys.stdout, __doc__)
print >> sys.stdout, __doc__
sys.exit(2)
elif opt == '-c':
number_client = int(arg)
......
......@@ -33,7 +33,7 @@ from os import path, mkdir
from os import environ, putenv
from cloudooo.handler.ooo.application.xvfb import xvfb
from cloudooo.handler.ooo.application.openoffice import openoffice
from cloudooo.handler.ooo.utils import waitStartDaemon
from cloudooo.handler.ooo.utils.utils import waitStartDaemon
from cloudooo.handler.ooo.mimemapper import mimemapper
config = ConfigParser()
......
......@@ -4,7 +4,7 @@ import sys
import unittest
from getopt import getopt, GetoptError
from time import sleep
from cloudooo.handler.ooo.utils import socketStatus
from cloudooo.handler.ooo.utils.utils import socketStatus
from ConfigParser import ConfigParser
from os import chdir, path, environ, curdir
from subprocess import Popen
......
......@@ -30,7 +30,7 @@ import unittest
from cloudoooTestCase import cloudoooTestCase
from cloudooo.handler.ooo.application.openoffice import OpenOffice
from cloudoooTestCase import make_suite
from cloudooo.handler.ooo.utils import waitStopDaemon
from cloudooo.handler.ooo.utils.utils import waitStopDaemon
from psutil import Process, AccessDenied
......
......@@ -28,7 +28,7 @@
import unittest
import logging
from cloudooo.handler.ooo.utils import logger, configureLogger, \
from cloudooo.utils.utils import logger, configureLogger, \
convertStringToBool
from cloudoooTestCase import make_suite
......
......@@ -29,7 +29,7 @@
import unittest
from cloudoooTestCase import cloudoooTestCase, make_suite
from cloudooo.handler.ooo.application.xvfb import Xvfb
from cloudooo.hanlder.ooo.utils import waitStopDaemon
from cloudooo.handler.ooo.utils.utils import waitStopDaemon
class TestXvfb(cloudoooTestCase):
......
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Hugo H. Maia Vieira <hugomaia@tiolive.com>
# Copyright (c) 2009-2010 Nexedi SA and Contributors. All Rights Reserved.
# Gabriel M. Monnerat <gabriel@tiolive.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
......@@ -26,23 +26,52 @@
#
##############################################################################
import unittest
from cloudoooTestCase import cloudoooTestCase, make_suite
from cloudooo.manager import Manager
from socket import socket, error
from errno import EADDRINUSE
from time import sleep
from os import remove, environ
from shutil import rmtree
from cloudooo.utils.utils import logger
class TestGranulate(cloudoooTestCase):
def removeDirectory(path):
"""Remove directory"""
try:
rmtree(path)
except OSError, msg:
logger.error(msg)
def testGranulateFile(self):
"""Test if the granulateFile returns the grains correctly"""
manager = Manager('some/path')
self.assertRaises(NotImplementedError, manager.granulateFile, 'some/file',
'odt')
def socketStatus(hostname, port):
"""Verify if the address is busy."""
try:
socket().bind((hostname, port),)
# False if the is free
return False
except error, (num, err):
if num == EADDRINUSE:
# True if the isn't free
return True
def test_suite():
return make_suite(TestGranulate)
if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(TestGranulate)
unittest.TextTestRunner(verbosity=2).run(suite)
def waitStartDaemon(daemon, attempts):
"""Wait a certain time to start the daemon."""
for num in range(attempts):
sleep(1)
if daemon.status():
return
def waitStopDaemon(daemon, attempts=5):
"""Wait a certain time to stop the daemon."""
for num in range(attempts):
sleep(1)
if not daemon.status():
break
def remove_file(filepath):
try:
remove(filepath)
except OSError, msg:
print msg.strerror
......@@ -33,7 +33,7 @@ from zope.interface import implements
from interfaces.manager import IManager, IERP5Compatibility
from handler.ooo.handler import OOHandler
from handler.ooo.mimemapper import mimemapper
from handler.ooo.utils import logger
from utils.utils import logger
class Manager(object):
......
......@@ -26,11 +26,7 @@
#
##############################################################################
from socket import socket, error
from errno import EADDRINUSE
from time import sleep
from os import remove, environ
from shutil import rmtree
from os import environ
import logging
logger = logging.getLogger('Cloudooo')
......@@ -59,42 +55,6 @@ def getCleanPythonEnvironment():
return env
def removeDirectory(path):
"""Remove directory"""
try:
rmtree(path)
except OSError, msg:
logger.error(msg)
def socketStatus(hostname, port):
"""Verify if the address is busy."""
try:
socket().bind((hostname, port),)
# False if the is free
return False
except error, (num, err):
if num == EADDRINUSE:
# True if the isn't free
return True
def waitStartDaemon(daemon, attempts):
"""Wait a certain time to start the daemon."""
for num in range(attempts):
sleep(1)
if daemon.status():
return
def waitStopDaemon(daemon, attempts=5):
"""Wait a certain time to stop the daemon."""
for num in range(attempts):
sleep(1)
if not daemon.status():
break
def configureLogger(level=None, debug_mode=False):
"""Configure logger.
Keyword arguments:
......@@ -127,13 +87,6 @@ def configureLogger(level=None, debug_mode=False):
logger.addHandler(ch)
def remove_file(filepath):
try:
remove(filepath)
except OSError, msg:
print msg.strerror
def convertStringToBool(string):
"""This function is used to convert string 'true' and 'false' only.
Keyword arguments:
......
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