~nmu-sscheel/gtg/rework-task-editor

« back to all changes in this revision

Viewing changes to scripts/close_launchpad_bugs.py

  • Committer: Bertrand Rousseau
  • Date: 2012-05-09 22:33:25 UTC
  • mfrom: (1178 trunk)
  • mto: This revision was merged to the branch mainline in revision 1179.
  • Revision ID: bertrand.rousseau@gmail.com-20120509223325-a53d8nwo0x9g93bc
Merge nimit branch and trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
#documentation: https://edge.launchpad.net/+apidoc/#bug_task
20
20
 
21
 
import sys, os, re
22
 
from launchpadlib.launchpad import Launchpad, EDGE_SERVICE_ROOT
23
 
from launchpadlib.credentials import Credentials
 
21
import os
 
22
import re
 
23
import sys
24
24
from re import findall
25
25
from urllib import urlopen
26
26
 
 
27
from launchpadlib.credentials import Credentials
 
28
from launchpadlib.launchpad import Launchpad, EDGE_SERVICE_ROOT
 
29
 
 
30
 
27
31
def lp_login():
28
 
        cachedir = os.path.expanduser('~/.cache/launchpadlib/')
29
 
        if not os.path.isdir(cachedir):
30
 
                os.makedirs(cachedir)
31
 
        creddir = os.path.expanduser("~/.cache/lp_credentials")
32
 
        if not os.path.isdir(creddir):
33
 
                os.makedirs(creddir)
34
 
                os.chmod(creddir, 0700)
35
 
        try:
36
 
                credfile = open(os.path.join(creddir, 'close_launchpad_bugs.txt'), 'r')
37
 
                credentials = Credentials()
38
 
                credentials.load(credfile)
39
 
                credfile.close()
40
 
                launchpad = Launchpad(credentials, EDGE_SERVICE_ROOT, cachedir)
41
 
        except IOError:
42
 
                launchpad = Launchpad.get_token_and_login('close_launchpad_bugs', EDGE_SERVICE_ROOT, cachedir)
43
 
                credfile = open(os.path.join(creddir, 'close_launchpad_bugs.txt'), 'w')
44
 
                launchpad.credentials.save(credfile)
45
 
                credfile.close()
46
 
        return launchpad
 
32
    cachedir = os.path.expanduser('~/.cache/launchpadlib/')
 
33
    if not os.path.isdir(cachedir):
 
34
        os.makedirs(cachedir)
 
35
    creddir = os.path.expanduser("~/.cache/lp_credentials")
 
36
    if not os.path.isdir(creddir):
 
37
        os.makedirs(creddir)
 
38
        os.chmod(creddir, 0700)
 
39
 
 
40
    credpath = os.path.join(creddir, 'close_launchpad_bugs.txt')
 
41
    try:
 
42
        credfile = open(credpath, 'r')
 
43
        credentials = Credentials()
 
44
        credentials.load(credfile)
 
45
        credfile.close()
 
46
        launchpad = Launchpad(credentials, EDGE_SERVICE_ROOT, cachedir)
 
47
    except IOError:
 
48
        launchpad = Launchpad.get_token_and_login('close_launchpad_bugs',
 
49
                                                EDGE_SERVICE_ROOT, cachedir)
 
50
        credfile = open(credpath, 'w')
 
51
        launchpad.credentials.save(credfile)
 
52
        credfile.close()
 
53
 
 
54
    return launchpad
 
55
 
 
56
 
 
57
def process_bug(bug):
 
58
    for task in bug.bug_tasks:
 
59
        if task.bug_target_name == 'gtg' and task.status == 'Fix Committed':
 
60
            task.status = 'Fix Released'
 
61
            task.lp_save()
47
62
 
48
63
if len(sys.argv) != 2:
49
64
    print 'Usage: %s <release>' % sys.argv[0]
52
67
data = urlopen('https://launchpad.net/gtg/+milestone/%s' % sys.argv[1]).read()
53
68
bugs = findall('<a href="\S+/bugs/(\d+)">', data)
54
69
launchpad = lp_login()
 
70
 
55
71
if not 'gtg' in [e.name for e in launchpad.people[launchpad.me].super_teams]:
56
72
    print 'You are not a GTG developer, exiting.'
57
73
    sys.exit(0)
 
74
 
58
75
for bugno in bugs:
59
76
    try:
60
 
        bug = launchpad.bugs[bugno]
61
 
        for task in bug.bug_tasks:
62
 
            if task.bug_target_name == 'gtg' and task.status == 'Fix Committed':
63
 
                task.status = 'Fix Released'
64
 
                #task.milestone_link = 'https://api.edge.launchpad.net/beta/gtg/+milestone/0.2.2'
65
 
                task.lp_save()
66
 
                print """Bug %s marked as Fix Released,
67
 
                    (https://bugs.edge.launchpad.net/gtg/+bug/%s""" % (bugno, bugno)
68
 
 
 
77
        process_bug(launchpad.bugs[bugno])
 
78
        print "Bug #%s marked as Fix Released: " \
 
79
            "https://bugs.edge.launchpad.net/gtg/+bug/%s" % (bugno, bugno)
69
80
    except:
70
 
        print 'UNABLE TO PROCESS BUG #%s' % bugno
71
 
        pass
 
81
        print "UNABLE TO PROCESS BUG #%s" % bugno