import os
import random
import string
import zipfile
from xml.etree import cElementTree as ET
from uuid import uuid4

from ngx_task import settings


def make_name(count=settings.OBJECT_NAME_LENGTH):
    return ''.join(random.sample(string.ascii_letters, count))


def generate_document():
    root = ET.Element('root')
    id_element = ET.Element('var', {'name': 'id', 'value': str(uuid4())})
    level_element = ET.Element('var', {'name': 'level', 'value': str(random.randint(1, 100))})

    objects = ET.Element('objects')
    objects.extend(ET.Element('object', {'name': make_name()})
                   for _ in range(random.randint(1, 10)))

    root.extend((id_element, level_element, objects))
    return root


def archive_documents(filename, count=settings.ARCHIVE_DOCUMENTS_COUNT):
    arc_filename = os.path.join(settings.DATA_DIR, filename)
    with zipfile.ZipFile(arc_filename, 'w') as zf:
        for doc_number in range(1, count + 1):
            document_name = '{}-document-{}.xml'.format(filename, doc_number)
            zf.write(document_name, ET.tostring(generate_document(), encoding='utf-8'))


def unarchive_documents(filename):
    arc_filename = os.path.join(settings.DATA_DIR, filename)
    if not os.path.exists(arc_filename):
        return

    with zipfile.ZipFile(arc_filename, 'r') as zf:
        for name in zf.namelist():
            xml_data = ET.fromstring(zf.read(name).decode('utf-8'))
            yield {
                'id': xml_data.find('var[@name="id"]').get('value'),
                'level': xml_data.find('var[@name="level"]').get('value'),
                'objects': [obj.get('name') for obj in xml_data.iterfind('objects/object')],
            }

@@ -1121,156 +1121,50 @@
 def 
-unarchive_documents(filename):%0A    arc_filename = os.path.join(settings.DATA_DIR, filename)%0A    if not os.path.exists(arc_filename):%0A        return%0A
+process_archive(path, f_queue, obj_queue):
 %0A   
@@ -1185,28 +1185,20 @@
 ZipFile(
-arc_filename
+path
 , 'r') a
@@ -1215,20 +1215,22 @@
     for 
-na
 me
+mber
  in zf.n
@@ -1285,20 +1285,22 @@
 zf.read(
-na
 me
+mber
 ).decode
@@ -1326,37 +1326,17 @@
     
-yield %7B%0A                'id':
+file_id =
  xml
@@ -1369,33 +1369,32 @@
 %5D').get('value')
-,
 %0A               
@@ -1394,20 +1394,20 @@
     
-    '
+file_
 level
-':
+ =
  xml
@@ -1451,17 +1451,17 @@
 'value')
-,
+%0A
 %0A       
@@ -1469,39 +1469,54 @@
     
-    'objects': %5Bobj.get('name')
+f_queue.put((file_id, file_level))%0A           
  for
@@ -1562,10 +1562,9 @@
 ct')
-%5D,
+:
 %0A   
@@ -1572,10 +1572,54 @@
         
-%7D
+    obj_queue.put((file_id, obj.get('name')))
 %0A

Replace unarchiving method to support passing objects to queues