Beispiel #1
0
    def SearchInFile(self, fname):
        """Search in a file for all lines with matches of the set query and
        yield the results as they are found.
        @param fname: filename
        @todo: unicode handling

        """
        if self._regex is None:
            return

        checker = fchecker.FileTypeChecker()
        if checker.IsReadableText(fname):
            try:
                fobj = open(fname, 'rb')
            except (IOError, OSError):
                return
            else:
                # Special token to signify start of a search
                yield (None, fname)

            for lnum, line in enumerate(fobj):
                if self._regex.search(line) is not None:
                    yield self._formatter(fname, lnum, line)
            fobj.close()
        return
Beispiel #2
0
    def __init__(self, header=None, template=u"%s~"):
        """Create a BackupManager
        @keyword header: header to id backups with (Text files only!!)
        @keyword template: template string for naming backup file with

        """
        object.__init__(self)

        # Attributes
        self.checker = fchecker.FileTypeChecker()
        self.header = header  # Backup id header
        self.template = template  # Filename template
Beispiel #3
0
import shutil
import sys
import zipfile

import noval.util.logger as logger
import noval.util.sysutils as sysutils
import noval.util.utillang as utillang
from noval.util.lang import *
import subprocess
import strutils
from chardet.universaldetector import UniversalDetector
import chardet
import fchecker
from noval.tool.consts import ERROR_OK, UNKNOWN_ERROR

_Checker = fchecker.FileTypeChecker()

global fileutilsLogger
fileutilsLogger = logging.getLogger("activegrid.util.fileutils")
# FATAL : No logging
# ERROR : No logging
# WARN  : No logging
# INFO  : No logging
# DEBUG : debugging
logger.setLevelFatal(fileutilsLogger)
#logging.getLogger().addHandler(logging.StreamHandler(sys.stderr))


def addRef(varname):
    return "${%s}" % varname