Example #1
0
        public override IEnumerable <OSSIndexQueryObject> GetPackages(params string[] o)
        {
            List <OSSIndexQueryObject> packages = new List <OSSIndexQueryObject> ();

            if (this.UseDockerContainer)
            {
                Docker.ProcessStatus process_status;
                string process_output, process_error;
                if (Docker.ExecuteInContainer(this.DockerContainerId, @"yum list installed", out process_status, out process_output, out process_error))
                {
                    string[] p = process_output.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                    for (int i = 0; i < p.Count(); i++)
                    {
                        string[] k = p [i].Split("|".ToCharArray());
                        packages.Add(new OSSIndexQueryObject("dpkg", k [0], k [1]));
                    }
                }
                else
                {
                    throw new Exception(string.Format("Error running {0} command on docker container {1}: {2}", @"dpkg-query -W -f ${Package}'${Version}\n",
                                                      this.DockerContainerId, process_error));
                }
                return(packages);
            }
            else
            {
                string command   = @"yum";
                string arguments = @"list installed";
                Regex  process_output_pattern = new Regex(@"^(\S+)\s(\S+)$", RegexOptions.Compiled);
                HostEnvironment.ProcessStatus process_status;
                string process_output, process_error;
                if (HostEnvironment.Execute(command, arguments, out process_status, out process_output, out process_error))
                {
                    string[] p = process_output.Split("\n".ToCharArray());
                    for (int i = 0; i < p.Count(); i++)
                    {
                        Match m = process_output_pattern.Match(p [i].TrimStart());
                        if (!m.Success)
                        {
                            throw new Exception("Could not parse dpkg command output row: " + i.ToString()
                                                + "\n" + p [i]);
                        }
                        else
                        {
                            packages.Add(new OSSIndexQueryObject("dpkg", m.Groups [1].Value, m.Groups [2].Value, ""));
                        }
                    }
                }
                else
                {
                    throw new Exception(string.Format("Error running {0} {1} command in host environment: {2}.", command,
                                                      arguments, process_error));
                }
                return(packages);
            }
        }
Example #2
0
        public override IEnumerable <OSSIndexQueryObject> GetPackages(params string[] o)
        {
            List <OSSIndexQueryObject> packages = new List <OSSIndexQueryObject> ();

            if (this.UseDockerContainer)
            {
                Docker.ProcessStatus process_status;
                string process_output, process_error;
                if (Docker.ExecuteInContainer(this.DockerContainerId, @"rpm -qa --qf ""%{NAME} %{VERSION}\n""", out process_status, out process_output, out process_error))
                {
                    string[] p = process_output.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    Regex    process_output_pattern = new Regex(@"^(\S+)\s(\S+)", RegexOptions.Compiled);
                    Match    m;
                    for (int i = 0; i < p.Count(); i++)
                    {
                        m = process_output_pattern.Match(p[i]);
                        if (!m.Success)
                        {
                            throw new Exception("Could not parse rpm command output row: " + i.ToString() + "\n" + p [i]);
                        }
                        else
                        {
                            packages.Add(new OSSIndexQueryObject("rpm", m.Groups [1].Value, m.Groups [2].Value));
                        }
                    }
                }
                else
                {
                    throw new Exception(string.Format("Error running {0} command on docker container {1}: {2}", @"rpm -qa --qf ""%{NAME} %{VERSION}\n""",
                                                      this.DockerContainerId, process_error));
                }
                return(packages);
            }
            else
            {
                string command   = @"rpm";
                string arguments = @"-qa --qf ""%{NAME} %{VERSION}\n""";
                Regex  process_output_pattern = new Regex(@"^(\S+)\s(\S+)", RegexOptions.Compiled);
                HostEnvironment.ProcessStatus process_status;
                string process_output, process_error;
                if (HostEnvironment.Execute(command, arguments, out process_status, out process_output, out process_error))
                {
                    string[] p = process_output.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    Match    m;
                    for (int i = 0; i < p.Count(); i++)
                    {
                        m = process_output_pattern.Match(p[i]);
                        if (!m.Success)
                        {
                            throw new Exception("Could not parse rpm command output row: " + i.ToString() + "\n" + p [i]);
                        }
                        else
                        {
                            packages.Add(new OSSIndexQueryObject("rpm", m.Groups [1].Value, m.Groups [2].Value));
                        }
                    }
                }
                else
                {
                    throw new Exception(string.Format("Error running {0} {1} command in host environment: {2}.", command,
                                                      arguments, process_error));
                }
                return(packages);
            }
        }