summaryrefslogtreecommitdiff
path: root/sys/src/cmd/python/Demo/scripts/mkrcs.py
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@localhost>2011-05-03 11:25:13 +0000
committercinap_lenrek <cinap_lenrek@localhost>2011-05-03 11:25:13 +0000
commit458120dd40db6b4df55a4e96b650e16798ef06a0 (patch)
tree8f82685be24fef97e715c6f5ca4c68d34d5074ee /sys/src/cmd/python/Demo/scripts/mkrcs.py
parent3a742c699f6806c1145aea5149bf15de15a0afd7 (diff)
add hg and python
Diffstat (limited to 'sys/src/cmd/python/Demo/scripts/mkrcs.py')
-rwxr-xr-xsys/src/cmd/python/Demo/scripts/mkrcs.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/sys/src/cmd/python/Demo/scripts/mkrcs.py b/sys/src/cmd/python/Demo/scripts/mkrcs.py
new file mode 100755
index 000000000..cacdda0a5
--- /dev/null
+++ b/sys/src/cmd/python/Demo/scripts/mkrcs.py
@@ -0,0 +1,61 @@
+#! /usr/bin/env python
+
+# A rather specialized script to make sure that a symbolic link named
+# RCS exists pointing to a real RCS directory in a parallel tree
+# referenced as RCStree in an ancestor directory.
+# (I use this because I like my RCS files to reside on a physically
+# different machine).
+
+import os
+
+def main():
+ rcstree = 'RCStree'
+ rcs = 'RCS'
+ if os.path.islink(rcs):
+ print '%r is a symlink to %r' % (rcs, os.readlink(rcs))
+ return
+ if os.path.isdir(rcs):
+ print '%r is an ordinary directory' % (rcs,)
+ return
+ if os.path.exists(rcs):
+ print '%r is a file?!?!' % (rcs,)
+ return
+ #
+ p = os.getcwd()
+ up = ''
+ down = ''
+ # Invariants:
+ # (1) join(p, down) is the current directory
+ # (2) up is the same directory as p
+ # Ergo:
+ # (3) join(up, down) is the current directory
+ #print 'p =', repr(p)
+ while not os.path.isdir(os.path.join(p, rcstree)):
+ head, tail = os.path.split(p)
+ #print 'head = %r; tail = %r' % (head, tail)
+ if not tail:
+ print 'Sorry, no ancestor dir contains %r' % (rcstree,)
+ return
+ p = head
+ up = os.path.join(os.pardir, up)
+ down = os.path.join(tail, down)
+ #print 'p = %r; up = %r; down = %r' % (p, up, down)
+ there = os.path.join(up, rcstree)
+ there = os.path.join(there, down)
+ there = os.path.join(there, rcs)
+ if os.path.isdir(there):
+ print '%r already exists' % (there, )
+ else:
+ print 'making %r' % (there,)
+ makedirs(there)
+ print 'making symlink %r -> %r' % (rcs, there)
+ os.symlink(there, rcs)
+
+def makedirs(p):
+ if not os.path.isdir(p):
+ head, tail = os.path.split(p)
+ makedirs(head)
+ os.mkdir(p, 0777)
+
+if __name__ == "__main__":
+ main()