Back to index

python3.2  3.2.2
Functions | Variables
linktree Namespace Reference

Functions

def main
def linknames

Variables

string LINK = '.LINK'
int debug = 0

Function Documentation

def linktree.linknames (   old,
  new,
  link 
)

Definition at line 50 of file linktree.py.

00050 
00051 def linknames(old, new, link):
00052     if debug: print('linknames', (old, new, link))
00053     try:
00054         names = os.listdir(old)
00055     except os.error as msg:
00056         print(old + ': warning: cannot listdir:', msg)
00057         return
00058     for name in names:
00059         if name not in (os.curdir, os.pardir):
00060             oldname = os.path.join(old, name)
00061             linkname = os.path.join(link, name)
00062             newname = os.path.join(new, name)
00063             if debug > 1: print(oldname, newname, linkname)
00064             if os.path.isdir(oldname) and \
00065                not os.path.islink(oldname):
00066                 try:
00067                     os.mkdir(newname, 0o777)
00068                     ok = 1
00069                 except:
00070                     print(newname + \
00071                           ': warning: cannot mkdir:', msg)
00072                     ok = 0
00073                 if ok:
00074                     linkname = os.path.join(os.pardir,
00075                                             linkname)
00076                     linknames(oldname, newname, linkname)
00077             else:
00078                 os.symlink(linkname, newname)

Here is the call graph for this function:

Here is the caller graph for this function:

def linktree.main ( void  )

Definition at line 19 of file linktree.py.

00019 
00020 def main():
00021     if not 3 <= len(sys.argv) <= 4:
00022         print('usage:', sys.argv[0], 'oldtree newtree [linkto]')
00023         return 2
00024     oldtree, newtree = sys.argv[1], sys.argv[2]
00025     if len(sys.argv) > 3:
00026         link = sys.argv[3]
00027         link_may_fail = 1
00028     else:
00029         link = LINK
00030         link_may_fail = 0
00031     if not os.path.isdir(oldtree):
00032         print(oldtree + ': not a directory')
00033         return 1
00034     try:
00035         os.mkdir(newtree, 0o777)
00036     except os.error as msg:
00037         print(newtree + ': cannot mkdir:', msg)
00038         return 1
00039     linkname = os.path.join(newtree, link)
00040     try:
00041         os.symlink(os.path.join(os.pardir, oldtree), linkname)
00042     except os.error as msg:
00043         if not link_may_fail:
00044             print(linkname + ': cannot symlink:', msg)
00045             return 1
00046         else:
00047             print(linkname + ': warning: cannot symlink:', msg)
00048     linknames(oldtree, newtree, link)
00049     return 0

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 17 of file linktree.py.

Definition at line 15 of file linktree.py.