Ejemplo n.º 1
0
def findDupliated():
    dirpath = 'smallsite'
    content = ''
    for f in os.listdir(dirpath):
        selectors = {}
        path = dirpath + '/' + f
        parser = CssParser(open(path, 'r').read(), f)
        parser.doParse()
        for ruleSet in parser.styleSheet._ruleSets:
            selector = ruleSet.selector
            splited = selector.split(',')
            for x in splited:
                x = x.strip()
                if x == '':
                    continue
                if selectors.has_key(x):
                    selectors[x].append(f)
                else:
                    selectors[x] = [f]
        for name, value in selectors.items():
            if len(value) > 2:
                content = content + name + " =====> " + value[0] + "(" + str(
                    len(value)) + 'times)\n'

    open('result.txt', 'w').write(content)
Ejemplo n.º 2
0
def findDupliated():
    dirpath = 'smallsite'
    content = ''
    for f in os.listdir(dirpath):
        selectors = {}
        path = dirpath + '/' + f
        parser = CssParser(open(path, 'r').read(), f)
        parser.doParse()
        for ruleSet in parser.styleSheet._ruleSets:
            selector = ruleSet.selector
            splited = selector.split(',')
            for x in splited:
                x = x.strip()
                if x == '':
                    continue
                if selectors.has_key(x):
                    selectors[x].append(f)
                else:
                    selectors[x] = [f]
        for name, value in selectors.items():
            if len(value) > 2:
                content = content + name + " =====> " + value[0] + "(" + str(len(value)) + 'times)\n'

    open('result.txt', 'w').write(content)
Ejemplo n.º 3
0
                    len(value)) + 'times)\n'

    open('result.txt', 'w').write(content)

    #path = os.path.realpath(os.path.join(__file__, '../test.css'))
    #checkCssFileByOpm(path)
    #fixCss('test.css')
    #compressCss(path)


if __name__ == '__main__':
    dirpath = 'smallsite'
    content = ''
    counter = 0
    import re
    pattern = re.compile(r'[@\*>\[\]\(\):]')
    collector = []
    for f in os.listdir(dirpath):
        counter = counter + 1
        selectors = {}
        path = dirpath + '/' + f
        parser = CssParser(open(path, 'r').read(), f)
        parser.doParse()
        for ruleSet in parser.styleSheet._ruleSets:
            selector = ruleSet.selector
            if len(pattern.findall(selector)) != 0:
                collector.extend(pattern.findall(selector))
    #open('result.txt', 'w').write(content)
    print set(collector)
    print pattern.findall('@>*li:nth-child(even)')
Ejemplo n.º 4
0
    print checker.parser.styleSheet.getRuleSets()[0].values
    print checker.parser.styleSheet.getRuleSets()[0].getRules()[0].fixedValue

def compressCss(filePath):
    fileContent = open(filePath).read()
    checker, content = doCompress(fileContent, filePath)
    print content

if __name__ == '__main__':
    dirpath = 'smallsite'
    content = ''
    for f in os.listdir(dirpath):
        selectors = {}
        path = dirpath + '/' + f
        parser = CssParser(open(path, 'r').read(), f)
        parser.doParse()
        for ruleSet in parser.styleSheet._ruleSets:
            selector = ruleSet.selector
            splited = selector.split(',')
            for x in splited:
                x = x.strip()
                if x == '':
                    continue
                if selectors.has_key(x):
                    selectors[x].append(f)
                else:
                    selectors[x] = [f]
        for name, value in selectors.items():
            if len(value) > 2:
                content = content + name + " =====> " + value[0] + "(" + str(len(value)) + 'times)\n'