Show More
@@ -1,5 +1,5 b'' | |||||
1 | import re |
|
1 | import re | |
2 | import urllib |
|
2 | import urllib.parse | |
3 | import httplib2 |
|
3 | import httplib2 | |
4 | from django.core.management import BaseCommand |
|
4 | from django.core.management import BaseCommand | |
5 | from boards.models import GlobalId |
|
5 | from boards.models import GlobalId | |
@@ -7,18 +7,23 b' from boards.models import GlobalId' | |||||
7 | __author__ = 'neko259' |
|
7 | __author__ = 'neko259' | |
8 |
|
8 | |||
9 |
|
9 | |||
10 |
REGEX_GLOBAL_ID = r'\[ |
|
10 | REGEX_GLOBAL_ID = re.compile(r'(\w+)::([\w\+/]+)::(\d+)') | |
11 |
|
11 | |||
12 |
|
12 | |||
13 | class Command(BaseCommand): |
|
13 | class Command(BaseCommand): | |
14 | help = 'Send a sync or get request to the server.' + \ |
|
14 | help = 'Send a sync or get request to the server.' + \ | |
15 | 'sync_with_server <server_url> [post_global_id]' |
|
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 | def handle(self, *args, **options): |
|
21 | def handle(self, *args, **options): | |
18 | url = args[0] |
|
22 | url = options.get('url') | |
19 | if len(args) > 1: |
|
23 | global_id_str = options.get('global_id') | |
20 |
|
|
24 | if global_id_str: | |
21 |
match = |
|
25 | match = REGEX_GLOBAL_ID.match(global_id_str) | |
|
26 | if match: | |||
22 | key_type = match.group(1) |
|
27 | key_type = match.group(1) | |
23 | key = match.group(2) |
|
28 | key = match.group(2) | |
24 | local_id = match.group(3) |
|
29 | local_id = match.group(3) | |
@@ -28,10 +33,14 b' class Command(BaseCommand):' | |||||
28 |
|
33 | |||
29 | xml = GlobalId.objects.generate_request_get([global_id]) |
|
34 | xml = GlobalId.objects.generate_request_get([global_id]) | |
30 | data = {'xml': xml} |
|
35 | data = {'xml': xml} | |
31 | body = urllib.urlencode(data) |
|
36 | body = urllib.parse.urlencode(data) | |
32 | h = httplib2.Http() |
|
37 | h = httplib2.Http() | |
33 | response, content = h.request(url, method="POST", body=body) |
|
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 | else: |
|
45 | else: | |
37 | raise Exception('Full sync is not supported yet.') |
|
46 | raise Exception('Full sync is not supported yet.') |
General Comments 0
You need to be logged in to leave comments.
Login now