refactor: use gzip library's compress() and decompress() methods directly (backport #37611) (#37621)
refactor: use gzip library's compress() and decompress() methods directly (#37611) The util methods in framework were added for python2.7 compat, so can be removed Signed-off-by: Akhil Narang <me@akhilnarang.dev> [skip ci] (cherry picked from commit 21c3d9c3712ffca28d763b560ec8dbc9e5512fb0) Co-authored-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
parent
9863ba5fd8
commit
bdb369e2b4
@ -1,6 +1,6 @@
|
|||||||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
import gzip
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
@ -8,7 +8,7 @@ from frappe import _
|
|||||||
from frappe.core.doctype.prepared_report.prepared_report import create_json_gz_file
|
from frappe.core.doctype.prepared_report.prepared_report import create_json_gz_file
|
||||||
from frappe.desk.form.load import get_attachments
|
from frappe.desk.form.load import get_attachments
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import get_link_to_form, gzip_decompress, parse_json
|
from frappe.utils import get_link_to_form, parse_json
|
||||||
from frappe.utils.background_jobs import enqueue
|
from frappe.utils.background_jobs import enqueue
|
||||||
|
|
||||||
from erpnext.stock.report.stock_balance.stock_balance import execute
|
from erpnext.stock.report.stock_balance.stock_balance import execute
|
||||||
@ -109,7 +109,7 @@ class ClosingStockBalance(Document):
|
|||||||
attachment = attachments[0]
|
attachment = attachments[0]
|
||||||
attached_file = frappe.get_doc("File", attachment.name)
|
attached_file = frappe.get_doc("File", attachment.name)
|
||||||
|
|
||||||
data = gzip_decompress(attached_file.get_content())
|
data = gzip.decompress(attached_file.get_content())
|
||||||
if data := json.loads(data.decode("utf-8")):
|
if data := json.loads(data.decode("utf-8")):
|
||||||
data = data
|
data = data
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
import gzip
|
||||||
import json
|
import json
|
||||||
from typing import Optional, Set, Tuple
|
from typing import Optional, Set, Tuple
|
||||||
|
|
||||||
@ -10,17 +11,7 @@ from frappe import _, scrub
|
|||||||
from frappe.model.meta import get_field_precision
|
from frappe.model.meta import get_field_precision
|
||||||
from frappe.query_builder import Case
|
from frappe.query_builder import Case
|
||||||
from frappe.query_builder.functions import CombineDatetime, Sum
|
from frappe.query_builder.functions import CombineDatetime, Sum
|
||||||
from frappe.utils import (
|
from frappe.utils import cint, flt, get_link_to_form, getdate, now, nowdate, parse_json
|
||||||
cint,
|
|
||||||
flt,
|
|
||||||
get_link_to_form,
|
|
||||||
getdate,
|
|
||||||
gzip_compress,
|
|
||||||
gzip_decompress,
|
|
||||||
now,
|
|
||||||
nowdate,
|
|
||||||
parse_json,
|
|
||||||
)
|
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
from erpnext.stock.doctype.bin.bin import update_qty as update_bin_qty
|
from erpnext.stock.doctype.bin.bin import update_qty as update_bin_qty
|
||||||
@ -295,7 +286,7 @@ def get_reposting_data(file_path) -> dict:
|
|||||||
|
|
||||||
attached_file = frappe.get_doc("File", file_name)
|
attached_file = frappe.get_doc("File", file_name)
|
||||||
|
|
||||||
data = gzip_decompress(attached_file.get_content())
|
data = gzip.decompress(attached_file.get_content())
|
||||||
if data := json.loads(data.decode("utf-8")):
|
if data := json.loads(data.decode("utf-8")):
|
||||||
data = data
|
data = data
|
||||||
|
|
||||||
@ -378,7 +369,7 @@ def get_reposting_file_name(dt, dn):
|
|||||||
|
|
||||||
def create_json_gz_file(data, doc, file_name=None) -> str:
|
def create_json_gz_file(data, doc, file_name=None) -> str:
|
||||||
encoded_content = frappe.safe_encode(frappe.as_json(data))
|
encoded_content = frappe.safe_encode(frappe.as_json(data))
|
||||||
compressed_content = gzip_compress(encoded_content)
|
compressed_content = gzip.compress(encoded_content)
|
||||||
|
|
||||||
if not file_name:
|
if not file_name:
|
||||||
json_filename = f"{scrub(doc.doctype)}-{scrub(doc.name)}.json.gz"
|
json_filename = f"{scrub(doc.doctype)}-{scrub(doc.name)}.json.gz"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user