FogBugz » FogBugzPy A Python wrapper for the FogBugz API Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.9.1, 0.9.2, and 0.9.3

Added fogbugz shell

Changeset 0caf7da2558d

Parent 2a85ddb94365

by Profile picture of User 10Tyler G. Hicks-Wright <tghw@fogcreek.com>

Changes to one file · Browse files at 0caf7da2558d Showing diff from parent 2a85ddb94365 Diff from another changeset...

Change 1 of 1 Show Entire File fbshell.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
 
@@ -1,0 +1,129 @@
+import os +import sys +import fogbugz +import cmd + +from getch import getch + +CONFIG_FILE = 'shell.ini' + +class Shell(cmd.Cmd): + _ixbug = None + _sfilter = None + + def __init__(self): + cmd.Cmd.__init__(self) + self.prompt = 'FB > ' + run_config = False + try: + config = {} + f = open(CONFIG_FILE, 'r') + for sLine in f.readlines(): + opt, val = map(lambda s: s.strip(), sLine.split('=')) + config[opt] = val + f.close() + self._fb = fogbugz.FogBugz(config['url']) + self._fb._token = config['token'] + except IOError: + run_config = True + except KeyError: + run_config = True + + if run_config: + f = open(CONFIG_FILE, 'w') + sys.stdout.write('FogBugz URL: ') + url = sys.stdin.readline().strip() + f.write('url = %s\n' % url) + sys.stdout.write('Email: ') + email = sys.stdin.readline().strip() + sys.stdout.write('Password: ') + password = "" + while True: + ch = getch() + if ch == '\n' or ch == '\r': + break + print ch + password += ch + self._fb = fogbugz.FogBugz(url) + self._fb.logon(email, password) + f.write('token = %s\n' % self._fb._token) + f.close() + + def list_cases(self, **kwargs): + r = self._fb.search(**kwargs) + if r.description is not None: + print 'Filter:', r.description.string + print + for case in r.findAll('case'): + print case['ixbug'].rjust(8), case.stitle.string + print " ", case.events.event.evtdescription.string + print + + def do_list(self, line): + """list + Lists cases in the current filter.""" + self.list_cases(cols='sTitle,latestEvent') + + def do_search(self, line): + """search [query] + Lists cases returned by the search.""" + self.list_cases(q=line, cols='sTitle,latestEvent') + + def get_case(self, ixbug): + r = self._fb.search(q=ixbug, cols='sTitle,sProject,sArea,sFixFor,sPersonAssignedTo,events') + return r.cases.case + + def print_case_info(self, case): + print '-' * 70 + print "Case %s: %s" % (case['ixbug'], case.stitle.string) + print "Project: %s | Area: %s" % (case.sproject.string, case.sarea.string) + print "Fix for: %s" % (case.sfixfor.string,) + print "Assigned to: %s" % (case.spersonassignedto.string,) + print '-' * 70 + + def print_events(self, events): + for event in events: + print event.dt.string.strip() + print event.evtdescription.string.strip() + if event.schanges and event.schanges.string: + print event.schanges.string.strip() + if event.s and event.s.string: + print + print event.s.string.strip() + print '-' * 40 + + def do_view(self, line): + """view [ixBug] + Shows all of the events in the case history. If no case is specified, the current case is used. + If one is specified, the current case is set to the new case.""" + ixbug = line.split()[0] + if self._ixbug: + case = self.get_case(self._ixbug) + self.print_case_info(case) + self.print_events(case.events.findAll('event')) + else: + print "No current case. Specify a case number." + + def do_filter(self, line): + if len(line) == 0: + + + def do_filters(self, line): + r = self._fb.listFilters() + for filter in r.findAll('filter'): + if filter.get('status', '') == 'current': + print "* %s" % filter.string + else: + print " %s" % filter.string + + def do_exit(self, line): + """exit + Exit the shell.""" + return True + +def main(): + shell = Shell() + shell.cmdloop() + +if __name__ == "__main__": + main() \ No newline at end of file