blob: dc8dffb4abf6e217ca675c28dea3b597ab99944b [file] [log] [blame]
Guido van Rossumb83ec8f1992-05-19 13:52:02 +00001#! /ufs/guido/bin/sgi/python
2#! /usr/local/python
3
4# A rather specialized script to make sure that a symbolic link named
5# RCS exists pointing to a real RCS directory in a parallel tree
6# referenced as RCStree in an ancestor directory.
7# (I use this because I like my RCS files to reside on a physically
8# different machine).
9
10import os
11
12def main():
13 rcstree = 'RCStree'
14 rcs = 'RCS'
15 if os.path.islink(rcs):
16 print `rcs`, 'is a symlink to', `os.readlink(rcs)`
17 return
18 if os.path.isdir(rcs):
19 print `rcs`, 'is an ordinary directory'
20 return
21 if os.path.exists(rcs):
22 print `rcs`, 'is a file?!?!'
23 return
24 #
25 p = os.getcwd()
26 up = ''
27 down = ''
28 # Invariants:
29 # (1) join(p, down) is the current directory
30 # (2) up is the same directory as p
31 # Ergo:
32 # (3) join(up, down) is the current directory
33 #print 'p =', `p`
34 while not os.path.isdir(os.path.join(p, rcstree)):
35 head, tail = os.path.split(p)
36 #print 'head =', `head`, '; tail =', `tail`
37 if not tail:
38 print 'Sorry, no ancestor dir contains', `rcstree`
39 return
40 p = head
41 up = os.path.join(os.pardir, up)
42 down = os.path.join(tail, down)
43 #print 'p =', `p`, '; up =', `up`, '; down =', `down`
44 there = os.path.join(up, rcstree)
45 there = os.path.join(there, down)
46 there = os.path.join(there, rcs)
47 if os.path.isdir(there):
48 print `there`, 'already exists'
49 else:
50 print 'making', `there`
51 makedirs(there)
52 print 'making symlink', `rcs`, '->', `there`
53 os.symlink(there, rcs)
54
55def makedirs(p):
56 if not os.path.isdir(p):
57 head, tail = os.path.split(p)
58 makedirs(head)
59 os.mkdir(p, 0777)
60
61main()