1 # fixgusidir - Modify filenames in the CWGUSI source tree, so
2 # that it can be put under CVS. Needed because there are files with slashes
3 # in their name, which CVS does not approve of.
6 # - On importing gusi in cvs:
7 # - Run the script after unpacking the gusi distribution. This creates
8 # _s_ files for all / files.
9 # - Remove all / files with "find file" or some such.
11 # - On checking out gusi:
12 # - After checkout, run the script to create / files for all _s_ files.
13 # - After modifying stuff, or later checkouts:
14 # - Run the script. Conflicts between / and _s_ files will be reported.
15 # - Fix the problems by removing the outdated / or _s_ file.
16 # - Run the script again. Possibly do a cvs checkin.
22 # Substitution for slashes in filenames
24 # Program to find those substitutions
25 SUBSTPROG
= re
.compile(SUBST
)
31 fss
, ok
= macfs
.GetDirectory("CWGUSI source folder?")
32 if not ok
: sys
.exit(0)
33 gusidir
= fss
.as_pathname()
34 fixgusifolder(gusidir
)
37 def fixgusifolder(gusidir
):
38 """Synchronize files with / in their name with their _s_ counterparts"""
39 os
.path
.walk(gusidir
, gusiwalk
, None)
41 def gusiwalk(dummy
, top
, names
):
42 """Helper for fixgusifolder: convert a single directory full of files"""
43 # First remember names with slashes and with our slash-substitution
49 if SUBSTPROG
.search(name
):
50 codenames
.append(name
)
51 # Next, check whether we need to copy any slash-files to subst-files
53 if os
.path
.isdir(name
):
54 print '** Folder with slash in name cannot be handled!'
56 othername
= mac2codename(name
)
57 if len(othername
) > 31:
58 print '** Converted filename too long:', othername
60 if othername
in codenames
:
61 codenames
.remove(othername
)
62 sync(os
.path
.join(top
, name
), os
.path
.join(top
, othername
))
63 # Now codenames contains only files that have no / equivalent
64 for name
in codenames
:
65 othername
= code2macname(name
)
66 sync(os
.path
.join(top
, name
), os
.path
.join(top
, othername
))
68 def mac2codename(name
):
69 return re
.sub('/', SUBST
, name
)
71 def code2macname(name
):
72 return re
.sub(SUBST
, '/', name
)
75 if os
.path
.exists(new
):
76 # Both exist. Check that they are indentical
77 d1
= open(old
, 'rb').read()
78 d2
= open(new
, 'rb').read()
82 print '** OUT-OF-SYNC', old
84 fp
.write(open(old
, 'rb').read())
85 print '-- COPIED ', old
87 if __name__
== '__main__':