'Unzip current file and replace it by its children'

def unzip(self):

    if (not (u'.zip' in self.file_name)):
        frappe.msgprint(_(u'Not    a    zip    file'))
        return
    zip_path = frappe.get_site_path(self.file_url.strip(u'/'))
    base_url = os.path.dirname(self.file_url)
    with zipfile.ZipFile(zip_path) as zf:
        zf.extractall(os.path.dirname(zip_path))
        for info in zf.infolist():
            if (not info.filename.startswith(u'__MACOSX')):
                file_url = file_url = ((base_url + u'/') + info.filename)
                file_name = frappe.db.get_value(u'File', dict(file_url=file_url))
                if file_name:
                    file_doc = frappe.get_doc(u'File', file_name)
                else:
                    file_doc = frappe.new_doc(u'File')
                file_doc.file_name = info.filename
                file_doc.file_size = info.file_size
                file_doc.folder = self.folder
                file_doc.is_private = self.is_private
                file_doc.file_url = file_url
                file_doc.attached_to_doctype = self.attached_to_doctype
                file_doc.attached_to_name = self.attached_to_name
                file_doc.save()
    frappe.delete_doc(u'File', self.name)
