Exemplo n.º 1
0
    def _remove_power(self, filename, debug=False):
        # STEP1: remove vdd/vss -------------------------------------
        input = open(filename, 'r')
        temp = TemporaryFile('w+')
        alim = re.compile('.*(vdd|vss)+.*', re.IGNORECASE)
        removed = 0

        for line in input:
            if not alim.search(line):
                temp.write(line)
            else:
                removed += 1

        if debug:
            print ' - removed %d power supply declarations' % removed

        input.close()

        # STEP2: remove ";\n)" and ",\n)" syntax errors -------------
        temp.seek(0)

        out = open(filename, 'w')

        comma = re.compile('.*\w+.*(;|,)')
        close = re.compile('^\s*\);')
        corrige = re.compile('(;|,)')
        corrected = 0

        previous = temp.next()
        for current in temp:
            if close.search(current) and comma.search(previous):
                out.write(corrige.sub('', previous))
                corrected += 1
            else:
                out.write(previous)
            previous = current
        out.write(previous)

        if debug:
            print ' - corrected %s syntax errors' % corrected

        # END -------------------------------------------------------
        temp.close()
        input.close()
        out.close()