~rom1-chal/+junk/recipes-automat

« back to all changes in this revision

Viewing changes to update_records.py

  • Committer: Romain Chalumeau
  • Date: 2011-09-23 07:23:05 UTC
  • Revision ID: rchalumeau.ext@orange-ftgroup.com-20110923072305-dnjxowubeuckgzsi
Ajout de la recuperation des bugs gforge

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
    branch,
4
4
    repository,
5
5
    bugtracker,
6
 
    errors
 
6
    errors,
 
7
    ui,
7
8
)
8
9
import ConfigParser
9
10
import sys
11
12
import inspect
12
13
import xmlrpclib
13
14
import exceptions 
14
 
 
 
15
from bzrlib.plugins.melanie.trackers import gforge
15
16
from externals_analyser import get_repos_from_externals
16
17
 
17
18
from config import *
18
19
 
 
20
import MySQLdb
 
21
 
 
22
 
19
23
class SuntoolUpdater(object):
20
24
    def update(self, records, gforge_project, username, branch_url, old_revno, new_revno, complete_bugs):
21
25
        proxy = xmlrpclib.ServerProxy(SUNTOOL_SERVER)
25
29
            proxy.inserttoken([record], branch_url, ','.join(complete_bugs[record]['developers']), complete_bugs[record]['from_merge'])
26
30
 
27
31
class GforgeUpdater(object):
 
32
 
 
33
    def open_connection(self):
 
34
        server="kecompil.dev.gen01.ke.p.fti.net"
 
35
        user="keadmin"
 
36
        password="M0tEur?"
 
37
        base="suntool"
 
38
        self.conn = MySQLdb.connect(
 
39
                                server,
 
40
                                user,
 
41
                                password, 
 
42
                                base)
 
43
        self.curs = self.conn.cursor()
 
44
 
 
45
    def close_connection(self):
 
46
        self.curs.close()
 
47
        self.conn.close()
 
48
        
 
49
    def run_update(self, query):
 
50
        self.curs.execute(query)
 
51
        return 0
 
52
    
 
53
    def run_select(self, query):
 
54
        
 
55
        self.curs.execute(query)
 
56
        ret = self.curs.fetchall()
 
57
        print "#### %s " % str(ret)
 
58
        return ret
 
59
 
28
60
    def update(self, records, gforge_project, username, branch_url, old_revno, new_revno,complete_bugs):
29
 
        if gforge_project is not None:
30
 
            # Transform set in array for serialization
31
 
            a_bugs = []
32
 
            for b in set(bugs):
33
 
                a_bugs.append(str(b))
34
 
 
35
 
            SubmitVars = []
36
 
            SubmitVars.append({
37
 
                                'UserName': username, 
38
 
                                'Repository': gforge_project, 
39
 
                                "FileName" : branch_url,
40
 
                                'PrevVersion': old_revno,
41
 
                                'ActualVersion' : new_revno,
42
 
                                'Log' : 'Publication sur gforge',
43
 
                                'TaskNumbers' : None, 
44
 
                                'ArtifactNumbers' : a_bugs,
45
 
                                "CvsDate" : int(time.time())
46
 
                                })
47
 
            s = PHPSerialize()
48
 
            post_vars = {}
49
 
            post_vars['data'] = s.serialize(SubmitVars)
50
 
            post_params = urllib.urlencode(post_vars)
51
 
 
52
 
            headers = {"Content-type": "application/x-www-form-urlencoded",
53
 
                        "Accept": "text/plain"}
54
 
            conn = httplib.HTTPConnection(GFORGE_SERVER) 
55
 
            conn.request("POST", "/plugins/cvstracker/newcommit.php", post_params , headers)
56
 
            response = conn.getresponse()
57
 
            data = response.read()
58
 
            conn.close()
59
 
 
 
61
        #proxy = xmlrpclib.ServerProxy(SUNTOOL_SERVER)
 
62
        #proxy.insertreleasenotes()
 
63
        
 
64
        self.open_connection()
 
65
        for record in complete_bugs.iterkeys():
 
66
            #update du record
 
67
            query = "select id from gforge_records where id=%s" % record
 
68
            if not len( self.run_select(query) ):
 
69
                # Recuperation du titre via soap
 
70
                print "recuperation du record %s" % record
 
71
                try:
 
72
                    GFORGE = gforge.GForgeProxy(ui.ui_factory)
 
73
                    print "#### %s" % str(GFORGE.session)
 
74
                    title = GFORGE.get_title(int(record))
 
75
                    GFORGE.logout()
 
76
                    print '~~~' + title
 
77
                    insert_gforge = "insert into gforge_records (id, title) values (%s, '%s')" % (record, title.replace("'", ""))
 
78
                    self.run_update(insert_gforge)
 
79
                except Exception, e:
 
80
                    print e
 
81
                    pass
 
82
            
 
83
            # id de la branch bzr
 
84
            updatequery = """insert ignore into bzr_branch_gforge_records (idbzr, idgforge)
 
85
                        select bzr_branch_id, %s from bzr_branch
 
86
                        where bzr_branch_name="%s"
 
87
                        """ % (record, branch_url)
 
88
            self.run_update(updatequery )
 
89
            
 
90
        self.close_connection()
60
91
 
61
92
 
62
93
# Dictionary containing the handled tracker for updates and the method abugtrackerssociated to the update action
63
 
#RECORDS_UPDATERS = {"sunke" : SuntoolUpdater(), "gforge" : GforgeUpdater()}
64
 
RECORDS_UPDATERS = {"sunke" : SuntoolUpdater() }
 
94
RECORDS_UPDATERS = {"sunke" : SuntoolUpdater(), "gforge" : GforgeUpdater()}
 
95
#RECORDS_UPDATERS = {"sunke" : SuntoolUpdater() }
 
96
 
 
97
 
65
98
 
66
99
class RecordsAnalyser(object):
67
100
    
73
106
        self.trackers = {}
74
107
        # Dict of records by tracker
75
108
        self.records = {}
 
109
        from bzrlib.plugins.melanie import trackers
76
110
 
77
111
        # Construction of handled bugtrackers dictionary
78
112
        for t in RECORDS_UPDATERS.iterkeys():
82
116
 
83
117
        # Launch the branch analysis
84
118
        self.get_records_from_revisions(start_id=old_revid)
85
 
    
 
119
        
 
120
        #GFORGE.logout()
86
121
 
87
122
    # Method to parse the revisions and retrieve a set of unique bug id
88
123
    def get_records_from_revisions(self, start_id=None, end_id=None):
144
179
 
145
180
        if not cmd:
146
181
            self.outf = sys.stdout
147
 
 
148
182
        
149
183
        #_dir = os.path.dirname(inspect.getfile( inspect.currentframe() ))
150
184
        cache_path = os.path.join(config.get('default', 'cache_path'), 'branches_bug.cache')