def checkFile(filePath, config = defaultConfig):
    '''通过路径检查css文件'''
    fileContent = open(filePath).read()
    console.log('[ckstyle] checking %s' % filePath)
    checker = doCheck(fileContent, filePath, config)
    path = os.path.realpath(filePath + config.extension)
    if checker.hasError():
        reporter = ReporterUtil.getReporter('json' if config.exportJson else 'text', checker)
        reporter.doReport()
        if config.printFlag:
            if os.path.exists(path):
                os.remove(path)
            console.show(reporter.export() + '\n')
        else:
            open(path, 'w').write(reporter.export())
            console.show('[ckstyle] @see %s\n' % path)
        return False
    else:
        if config.exportJson:
            console.show('{"status":"ok","result":"%s is ok"}' % filePath)
        else:
            console.show('[ckstyle] %s is ok\n' % filePath)
        if os.path.exists(path):
            os.remove(path)
        return True
Exemple #2
0
def checkFile(filePath, config = defaultConfig):
    '''通过路径检查css文件'''
    fileContent = open(filePath).read()
    console.log('[ckstyle] checking %s' % filePath)
    checker = doCheck(fileContent, filePath, config)
    path = os.path.realpath(filePath + config.extension)
    if checker.hasError():
        reporter = ReporterUtil.getReporter('json' if config.exportJson else 'text', checker)
        reporter.doReport()
        if config.printFlag:
            if os.path.exists(path):
                os.remove(path)
            console.show(reporter.export() + '\n')
        else:
            open(path, 'w').write(reporter.export())
            console.show('[ckstyle] @see %s\n' % path)
        return False
    else:
        if config.exportJson:
            console.show('{"status":"ok","result":"%s is ok"}' % filePath)
        else:
            console.show('[ckstyle] %s is ok\n' % filePath)
        if os.path.exists(path):
            os.remove(path)
        return True
def getInt(config, group, attr, default):
    if config.has_option(group, attr):
        try:
            result = config.getint(group, attr)
            return result
        except Exception:
            console.log('%s of %s in config file should be int' % (attr, group))
    return default
 def __init__(self, filePath, debug = False):
     self.args = args.CommandArgs()
     if exists(filePath):
         if not debug:
             console.log('load config from %s' % filePath)
         self.load(filePath)
     else:
         if not debug:
             console.log('no config file specified, will use default settings.')
def getBoolean(config, group, attr, default):
    if config.has_option(group, attr):
        try:
            result = config.getboolean(group, attr)
            return result
        except Exception:
            console.log('%s of %s in config file should be boolean' %
                        (attr, group))
    return default
def get(config, group, attr, default, lowerFlag = False):
    if config.has_option(group, attr):
        try:
            result = config.get(group, attr)
            if lowerFlag:
                result = result.lower()
            return result
        except Exception:
            console.log('%s of %s in config file should be valid string' % (attr, group))
    return default
 def __init__(self, filePath, debug=False):
     self.args = args.CommandArgs()
     if exists(filePath):
         if not debug:
             console.log('load config from %s' % filePath)
         self.load(filePath)
     else:
         if not debug:
             console.log(
                 'no config file specified, will use default settings.')
def get(config, group, attr, default, lowerFlag=False):
    if config.has_option(group, attr):
        try:
            result = config.get(group, attr)
            if lowerFlag:
                result = result.lower()
            return result
        except Exception:
            console.log('%s of %s in config file should be valid string' %
                        (attr, group))
    return default