Exemple #1
0
def getAllExistingFiles(files, basepath=None, forceForwardSlashes=False):
    """For each file in files, if it exists, adds its absolute path to the rtn list. If file is a dir, calls this function recursively on all child files in the dir.
    If basepath is set, and if the file being processed is relative to basedir, adds that relative path to rtn list instead of the abs path.
    Is this is Windows, and forceForwardSlashes is True, make sure returned paths only have forward slashes."""
    if isinstance(files, basestring):
        files = [files]
    rtn = []
    for file in files:
        if os.path.exists(file): 
            if os.path.isfile(file):
                if basepath and hasAncestorDir(file, basepath):
                    rtn.append(getRelativePath(file, basepath))
                else:
                    rtn.append(os.path.abspath(str(file)))
            elif os.path.isdir(file):
                dircontent = [os.path.join(file, f) for f in os.listdir(file)]
                rtn.extend(getAllExistingFiles(dircontent, basepath))
                
    if forceForwardSlashes and sysutils.isWindows():
        newRtn = []
        for f in rtn:
            newRtn.append(f.replace("\\", "/"))
        rtn = newRtn
        
    return rtn
Exemple #2
0
def _getSystemDir(kind):
    if kind == AG_LOGS_DIR:
        return os.path.join(getSystemDir(AG_SYSTEM_DIR), "logs")
    elif kind == AG_DEMOS_DIR:
        return os.path.join(getSystemDir(AG_SYSTEM_DIR), "demos")
    else:
        path = ""
        if sysutils.isServer():
            path = os.getenv("ACTIVEGRID_SERVER_HOME")
            if (path is None) or (len(path) < 1):
                path = sysutils.mainModuleDir
        else:
            path = os.getenv("AG_DOCUMENTS_DIR")
            if (path is None) or (len(path) < 1):
                if sysutils.isWindows():
                    ifDefPy()
                    try:
                        from win32com.shell import shell, shellcon

                        path = shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, None, 0)
                    except:
                        pass
                    endIfDef()
                    if (path is None) or (len(path) < 1):
                        homedrive = asString(os.getenv("HOMEDRIVE"))
                        homepath = os.getenv("HOMEPATH")
                        ##                        if ((homedrive is not None) and (len(homedrive) > 0) and (homepath is not None) and (len(homepath) > 0)):
                        path = os.path.join(homedrive, homepath, "MYDOCU~1")
                else:
                    ifDefPy()
                    if sys.platform == "darwin":
                        try:
                            import macfs
                            import MACFS

                            fsspec_disk, fsspec_desktop = macfs.FindFolder(
                                MACFS.kOnSystemDisk, MACFS.kDocumentsFolderType, 0
                            )
                            path = macfs.FSSpec((fsspec_disk, fsspec_desktop, "")).as_pathname()
                        except:
                            pass
                    endIfDef()

                ifDefPy()
                if (path is None) or (len(path) < 1):
                    path = os.path.expanduser("~")
                endIfDef()
                if (path is None) or (len(path) < 1):
                    path = "/"
                path = os.path.join(path, "ActiveGrid")

        return path
Exemple #3
0
def parameterizePathWithAGSystemVar(inpath):
    """Returns parameterized path if path starts with a known AG directory. Otherwise returns path as it was passed in."""
    _initAGSystemVars()
    path = inpath
    if not sysutils.isWindows():
        # ensure we have forward slashes
        path = path.replace("\\", "/")
        
    path = os.path.abspath(path)

    for varname in AG_SYSTEM_VARS_LENGTH_ORDER:
        varval = EXPANDED_AG_SYSTEM_VARS[varname]
        if path.startswith(varval):
            return path.replace(varval, varname)
        
    return inpath