예제 #1
0
def run_rbatch(**kwargs):
    """Run an R batch program with log file"""

    try:
        run = RunProgramDirective(kwargs)
        run.error_check('rbatch')

        # Get option
        option = run.option
        if not run.option:
            option = metadata.default_options['rbatch']
        if run.changedir:
            program = '"' + run.program + '"'
            default_log = os.path.join(run.program_path,
                                       run.program_name + '.Rout')
        else:
            program = '"' + os.path.join(run.program_path, run.program) + '"'
            default_log = os.path.join(os.getcwd(), run.program_name + '.Rout')

        # Get executable
        executable = run.executable
        if not run.executable:
            executable = metadata.default_executables['rbatch']

        command = metadata.commands['rbatch'] % (executable, option, program,
                                                 run.program_name + '.Rout')

        run.execute_run(command)
        run.move_log(default_log)
    except:
        add_error_to_log(run.makelog)
예제 #2
0
def run_stata(**kwargs):
    """Execute a Stata script 

    Description:
    This function executes a Stata script and produces a log file
    for this run.

    e.g. To run the script analysis.do with the default specifications,
         use the command:
        `run_stata(program = 'analysis.do')` or 
        `run_stata(program = 'analysis')` 

        To run analysis.do with StataSE as the executable instead:    
        `run_stata(program = 'analysis.do', executable = 'stataSE');`
    """

    try:
        run = RunProgramDirective(kwargs)
        run.error_check('stata')

        # Set option
        option = run.option
        if not option:
            if run.osname == 'posix':
                option = metadata.default_options['stataunix']
            else:
                option = metadata.default_options['statawin']

        # Set executable
        executable = run.executable
        if not executable:
            if run.osname == 'posix':
                executable = metadata.default_executables['stataunix']
            else:
                executable = metadata.default_executables['statawin']

        # Set default_log
        if run.changedir:
            program = '"' + run.program + '"'
            default_log = os.path.join(run.program_path,
                                       run.program_name + '.log')
        else:
            program = '"' + os.path.join(run.program_path, run.program) + '"'
            default_log = os.path.join(os.getcwd(), run.program_name + '.log')

        command = metadata.commands['stata'] % (executable, option, program)
        run.execute_run(command)

        run.move_log(default_log)
    except:
        add_error_to_log(run.makelog)
예제 #3
0
def run_sas(**kwargs):
    """Run a SAS script"""

    try:
        run = RunProgramDirective(kwargs)
        run.error_check('sas')

        # Get option
        option = run.option
        if not run.option:
            if run.osname != 'posix':
                option = metadata.default_options['saswin']

        # Get executable
        executable = run.executable
        if not run.executable:
            executable = metadata.default_executables['sas']

        # Get log, lst, and program
        if run.changedir:
            program = '"' + run.program + '"'
            default_log = os.path.join(run.program_path,
                                       run.program_name + '.log')
            default_lst = os.path.join(run.program_path,
                                       run.program_name + '.lst')
        else:
            program = '"' + os.path.join(run.program_path, run.program) + '"'
            default_log = os.path.join(os.getcwd(), run.program_name + '.log')
            default_lst = os.path.join(os.getcwd(), run.program_name + '.lst')

        if run.osname == 'posix':
            command = metadata.commands['sas'] % (executable, option, program)
        else:
            command = metadata.commands['sas'] % (executable, program, option)

        run.execute_run(command)
        run.move_log(default_log)
        run.move_lst(default_lst)
    except:
        add_error_to_log(run.makelog)
예제 #4
0
def run_matlab(**kwargs):
    """ Run a Matlab script

    Description:
    This function executes a Matlab script and produces a log file
    for this run. See private/metadata.py for its defaults.

    e.g. To run the script analysis.do with the default specifications,
         use the command:
        `run_matlab(program = 'analysis.m')` or 
        `run_matlab(program = 'analysis')` 
    """

    try:
        run = RunProgramDirective(kwargs)
        run.error_check('matlab')
        run.changedir = True

        # Get option
        option = run.option
        if not run.option:
            if run.osname == 'posix':
                option = metadata.default_options['matlabunix']
            else:
                option = metadata.default_options['matlabwin']
        # Get executable
        executable = run.executable
        if not run.executable:
            executable = metadata.default_executables['matlab']

        program = run.program_name
        default_log = os.path.join(run.program_path, run.program_name + '.log')
        command = metadata.commands['matlab'] % (
            executable, program, run.program_name + '.log', option)

        run.execute_run(command)
        run.move_log(default_log)
    except:
        add_error_to_log(run.makelog)