#!/usr/bin/env python2
"""
    Installs the API files for all cpanel frontends

    Copyright  Afrihost.com (PTY) Ltd 2004
    Original file by: Ed Pascoe <ed@pascoe.co.za>
"""
__author__  = "Ed Pascoe <ed@pascoe.co.za>"
__credits__ = "Afrihost.com -- The best webhosting. Ever."

import os.path, sys, dircache

cpfrontend="/usr/local/cpanel/base/frontend"

if __name__=='__main__': sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0]))+'/../pylib')

os.chdir(os.path.join(os.path.dirname(sys.argv[0]),"reseller_api"))

#First lets get a list of files and directories to create
sourcelist=[]
def walk(path):
    for f in dircache.listdir(path):
        if f==".svn": continue
        f=os.path.join(path,f)
        if os.path.isdir(f): 
            walk(f)
            continue
        sourcelist.append(f)

walk(".")

#Now lets look at where we need to put it
for f in dircache.listdir(cpfrontend):
    f=os.path.join(cpfrontend,f)
    if not os.path.isdir(f):  continue
    for i in sourcelist:
        t=os.path.join(f,i) 
        #if not os.path.exists(os.path.dirname(t)): print "mkdir ",os.path.dirname(t)
        if not os.path.exists(t):
            #print "linking ",t
            try: os.symlink(os.path.realpath(i),t)
            except OSError: continue
                #print "Could not link",i,t
                #continue



#    vim600: sw=4 fdm=marker expandtab sm ts=3
