File: bts.rb

package info (click to toggle)
apt-listbugs 0.1.47
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,048 kB
  • sloc: ruby: 2,339; sh: 166; makefile: 64
file content (113 lines) | stat: -rw-r--r-- 3,830 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#
# bts.rb - ruby interface for debian bts
# Copyright (C) 2002       Masato Taruishi <taru@debian.org>
# Copyright (C) 2006-2007  Junichi Uekawa <dancer@debian.org>
# Copyright (C) 2013-2023  Francesco Poli <invernomuto@paranoici.org>
# Copyright (C) 2015       Michael Gold <michael@bitplane.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License with
# the Debian GNU/Linux distribution in file /usr/share/common-licenses/GPL-2;
# if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Currently, this interface has only acquires to create bugs.

require 'aptlistbugs/debian/bug'
require 'uri.rb'
require 'find'
require 'zlib'
require 'thread'

module Debian
  module BTS
    class Parser

      def initialize(url, debugfile)
        @soapurl = url
        @debugfile = debugfile
      end

      # use SOAP interface to obtain the index.
      class SoapIndex < Parser
        def initialize(url, debugfile)
          @soapurl = url
          @debugfile = debugfile
          @indexes = {}
          @buf = nil
        end

        def parse_bug(bugnum)
          require 'aptlistbugs/debian/btssoap'
          soap = Debian::BTSSOAP::Soap.new(@soapurl, @debugfile)
          sa = Debian::BTSSOAP::StringArray.new

          # query the BTS about the given bug number
          sa << bugnum
          bugs = soap.get_status(sa)
          parse_bug = nil
          parse_bug = bugs.fetch(0) if bugs.length > 0
          parse_bug
        end

        def parse(ma_copies, querystep, parsestep, severities = ["critical", "grave"])
          require 'aptlistbugs/debian/btssoap'
          soap = Debian::BTSSOAP::Soap.new(@soapurl, @debugfile)
          sa = Debian::BTSSOAP::StringArray.new
          bugs = Debian::Bugs.new
          reqbugs = []

          # obtain a list of package names
          names = ma_copies.keys

          # query the BTS: ask for a list of bug numbers of given severities
          # affecting the given package names, in batches of querystep
          # packages
          names.each { |nm|
            sa << nm
            if sa.length >= querystep
              soap.get_bugs('severity', severities,
                             'package', sa).each { |b| reqbugs << b }
              sa = Debian::BTSSOAP::StringArray.new
            end
          }
          if sa.length != 0
            soap.get_bugs('severity', severities,
                           'package', sa).each { |b| reqbugs << b }
            sa = Debian::BTSSOAP::StringArray.new
          end

          # the total number of bugs
          max = reqbugs.length
          # progressed amount
          offset_i = 0

          # process each bug number and get contents, in batches of
          # parsestep bugs
          reqbugs.each { |bug|
            sa << bug
            if sa.length >= parsestep
              soap.get_status(sa, ma_copies).each { |b| bugs << b }
              offset_i += sa.length
              sa = Debian::BTSSOAP::StringArray.new
              pct = "#{((offset_i).to_f*100/max.to_f).to_i}%"
              pct = "#{pct}   ##{bug}" if parsestep == 1
              yield pct
            end
          }
          soap.get_status(sa, ma_copies).each { |b| bugs << b }
          bugs
        end
      end
    end
  end
end