# Path: jasper_erpnext_report/utils/file.py
# def get_file(path, modes="r", raise_not_found=False):
# 	if modes != "r":
# 		content = read_file(path, modes=modes, raise_not_found=raise_not_found)
# 	else:
# 		content = frappe.read_file(path, raise_not_found=raise_not_found)
# 
# 	return content
# 
# def get_html_reports_images_path(report_path, where="images"):
# 	path = os.path.join(report_path, where)
# 	frappe.create_folder(path)
# 	return path
# 
# Path: jasper_erpnext_report/utils/file.py
# def get_image_name(iname):
# def get_images_path(compiled_path):
# def get_jasper_path(for_all_sites = False):
# def write_StringIO_to_file(file_path, output):
# def write_file(content, file_path, modes="w+"):
# def check_extension(fname):
# def get_extension(fname):
# def remove_from_doc(dt, dn, field, where_field = "name"):
# def delete_from_doc(dt, dn, field, value, where_field):
# def delete_from_FileData(dt, dn, file_url):
# def remove_directory(path, ignore_errors=True):
# def remove_compiled_report(root_path):
# def get_file(path, modes="r", raise_not_found=False):
# def read_file(path, modes="r", raise_not_found=False):
# def get_html_reports_path(report_name, where="reports", hash=None, localsite=None):
# def get_html_reports_images_path(report_path, where="images"):


from frappe.model.document import Document
from frappe import _
from io import BytesIO
from jasper_erpnext_report.utils.file import get_file, get_html_reports_images_path
from jasper_erpnext_report.utils.file import JasperXmlReport, get_html_reports_path
		from distutils.dir_util import copy_tree
		from jasper_erpnext_report.utils.utils import getFrappeVersion
import frappe
import uuid, os
import jasper_erpnext_report.utils.utils as utils
							import re
		import hashlib
			import frappe.utils.email_lib
			import frappe.email
		if data:
			d = data['data']
			for ids in d.get('reqids'):
				for id in ids:
					res = self.polling(id)
					if not res:
						frappe.msgprint(_("There was an error in report request."),raise_exception=True)
					if res.get('status', "not ready") != "ready":
						result = []
						error = res.get("error", None)
						break
					result.append(res)
				if not result:
					break
			for r in result:
				new_data = {"data":{"result": r, "report_name": report_name, "last_updated": frappe.utils.now(), 'session_expiry': d.get('session_expiry')}}
				self.update_jasper_reqid_record(r.get('requestId'), new_data)
			if result:
				req = [{"requestId": reqId, "reqtime": frappe.utils.now(), "status": "ready"}]
		else:
			frappe.throw(_("Report Not Found."))
		if error:
			req[0]["error"] = error
		return req

	def get_html_path(self, report_name, localsite=None, content=None):
		site = localsite or frappe.local.site
		if not self.html_hash:
			hash_obj = hashlib.md5(frappe.utils.encode(content))
			self.html_hash = hash_obj.hexdigest()

# Path: jasper_erpnext_report/utils/file.py
# def get_file(path, modes="r", raise_not_found=False):
# 	if modes != "r":
# 		content = read_file(path, modes=modes, raise_not_found=raise_not_found)
# 	else:
# 		content = frappe.read_file(path, raise_not_found=raise_not_found)
# 
# 	return content
# 
# def get_html_reports_images_path(report_path, where="images"):
# 	path = os.path.join(report_path, where)
# 	frappe.create_folder(path)
# 	return path
# 
# Path: jasper_erpnext_report/utils/file.py
# def get_image_name(iname):
# def get_images_path(compiled_path):
# def get_jasper_path(for_all_sites = False):
# def write_StringIO_to_file(file_path, output):
# def write_file(content, file_path, modes="w+"):
# def check_extension(fname):
# def get_extension(fname):
# def remove_from_doc(dt, dn, field, where_field = "name"):
# def delete_from_doc(dt, dn, field, value, where_field):
# def delete_from_FileData(dt, dn, file_url):
# def remove_directory(path, ignore_errors=True):
# def remove_compiled_report(root_path):
# def get_file(path, modes="r", raise_not_found=False):
# def read_file(path, modes="r", raise_not_found=False):
# def get_html_reports_path(report_name, where="reports", hash=None, localsite=None):
# def get_html_reports_images_path(report_path, where="images"):


# Path: jasper_erpnext_report/core/JasperBase.py
from frappe.model.document import Document
from frappe import _
from io import BytesIO
from jasper_erpnext_report.utils.file import get_file, get_html_reports_images_path
from jasper_erpnext_report.utils.file import JasperXmlReport, get_html_reports_path
		from distutils.dir_util import copy_tree
		from jasper_erpnext_report.utils.utils import getFrappeVersion
import frappe
import uuid, os
import jasper_erpnext_report.utils.utils as utils
							import re
		import hashlib
			import frappe.utils.email_lib
			import frappe.email

		if data:
			d = data['data']
			for ids in d.get('reqids'):
				for id in ids:
					res = self.polling(id)
					if not res:
						frappe.msgprint(_("There was an error in report request."),raise_exception=True)
					if res.get('status', "not ready") != "ready":
						result = []
						error = res.get("error", None)
						break
					result.append(res)
				if not result:
					break
			for r in result:
				new_data = {"data":{"result": r, "report_name": report_name, "last_updated": frappe.utils.now(), 'session_expiry': d.get('session_expiry')}}
				self.update_jasper_reqid_record(r.get('requestId'), new_data)
			if result:
				req = [{"requestId": reqId, "reqtime": frappe.utils.now(), "status": "ready"}]
		else:
			frappe.throw(_("Report Not Found."))
		if error:
			req[0]["error"] = error
		return req

	def get_html_path(self, report_name, localsite=None, content=None):
		site = localsite or frappe.local.site
		if not self.html_hash:
			hash_obj = hashlib.md5(frappe.utils.encode(content))
			self.html_hash = hash_obj.hexdigest()

		self.report_html_path = get_html_reports_path(report_name, localsite=site, hash=self.html_hash)