Guest User

Untitled

a guest
Oct 11th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. __author__ = "Sven Eberth"
  5.  
  6. """
  7. IGNITE 3 PORTER
  8. changes the syntax of CSS classes according to the new ignite syntax
  9.  
  10. former snytax (camelcase):
  11. .element-vSmall
  12. .element-vBig
  13.  
  14. new syntax
  15. .element--small
  16. .element--big
  17. """
  18.  
  19. import os, re
  20.  
  21. # GLOBALS
  22. lineCounter = filename = None
  23. changes = False
  24.  
  25.  
  26. def replacement(match):
  27. rep = match.group(1) + "--" + str.lower(match.group(2)) + match.group(3)
  28. print "Replaced <%s> by <%s> in %s:%s" % (match.group(), rep, filename, lineCounter)
  29. changes = True
  30. return rep
  31.  
  32.  
  33. def run(dictionary):
  34. global lineCounter, filename, changes
  35.  
  36. for dirname, dirnames, filenames in os.walk(dictionary):
  37. if dirname == ".":
  38. for ignore in [".idea", ".git", "server", "node_modules"]:
  39. if ignore in dirnames:
  40. dirnames.remove(ignore)
  41.  
  42. for ignore in ["README.md", ".editorconfig", ".gitmodules", os.path.basename(__file__)]:
  43. if ignore in filenames:
  44. filenames.remove(ignore)
  45.  
  46. for file in filenames:
  47. filename = ((dirname + "/") if dirname else "") + file
  48.  
  49. # print "handle file <%s>" % filename
  50.  
  51. source = open(filename, "r")
  52. lines = source.readlines()
  53. source.close()
  54.  
  55. newLines = []
  56. lineCounter = 0
  57.  
  58. for line in lines:
  59. new = re.sub(r"(\w+)-v([A-Z]{1})(\w+)", replacement, line)
  60. newLines.append(new)
  61. lineCounter += 1
  62.  
  63. if changes:
  64. target = open(filename, "w")
  65. target.write("".join(newLines))
  66. target.close()
  67.  
  68.  
  69. def main():
  70. run(".")
  71.  
  72.  
  73. if __name__ == "__main__":
  74. main()
Add Comment
Please, Sign In to add comment