# 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
	return removed

#to be called from terminal: bench frappe --execute jasper_erpnext_report.utils.scheduler.clear_all_jasper_user_cache_v4 to force clear cache
def clear_all_jasper_user_cache_v4(force=True):
	removed = 0
	#use memcache_stats for delete any cache that remains
	memc = MemcachedStats()
	for m in memc.keys():
		if "jasper:user" in m:
			if force:
				#remove site from key
				value = m.split(":", 1)
				frappe.cache().delete_value(value[1])
				removed += 1
			else:
				#remove jasper from key
				value = m.split(":", 1)
				v = value[1].split(":", 1)
				deleted = check_if_expire(v[1])
				if deleted:
					frappe.cache().delete_value(value[1])
					removed += 1
	if removed == 0:
		print _("No user cache was removed.")
	else:
		print _("Was removed {0} user cache(s)".format(removed))
	return removed


def check_if_expire(reqId):

# 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

	return removed

#to be called from terminal: bench frappe --execute jasper_erpnext_report.utils.scheduler.clear_all_jasper_user_cache_v4 to force clear cache
def clear_all_jasper_user_cache_v4(force=True):
	removed = 0
	#use memcache_stats for delete any cache that remains
	memc = MemcachedStats()
	for m in memc.keys():
		if "jasper:user" in m:
			if force:
				#remove site from key
				value = m.split(":", 1)
				frappe.cache().delete_value(value[1])
				removed += 1
			else:
				#remove jasper from key
				value = m.split(":", 1)
				v = value[1].split(":", 1)
				deleted = check_if_expire(v[1])
				if deleted:
					frappe.cache().delete_value(value[1])
					removed += 1
	if removed == 0:
		print _("No user cache was removed.")
	else:
		print _("Was removed {0} user cache(s)".format(removed))
	return removed


def check_if_expire(reqId):

	req = jaspersession_get_value(reqId)