]>
git.ipfire.org Git - people/jschlag/pbs.git/blob - src/buildservice/bugtracker.py
7 from .decorators
import *
9 class BugzillaBug(base
.Object
):
10 def __init__(self
, bugzilla
, bug_id
):
11 base
.Object
.__init
__(self
, bugzilla
.pakfire
)
12 self
.bugzilla
= bugzilla
17 def __cmp__(self
, other
):
18 return cmp(self
.bug_id
, other
.bug_id
)
20 def call(self
, *args
, **kwargs
):
21 args
= (("Bug",) + args
)
23 return self
.bugzilla
.call(*args
, **kwargs
)
31 # Fetch bug information from cache
32 data
= self
.backend
.cache
.get(self
._cache
_key
)
38 # Fetch bug information from Bugzilla
39 for data
in self
.call("get", ids
=[self
.id,])["bugs"]:
40 # Put it into the cache
41 self
.backend
.cache
.set(self
._cache
_key
, data
, self
.backend
.bugzilla
.cache_lifetime
)
47 return "bug-%s" % self
.bug_id
51 return self
.bugzilla
.bug_url(self
.id)
55 return self
.data
.get("summary")
59 return self
.data
.get("assigned_to")
63 return self
.data
.get("status")
67 return self
.data
.get("resolution")
71 return not self
.data
["is_open"]
73 def set_status(self
, status
, resolution
=None, comment
=None):
74 kwargs
= { "status" : status
}
76 kwargs
["resolution"] = resolution
78 kwargs
["comment"] = { "body" : comment
}
80 self
.call("update", ids
=[self
.id,], **kwargs
)
83 self
.backend
.cache
.delete(self
.cache_key
)
86 class Bugzilla(base
.Object
):
87 def __init__(self
, pakfire
):
88 base
.Object
.__init
__(self
, pakfire
)
90 # Open the connection to the server.
91 self
.server
= xmlrpclib
.ServerProxy(self
.url
, use_datetime
=True)
93 # Cache the credentials.
94 self
.__credentials
= {
95 "Bugzilla_login" : self
.user
,
96 "Bugzilla_password" : self
.password
,
99 def call(self
, *args
, **kwargs
):
100 # Add authentication information.
101 kwargs
.update(self
.__credentials
)
105 method
= getattr(method
, arg
)
107 return method(kwargs
)
109 def bug_url(self
, bug_id
):
110 url
= self
.settings
.get("bugzilla_url", None)
112 return url
% { "bug_id" : bug_id
}
114 def enter_url(self
, component
):
116 "product" : self
.settings
.get("bugzilla_product", ""),
117 "component" : component
,
120 url
= self
.settings
.get("bugzilla_url_new")
124 def buglist_url(self
, component
):
126 "product" : self
.settings
.get("bugzilla_product", ""),
127 "component" : component
,
130 url
= self
.settings
.get("bugzilla_url_buglist")
136 return self
.settings
.get("bugzilla_url_xmlrpc", None)
140 return self
.settings
.get("bugzilla_xmlrpc_user", "")
144 return self
.settings
.get("bugzilla_xmlrpc_password")
147 def cache_lifetime(self
):
148 return self
.settings
.get("bugzilla_cache_lifetime", 3600)
150 def get_bug(self
, bug_id
):
152 bug
= BugzillaBug(self
, bug_id
)
154 except xmlrpclib
.Fault
:
159 def find_users(self
, pattern
):
160 users
= self
.call("User", "get", match
=[pattern
,])
162 return users
["users"]
164 def find_user(self
, pattern
):
165 users
= self
.find_users(pattern
)
171 raise Exception, "Got more than one result."
175 def get_bugs_from_component(self
, component
, closed
=False):
177 "product" : self
.settings
.get("bugzilla_product", ""),
178 "component" : component
,
181 query
= self
.call("Bug", "search", include_fields
=["id"], **kwargs
)
184 for bug
in query
["bugs"]:
185 bug
= self
.get_bug(bug
["id"])
187 if not bug
.is_closed
== closed
:
194 def send_all(self
, limit
=100):
195 # Get up to ten updates.
196 query
= self
.db
.query("SELECT * FROM builds_bugs_updates \
197 WHERE error IS FALSE ORDER BY time LIMIT %s", limit
)
199 # XXX CHECK IF BZ IS ACTUALLY REACHABLE AND WORKING
203 bug
= self
.backend
.bugzilla
.get_bug(update
.bug_id
)
205 logging
.error("Bug #%s does not exist." % update
.bug_id
)
209 bug
.set_status(update
.status
, update
.resolution
, update
.comment
)
212 # If there was an error, we save that and go on.
213 self
.db
.execute("UPDATE builds_bugs_updates SET error = 'Y', error_msg = %s \
214 WHERE id = %s", "%s" % e
, update
.id)
217 # Remove the update when it has been done successfully.
218 self
.db
.execute("DELETE FROM builds_bugs_updates WHERE id = %s", update
.id)