/build/win32/mozilla-dos2unix.py

http://github.com/zpao/v8monkey · Python · 73 lines · 53 code · 18 blank · 2 comment · 14 complexity · b68af67a903bbdb47b4eff22c1e3d871 MD5 · raw file

  1. #!/usr/bin/python
  2. import sys
  3. if not sys.platform == "win32":
  4. raise Exception("This script was only meant for Windows.")
  5. import os
  6. def dos2unix(path):
  7. print "dos2unix: %s" % path
  8. inf = open(path, "r")
  9. data = inf.read()
  10. inf.close()
  11. outf = open(path, "wb")
  12. outf.write(data)
  13. outf.close()
  14. adminfiles = [
  15. "Root",
  16. "Repository",
  17. "Entries",
  18. "Entries.Log",
  19. "Entries.Static",
  20. "Tag",
  21. "Notify",
  22. "Template"
  23. ]
  24. def walkdirectory(path):
  25. if not os.path.exists(os.path.join(path, "CVS")):
  26. return
  27. print "Directory: %s" % path
  28. for f in adminfiles:
  29. cvsf = os.path.join(path, "CVS", f)
  30. if os.path.exists(cvsf):
  31. dos2unix(cvsf)
  32. entries = open(os.path.join(path, "CVS", "Entries"), "r")
  33. for entry in entries:
  34. if entry == "D\n":
  35. continue
  36. (type, filename, rev, date, flags, extra) = entry.split('/')
  37. if type == "D" or flags == "-kb" or rev[0] == "-":
  38. continue
  39. dos2unix(os.path.join(path, filename))
  40. # Now walk subdirectories
  41. for entry in os.listdir(path):
  42. subdir = os.path.join(path, entry)
  43. if os.path.isdir(subdir):
  44. walkdirectory(subdir)
  45. topsrcdir = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-3])
  46. print """This command will convert the source tree at
  47. %s
  48. to an MSYS-compatible (unix mode) source tree. You can run this
  49. command multiple times safely. Are you sure you want to continue (Y/N)? """ % topsrcdir,
  50. sys.stdout.flush()
  51. print
  52. ask = raw_input()
  53. if len(ask) == 0 or (ask[0] != "y" and ask[0] != "Y"):
  54. raise Exception("User aborted action.")
  55. walkdirectory(topsrcdir)