~debian-lptools/debian/sid/lptools/sid

« back to all changes in this revision

Viewing changes to bin/lp-review-list

  • Committer: Robert Collins
  • Date: 2010-02-20 02:27:13 UTC
  • mto: (2.2.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: robertc@robertcollins.net-20100220022713-93gxeb1h8gltbz7g
Unify the credentials file used by lp-review-list and lp-review-notifier.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# with this program.  If not, see <http://www.gnu.org/licenses/>.
18
18
 
19
19
from __future__ import with_statement
 
20
from ConfigParser import ConfigParser
 
21
import os
 
22
import re
 
23
import subprocess
 
24
import sys
 
25
from threading import Thread
20
26
 
21
27
import pygtk
22
28
pygtk.require('2.0')
23
29
import gobject
24
30
import gtk
25
31
import pango
26
 
 
27
 
from ConfigParser import ConfigParser
28
 
import os
29
 
import re
30
 
import subprocess
31
 
import sys
32
 
 
33
32
from xdg.BaseDirectory import xdg_cache_home, xdg_config_home
34
33
 
35
 
from threading import Thread
36
 
 
37
 
from launchpadlib.launchpad import Launchpad, EDGE_SERVICE_ROOT
38
 
from launchpadlib.credentials import Credentials
 
34
from lptools import config
39
35
 
40
36
VOTES = { "Approve" : "#00ff00",
41
37
          "Needs Fixing" : "#993300",
65
61
            else:
66
62
                  self.projects = []
67
63
 
 
64
            # XXX: Not currently honoured - not sure if it ever worked.
68
65
            if self.config.has_option("lptools", "server"):
69
66
                  self.api_server = self.config.get("lptools", "server")
70
67
            else:
167
164
            self.set_title("Pending Reviews")
168
165
            self.set_default_size(320, 400)
169
166
            self.connect("destroy", lambda w: gtk.main_quit())
170
 
            self.connect("delete_event", lambda w: gtk.main_quit())
 
167
            self.connect("delete_event", lambda w,x: gtk.main_quit())
171
168
 
172
169
            vbox = gtk.VBox()
173
170
            self.add(vbox)
203
200
            col = gtk.TreeViewColumn("Branch", cell, markup=0)
204
201
            view.append_column(col)
205
202
 
206
 
            self.cachedir = os.path.join(xdg_cache_home, "review-list")
207
 
            if not os.path.isdir(self.cachedir):
208
 
                  os.makedirs(self.cachedir)
 
203
            self.cachedir = os.path.join(config.xdg_cache_home, "review-list")
 
204
            config.ensure_dir(self.cachedir)
209
205
 
210
206
            self.launchpad = None
211
207
            self.me = None
220
216
            Thread(target=self.__lp_login).start()
221
217
 
222
218
      def __lp_login(self):
223
 
            credsfile = os.path.join(self.cachedir, "credentials")
224
 
 
225
 
            if os.path.exists(credsfile):
226
 
                  creds = Credentials()
227
 
 
228
 
                  with file(credsfile) as f:
229
 
                        creds.load(f)
230
 
                  self.launchpad = Launchpad(creds, EDGE_SERVICE_ROOT)
231
 
            else:
232
 
                  self.launchpad = Launchpad.get_token_and_login(
233
 
                        'review-list',
234
 
                        EDGE_SERVICE_ROOT,
235
 
                        self.cachedir)
236
 
                  with file(credsfile, "w") as f:
237
 
                        self.launchpad.credentials.save(f)
 
219
            self.launchpad = config.get_launchpad(self.cachedir)
238
220
 
239
221
            self.me = self.launchpad.me
240
222