diff --git a/boards/management/commands/sync_with_server.py b/boards/management/commands/sync_with_server.py --- a/boards/management/commands/sync_with_server.py +++ b/boards/management/commands/sync_with_server.py @@ -1,4 +1,5 @@ import re +import logging import xml.etree.ElementTree as ET import httplib2 @@ -25,6 +26,8 @@ class Command(BaseCommand): ' number of posts in one') def handle(self, *args, **options): + logger = logging.getLogger('boards.sync') + url = options.get('url') list_url = url + 'api/sync/list/' @@ -50,11 +53,11 @@ class Command(BaseCommand): else: raise Exception('Invalid global ID') else: - print('Running LIST request...') + logger.info('Running LIST request...') h = httplib2.Http() xml = GlobalId.objects.generate_request_list() response, content = h.request(list_url, method="POST", body=xml) - print('Processing response...') + logger.info('Processing response...') root = ET.fromstring(content) status = root.findall('status')[0].text @@ -71,20 +74,23 @@ class Command(BaseCommand): else: version = 1 if not exists or global_id.post.version < version: + logger.debug('* Processed (+) post {}'.format(global_id)) ids_to_sync.append(global_id) - print('Starting sync...') + else: + logger.debug('* Processed (-) post {}'.format(global_id)) + logger.info('Starting sync...') if len(ids_to_sync) > 0: limit = options.get('split_query', len(ids_to_sync)) for offset in range(0, len(ids_to_sync), limit): xml = GlobalId.objects.generate_request_get(ids_to_sync[offset:offset+limit]) h = httplib2.Http() - print('Running GET request...') + logger.info('Running GET request...') response, content = h.request(get_url, method="POST", body=xml) - print('Processing response...') + logger.info('Processing response...') SyncManager.parse_response_get(content, file_url) else: - print('Nothing to get, everything synced') + logger.info('Nothing to get, everything synced') else: raise Exception('Invalid response status')