5
from gettext import gettext as _
9
3
from core import Core
13
if os.path.exists(c.tag_file):
14
return map(lambda a: a.strip(), open(c.tag_file).readlines())
18
if os.path.exists(c.team_file):
19
return map(lambda a: a.strip(), open(c.team_file).readlines())
22
6
def preserve_old_signature():
23
7
sig = c.signature_file
24
8
oldsig = c.old_signature_file
28
12
os.system("mv %s %s" % (sig, oldsig))
33
if os.path.exists(c.log_file):
34
lines = open(c.log_file).readlines()
35
return filter(lambda b: b != "", map(lambda a: a.strip(), lines))
39
def first_element_is_int(s):
47
class LogFile(object):
49
self.tags = get_tags()
50
self.entries = get_old_log()
52
# we used "2008-4-1 123456" entries before, now they're simply
54
self.correct_new_entries = filter(lambda a: first_element_is_int(a),
57
self.correct_new_entries = []
59
def add(self, t, entries):
60
# TODO: move parsing/validation of bug numbers to parser?!
61
# This method should only get a list of bug numbers probably.
63
# Parse/validate bug arguments:
66
for i in entry.split(","):
72
print >> sys.stderr, _("'%s' is not a valid bug number. Aborting.") % n
73
return 105 #105: invalid bug number
74
if filter(lambda a: (int(t)-int(a.split()[0]) < 60*60*24) and \
75
(a.split()[1]==str(n)),
76
self.correct_new_entries):
77
print >> sys.stderr, _("Bug '%s' has already been added today. Aborting.") % n
78
return 106 #106: bug has already been added today
81
if os.path.exists(c.log_file):
82
f = open(c.log_file, "a")
84
f = open(c.log_file, "w")
86
data_str = "%s %s %s\n" % (int(t), bug, " ".join(self.tags))
91
current_tags = get_tags()
93
if t not in current_tags:
94
current_tags.append(t)
95
set_tags(current_tags)
97
def remove_tags(tags):
98
current_tags = get_tags()
100
if t in current_tags:
101
current_tags.remove(t)
102
set_tags(current_tags)
104
def set_tags(new_tags):
105
f = open(c.tag_file, "w")
106
f.write("\n".join(new_tags))
112
print _("No tags set right now.")
115
print _("Your current tag is: %s" % tags[0])
117
print _("Your current tags are: %s" % ", ".join(tags))
119
def set_teams(new_teams):
120
current_teams = get_teams()
122
lp_teams = [a for a in lpteams.get_teams(c.lplogin)]
124
if t not in current_teams:
126
current_teams.append(t)
128
print >> sys.stderr, _("You're not in team '%s', not adding.") % t
129
for t in current_teams:
130
if t not in new_teams:
131
current_teams.remove(t)
132
if t not in lp_teams:
133
current_teams.remove(t)
135
os.remove(c.team_file)
138
f = open(c.team_file, "w")
139
f.write("\n".join(current_teams))
143
def add_teams(teams):
144
current_teams = get_teams()
146
if t not in current_teams:
147
current_teams.append(t)
148
return set_teams(current_teams)
150
def remove_teams(teams):
151
current_teams = get_teams()
153
if t in current_teams:
154
current_teams.remove(t)
155
return set_teams(current_teams)
160
print _("No teams set right now.")
163
print _("Your current team is: %s" % teams[0])
165
print _("Your current teams are: %s" % ", ".join(teams))