예제 #1
0
 def test_normal(self):
     logger.clear_log()
     assert len(logger.get_log()) == 0
     logger.info("a")
     assert len(logger.get_log()) == 1
     logger.clear_log()
     assert len(logger.get_log()) == 0
예제 #2
0
파일: gfile.py 프로젝트: thombashi/thutils
    def moveFile(cls, src_path, dst_path):
        import shutil

        try:
            check_file_existence(src_path)
        except FileNotFoundError:
            _, e, _ = sys.exc_info()  # for python 2.5 compatibility
            logger.debug(e)
            return False

        if os.path.realpath(src_path) == os.path.realpath(dst_path):
            logger.debug("%s and %s are the same file" % (
                src_path, dst_path))
            return True

        logger.info("move: %s -> %s" % (src_path, dst_path))
        if not cls.__dry_run:
            shutil.move(src_path, dst_path)

        return True
예제 #3
0
파일: gfile.py 프로젝트: thombashi/thutils
    def rename(cls, src_path, dst_path):
        try:
            check_file_existence(src_path)
        except (InvalidFilePathError, FileNotFoundError):
            _, e, _ = sys.exc_info()  # for python 2.5 compatibility
            logger.exception(e)
            return False

        if dataproperty.is_empty_string(dst_path):
            logger.error("empty destination path")
            return False

        if os.path.lexists(dst_path):
            logger.error("'%s' already exists" % (dst_path))
            return False

        logger.info("rename: %s -> %s" % (src_path, dst_path))
        if not cls.__dry_run:
            os.rename(src_path, dst_path)

        return True
예제 #4
0
파일: main.py 프로젝트: thombashi/thutils
    def __call__(self, *args):
        import thutils.gfile as gfile

        return_value = -1

        try:
            return_value = self.function()
            return return_value
        except (gfile.InvalidFilePathError, gfile.FileNotFoundError):
            _, e, _ = sys.exc_info()  # for python 2.5 compatibility
            logger.exception(e)
            return_value = EX_NOINPUT
            return return_value
        except IOError:
            _, e, _ = sys.exc_info()  # for python 2.5 compatibility
            logger.exception(e)
            return_value = EX_IOERR
            return return_value
        except ValueError:
            _, e, _ = sys.exc_info()  # for python 2.5 compatibility
            logger.exception(e)
            return_value = EX_SOFTWARE
            return return_value
        except ImportError:
            _, e, _ = sys.exc_info()  # for python 2.5 compatibility
            logger.exception(e)
            return_value = EX_OSFILE
            return return_value
        except KeyboardInterrupt:
            logger.info(
                self.KEYBOARD_INTERRUPT_FORMAT % (os.path.basename(__file__)))
            return_value = 1
            return return_value
        except Exception:
            _, e, _ = sys.exc_info()  # for python 2.5 compatibility
            logger.exception(e)
            return_value = 1
            return return_value
        finally:
            logger.debug("exit code: " + str(return_value))
예제 #5
0
 def test_smoke(self, message, caller):
     logger.info(message, caller)