~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/scripts/bzremotecomponentfinder.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-07-02 13:36:39 UTC
  • mfrom: (13341.2.5 lp-796645-cron-dies-on-404)
  • Revision ID: launchpad@pqm.canonical.com-20110702133639-0newiq2jfh5xf5oy
[r=sinzui][bug=796645] Log warning when bug trackers are not
        available.

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
        u"mozilla.org",
103
103
        ]
104
104
 
105
 
    def __init__(self, logger=None, static_bugzilla_text=None):
 
105
    def __init__(self, logger=None, static_bugzilla_scraper=None):
106
106
        """Instantiates object, without performing any parsing.
107
107
 
108
108
        :param logger: A logger object
109
 
        :param static_bugzilla_text: Instead of retrieving the remote
110
 
         web page for a bug tracker, act as if this static text was
111
 
         returned.  This is intended for testing purposes to avoid
112
 
         needing to make remote web connections.
 
109
        :param static_bugzilla_scraper: Substitute this custom bugzilla
 
110
         scraper object instead of constructing a new
 
111
         BugzillaRemoteComponentScraper for each bugtracker's URL.  This
 
112
         is intended for testing purposes to avoid needing to make remote
 
113
         web connections.
113
114
        """
114
115
        self.logger = logger
115
116
        if logger is None:
116
117
            self.logger = default_log
117
 
        self.static_bugzilla_text = static_bugzilla_text
 
118
        self.static_bugzilla_scraper = static_bugzilla_scraper
118
119
 
119
120
    def getRemoteProductsAndComponents(self, bugtracker_name=None):
120
121
        lp_bugtrackers = getUtility(IBugTrackerSet)
134
135
 
135
136
            self.logger.info("%s: %s" % (
136
137
                lp_bugtracker.name, lp_bugtracker.baseurl))
137
 
            bz_bugtracker = BugzillaRemoteComponentScraper(
138
 
                base_url=lp_bugtracker.baseurl)
139
 
 
140
 
            if self.static_bugzilla_text is not None:
141
 
                self.logger.debug("Using static bugzilla text")
142
 
                page_text = self.static_bugzilla_text
143
 
 
 
138
 
 
139
            if self.static_bugzilla_scraper is not None:
 
140
                bz_bugtracker = self.static_bugzilla_scraper
144
141
            else:
145
 
                try:
146
 
                    self.logger.debug("...Fetching page")
147
 
                    page_text = bz_bugtracker.getPage()
148
 
                except HTTPError, error:
149
 
                    self.logger.error("Error fetching %s: %s" % (
150
 
                        lp_bugtracker.baseurl, error))
151
 
                    continue
 
142
                bz_bugtracker = BugzillaRemoteComponentScraper(
 
143
                    base_url=lp_bugtracker.baseurl)
 
144
 
 
145
            try:
 
146
                self.logger.debug("...Fetching page")
 
147
                page_text = bz_bugtracker.getPage()
 
148
            except HTTPError, error:
 
149
                self.logger.warning("Could not fetch %s: %s" % (
 
150
                    lp_bugtracker.baseurl, error))
 
151
                continue
 
152
            except:
 
153
                self.logger.warning("Failed to access %s" % (
 
154
                    lp_bugtracker.baseurl))
 
155
                continue
152
156
 
153
157
            self.logger.debug("...Parsing html")
154
158
            bz_bugtracker.parsePage(page_text)