# 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
					values = getattr(frappe_doc, field)

				value = self.get_param_values(values)
				print "value do_params %s" % value

			else:
				#value sent take precedence from value in doctype jasper_param_value
				values = data.get("params", {}).get(p) or param.jasper_param_value or ""
				value = self.get_param_values(values)


			if param.jasper_param_type != "String":
				for idx, val in enumerate(value):
					value[idx] = str(val)
			"""
			if param.jasper_param_type == "Int":
				from jasper_erpnext_report.jasper_reports import Integer
				for idx, val in enumerate(value):
					value[idx] = Integer(val)
			"""

			pram.append({"name":p, 'value':value})

		return (pram, pram_server, copies)

	def get_reports_list_from_db(self, filters_report=None, filters_param=None):
		return utils.jasper_report_names_from_db(origin=self.get_report_origin(), filters_report=filters_report, filters_param=filters_param)

	def get_query_jrxmlFile_from_server(self, file_content):
		query = ""

# 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

					values = getattr(frappe_doc, field)

				value = self.get_param_values(values)
				print "value do_params %s" % value

			else:
				#value sent take precedence from value in doctype jasper_param_value
				values = data.get("params", {}).get(p) or param.jasper_param_value or ""
				value = self.get_param_values(values)


			if param.jasper_param_type != "String":
				for idx, val in enumerate(value):
					value[idx] = str(val)
			"""
			if param.jasper_param_type == "Int":
				from jasper_erpnext_report.jasper_reports import Integer
				for idx, val in enumerate(value):
					value[idx] = Integer(val)
			"""

			pram.append({"name":p, 'value':value})

		return (pram, pram_server, copies)

	def get_reports_list_from_db(self, filters_report=None, filters_param=None):
		return utils.jasper_report_names_from_db(origin=self.get_report_origin(), filters_report=filters_report, filters_param=filters_param)

	def get_query_jrxmlFile_from_server(self, file_content):
		query = ""

		xmldoc = JasperXmlReport(BytesIO(file_content))