CombinePath() public method

public CombinePath ( string dir, string file ) : string
dir string
file string
return string
Esempio n. 1
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);
        }
Esempio n. 2
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);
                }
            }
        }
Esempio n. 3
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);
        }