def test_daterange(self): high = datetime.date(2022, 1, 2) low = datetime.date(2022, 1, 1) self.assertListEqual( list(daterange(high, low)), [datetime.date(2022, 1, 1), datetime.date(2022, 1, 2)]) self.assertListEqual( list(daterange(high, low, desc=True)), [datetime.date(2022, 1, 2), datetime.date(2022, 1, 1)])
def test_daterange(self): high = datetime.date(2022, 1, 2) low = datetime.date(2022, 1, 1) self.assertListEqual( list(daterange(high, low)), [datetime.date(2022, 1, 1), datetime.date(2022, 1, 2)]) self.assertListEqual( list(daterange(high, low, desc=True)), [datetime.date(2022, 1, 2), datetime.date(2022, 1, 1)])
def test_daterange_step(self): high = datetime.date(2022, 1, 10) low = datetime.date(2022, 1, 1) self.assertListEqual( list(daterange(high, low, step=5)), [datetime.date(2022, 1, 1), datetime.date(2022, 1, 6), datetime.date(2022, 1, 10)])
def test_daterange_step(self): high = datetime.date(2022, 1, 10) low = datetime.date(2022, 1, 1) self.assertListEqual(list(daterange(high, low, step=5)), [ datetime.date(2022, 1, 1), datetime.date(2022, 1, 6), datetime.date(2022, 1, 10) ])
def list_bugs(self, *args, **kwargs): """ Fetch all bugs by creation or modification date starting `from_date` until we are not able to find more of them or `to_date` is hit. Bugs are pulled in date ranges defined by `step` not to hit bugzilla timeouts. Number of empty queries required before we stop querying is controlled by `stop_after_empty_steps`. If `updated_first` is True, recently modified bugs are queried first. `custom_fields` dictionary can be used to create more specific bugzilla queries. """ from_date = kwargs.get('from_date', datetime.date.today()) to_date = kwargs.get('to_date', datetime.date(2000, 1, 1)) step = kwargs.get('step', 7) stop_after_empty_steps = kwargs.get('stop_after_empty_steps', 10) updated_first = kwargs.get('updated_first', False) custom_fields = kwargs.get('custom_fields', dict()) if not updated_first: custom_fields.update(dict(chfield="[Bug creation]")) empty = 0 over_days = list(daterange(from_date, to_date, step, desc=True)) prev = over_days[0] for current in over_days[1:]: limit = 100 offset = 0 fetched_per_date_range = 0 while True: try: result = self._query_bugs( prev, current, limit, offset, custom_fields) except Exception as e: # pylint: disable=broad-except self.log_error("Exception after multiple attempts: {0}." " Ignoring".format(e)) continue count = len(result) fetched_per_date_range += count self.log_debug("Got {0} bugs".format(count)) for bug in result: yield bug.bug_id if not count: self.log_debug("No more bugs in this date range") break offset += limit if not fetched_per_date_range: empty += 1 if empty >= stop_after_empty_steps: break else: empty = 0 prev = current - datetime.timedelta(1)
def list_bugs(self, *args, **kwargs): """ Fetch all bugs by creation or modification date starting `from_date` until we are not able to find more of them or `to_date` is hit. Bugs are pulled in date ranges defined by `step` not to hit bugzilla timeouts. Number of empty queries required before we stop querying is controlled by `stop_after_empty_steps`. If `updated_first` is True, recently modified bugs are queried first. `custom_fields` dictionary can be used to create more specific bugzilla queries. """ from_date = kwargs.get('from_date', datetime.date.today()) to_date = kwargs.get('to_date', datetime.date(2000, 1, 1)) step = kwargs.get('step', 7) stop_after_empty_steps = kwargs.get('stop_after_empty_steps', 10) updated_first = kwargs.get('updated_first', False) custom_fields = kwargs.get('custom_fields', dict()) if not updated_first: custom_fields.update(dict(chfield="[Bug creation]")) empty = 0 over_days = list(daterange(from_date, to_date, step, desc=True)) prev = over_days[0] for current in over_days[1:]: limit = 100 offset = 0 fetched_per_date_range = 0 while True: try: result = self._query_bugs( prev, current, limit, offset, custom_fields) except Exception as e: # pylint: disable=broad-except self.log_error("Exception after multiple attempts: {0}." " Ignoring".format(e)) continue count = len(result) fetched_per_date_range += count self.log_debug("Got {0} bugs".format(count)) for bug in result: yield bug.bug_id if not count: self.log_debug("No more bugs in this date range") break offset += limit if not fetched_per_date_range: empty += 1 if empty >= stop_after_empty_steps: break else: empty = 0 prev = current - datetime.timedelta(1)