Mercurial > cpython-lru_cache-weakref
annotate Demo/scripts/mkrcs.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 73758db2f464 |
| children | 71a294bd7950 |
| rev | line source |
|---|---|
|
4573
73758db2f464
/usr/local/bin/python -> /usr/bin/env python
Guido van Rossum <guido@python.org>
parents:
1506
diff
changeset
|
1 #! /usr/bin/env python |
| 875 | 2 |
| 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 | |
| 9 import os | |
| 10 | |
| 11 def main(): | |
| 12 rcstree = 'RCStree' | |
| 13 rcs = 'RCS' | |
| 14 if os.path.islink(rcs): | |
| 15 print `rcs`, 'is a symlink to', `os.readlink(rcs)` | |
| 16 return | |
| 17 if os.path.isdir(rcs): | |
| 18 print `rcs`, 'is an ordinary directory' | |
| 19 return | |
| 20 if os.path.exists(rcs): | |
| 21 print `rcs`, 'is a file?!?!' | |
| 22 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 | |
| 32 #print 'p =', `p` | |
| 33 while not os.path.isdir(os.path.join(p, rcstree)): | |
| 34 head, tail = os.path.split(p) | |
| 35 #print 'head =', `head`, '; tail =', `tail` | |
| 36 if not tail: | |
| 37 print 'Sorry, no ancestor dir contains', `rcstree` | |
| 38 return | |
| 39 p = head | |
| 40 up = os.path.join(os.pardir, up) | |
| 41 down = os.path.join(tail, down) | |
| 42 #print 'p =', `p`, '; up =', `up`, '; down =', `down` | |
| 43 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): | |
| 47 print `there`, 'already exists' | |
| 48 else: | |
| 49 print 'making', `there` | |
| 50 makedirs(there) | |
| 51 print 'making symlink', `rcs`, '->', `there` | |
| 52 os.symlink(there, rcs) | |
| 53 | |
| 54 def 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 | |
| 60 main() |
