Mercurial > p > roundup > code
view scripts/weekly-report @ 7968:d7e79f8eb943
issue2551350 - Python changes for 3.12 with roundup 2.3.0 mailer.py
Fix due to change in smtplib.SMTP.starttls() signature.
As of 3.3 it can use an optional ssl context argument for
certificates/keys. In 3.12 it dropped legacy support for specifing
cert/key files as arguments and requires a context.
I modified Andrew's original patch to initialize SSLContext with
ssl.PROTOCOL_TLS_CLIENT.
If there is a cert file specified, enable
check_hostname - verify that the cert supplied by the server matches
the hostname we supplied.
If there is no cert file call
load_default_certs()
Also opened issue2551351 to look into more SMTP ssmtp tightening. We
also should have an option in Roundup to use TLS/SSL (smtps) without
using starttls.
Note that this code is untested by the test suite due to the need to
setup an SMTP server with STARTTLS support. issue2551351 has some
notes on this.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 15 May 2024 00:08:05 -0400 |
| parents | 20ab9a4b76e9 |
| children | 9c3ec0a5c7fc |
line wrap: on
line source
#! /usr/bin/env python # This script generates a simple report outlining the activity in one # tracker for the most recent week. # A second argument is the negative interval to change period # of time. # This script is free software, you may redistribute it # and/or modify under the same terms as Python. #Example output #CREATED: #2702: new item # #RESOLVED: #1995: Where is my Power plugs #2501: Can you help me with Sanity #459: I need Sanity # #TOP TEN MOST DISCUSSED: #2 - 491: Can you help me with Sanity #1 - 1995: Where is my Power plugs from __future__ import print_function import sys from roundup import date, instance # position for arguments tracker_home_pos = 1 optional_interval_pos = 2 # gather args arg_len = len(sys.argv) # map pos to length by adding 1. if arg_len not in [tracker_home_pos + 1, optional_interval_pos + 1]: print('Usage: %s tracker-home [interval -1w]' % sys.argv[0]) if (arg_len < tracker_home_pos + 1 ): print(' You need to specify a tracker home directory') sys.exit(1) instance_home = sys.argv[tracker_home_pos] lookback_interval = sys.argv[optional_interval_pos] if \ len(sys.argv) == optional_interval_pos + 1 else '-1w' # open the instance instance = instance.open(instance_home) db = instance.open('admin') old = date.Date(lookback_interval) created = [] # [issue_id_created_issue] summary = {} # {status_id: [issue_ids in that status]} messages = [] # [(number_of_messages, issue_id)] # loop through all the recently-active issues for issue_id in db.issue.filter(None, {'activity': '-1w;'}): message_count = 0 for _x,ts,_userid,action,data in db.issue.history(issue_id): if ts < old: # history occurred before our current window continue if action == 'create': created.append(issue_id) elif action == 'set' and 'messages' in data: message_count += 1 summary.setdefault(db.issue.get(issue_id, 'status'), []).append(issue_id) messages.append((message_count, issue_id)) #print('STATUS SUMMARY:') #for k,v in summary.items(): # print(k, len(v)) print('\nCREATED:') if created: print('\n'.join(['%s: %s'%(itemid, db.issue.get(itemid, 'title')) for itemid in created])) else: print("No issue created in interval %s" % lookback_interval) print('\nRESOLVED:') resolved_id = db.status.lookup('resolved') if summary: # deduplicate - duplicates happen when issue with resolved status # has multiple history items (e.g. message or other # change after resolution) resolved_ids = sorted(set(summary.get(resolved_id, [])), key=int) print('\n'.join(['%s: %s' % (itemid, db.issue.get(itemid, 'title')) for itemid in resolved_ids ])) else: print("No issue resolved in interval %s" % lookback_interval) print('\nTOP TEN MOST DISCUSSED:') # filter out issues with no messages messages = [ message for message in messages if message[0] > 0 ] if messages: messages.sort() messages.reverse() nmax = messages[0][0] or 1 fmt = '%%%dd - %%s: %%s'%(len(str(nmax))) print('\n'.join([fmt%(num, itemid, db.issue.get(itemid, 'title')) for num, itemid in messages[:10]])) else: print("No issues discussed in interval %s" % lookback_interval) # vim: set filetype=python ts=4 sw=4 et si
