blob: 917b4fe2cbec0270ff54f19c3e322a857ba6f481 [file] [log] [blame]
Guido van Rossumf06ee5f1996-11-27 19:52:01 +00001#! /usr/bin/env python
Guido van Rossumb83ec8f1992-05-19 13:52:02 +00002
3# A rather specialized script to make sure that a symbolic link named
4# RCS exists pointing to a real RCS directory in a parallel tree
5# referenced as RCStree in an ancestor directory.
6# (I use this because I like my RCS files to reside on a physically
7# different machine).
8
9import os
10
11def main():
12 rcstree = 'RCStree'
13 rcs = 'RCS'
14 if os.path.islink(rcs):
Walter Dörwald70a6b492004-02-12 17:35:32 +000015 print '%r is a symlink to %r' % (rcs, os.readlink(rcs))
Guido van Rossumb83ec8f1992-05-19 13:52:02 +000016 return
17 if os.path.isdir(rcs):
Walter Dörwald70a6b492004-02-12 17:35:32 +000018 print '%r is an ordinary directory' % (rcs,)
Guido van Rossumb83ec8f1992-05-19 13:52:02 +000019 return
20 if os.path.exists(rcs):
Walter Dörwald70a6b492004-02-12 17:35:32 +000021 print '%r is a file?!?!' % (rcs,)
Guido van Rossumb83ec8f1992-05-19 13:52:02 +000022 return
23 #
24 p = os.getcwd()
25 up = ''
26 down = ''
27 # Invariants:
28 # (1) join(p, down) is the current directory
29 # (2) up is the same directory as p
30 # Ergo:
31 # (3) join(up, down) is the current directory
Walter Dörwald70a6b492004-02-12 17:35:32 +000032 #print 'p =', repr(p)
Guido van Rossumb83ec8f1992-05-19 13:52:02 +000033 while not os.path.isdir(os.path.join(p, rcstree)):
34 head, tail = os.path.split(p)
Walter Dörwald70a6b492004-02-12 17:35:32 +000035 #print 'head = %r; tail = %r' % (head, tail)
Guido van Rossumb83ec8f1992-05-19 13:52:02 +000036 if not tail:
Walter Dörwald70a6b492004-02-12 17:35:32 +000037 print 'Sorry, no ancestor dir contains %r' % (rcstree,)
Guido van Rossumb83ec8f1992-05-19 13:52:02 +000038 return
39 p = head
40 up = os.path.join(os.pardir, up)
41 down = os.path.join(tail, down)
Walter Dörwald70a6b492004-02-12 17:35:32 +000042 #print 'p = %r; up = %r; down = %r' % (p, up, down)
Guido van Rossumb83ec8f1992-05-19 13:52:02 +000043 there = os.path.join(up, rcstree)
44 there = os.path.join(there, down)
45 there = os.path.join(there, rcs)
46 if os.path.isdir(there):
Walter Dörwald70a6b492004-02-12 17:35:32 +000047 print '%r already exists' % (there, )
Guido van Rossumb83ec8f1992-05-19 13:52:02 +000048 else:
Walter Dörwald70a6b492004-02-12 17:35:32 +000049 print 'making %r' % (there,)
Guido van Rossumb83ec8f1992-05-19 13:52:02 +000050 makedirs(there)
Walter Dörwald70a6b492004-02-12 17:35:32 +000051 print 'making symlink %r -> %r' % (rcs, there)
Guido van Rossumb83ec8f1992-05-19 13:52:02 +000052 os.symlink(there, rcs)
53
54def makedirs(p):
55 if not os.path.isdir(p):
56 head, tail = os.path.split(p)
57 makedirs(head)
58 os.mkdir(p, 0777)
59
60main()