def copy_modules(filespath=None, modules_path=None, verbose=None):
    ''' Copy over the tree module files into your path '''

    # find or define a modules path
    if not modules_path:
        modulepath = os.getenv("MODULEPATH")
        if not modulepath:
            modules_path = input('Enter the root path for your module files:')
        else:
            split_mods = modulepath.split(':')
            if len(split_mods) > 1:
                if verbose:
                    print('Multiple module paths found.  Finding all that contain a tree directory.')
                for mfile in split_mods:
                    if os.path.exists(os.path.join(mfile, 'tree')):
                        copy_modules(filespath=filespath, modules_path=mfile, verbose=verbose)
                    else:
                        return
            else:
                modules_path = split_mods[0]

    # check for the tree module directory
    tree_mod = os.path.join(modules_path, 'tree')
    if not os.path.isdir(tree_mod):
        os.makedirs(tree_mod)

    # copy the modules into the tree
    if verbose:
        print('Copying modules from etc/ into {0}'.format(tree_mod))
    module_files = glob.glob(os.path.join(filespath, '*.module'))
    for mfile in module_files:
        base = os.path.splitext(os.path.basename(mfile))[0]
        tree_out = os.path.join(tree_mod, base)
        shutil.copy2(mfile, tree_out)

    # copy the default version into the tree
    version = os.path.join(filespath, '.version')
    if os.path.isfile(version):
        shutil.copy2(version, tree_mod)
def copy_modules ( filespath = None , modules_path = None , verbose = None ) : if not modules_path : modulepath = os . getenv ( "MODULEPATH" ) if not modulepath : modules_path = input ( 'Enter the root path for your module files:' ) else : split_mods = modulepath . split ( ':' ) if len ( split_mods ) > 1 : if verbose : print ( 'Multiple module paths found.  Finding all that contain a tree directory.' ) for mfile in split_mods : if os . path . exists ( os . path . join ( mfile , 'tree' ) ) : copy_modules ( filespath = filespath , modules_path = mfile , verbose = verbose ) else : return else : modules_path = split_mods [ 0 ] tree_mod = os . path . join ( modules_path , 'tree' ) if not os . path . isdir ( tree_mod ) : os . makedirs ( tree_mod ) if verbose : print ( 'Copying modules from etc/ into {0}' . format ( tree_mod ) ) module_files = glob . glob ( os . path . join ( filespath , '*.module' ) ) for mfile in module_files : base = os . path . splitext ( os . path . basename ( mfile ) ) [ 0 ] tree_out = os . path . join ( tree_mod , base ) shutil . copy2 ( mfile , tree_out ) version = os . path . join ( filespath , '.version' ) if os . path . isfile ( version ) : shutil . copy2 ( version , tree_mod )
Copy over the tree module files into your path