Project

General

Profile

Paste
Download (1.83 KB) Statistics
| Branch: | Revision:

root / scripts_divers / migrer_taches_vers_redmine / goto_redmine.py @ 565596d9

1
import node_parser
2
import comments_parser
3
import submiters_parser
4
import url_parser
5
import urllib.request
6
import httplib2
7
import json
8
import re
9

    
10
SUBMITERS = {'jenselme': 'auieeui'}
11
Headers = {'content-type': 'application/json', 'X-Redmine-API-Key': ''}
12
MY_API_KEY = '4a36554437feef722e82a206de1bc1c1250df973'
13
URL = 'http://localhost/redmine/issues'
14

    
15
def give_api_key(submiter):
16
    if submiter in SUBMITERS:
17
        return SUBMITERS[submiter]
18
    else:
19
        return  SUBMITERS['jenselme']
20

    
21
nids = url_parser.give_nids()
22
urls = url_parser.give_urls(nids)
23

    
24
h = httplib2.Http()
25

    
26
for url in urls:
27
    nid = nids[urls.index(url)]
28

    
29
    page = urllib.request.urlopen('url')
30
    txt = page.read()
31
    #tout les scripts fonctionnent en lisant ligne à ligne le fichier.
32
    #la liste input permet de mimer ce comportement
33
    input = txt.split('\n')
34

    
35
    submiters = submiters_parser.parse_submiters(input)
36
    node = node_parser.parse_node(input)
37
    comments = comments_parser.parse_comment(input)
38

    
39
    #on a besoin de drupal_done_ratio pour fermer/rejeter une tache
40
    drupal_done_ratio = node['done_ratio']
41

    
42
    issue = {}
43
    issue['issue'] = node
44
    data = json.dumps(issue)
45

    
46
    Headers['X-Redmine-API-Key'] = give_api_key(submiters[0])
47

    
48
    resp, content = h.request(URL + '.json', 'POST', body=data, headers=Headers)
49

    
50
    iid = re.findall(r',"id":([0-9]*),', content.decode('utf-8'))[0]
51

    
52
    for index, comment in enumerate(comments):
53
       submiter = submiters[index + 1]  #le premier est celui qui a soumis le node
54
       Headers['X-Redmine-API-Key'] = give_api_key(submiters[0])
55

    
56
       h.request(URL + '/' + iid + '.json', 'PUT', body=data, headers=Headers)
57

    
58
    #Les taches sont crées avec le status nouveau peu importe ce qu’il y a dans le json
59
    #on modifie le status après coup
60
    update_status = '{"issue": {"status_id":' + node['status_id'] + '}}'