# Path: waflib/TaskGen.py
# HEADER_EXTS = ['.h', '.hpp', '.hxx', '.hh']
# class task_gen(object):
# class subst_pc(Task.Task):
# class subst(subst_pc):
# 	def __init__(self, *k, **kw):
# 	def __str__(self):
# 	def __repr__(self):
# 	def get_cwd(self):
# 	def get_name(self):
# 	def set_name(self, name):
# 	def to_list(self, val):
# 	def post(self):
# 	def get_hook(self, node):
# 	def create_task(self, name, src=None, tgt=None, **kw):
# 	def clone(self, env):
# def declare_chain(name='', rule=None, reentrant=None, color='BLUE',
# 	ext_in=[], ext_out=[], before=[], after=[], decider=None, scan=None, install_path=None, shell=False):
# 	def x_file(self, node):
# def taskgen_method(func):
# def feature(*k):
# 	def deco(func):
# def before_method(*k):
# 	def deco(func):
# def after_method(*k):
# 	def deco(func):
# def extension(*k):
# 	def deco(func):
# def to_nodes(self, lst, path=None):
# def process_source(self):
# def process_rule(self):
# 			def chmod_fun(tsk):
# 			def scan(self):
# def sequence_order(self):
# 	def force_permissions(self):
# 	def run(self):
# 		def repl(match):
# 	def sig_vars(self):
# def add_pcfile(self, node):
# def process_subst(self):


import os, sys
from waflib import Task, TaskGen, Logs
Else:\n
	Do not load the 'run_r_script' tool in the main wscript.\n\n"""  % R_COMMANDS)
	ctx.env.RFLAGS = 'CMD BATCH --slave'

class run_r_script_base(Task.Task):
	"""Run a R script."""
	run_str = '"${RCMD}" ${RFLAGS} "${SRC[0].abspath()}" "${LOGFILEPATH}"'
	shell = True

class run_r_script(run_r_script_base):
	"""Erase the R overall log file if everything went okay, else raise an
	error and print its 10 last lines.
	"""
	def run(self):
		ret = run_r_script_base.run(self)
		logfile = self.env.LOGFILEPATH
		if ret:
			mode = 'r'
			if sys.version_info.major >= 3:
				mode = 'rb'
			with open(logfile, mode=mode) as f:
				tail = f.readlines()[-10:]
			Logs.error("""Running R on %r returned the error %r\n\nCheck the log file %s, last 10 lines\n\n%s\n\n\n""",
				self.inputs[0], ret, logfile, '\n'.join(tail))
		else:
			os.remove(logfile)
		return ret


@TaskGen.feature('run_r_script')

# Path: waflib/TaskGen.py
# HEADER_EXTS = ['.h', '.hpp', '.hxx', '.hh']
# class task_gen(object):
# class subst_pc(Task.Task):
# class subst(subst_pc):
# 	def __init__(self, *k, **kw):
# 	def __str__(self):
# 	def __repr__(self):
# 	def get_cwd(self):
# 	def get_name(self):
# 	def set_name(self, name):
# 	def to_list(self, val):
# 	def post(self):
# 	def get_hook(self, node):
# 	def create_task(self, name, src=None, tgt=None, **kw):
# 	def clone(self, env):
# def declare_chain(name='', rule=None, reentrant=None, color='BLUE',
# 	ext_in=[], ext_out=[], before=[], after=[], decider=None, scan=None, install_path=None, shell=False):
# 	def x_file(self, node):
# def taskgen_method(func):
# def feature(*k):
# 	def deco(func):
# def before_method(*k):
# 	def deco(func):
# def after_method(*k):
# 	def deco(func):
# def extension(*k):
# 	def deco(func):
# def to_nodes(self, lst, path=None):
# def process_source(self):
# def process_rule(self):
# 			def chmod_fun(tsk):
# 			def scan(self):
# def sequence_order(self):
# 	def force_permissions(self):
# 	def run(self):
# 		def repl(match):
# 	def sig_vars(self):
# def add_pcfile(self, node):
# def process_subst(self):


# Path: waflib/extras/run_r_script.py
import os, sys
from waflib import Task, TaskGen, Logs

Else:\n
	Do not load the 'run_r_script' tool in the main wscript.\n\n"""  % R_COMMANDS)
	ctx.env.RFLAGS = 'CMD BATCH --slave'

class run_r_script_base(Task.Task):
	"""Run a R script."""
	run_str = '"${RCMD}" ${RFLAGS} "${SRC[0].abspath()}" "${LOGFILEPATH}"'
	shell = True

class run_r_script(run_r_script_base):
	"""Erase the R overall log file if everything went okay, else raise an
	error and print its 10 last lines.
	"""
	def run(self):
		ret = run_r_script_base.run(self)
		logfile = self.env.LOGFILEPATH
		if ret:
			mode = 'r'
			if sys.version_info.major >= 3:
				mode = 'rb'
			with open(logfile, mode=mode) as f:
				tail = f.readlines()[-10:]
			Logs.error("""Running R on %r returned the error %r\n\nCheck the log file %s, last 10 lines\n\n%s\n\n\n""",
				self.inputs[0], ret, logfile, '\n'.join(tail))
		else:
			os.remove(logfile)
		return ret


@TaskGen.feature('run_r_script')

@TaskGen.before_method('process_source')