##// END OF EJS Templates
Use logging during sync. Log list response processing
neko259 -
r1605:25856b69 default
parent child Browse files
Show More
@@ -1,4 +1,5 b''
1 import re
1 import re
2 import logging
2 import xml.etree.ElementTree as ET
3 import xml.etree.ElementTree as ET
3
4
4 import httplib2
5 import httplib2
@@ -25,6 +26,8 b' class Command(BaseCommand):'
25 ' number of posts in one')
26 ' number of posts in one')
26
27
27 def handle(self, *args, **options):
28 def handle(self, *args, **options):
29 logger = logging.getLogger('boards.sync')
30
28 url = options.get('url')
31 url = options.get('url')
29
32
30 list_url = url + 'api/sync/list/'
33 list_url = url + 'api/sync/list/'
@@ -50,11 +53,11 b' class Command(BaseCommand):'
50 else:
53 else:
51 raise Exception('Invalid global ID')
54 raise Exception('Invalid global ID')
52 else:
55 else:
53 print('Running LIST request...')
56 logger.info('Running LIST request...')
54 h = httplib2.Http()
57 h = httplib2.Http()
55 xml = GlobalId.objects.generate_request_list()
58 xml = GlobalId.objects.generate_request_list()
56 response, content = h.request(list_url, method="POST", body=xml)
59 response, content = h.request(list_url, method="POST", body=xml)
57 print('Processing response...')
60 logger.info('Processing response...')
58
61
59 root = ET.fromstring(content)
62 root = ET.fromstring(content)
60 status = root.findall('status')[0].text
63 status = root.findall('status')[0].text
@@ -71,20 +74,23 b' class Command(BaseCommand):'
71 else:
74 else:
72 version = 1
75 version = 1
73 if not exists or global_id.post.version < version:
76 if not exists or global_id.post.version < version:
77 logger.debug('* Processed (+) post {}'.format(global_id))
74 ids_to_sync.append(global_id)
78 ids_to_sync.append(global_id)
75 print('Starting sync...')
79 else:
80 logger.debug('* Processed (-) post {}'.format(global_id))
81 logger.info('Starting sync...')
76
82
77 if len(ids_to_sync) > 0:
83 if len(ids_to_sync) > 0:
78 limit = options.get('split_query', len(ids_to_sync))
84 limit = options.get('split_query', len(ids_to_sync))
79 for offset in range(0, len(ids_to_sync), limit):
85 for offset in range(0, len(ids_to_sync), limit):
80 xml = GlobalId.objects.generate_request_get(ids_to_sync[offset:offset+limit])
86 xml = GlobalId.objects.generate_request_get(ids_to_sync[offset:offset+limit])
81 h = httplib2.Http()
87 h = httplib2.Http()
82 print('Running GET request...')
88 logger.info('Running GET request...')
83 response, content = h.request(get_url, method="POST", body=xml)
89 response, content = h.request(get_url, method="POST", body=xml)
84 print('Processing response...')
90 logger.info('Processing response...')
85
91
86 SyncManager.parse_response_get(content, file_url)
92 SyncManager.parse_response_get(content, file_url)
87 else:
93 else:
88 print('Nothing to get, everything synced')
94 logger.info('Nothing to get, everything synced')
89 else:
95 else:
90 raise Exception('Invalid response status')
96 raise Exception('Invalid response status')
General Comments 0
You need to be logged in to leave comments. Login now