FileExists() public méthode

public FileExists ( string filePath ) : bool
filePath string
Résultat bool
Exemple #1
0
        private void CreateCacheDirectory()
        {
            var p = FileSystem.CombinePath(FileSystem.getSystemTempDir(), "pysonar2");

            cacheDir = FileSystem.CombinePath(p, "ast_cache");
            string f = cacheDir;

            msg("AST cache is at: " + cacheDir);

            if (!FileSystem.FileExists(f))
            {
                try
                {
                    FileSystem.CreateDirectory(f);
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(
                              "Failed to create tmp directory: " + cacheDir + ".", ex);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Find the path that contains modname. Used to find the starting point of locating a qname.
        /// </summary>
        /// <param name="headName">first module name segment</param>
        public string locateModule(string headName)
        {
            List <string> loadPath = getLoadPath();

            foreach (string p in loadPath)
            {
                string startDir = FileSystem.CombinePath(p, headName);
                string initFile = FileSystem.CombinePath(startDir, "__init__.py");

                if (FileSystem.FileExists(initFile))
                {
                    return(p);
                }

                string startFile = FileSystem.CombinePath(startDir, suffix);
                if (FileSystem.FileExists(startFile))
                {
                    return(p);
                }
            }
            return(null);
        }
Exemple #3
0
        public DataType LoadFile(string path)
        {
            path = FileSystem.GetFullPath(path);

            if (!FileSystem.FileExists(path))
            {
                return(null);
            }

            ModuleType module = GetCachedModule(path);

            if (module != null)
            {
                return(module);
            }

            // detect circular import
            if (inImportStack(path))
            {
                return(null);
            }

            // set new CWD and save the old one on stack
            string oldcwd = cwd;

            setCWD(FileSystem.GetDirectoryName(path));

            pushImportStack(path);
            DataType type = parseAndResolve(path);

            popImportStack(path);

            // restore old CWD
            setCWD(oldcwd);
            return(type);
        }
Exemple #4
0
        public DataType LoadModule(List <Name> name, State state)
        {
            if (name.Count == 0)
            {
                return(null);
            }

            string   qname = MakeQname(name);
            DataType mt    = getBuiltinModule(qname);

            if (mt != null)
            {
                state.Insert(
                    this,
                    name[0].Name,
                    new Url(Builtins.LIBRARY_URL + mt.Table.Path + ".html"),
                    mt, BindingKind.SCOPE);
                return(mt);
            }

            // If there are more than one segment
            // load the packages first
            DataType prev      = null;
            string   startPath = locateModule(name[0].Name);

            if (startPath == null)
            {
                return(null);
            }

            string path = startPath;

            for (int i = 0; i < name.Count; i++)
            {
                path = FileSystem.CombinePath(path, name[i].Name);
                string initFile = FileSystem.CombinePath(path, "__init__.py");
                if (FileSystem.FileExists(initFile))
                {
                    DataType mod = LoadFile(initFile);
                    if (mod == null)
                    {
                        return(null);
                    }

                    if (prev != null)
                    {
                        prev.Table.Insert(this, name[i].Name, name[i], mod, BindingKind.VARIABLE);
                    }
                    else
                    {
                        state.Insert(this, name[i].Name, name[i], mod, BindingKind.VARIABLE);
                    }

                    prev = mod;
                }
                else if (i == name.Count - 1)
                {
                    string startFile = path + suffix;
                    if (FileSystem.FileExists(startFile))
                    {
                        DataType mod = LoadFile(startFile);
                        if (mod == null)
                        {
                            return(null);
                        }
                        if (prev != null)
                        {
                            prev.Table.Insert(this, name[i].Name, name[i], mod, BindingKind.VARIABLE);
                        }
                        else
                        {
                            state.Insert(this, name[i].Name, name[i], mod, BindingKind.VARIABLE);
                        }
                        prev = mod;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            return(prev);
        }