# Path: jasper_erpnext_report/utils/utils.py
# def jasper_report_names_from_db(origin="both", filters_report=None, filters_param=None, filters_permrole=None):
# def jasper_print_formats(doc):
# def validate_print_permission(doc):
# def import_all_jasper_remote_reports(docs, force=True):
# def check_queryString_with_param(query, param):
# def check_queryString_param(query, param):
# def get_default_param_value(param, error=True):
# def call_hook_for_param(doc, method, *args):
# def call_hook_for_param_with_default(doc, hook_name, *args):
# def testHookScriptlet(JasperScriptlet, ids, data, cols, cur_doctype, cur_docname):
# 		def __init__(self, JasperScriplet, ids=None, data=None, cols=None, doctype=None):
# 		def test(self, args):
# def make_jasper_hooks_path():
# def get_hook_module(hook_name, report_name=None):
# def jasper_run_method(hook_name, *args, **kargs):
# def jasper_run_method_once_with_default(hook_name, docname, default):
# def check_jasper_perm(perms, ptypes=("read",), user=None):
# 		def check_perm(perms, user_roles, ptype):
# def check_frappe_permission(doctype, docname, ptypes=("read", )):
# def jasper_users_login(user):
# def pipInstall(package=None):
# def get_Frappe_Version(version=None):
# def getFrappeVersion():
# def add_to_time_str(date=None, hours=0, days=0, weeks=0):
# 	def __init__(self, site, user):
# 	def __enter__(self):
# 	def __exit__(self, type, value, trace):
# 	class MyJasperCustomScripletDefault(JasperCustomScripletDefault):
# class FrappeContext:
# 
# Path: jasper_erpnext_report/utils/file.py
# def remove_directory(path, ignore_errors=True):
# 	import shutil
# 	shutil.rmtree(path, ignore_errors)


import frappe
	import ast
	import frappe.utils
from frappe import _
from jasper_erpnext_report.utils.utils import jaspersession_get_value,get_expiry_in_seconds,\
	get_jasper_data, get_jasper_session_expiry_seconds, getFrappeVersion
from jasper_erpnext_report.utils.file import remove_directory
	from memcache_stats import MemcachedStats
	from memcache_stats import MemcachedStats
	from memcache_stats import MemcachedStats
	from jasper_erpnext_report.utils.jasper_email import get_email_pdf_path
def clear_all_jasper_reports(force=True):
	deleted = force
	compiled_removed = 0
	emailed_removed = 0
	#to every intern_reqid is one local_report_ or from server?(to check)
	tabReqids = frappe.db.sql("select * from tabJasperReqids where reqid like 'intern_reqid_%'", as_dict=True)

	for m in tabReqids:
		d = m.get('data')
		req = ast.literal_eval(d)
		reqId = req.get("reqids")[0][0]
		data = jaspersession_get_value(reqId)
		if not force:
			deleted = _f(data)

		if deleted:

			if "local_report_" not in reqId:
					continue

			intern_reqid = m.get("reqid")

			try:

				if not data:
					d = frappe.db.sql("select * from tabJasperReqids where reqid='{0}'".format(reqId), as_dict=True)
					data = ast.literal_eval(d[0]['data'])

				file_path = data.get('result').get("uri").rsplit("/",1)
				compiled_path = file_path[0]

# Path: jasper_erpnext_report/utils/utils.py
# def jasper_report_names_from_db(origin="both", filters_report=None, filters_param=None, filters_permrole=None):
# def jasper_print_formats(doc):
# def validate_print_permission(doc):
# def import_all_jasper_remote_reports(docs, force=True):
# def check_queryString_with_param(query, param):
# def check_queryString_param(query, param):
# def get_default_param_value(param, error=True):
# def call_hook_for_param(doc, method, *args):
# def call_hook_for_param_with_default(doc, hook_name, *args):
# def testHookScriptlet(JasperScriptlet, ids, data, cols, cur_doctype, cur_docname):
# 		def __init__(self, JasperScriplet, ids=None, data=None, cols=None, doctype=None):
# 		def test(self, args):
# def make_jasper_hooks_path():
# def get_hook_module(hook_name, report_name=None):
# def jasper_run_method(hook_name, *args, **kargs):
# def jasper_run_method_once_with_default(hook_name, docname, default):
# def check_jasper_perm(perms, ptypes=("read",), user=None):
# 		def check_perm(perms, user_roles, ptype):
# def check_frappe_permission(doctype, docname, ptypes=("read", )):
# def jasper_users_login(user):
# def pipInstall(package=None):
# def get_Frappe_Version(version=None):
# def getFrappeVersion():
# def add_to_time_str(date=None, hours=0, days=0, weeks=0):
# 	def __init__(self, site, user):
# 	def __enter__(self):
# 	def __exit__(self, type, value, trace):
# 	class MyJasperCustomScripletDefault(JasperCustomScripletDefault):
# class FrappeContext:
# 
# Path: jasper_erpnext_report/utils/file.py
# def remove_directory(path, ignore_errors=True):
# 	import shutil
# 	shutil.rmtree(path, ignore_errors)


# Path: jasper_erpnext_report/utils/scheduler.py
import frappe
	import ast
	import frappe.utils
from frappe import _
from jasper_erpnext_report.utils.utils import jaspersession_get_value,get_expiry_in_seconds,\
	get_jasper_data, get_jasper_session_expiry_seconds, getFrappeVersion
from jasper_erpnext_report.utils.file import remove_directory
	from memcache_stats import MemcachedStats
	from memcache_stats import MemcachedStats
	from memcache_stats import MemcachedStats
	from jasper_erpnext_report.utils.jasper_email import get_email_pdf_path

def clear_all_jasper_reports(force=True):
	deleted = force
	compiled_removed = 0
	emailed_removed = 0
	#to every intern_reqid is one local_report_ or from server?(to check)
	tabReqids = frappe.db.sql("select * from tabJasperReqids where reqid like 'intern_reqid_%'", as_dict=True)

	for m in tabReqids:
		d = m.get('data')
		req = ast.literal_eval(d)
		reqId = req.get("reqids")[0][0]
		data = jaspersession_get_value(reqId)
		if not force:
			deleted = _f(data)

		if deleted:

			if "local_report_" not in reqId:
					continue

			intern_reqid = m.get("reqid")

			try:

				if not data:
					d = frappe.db.sql("select * from tabJasperReqids where reqid='{0}'".format(reqId), as_dict=True)
					data = ast.literal_eval(d[0]['data'])

				file_path = data.get('result').get("uri").rsplit("/",1)
				compiled_path = file_path[0]

				remove_directory(compiled_path)