summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Copeland <ben.copeland@linaro.org>2018-12-13 12:12:51 +0000
committerLinaro Code Review <review@review.linaro.org>2018-12-13 12:12:51 +0000
commitab13703912aa4ed6254b23fb16cb585f1a1385eb (patch)
treefdcd03847c5d46852a66cf09af0ae41a90d7f6cc
parentca07a212ac1eb2bc463b6242d0ddc894cdf3a334 (diff)
parent706090e6ddd8c465b442b584c3222f9a1b069f32 (diff)
downloadpatchwork-tools-ab13703912aa4ed6254b23fb16cb585f1a1385eb.tar.gz
Merge "Teamcredit: Update patches with missing credit"
-rwxr-xr-xlinaro_metrics/teamcredit.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/linaro_metrics/teamcredit.py b/linaro_metrics/teamcredit.py
new file mode 100755
index 0000000..a8f5c8b
--- /dev/null
+++ b/linaro_metrics/teamcredit.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+import datetime
+from linaro_metrics.models import Team, TeamMembership, TeamCredit
+from patchwork.models import Patch
+from bin import django_setup
+import logging
+import os
+import sys
+
+sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
+django_setup() # must be called to get sys.path and django settings in place
+
+dateb = datetime.datetime.now() - datetime.timedelta(days=180)
+
+log = logging.getLogger('teamcredit')
+
+"""
+This is a thrown together script to fix the teamcredit statistics. It should
+not often be needed, but at times a ldap team can change and the team lead
+forgets to inform patches of this change. Hence the teamcredit will go out of
+sync.
+
+The script runs in a default of 180 days.
+
+"""
+
+team = 'team-ldcg'
+t = Team.objects.get(name=team)
+tm = TeamMembership.objects.filter(team=t)
+
+for p in tm:
+ logging.info("#### %s %s", p.user, p.id)
+ # get all patches to that user
+ patchu = Patch.objects.filter(submitter__user=p.user)
+ for pa in patchu:
+ if dateb < pa.date:
+ tcs = TeamCredit.objects.filter(patch=pa)
+ if not tcs:
+ logging.info("No Patch: %s, %s", pa, tcs)
+ new_values = {
+ 'patch': pa, 'team': t, 'last_state_change': pa.date
+ }
+ tcs = TeamCredit(**new_values)
+ tcs.save()
+ else:
+ tcsno = TeamCredit.objects.filter(patch=pa,
+ team__name='no-team'
+ )
+ if tcsno:
+ logging.info("No Credit: %s, %s", tcsno, pa.date)
+ TeamCredit.objects.filter(patch=pa).update(team=t)