-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.py
76 lines (61 loc) · 2.6 KB
/
generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf8 -*-
import getpass
from jira.client import JIRA, GreenHopper
from issues import BlankFinder, BoardFinder, IssueFinder
from cards import CardFormatter, CardRenderer
class Generator:
def __init__(self, arguments):
issues = self.get_issues(arguments)
if arguments.mode == 'blank':
formatter = CardFormatter('format/blank.html')
else:
formatter = CardFormatter(arguments.format)
if arguments.debug:
for issue in issues:
flat_issue = formatter.flatten(issue.raw)
print('\n' + flat_issue['key'] + ':')
for item in sorted(flat_issue.items()):
print(' ' + str(item[0]) + ': ' + str(item[1]))
formatted_issues = []
for issue in issues:
formatted_issues.append(formatter.format(issue))
renderer = CardRenderer(arguments.layout, arguments.style)
renderer.render(formatted_issues)
print('Generated cards.html')
def get_issues(self, arguments):
if arguments.mode == 'blank':
return BlankFinder().get_issues(arguments.number)
else:
if arguments.mode == 'board':
jira = self.connect(GreenHopper, arguments)
board_finder = BoardFinder(jira)
if arguments.board:
board_name = arguments.board
else:
print('Found boards:')
for board in board_finder.get_board_names():
print(' ' + str(board))
board_name = raw_input('Select board: ')
return board_finder.get_open_sprint(board_name)
if arguments.mode == 'issues':
jira = self.connect(JIRA, arguments)
issue_finder = IssueFinder(jira)
return issue_finder.get_issues(arguments.issues)
def connect(self, constructor, arguments):
options = {'server': arguments.server}
try:
if arguments.anonymous:
return constructor(options)
else:
auth = self.get_auth(arguments.username, arguments.password)
return constructor(options, basic_auth=auth)
except Exception as e:
print('Could not connect to jira instance at ' + arguments.server)
print(str(e))
exit(1)
def get_auth(self, username, password):
if not username:
username = raw_input('Username: ')
if not password:
password = getpass.getpass()
return username, password