##// END OF EJS Templates
Small progress in getting a sync data from server
neko259 -
r1138:7246d9ec decentral
parent child Browse files
Show More
@@ -1,5 +1,5 b''
1 1 import re
2 import urllib
2 import urllib.parse
3 3 import httplib2
4 4 from django.core.management import BaseCommand
5 5 from boards.models import GlobalId
@@ -7,31 +7,40 b' from boards.models import GlobalId'
7 7 __author__ = 'neko259'
8 8
9 9
10 REGEX_GLOBAL_ID = r'\[(\w+)\]\[(\w+)\]\[(\d+)\]'
10 REGEX_GLOBAL_ID = re.compile(r'(\w+)::([\w\+/]+)::(\d+)')
11 11
12 12
13 13 class Command(BaseCommand):
14 14 help = 'Send a sync or get request to the server.' + \
15 15 'sync_with_server <server_url> [post_global_id]'
16 16
17 def add_arguments(self, parser):
18 parser.add_argument('url', type=str)
19 parser.add_argument('global_id', type=str)
20
17 21 def handle(self, *args, **options):
18 url = args[0]
19 if len(args) > 1:
20 global_id_str = args[1]
21 match = re.match(REGEX_GLOBAL_ID, global_id_str)
22 key_type = match.group(1)
23 key = match.group(2)
24 local_id = match.group(3)
22 url = options.get('url')
23 global_id_str = options.get('global_id')
24 if global_id_str:
25 match = REGEX_GLOBAL_ID.match(global_id_str)
26 if match:
27 key_type = match.group(1)
28 key = match.group(2)
29 local_id = match.group(3)
25 30
26 global_id = GlobalId(key_type=key_type, key=key,
31 global_id = GlobalId(key_type=key_type, key=key,
27 32 local_id=local_id)
28 33
29 xml = GlobalId.objects.generate_request_get([global_id])
30 data = {'xml': xml}
31 body = urllib.urlencode(data)
32 h = httplib2.Http()
33 response, content = h.request(url, method="POST", body=body)
34 xml = GlobalId.objects.generate_request_get([global_id])
35 data = {'xml': xml}
36 body = urllib.parse.urlencode(data)
37 h = httplib2.Http()
38 response, content = h.request(url, method="POST", body=body)
34 39
35 # TODO Parse content and get the model list
40 # TODO Parse content and get the model list
41
42 print(content)
43 else:
44 raise Exception('Invalid global ID')
36 45 else:
37 46 raise Exception('Full sync is not supported yet.')
General Comments 0
You need to be logged in to leave comments. Login now