def zip_package(current_document=None, eml_node=None):
    if (not current_document):
        current_document = current_user.get_filename()
    if (not current_document):
        raise FileNotFoundError
    if (not eml_node):
        eml_node = load_eml(filename=current_document)
    user_folder = user_data.get_user_folder_name()
    zipfile_name = f'{current_document}.zip'
    zipfile_path = os.path.join(user_folder, zipfile_name)
    zip_object = ZipFile(zipfile_path, 'w')
    manifest_files = []
    pathname = f'{user_folder}/{current_document}.json'
    arcname = f'{current_document}.json'
    zip_object.write(pathname, arcname)
    manifest_files.append(('JSON', f'{current_document}.json', pathname))
    package_id = user_data.get_active_packageid()
    if package_id:
        arcname = f'{package_id}.xml'
        copyfile(f'{user_folder}/{current_document}.xml', f'{user_folder}/{arcname}')
    else:
        arcname = f'{current_document}.xml'
    pathname = f'{user_folder}/{arcname}'
    manifest_files.append(('XML', arcname, pathname))
    zip_object.write(pathname, arcname)
    create_ezeml_package_manifest(user_folder, manifest_files)
    pathname = f'{user_folder}/ezEML_manifest.txt'
    arcname = 'ezEML_manifest.txt'
    zip_object.write(pathname, arcname)
    uploads_folder = user_data.get_document_uploads_folder_name()
    data_table_nodes = []
    eml_node.find_all_descendants(names.DATATABLE, data_table_nodes)
    entity_nodes = []
    eml_node.find_all_descendants(names.OTHERENTITY, entity_nodes)
    data_nodes = (data_table_nodes + entity_nodes)
    for data_node in data_nodes:
        object_name_node = data_node.find_single_node_by_path([names.PHYSICAL, names.OBJECTNAME])
        if object_name_node:
            object_name = object_name_node.content
            pathname = f'{uploads_folder}/{object_name}'
            arcname = f'data/{object_name}'
            try:
                zip_object.write(pathname, arcname)
            except FileNotFoundError as err:
                filename = os.path.basename(err.filename)
                msg = f'Unable to archive the package. Missing file: {filename}.'
                flash(msg, category='error')
                return None
    zip_object.close()
    return zipfile_path
def zip_package(current_document=None, eml_node=None):
    if (not current_document):
        current_document = current_user.get_filename()
    if (not current_document):
        raise FileNotFoundError
    if (not eml_node):
        eml_node = load_eml(filename=current_document)
    user_folder = user_data.get_user_folder_name()
    zipfile_name = f'{current_document}.zip'
    zipfile_path = os.path.join(user_folder, zipfile_name)
    zip_object = ZipFile(zipfile_path, 'w')
    manifest_files = []
    pathname = f'{user_folder}/{current_document}.json'
    arcname = f'{current_document}.json'
    zip_object.write(pathname, arcname)
    manifest_files.append(('JSON', f'{current_document}.json', pathname))
    package_id = user_data.get_active_packageid()
    if package_id:
        arcname = f'{package_id}.xml'
        copyfile(f'{user_folder}/{current_document}.xml', f'{user_folder}/{arcname}')
    else:
        arcname = f'{current_document}.xml'
    pathname = f'{user_folder}/{arcname}'
    manifest_files.append(('XML', arcname, pathname))
    zip_object.write(pathname, arcname)
    create_ezeml_package_manifest(user_folder, manifest_files)
    pathname = f'{user_folder}/ezEML_manifest.txt'
    arcname = 'ezEML_manifest.txt'
    zip_object.write(pathname, arcname)
    uploads_folder = user_data.get_document_uploads_folder_name()
    data_table_nodes = []
    eml_node.find_all_descendants(names.DATATABLE, data_table_nodes)
    entity_nodes = []
    eml_node.find_all_descendants(names.OTHERENTITY, entity_nodes)
    data_nodes = (data_table_nodes + entity_nodes)
    for data_node in data_nodes:
        object_name_node = data_node.find_single_node_by_path([names.PHYSICAL, names.OBJECTNAME])
        if object_name_node:
            object_name = object_name_node.content
            pathname = f'{uploads_folder}/{object_name}'
            arcname = f'data/{object_name}'
            try:
                zip_object.write(pathname, arcname)
            except FileNotFoundError as err:
                filename = os.path.basename(err.filename)
                msg = f'Unable to archive the package. Missing file: {filename}.'
                flash(msg, category='error')
                return None
    zip_object.close()
    return zipfile_path