summaryrefslogtreecommitdiffstats
path: root/Demo/scripts
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-05-19 13:52:02 (GMT)
committerGuido van Rossum <guido@python.org>1992-05-19 13:52:02 (GMT)
commitb83ec8f58de07a3c5ba53342b19670a96dcd254d (patch)
tree46d9c39dbc0f8c9f1cf001cff4e5cc1624861383 /Demo/scripts
parentc99a4f900d1feb2f3be88949b766bb81ca0ccf08 (diff)
downloadcpython-b83ec8f58de07a3c5ba53342b19670a96dcd254d.zip
cpython-b83ec8f58de07a3c5ba53342b19670a96dcd254d.tar.gz
cpython-b83ec8f58de07a3c5ba53342b19670a96dcd254d.tar.bz2
Initial revision
Diffstat (limited to 'Demo/scripts')
-rwxr-xr-xDemo/scripts/makedir.py20
-rwxr-xr-xDemo/scripts/mkrcs.py61
2 files changed, 81 insertions, 0 deletions
diff --git a/Demo/scripts/makedir.py b/Demo/scripts/makedir.py
new file mode 100755
index 0000000..b08e455
--- /dev/null
+++ b/Demo/scripts/makedir.py
@@ -0,0 +1,20 @@
+#! /usr/local/python
+
+# Like mkdir, but also make intermediate directories if necessary.
+# It is not an error if the given directory already exists (as long
+# as it is a directory).
+# Errors are not treated specially -- you just get a Python exception.
+
+import sys, os
+
+def main():
+ for p in sys.argv[1:]:
+ makedirs(p)
+
+def makedirs(p):
+ if not os.path.isdir(p):
+ head, tail = os.path.split(p)
+ makedirs(head)
+ os.mkdir(p, 0777)
+
+main()
diff --git a/Demo/scripts/mkrcs.py b/Demo/scripts/mkrcs.py
new file mode 100755
index 0000000..dc8dffb
--- /dev/null
+++ b/Demo/scripts/mkrcs.py
@@ -0,0 +1,61 @@
+#! /ufs/guido/bin/sgi/python
+#! /usr/local/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 `rcs`, 'is a symlink to', `os.readlink(rcs)`
+ return
+ if os.path.isdir(rcs):
+ print `rcs`, 'is an ordinary directory'
+ return
+ if os.path.exists(rcs):
+ print `rcs`, 'is a file?!?!'
+ 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 =', `p`
+ while not os.path.isdir(os.path.join(p, rcstree)):
+ head, tail = os.path.split(p)
+ #print 'head =', `head`, '; tail =', `tail`
+ if not tail:
+ print 'Sorry, no ancestor dir contains', `rcstree`
+ return
+ p = head
+ up = os.path.join(os.pardir, up)
+ down = os.path.join(tail, down)
+ #print 'p =', `p`, '; up =', `up`, '; down =', `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 `there`, 'already exists'
+ else:
+ print 'making', `there`
+ makedirs(there)
+ print 'making symlink', `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)
+
+main()