~tribaal/txaws/xss-hardening

« back to all changes in this revision

Viewing changes to admin/base.py

  • Committer: Duncan McGreggor
  • Date: 2009-10-06 18:34:35 UTC
  • mfrom: (33.1.5 444124-describe-zones)
  • Revision ID: duncan@canonical.com-20091006183435-el9j4wdv2229l63f
Merged 444124-describe-zones [r=therve] [f=444124]

Added support for getting a list of availability zones.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python2.7
2
 
import os
3
 
import sys
4
 
 
5
 
from launchpadlib.launchpad import Launchpad
6
 
 
7
 
 
8
 
class Error(Exception):
9
 
    """ 
10
 
    A base class for exceptions.
11
 
    """
12
 
    def __init__(self, msg=None):
13
 
        if msg == None:
14
 
            msg = self.__doc__.strip()
15
 
        super(Error, self).__init__(msg)
16
 
 
17
 
 
18
 
class CredentialsError(Error):
19
 
    """
20
 
    Can't proceed without Launchpad credential.
21
 
    """
22
 
 
23
 
 
24
 
class UnknownState(Error):
25
 
    pass
26
 
 
27
 
 
28
 
class Client(object):
29
 
    """
30
 
    A convenience wrapper for the Launchpad object.
31
 
    """
32
 
    def __init__(self, name=""):
33
 
        cachedir = os.path.expanduser("~/.launchpadlib/cache/")
34
 
        self.launchpad = Launchpad.login_with(
35
 
            name, 'production', cachedir,
36
 
            credential_save_failed=CredentialsError)
37
 
        self.project = self.get_project()
38
 
        self.set_state_map()
39
 
 
40
 
    def set_state_map(self):
41
 
        self.state_map = {
42
 
            "begin_state": {
43
 
                "fixcommitted": self.get_committed_bugs,
44
 
            },
45
 
            "end_state": {
46
 
                "fixreleased": self.set_released,
47
 
            },
48
 
        }
49
 
 
50
 
    def get_project(self, name="txaws"):
51
 
        return self.launchpad.projects["txaws"]
52
 
 
53
 
    def get_committed_bugs(self):
54
 
        return self.project.searchTasks(status="Fix Committed")
55
 
 
56
 
    def set_released(self, bugs=[]):
57
 
        count = int(bugs._wadl_resource.representation['total_size'])
58
 
        print "Found %s bugs." % count
59
 
        for bug_entry in bugs:
60
 
            status = "Fix Released"
61
 
            print "\tUpdating status of %s to '%s' ... " % (
62
 
                bug_entry.title, bug_entry.status),
63
 
            bug_entry.status = status
64
 
            bug_entry.lp_save()
65
 
            print "Done."