Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- __author__ = "Sven Eberth"
- """
- IGNITE 3 PORTER
- changes the syntax of CSS classes according to the new ignite syntax
- former snytax (camelcase):
- .element-vSmall
- .element-vBig
- new syntax
- .element--small
- .element--big
- """
- import os, re
- # GLOBALS
- lineCounter = filename = None
- changes = False
- def replacement(match):
- rep = match.group(1) + "--" + str.lower(match.group(2)) + match.group(3)
- print "Replaced <%s> by <%s> in %s:%s" % (match.group(), rep, filename, lineCounter)
- changes = True
- return rep
- def run(dictionary):
- global lineCounter, filename, changes
- for dirname, dirnames, filenames in os.walk(dictionary):
- if dirname == ".":
- for ignore in [".idea", ".git", "server", "node_modules"]:
- if ignore in dirnames:
- dirnames.remove(ignore)
- for ignore in ["README.md", ".editorconfig", ".gitmodules", os.path.basename(__file__)]:
- if ignore in filenames:
- filenames.remove(ignore)
- for file in filenames:
- filename = ((dirname + "/") if dirname else "") + file
- # print "handle file <%s>" % filename
- source = open(filename, "r")
- lines = source.readlines()
- source.close()
- newLines = []
- lineCounter = 0
- for line in lines:
- new = re.sub(r"(\w+)-v([A-Z]{1})(\w+)", replacement, line)
- newLines.append(new)
- lineCounter += 1
- if changes:
- target = open(filename, "w")
- target.write("".join(newLines))
- target.close()
- def main():
- run(".")
- if __name__ == "__main__":
- main()
Add Comment
Please, Sign In to add comment