Update fsij_list remove 2006 list, adding fsij-meeting.
[fsij-server-admin.git] / setup_forward.py
1 from time import sleep
2 from gandi_tool import gandi_tool
3 from get_list_by_sql import individual_member_list, board_member_list, fsij_member_list
4
5 def string_repr(l):
6     return u'\n'.join(sorted(l))
7
8 if __name__ == "__main__":
9     url='https://rpc.gandi.net/xmlrpc/'
10     encrypted_key_file='api-key-info.json.gpg'
11     domain='fsij.org'
12     encrypted_list_file='fsij_list.json.gpg'
13
14     import subprocess, json
15     command=['gpg', '--decrypt', '-o', '-', encrypted_list_file]
16     p = subprocess.Popen(command, stdout=subprocess.PIPE)
17     listdata_string = p.communicate()[0]
18     fsij_aliases = json.loads(listdata_string)
19
20     g=gandi_tool(url, encrypted_key_file, domain)
21     print("API Version: %s" % g.api_version()['api_version'])
22     info=g.info()
23     print("Domain owner handle: %s" % info['contacts']['owner']['handle'])
24     print("Current number of forwards %d" % g.forward_count())
25     for i in fsij_aliases.items():
26         l = g.forward_list({ 'source' : i[0]})
27         dest = i[1]
28         if l:
29             if string_repr(l[0]['destinations']) == string_repr(dest):
30                 print("Skip: %s" % i[0])
31             else:
32                 print("Update: %s" % i[0])
33                 g.forward_update(i[0], {'destinations': dest})
34         else:
35             print("Create: %s" % i[0])
36             g.forward_create(i[0], {'destinations': dest})
37     for i in individual_member_list:
38         l = g.forward_list({ 'source' : i[0]})
39         dest = i[1]
40         if l:
41             if string_repr(l[0]['destinations']) == string_repr(dest):
42                 print("Skip: %s" % i[0])
43             else:
44                 print("Update: %s" % i[0])
45                 g.forward_update(i[0], {'destinations': dest})
46         else:
47             print("Create: %s" % i[0])
48             g.forward_create(i[0], {'destinations': dest})
49     l = g.forward_list({ 'source' : 'board' })
50     dest = board_member_list
51     if l:
52         if string_repr(l[0]['destinations']) == string_repr(dest):
53             print("Skip: %s" % 'board')
54         else:
55             print("Update: %s" % 'board')
56             # g.forward_update('board', {'destinations': dest})
57     else:
58         print("Create: %s" % 'board')
59         g.forward_create('board', {'destinations': dest})
60     l = g.forward_list({ 'source' : 'members' })
61     dest = fsij_member_list
62     if l:
63         if string_repr(l[0]['destinations']) == string_repr(dest):
64             print("Skip: %s" % 'members')
65         else:
66             print("Update: %s" % 'members')
67             g.forward_update('members', {'destinations': dest})
68     else:
69         print("Create: %s" % 'members')
70         g.forward_create('members', {'destinations': dest})
71     print("Current number of forwards %d" % g.forward_count())
72     for entry in g.forward_list():
73         print("%s -> %s" % (entry['source'], entry['destinations']))