summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilosz Wasilewski <milosz.wasilewski@linaro.org>2013-09-23 10:04:55 +0000
committerLinaro Code Review <review@review.linaro.org>2013-09-23 10:04:55 +0000
commit802d6969c62f22ee3b65bba0637bd5fb289c310a (patch)
tree35944735ddc84a318a041795d63b0bdb1b79fcad
parent10b4f739860fbdd697447722330eedb398687a1b (diff)
parentfb228082709de72ceb114a064d80befbe14a7725 (diff)
downloadroadmap-802d6969c62f22ee3b65bba0637bd5fb289c310a.tar.gz
Merge "More PEP8 and license."
-rw-r--r--roadmap/forms.py18
-rw-r--r--roadmap/helpers.py212
2 files changed, 141 insertions, 89 deletions
diff --git a/roadmap/forms.py b/roadmap/forms.py
index af3d7d3..e6df884 100644
--- a/roadmap/forms.py
+++ b/roadmap/forms.py
@@ -1,4 +1,22 @@
+# Copyright (C) 2013 Linaro
+#
+# This file is part of roadmap.
+#
+# roadmap is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# roadmap 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with roadmap. If not, see <http://www.gnu.org/licenses/>.
+
from django import forms
+
class RoadmapForm(forms.Form):
name = forms.RegexField(max_length=7, regex="^[1-9][0-9]{3}-[0-9]{2}$")
diff --git a/roadmap/helpers.py b/roadmap/helpers.py
index af5f728..deea928 100644
--- a/roadmap/helpers.py
+++ b/roadmap/helpers.py
@@ -1,39 +1,60 @@
+# Copyright (C) 2013 Linaro
+#
+# This file is part of roadmap.
+#
+# roadmap is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# roadmap 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with roadmap. If not, see <http://www.gnu.org/licenses/>.
+
from django.conf import settings
from django.db.models import ManyToManyField, Count
-from django.utils import timezone
+from django.utils import timezone
from datetime import datetime
from operator import attrgetter
from roadmap.models import (
Burndown,
- BurndownSnapshot,
BurndownBar,
+ BurndownSnapshot,
Card,
- CardType,
+ CardType,
Component,
- Status,
- FixVersion,
- Resolution,
+ FixVersion,
Label,
Project,
- SecurityLevel
+ Resolution,
+ SecurityLevel,
+ Status,
)
-JIRA_SERVER='jira_server'
-JIRA_USER='jira_user'
-JIRA_VERIFY='jira_verify'
-JIRA_DEPENDSON='dependson'
-JIRA_IMPLEMENTS='implements'
-JIRA_KEY='key'
-VERBOSE='verbose'
-SINGLE_UPDATE='single_update'
+JIRA_SERVER = 'jira_server'
+JIRA_USER = 'jira_user'
+JIRA_VERIFY = 'jira_verify'
+JIRA_DEPENDSON = 'dependson'
+JIRA_IMPLEMENTS = 'implements'
+JIRA_KEY = 'key'
+VERBOSE = 'verbose'
+SINGLE_UPDATE = 'single_update'
+
class Issue(object):
+
def __init__(self, d):
for a, b in d.iteritems():
if isinstance(b, (list, tuple)):
- setattr(self, a, [Issue(x) if isinstance(x, dict) else x for x in b])
+ setattr(self, a,
+ [Issue(x) if isinstance(x, dict) else x for x in b])
else:
- setattr(self, a, Issue(b) if isinstance(b, dict) else b)
+ setattr(self, a, Issue(b) if isinstance(b, dict) else b)
+
def create_or_update(issue, options, jira=None):
if isinstance(issue, dict):
@@ -41,20 +62,24 @@ def create_or_update(issue, options, jira=None):
project = None
if hasattr(issue.fields, 'project') and issue.fields.project:
- project, created = Project.objects.get_or_create(
- name=issue.fields.project.name, key=issue.fields.project.key)
+ project, created = Project.objects.get_or_create(
+ name=issue.fields.project.name, key=issue.fields.project.key)
+
card_type = None
if hasattr(issue.fields, 'issuetype') and issue.fields.issuetype:
- card_type, created = CardType.objects.get_or_create(
- name=issue.fields.issuetype.name)
+ card_type, created = CardType.objects.get_or_create(
+ name=issue.fields.issuetype.name)
+
resolution = None
if hasattr(issue.fields, 'resolution') and issue.fields.resolution:
- resolution, created = Resolution.objects.get_or_create(
- name=issue.fields.resolution.name, project=project)
+ resolution, created = Resolution.objects.get_or_create(
+ name=issue.fields.resolution.name, project=project)
+
security = None
if hasattr(issue.fields, 'security') and issue.fields.security:
- security, created = SecurityLevel.objects.get_or_create(
- name=issue.fields.security.name)
+ security, created = SecurityLevel.objects.get_or_create(
+ name=issue.fields.security.name)
+
components = []
if hasattr(issue.fields, 'components') and issue.fields.components:
for comp in issue.fields.components:
@@ -67,64 +92,63 @@ def create_or_update(issue, options, jira=None):
if options[VERBOSE]:
print "****** NO COMPONENT *******"
print issue.key
+
fixVersion = None
fixVersions = []
if hasattr(issue.fields, 'fixVersions') and issue.fields.fixVersions:
# find the fixVersion in db or create one
for fixv in issue.fields.fixVersions:
fix_date = timezone.make_aware(
- datetime(2015, 1, 1),
+ datetime(2015, 1, 1),
timezone.get_default_timezone())
if hasattr(fixv, "releaseDate"):
fix_date = timezone.make_aware(
datetime.strptime(fixv.releaseDate, "%Y-%m-%d"),
timezone.get_default_timezone())
fv, created = FixVersion.objects.get_or_create(
- name=fixv.name,
+ name=fixv.name,
fix_date=fix_date,
project=project
)
fixVersions.append(fv)
fixVersion = min(fixVersions, key=attrgetter('fix_date'))
if options[VERBOSE]:
- print "fixVersion: %s" % (fixVersion)
+ print "fixVersion: %s" % (fixVersion)
status = None
if hasattr(issue.fields, 'status') and issue.fields.status:
# find status in database or create one
status, created = Status.objects.get_or_create(
name=issue.fields.status.name, project=project)
if options[VERBOSE]:
- print "status: %s" % (status)
+ print "status: %s" % (status)
+
key = issue.key
- url = options[JIRA_SERVER] + "/browse/" + issue.key
+ url = options[JIRA_SERVER] + "/browse/" + issue.key
summary = issue.fields.summary
cardStart = None
end = None
+
if fixVersion:
if fixVersion.name == "ONGOING":
- if hasattr(issue.fields, 'customfield_10300') and issue.fields.customfield_10300:
+ if (hasattr(issue.fields, 'customfield_10300')
+ and issue.fields.customfield_10300):
cardStart = issue.fields.customfield_10300
if hasattr(issue, "changelog"):
for history in issue.changelog.histories:
for item in history.items:
- # start date is taken from the field now
- #if item.field == 'status' and item.toString == "Planning":
- # cardStart = datetime.strptime(
- # history.created,
- # "%Y-%m-%dT%H:%M:%S.000+0000").isoformat()
- # if end:
- # break
- if item.field == 'status' and item.toString == "Closed":
+ if (item.field == "status"
+ and item.toString == "Closed"):
end = datetime.strptime(
- history.created,
+ history.created,
"%Y-%m-%dT%H:%M:%S.000+0000").isoformat()
if cardStart:
break
- else: # fixVersion is not ONGOING
+ else:
+ # fixVersion is not ONGOING
cardStart = fixVersion.fix_date
if options[VERBOSE]:
- print "start: %s, end: %s" % (cardStart, end)
+ print "start: {0}, end: {1}".format(cardStart, end)
implementedby_list = []
depends_list = []
if hasattr(issue.fields, 'issuelinks'):
@@ -133,54 +157,51 @@ def create_or_update(issue, options, jira=None):
if hasattr(link, "inwardIssue"):
if jira:
implementedby_list.append(
- create_or_update(
- jira.issue(
- link.inwardIssue.key,
- expand="changelog"),
- options,
- jira).pk)
+ create_or_update(
+ jira.issue(link.inwardIssue.key,
+ expand="changelog"),
+ options, jira).pk)
elif not options[SINGLE_UPDATE]:
implementedby_list.append(
- create_or_update(
- link.inwardIssue,
- options,
- jira).pk)
- else: # don't do full update on related cards
+ create_or_update(
+ link.inwardIssue, options, jira).pk)
+ else:
+ # don't do full update on related cards
try:
- implementedby_list.append(
- Card.objects.get(key=link.inwardIssue.key))
+ implementedby_list.append(
+ Card.objects.get(key=link.inwardIssue.key))
except:
if options[VERBOSE]:
- print "Card not found" #should not happen
+ # should not happen
+ print "Card not found"
if link.type.name == "Depends" and options[JIRA_DEPENDSON]:
if hasattr(link, "inwardIssue"):
if jira:
depends_list.append(
- create_or_update(
- jira.issue(
- link.inwardIssue.key,
- expand="changelog"),
- options,
- jira).pk)
+ create_or_update(
+ jira.issue(
+ link.inwardIssue.key, expand="changelog"),
+ options, jira).pk)
elif not options[SINGLE_UPDATE]:
depends_list.append(
- create_or_update(
- link.inwardIssue,
- options,
- jira).pk)
- else: # don't do full update on related cards
+ create_or_update(
+ link.inwardIssue, options, jira).pk)
+ else:
+ # don't do full update on related cards
try:
- depends_list.append(
- Card.objects.get(key=link.inwardIssue.key))
+ depends_list.append(
+ Card.objects.get(key=link.inwardIssue.key))
except:
if options[VERBOSE]:
- print "Card not found" #should not happen
-
+ # should not happen
+ print "Card not found"
+
if options[VERBOSE]:
print "Dependencies"
print depends_list
print "Implements"
print implementedby_list
+
label_list = []
if hasattr(issue.fields, 'labels'):
for label in issue.fields.labels:
@@ -191,7 +212,7 @@ def create_or_update(issue, options, jira=None):
lbl = Label(name=label)
lbl.save()
label_list.append(lbl.pk)
-
+
defaults = {
'url': url,
'summary': summary,
@@ -204,39 +225,47 @@ def create_or_update(issue, options, jira=None):
'security': security,
'card_type': card_type
}
+
if options[VERBOSE]:
- print defaults
+ print defaults
+
card, created = Card.objects.get_or_create(key=key, defaults=defaults)
defaults.update({'components': components})
+
if options[JIRA_IMPLEMENTS]:
defaults.update({'implementedby': implementedby_list})
if options[JIRA_DEPENDSON]:
- defaults.update({'dependson':depends_list})
+ defaults.update({'dependson': depends_list})
defaults.update({'labels': label_list})
+
if not created:
- for attr, value in defaults.iteritems():
- attribute = getattr(card, attr)
- if isinstance(card._meta.get_field_by_name(attr)[0], ManyToManyField):
+ for attr, value in defaults.iteritems():
+ attribute = getattr(card, attr)
+ if isinstance(card._meta.get_field_by_name(attr)[0],
+ ManyToManyField):
if set([x.pk for x in attribute.all()]) != set(value):
- print "%s old: %s, new: %s" % (attr, [x.pk for x in attribute.all()], value)
+ print "{0} old: {1}, new: {2}".format(
+ attr, [x.pk for x in attribute.all()], value)
setattr(card, attr, value)
else:
if attribute != value:
- print "%s old: %s, new: %s" % (attr, getattr(card, attr), value)
+ print "{0} old: {1}, new: {2}".format(
+ attr, getattr(card, attr), value)
setattr(card, attr, value)
card.save()
else:
- card.components=components
+ card.components = components
if options[JIRA_IMPLEMENTS]:
- card.implementedby=implementedby_list
+ card.implementedby = implementedby_list
if options[JIRA_DEPENDSON]:
- card.dependson=depends_list
+ card.dependson = depends_list
card.labels = label_list
card.save()
if options[VERBOSE]:
- print "Saving %s %s" % (key,summary)
+ print "Saving %s %s" % (key, summary)
return card
+
def get_card_blueprints(card):
blueprint_type = CardType.objects.get(name="Blueprint")
blueprints = []
@@ -247,6 +276,7 @@ def get_card_blueprints(card):
blueprints.extend(get_card_blueprints(c))
return blueprints
+
def get_component_blueprints(component):
blueprint_type = CardType.objects.get(name="Blueprint")
blueprints = []
@@ -257,9 +287,10 @@ def get_component_blueprints(component):
blueprints.extend(get_card_blueprints(card))
return blueprints
+
def collect_component_burndown(project):
components = Component.objects.filter(project=project)
- status_names = settings.JIRA_STATUSES
+ status_names = settings.JIRA_STATUSES
for component in components:
blueprints = get_component_blueprints(component)
burndown, created = Burndown.objects.get_or_create(component=component)
@@ -272,17 +303,20 @@ def collect_component_burndown(project):
bbar.value = bbar.value + 1
bbar.save()
+
def collect_burndown(project, card_type, component=None):
- bar_values = Status.objects.filter(card__card_type=card_type).values('name').annotate(num_cards=Count('card'))
+ bar_values = Status.objects.filter(card__card_type=card_type).values(
+ 'name').annotate(num_cards=Count('card'))
burndown, created = Burndown.objects.get_or_create(project=project)
snapshot = BurndownSnapshot(burndown=burndown, date=datetime.now())
snapshot.save()
bar_names = []
for bar in bar_values:
bar_names.append(bar['name'])
- bbar = BurndownBar(snapshot=snapshot, name=bar['name'], value=bar['num_cards'])
+ bbar = BurndownBar(
+ snapshot=snapshot, name=bar['name'], value=bar['num_cards'])
bbar.save()
if set(bar_names) != set(settings.JIRA_STATUSES):
- for missing in set(settings.JIRA_STATUSES) - set(bar_names):
- bbar = BurndownBar(snapshot=snapshot, name=missing, value=0)
- bbar.save()
+ for missing in set(settings.JIRA_STATUSES) - set(bar_names):
+ bbar = BurndownBar(snapshot=snapshot, name=missing, value=0)
+ bbar.save()