Exemplo n.º 1
0
 def test_is_64_windows(self):
     '''
     Test that is_64_windows() returns True when PROGRAMFILES(X86)
     is a key in the system environment as accessed through 
     os.environ.
     '''
     environ = 'gslab_scons.misc.os.environ'
     mocked_environ = {'PROGRAMFILES(X86)': 'C:/Program Files (x86)'}
     with mock.patch(environ, mocked_environ):
         self.assertTrue(misc.is_64_windows())
     with mock.patch(environ, dict()):
         self.assertFalse(misc.is_64_windows())
Exemplo n.º 2
0
def check_stata(sf):
    import gslab_scons.misc as misc
    command = ''
    flavors = ['stata-mp', 'stata-se', 'stata']
    if sf is not None:
        flavors = [sf] + flavors
    if misc.is_unix():
        for flavor in flavors:
            if misc.is_in_path(flavor):
                command = misc.stata_command_unix(flavor)
                break
    elif sys.platform == 'win32':
        try:
            key_exist = os.environ['STATAEXE'] is not None
            command = misc.stata_command_win("%%STATAEXE%%")
        except KeyError:
            flavors = [(f.replace('-', '') + '.exe') for f in flavors]
            if misc.is_64_windows():
                flavors = [f.replace('.exe', '-64.exe') for f in flavors]
            for flavor in flavors:
                if misc.is_in_path(flavor):
                    command = misc.stata_command_win(flavor)
                    break
    if command == '':
        raise PrerequisiteError(
            'Stata is not installed or excecutable is not added to path')

    check_stata_packages(command)
Exemplo n.º 3
0
def build_stata(target, source, env):
    '''Build targets with a Stata command
 
    This function executes a Stata script to build objects specified
    by target using the objects specified by source.

    Parameters
    ----------
    target: string or list 
        The target(s) of the SCons command.
    source: string or list
        The source(s) of the SCons command. The first source specified
        should be the Stata .do script that the builder is intended to 
        execute. 

    Note: the user can specify a flavour by typing `scons sf=StataMP` 
    (By default, SCons will try to find each flavour). 
    '''
    cl_arg = misc.command_line_args(env)

    source = misc.make_list_if_string(source)
    target = misc.make_list_if_string(target)
    source_file = str(source[0])
    target_file = str(target[0])
    target_dir = misc.get_directory(target_file)

    start_time = misc.current_time()

    misc.check_code_extension(source_file, 'stata')
    log_file = target_dir + '/sconscript.log'
    loc_log = os.path.basename(source_file).replace('.do', '.log')

    user_flavor = env['user_flavor']
    if user_flavor is not None:
        if misc.is_unix():
            command = misc.stata_command_unix(user_flavor, cl_arg)
        elif sys.platform == 'win32':
            command = misc.stata_command_win(user_flavor, cl_arg)
    else:
        flavors = ['stata-mp', 'stata-se', 'stata']
        if misc.is_unix():
            for flavor in flavors:
                if misc.is_in_path(flavor):
                    command = misc.stata_command_unix(flavor, cl_arg)
                    break
        elif sys.platform == 'win32':
            try:
                key_exist = os.environ['STATAEXE'] is not None
                command = misc.stata_command_win("%%STATAEXE%%")
            except KeyError:
                flavors = [(f.replace('-', '') + '.exe') for f in flavors]
                if misc.is_64_windows():
                    flavors = [f.replace('.exe', '-64.exe') for f in flavors]
                for flavor in flavors:
                    if misc.is_in_path(flavor):
                        command = misc.stata_command_win(flavor, cl_arg)
                        break

    try:
        subprocess.check_output(command % source_file,
                                stderr=subprocess.STDOUT,
                                shell=True)
    except subprocess.CalledProcessError:
        raise BadExecutableError('Could not find executable.')

    shutil.move(loc_log, log_file)
    end_time = misc.current_time()
    log_timestamp(start_time, end_time, log_file)
    return None