Пример #1
0
        private static List <PythonPackage> ParseLegacyPipList(string PipLegacyList)
        {
            List <PythonPackage> PythonPackages = new List <PythonPackage>();
            IEnumerable <string> packageStrings = PipLegacyList.SplitLines();

            foreach (string packageString in packageStrings)
            {
                string pattern = @"(\S+)\s*\((\S+)\)";
                Match  match   = Regex.Match(packageString, pattern);
                if (match.Success)
                {
                    string        packageName   = match.Groups[1].Value;
                    string        versionString = match.Groups[2].Value;
                    PythonVersion version       = new PythonVersion(0, 0, 0);
                    pattern = @"(\d+)\.(\d+)\.(\d+)";
                    match   = Regex.Match(versionString, pattern);
                    if (match.Success)
                    {
                        version = new PythonVersion(Int32.Parse(match.Groups[1].Value), Int32.Parse(match.Groups[2].Value), Int32.Parse(match.Groups[3].Value));
                    }
                    else
                    {
                        pattern = @"(\d+)\.(\d+)";
                        match   = Regex.Match(versionString, pattern);
                        if (match.Success)
                        {
                            version = new PythonVersion(Int32.Parse(match.Groups[1].Value), Int32.Parse(match.Groups[2].Value), 0);
                        }
                        else
                        {
                            pattern = @"(\d+)";
                            match   = Regex.Match(versionString, pattern);
                            if (match.Success)
                            {
                                version = new PythonVersion(Int32.Parse(match.Groups[1].Value), 0, 0);
                            }
                        }
                    }
                    PythonPackage package = new PythonPackage();
                    package.Name    = packageName;
                    package.Version = version;
                    PythonPackages.Add(package);
                }
            }
            return(PythonPackages);
        }
Пример #2
0
 public PythonWheel(dynamic PyWheel)
 {
     Package = new PythonPackage(PyWheel.Package);
     Path    = PyWheel.Path;
     UninstallAllOtherCopies = PyWheel.UninstallAllOtherCopies;
 }
Пример #3
0
        private static List <PythonPackage> ParseJsonPipList(string PipJsonList)
        {
            List <PythonPackage> PythonPackages = new List <PythonPackage>();
            JSONNode             json           = JSON.Parse(PipJsonList);

            if (json == null)
            {
                throw new ArgumentException("Pip list JSON failed to parse.");
            }
            if (!json.IsArray)
            {
                throw new ArgumentException(string.Format("Pip list root JSON type is not list type"));
            }
            JSONArray array = json.AsArray;

            foreach (JSONNode node in array)
            {
                if (!node.IsObject)
                {
                    InstallLogger.Log(string.Format("Found unexpected json node {0}", node.Value));
                    continue;
                }
                Dictionary <string, JSONNode> jsonObject = node.Linq.ToDictionary(x => x.Key, x => x.Value);
                if (!jsonObject.ContainsKey("name") ||
                    !jsonObject.ContainsKey("version"))
                {
                    InstallLogger.Log(string.Format("Found unexpected json node {0}", node.Value));
                    continue;
                }
                string        versionString = jsonObject["version"].Value;
                PythonVersion version       = new PythonVersion(0, 0, 0);
                string        pattern       = @"(\d+)\.(\d+)\.(\d+)";
                Match         match         = Regex.Match(versionString, pattern);
                if (match.Success)
                {
                    version = new PythonVersion(Int32.Parse(match.Groups[1].Value), Int32.Parse(match.Groups[2].Value), Int32.Parse(match.Groups[3].Value));
                }
                else
                {
                    pattern = @"(\d+)\.(\d+)";
                    match   = Regex.Match(versionString, pattern);
                    if (match.Success)
                    {
                        version = new PythonVersion(Int32.Parse(match.Groups[1].Value), Int32.Parse(match.Groups[2].Value), 0);
                    }
                    else
                    {
                        pattern = @"(\d+)";
                        match   = Regex.Match(versionString, pattern);
                        if (match.Success)
                        {
                            version = new PythonVersion(Int32.Parse(match.Groups[1].Value), 0, 0);
                        }
                    }
                }
                PythonPackage package = new PythonPackage();
                package.Name    = jsonObject["name"].Value;
                package.Version = version;
                PythonPackages.Add(package);
            }

            return(PythonPackages);
        }
Пример #4
0
 public PythonWheel()
 {
     Package = new PythonPackage();
     Path    = string.Empty;
     UninstallAllOtherCopies = false;
 }