PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/build/win32/mozilla-dos2unix.py

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