import os, sys

#
# copyToCASTOR(from_path, to_path)
# author  Maurizio Nagni
# version 1.0 - 3 September 2005
#
# Copy recursively a file/directory into a defined CASTOR path.
#
#
# Parameters:
#       from_path    - the origin item to copy
#       to_path      - the destination root path where to copy the item
#
def copyToCASTOR(from_path, to_path):

    if (os.path.isdir(from_path)):
        os.system('rfmkdir ' + to_path)

    lista = os.listdir(from_path)
    for fileName in lista:
        new_from_path = from_path + '/' + fileName
        new_to_path   = to_path   + '/' + fileName

        #is a file?
        if (os.path.isfile(new_from_path)):
            os.system('rfcp ' + new_from_path + '  ' + new_to_path)
            #print 'rfcp ' + new_from_path + '  ' + new_to_path + '\n'

        #is a dir?
        if (os.path.isdir(new_from_path)):
            os.system('rfmkdir ' + new_to_path)
            #print 'rfmkdir ' + new_to_path + '\n'
            copyToCASTOR(new_from_path, new_to_path)
    return True

