def test_rawlaunch():
    a = Envi()
    configs = ['envipython1'] # the name of the application here is not relevant
    configs.append("-c dev_show")  # version

    os.environ['DSK_ENGINE'] = "maya-unitest"
    #try:
    #    a.execute(configs,True)
    #except Exception,e:
    #    print(str(e))

    #configs = ['envipython2']
    #configs.append("-p sgtkstudio_maya") # repo dev

    #try:
    #    a.execute(configs,True)
    #except Exception,e:
    #    print(str(e))

    #configs = ['envipython3']
    #configs.append("-c maya_prod") # get basic maya env
    configs.append("-c inhouse_maya") # get basic maya env
    #configs.extend(modedev) # include the 'rnd' environment
    configs.append("-p clean_prepath") # collapse pre_path
    # launch mayapy

    configs.append("-p studio_sgtk") # sgtk module is needed for
    configs.append("-d") # for user config
    configs.append("-a %s" % APP)

    try:
        a.execute(configs,True)
    except Exception,e:
        print(str(e))
Exemple #2
0
    def project_configuration(cls,
                              dskenvpath,
                              project_name="",
                              with_system=False,
                              user_file="",
                              user_login=""):
        """This is a query to return the basic configuration for a show

            :param    dskenvpath: envi config root
            :param    project_name: (str)
            :param    user_login: (str) default= ""
            :param    with_system = False
            :param    user_file: an optional user config

        """

        result = list()
        pr = ProdEnv(dskenvpath)
        res = list()
        if pr.is_valid():
            confpacks_list = cls._get_initshow_envi_config(
                project_name=project_name,
                with_system=with_system,
                user_file=user_file)

            for confpacks in confpacks_list:
                valid_command = list()
                res = list()
                for c_or_p, cp in cls._pairwise(confpacks):
                    if user_login != "":
                        valid_command.append("%s %s -D %s" %
                                             (c_or_p, cp, user_login))
                    else:
                        valid_command.append("%s %s" % (c_or_p, cp))

                envi = Envi()
                envi.init_with_cmd(valid_command)
                valid_names = [
                    pp.base for pp in envi.configsObject + envi.packsObject
                ]

                for c_or_p, cp in cls._pairwise(confpacks):
                    if cp in valid_names:
                        res.extend([c_or_p, cp])
                if len(res) > 0:
                    if user_login != "":
                        res.extend(['-D', user_login])

                    result.append(res)

        cleanresult = list()
        # clear empty list
        for x in result:
            if len(x) > 0:
                cleanresult.append(x)

        pr.back_to_global()
        return cleanresult
def test_rawlaunch():
    a = Envi()
    configs = ['envipython1'
               ]  # the name of the application here is not relevant
    configs.append("-c dev_show")  # version

    try:
        a.execute(configs, True)
    except Exception, e:
        print(str(e))
Exemple #4
0
    def launch_batch_file_with_console(filetoexecute,
                                       console='gnome-terminal',
                                       clean_tmp_dir=False,
                                       hold=True):
        """Same as launch_batch_file, with an optional console

            :param filetoexecute: a valid batch file
            :type filetoexecute: a valid executable file on disk
            :param console: (str) default = xterm
            :type console: (str) xterm or konsole or gnome-terminal
            :param clean_tmp_dir: option to remove the file
            :type clean_tmp_dir: bool, default = False
            :param hold: option keep the window up
            :type hold: bool, default = True
            :returns None: no return value

        """
        # console = 'gnome-terminal'
        # hold = False
        # assert console in ['xterm','konsole','gnome-terminal']
        '''
        cmds = list()
        cmds.append("gnome-terminal")
        cmds.append("-x")
        cmds.append("bash")
        cmds.append("-ic")
        #cmds.append("-e")
        cmds.append(filetoexecute)
        #cmds.append('-x bash')
        #cmds.append("-e %s" % filetoexecute)
        process_get_output(cmds)
        #subprocess.Popen(cmds,
        #                 close_fds=True,
        #                 env=get_dict_environ_envi())
        '''
        os.system("gnome-terminal -x bash -ic %r" % filetoexecute)
        return
        if hold:
            cmds = [console, '-hold', '-e', filetoexecute]
        else:
            cmds = [console, '-e', filetoexecute]
        if clean_tmp_dir:
            process_get_output(cmds)
            Envi.cleanup_temp_dir()
        else:
            subprocess.Popen(cmds, close_fds=True, env=get_dict_environ_envi())
Exemple #5
0
    def launch_batch_file(filetoexecute, clean_tmp_dir=False):
        """Exec the given file.

            :param filetoexecute: a valid batch file
            :type filetoexecute: a valid executable file on disk
            :param clean_tmp_dir: option to remove the file
            :type clean_tmp_dir: bool, default = False (NOT SUPPORTED, IGNORED)

            :return None:

        """
        if clean_tmp_dir:
            process_get_output(filetoexecute)
            Envi.cleanup_temp_dir()
        else:
            subprocess.Popen(filetoexecute,
                             close_fds=True,
                             env=get_dict_environ_envi())
Exemple #6
0
    def get_base_platform_config(cls):
        """Entry point for envi when it knows project_name

            :param project_name: (str) a project sgtk name

            :return str:  the base config for that project
                (default 'studio' if empty)

        """
        return Envi.pack_system()
Exemple #7
0
    def do_execute(x, dskenvpath):
        """Execute envi command in a specific environment

            :param x: list of envi command as single option or pack
            :param    dskenvpath: envi config root

        """
        pr = ProdEnv(dskenvpath)
        for xx in x:
            xx.insert(0, "do_execute")
            Envi().execute(xx, True)
        pr.back_to_global()
Exemple #8
0
def get_config_files():
    """
        Envi is a python package to build environment
        variable base on package
    """

    main_dev = os.path.join(os.environ.get("DSKENV", "/"), 'python')
    if not os.path.exists(main_dev):
        return []
    sys.path.insert(0, main_dev)

    try:
        from dskenv.envi import Envi
    except Exception as e:
        print("Error No envi %s" % str(e))
        return list()
    cmd = os.environ.get("CMS_ESN", None)
    if cmd:
        Envi().execute(["from_flask", cmd], True)
        return list(filter(lambda x: x != '',
                           os.environ.get(
                               'ESN_CONF_FILE', "").split(os.pathsep)))
    return list()
Exemple #9
0
def test_compare_os_env():

    from dskenv import base_env
    Env = Envi()
    Env.info_from_environment()
    Env.do_eval_pack()
    Env.build_history_variable()
    d = Env.get_environ(withRemoveCmd=True)
    Env.expand_vars(d)
    dos = dict()
    dos.update(os.environ)

    exp = base_env.keyEnvi -1 # hack for now, since we remove a key
    if len(d) != len(dos):
        assert len(d)- len(exp) == len(dos)
        # copy the missing key
        for i in exp:
            if i in d and not i in dos:
                dos[i] = d[i]
    assert sorted(dos.keys()) == sorted(d.keys())
    # 2 of the key _BASE_CURRENT_PACKAGES and _BASE_CURRENT_CONFIGS
    # we just remove the leading : of those 2 key
    #for e in exp:
    #    while dos[e].startswith(os.pathsep):
    #        dos[e] = dos[e][1:]
    # compare the final
    assert dos == d
Exemple #10
0
def test_get_cmd():
    Env = Envi()
    Env.info_from_environment()
    b = Envi()
    b.init_with_cmd(Env.get_commands())
    Env.do_eval_pack()
    b.do_eval_pack()

    assert Env.get_environ(withRemoveCmd=False) == b.get_environ(withRemoveCmd=False)
Exemple #11
0
def test_init_with_cmd():
    Env = Envi()
    Env.info_from_environment()
    b = Envi()
    b.init_with_cmd(Env.get_commands())
    assert Env.get_commands()==b.get_commands()
Exemple #12
0
def test_possible_run_config():
    # only base should be run when running this test
    Env = Envi()
    Env.info_from_environment()
    cmd = Env.get_commands()
    assert cmd == "-p base_envi" or cmd == []
Exemple #13
0
def test_info_from_environment():
    Env = Envi()
    # see if we can read the content of the environmement
    assert Env.info_from_environment()
Exemple #14
0
    def configuration(cls,
                      dskenvpath,
                      project_name="",
                      app_name="",
                      sgtk_path="",
                      user_login="",
                      with_system=False,
                      with_sgtk=False,
                      with_base=False,
                      with_td=True):
        """Same as get_default_envi_config but add configs
            if they exists only Also add user option

            :param    dskenvpath: envi config root
            :param    project_name: (str)
            :param    app_name: (str)
            :param    sgtk_path: (path) default = ""
            :param    user_login: (str) default = ""
            :param    with_base: (bool) default=False
                        start with config project_name
            :param    with_system: (bool) default=False
                        add platform specific default
            :param    with_sgtk: (bool) add the studio pack

        """

        pr = ProdEnv(dskenvpath)
        result = list()
        if pr.is_valid():
            confpacks_list = cls._get_default_envi_config(
                project_name=project_name,
                app_name=app_name,
                sgtk_path=sgtk_path,
                with_system=with_system,
                with_sgtk=with_sgtk,
                with_base=with_base,
                with_td=with_td)

            for confpacks in confpacks_list:
                valid_command = list()
                res = list()
                for c_or_p, cp in cls._pairwise(confpacks):
                    if user_login != "":
                        valid_command.append("%s %s -D %s" %
                                             (c_or_p, cp, user_login))
                    else:
                        valid_command.append("%s %s" % (c_or_p, cp))
                envi = Envi()
                envi.init_with_cmd(valid_command)
                valid_names = [
                    pp.base for pp in envi.configsObject + envi.packsObject
                ]

                for c_or_p, cp in cls._pairwise(confpacks):
                    if cp in valid_names:
                        res.extend([c_or_p, cp])
                if user_login != "" and len(res) > 0:
                    res.extend(['-D', user_login])
                result.append(res)

        cleanresult = list()
        # clear empty list
        for x in result:
            if len(x) > 0:
                cleanresult.append(x)

        pr.back_to_global()
        return cleanresult
Exemple #15
0
    def build_launch_bash(cls,
                          envicommands,
                          env_root=None,
                          app_tag="",
                          add_default_env=None,
                          add_history=True,
                          envi_dump_file="",
                          split_launch=False):
        """Dump the envicommands into a file, good for execution

            :param envicommands: is a list of valid envi command (list)
            :param app_tag: (str) use to document this launch.
             (store in DSK_ENGINE)
            :param add_default_env: (dict or list of key)support
             for extra export statement, ex: tank...
            :param add_history: bool default True, add the history envi config

            :returns launchfile: the name of the file ready for execution
                    see launch_batch_file and launch_batch_file_with_console

        """
        if env_root is None:
            env_root = os.environ.get(dskenv_constants.DSK_ENV_PATH_KEY)

        if envi_dump_file != "":
            launchfile = envi_dump_file
        else:
            launchpath = Envi.get_temp_dir("envizlaunch")
            launchfile = os.path.join(launchpath, "doenvi.sh")

        try:

            with open(launchfile, "w") as fh:
                scmd = list()
                scmd.append("#!/bin/bash -l")

                # reset the python path
                # ideally we will want to source system and init studio shell

                if add_default_env:
                    if isinstance(add_default_env, dict):
                        for x in add_default_env:
                            value = add_default_env[x]

                            if x == 'SGTK_CONTEXT' or x == 'TANK_CONTEXT':

                                value = value.replace('"', r'\"')
                                value = '"' + value + '"'
                                scmd.append('export %s=%s' % (x, value))
                            else:

                                if x in ['PYTHONPATH']:
                                    scmd.append("export %s=%s:${%s}" %
                                                (x, value, x))
                                else:
                                    scmd.append("export %s=%s" % (x, value))

                    elif isinstance(add_default_env, list):
                        for x in add_default_env:
                            value = os.environ.get(x, "")

                            if x == 'SGTK_CONTEXT' or x == 'TANK_CONTEXT':
                                value = value.replace('"', r'\"')
                                value = '"' + value + '"'
                                # f.write("value %s\n" % value)
                                scmd.append('export %s=%s' % (x, value))
                            else:
                                if x in ['PYTHONPATH']:
                                    # we cannot erase this one
                                    scmd.append("export %s=%s:${%s}" %
                                                (x, value, x))
                                else:
                                    scmd.append("export %s=%s" % (x, value))

                scmd.append("unset PYTHONHOME")
                scmd.append("export %s=%s" %
                            (dskenv_constants.DSK_ENV_PATH_KEY, env_root))

                scmd.append("export DSK_ENGINE=%s" % app_tag)

                scmd.append("type envi &> /dev/null")
                scmd.append("if [ ! -z $? ] ; then")

                scmd.append("\tenvi() {")
                scmd.append("\t\tsource $DSKENV/bin/linux/envi_bsh $*\n\t}")
                scmd.append("\texport -f envi")
                scmd.append("fi")

                if add_history:
                    for obj in cls.get_history_command(with_app=False,
                                                       remove_app=True):
                        # BaseEnv.command_history():
                        if obj and len(obj) > 0:
                            scmd.append("envi " + obj[0] + ";")

                envicommands = cls._valid_command_syntax(envicommands)
                if split_launch is False:
                    for cmds in envicommands:
                        scmd.append("envi %s" % cmds)
                else:
                    for cmds in envicommands:
                        if "-a" not in cmds:
                            scmd.append("envi %s" % cmds)
                        else:
                            X = cls.split_launch_command(cmds)
                            app, arg, cmds, alog = X
                            scmd.append("set -o pipefail")
                            scmd.append("envi %s" % cmds)
                            if alog != "":
                                scmd.append("%s %s |& tee -a %s" %
                                            (app, arg, alog))
                            else:
                                scmd.append("%s %s" % (app, arg))

                fh.write("\n".join(scmd))
            if sys.version_info[0] == 3:
                os.chmod(launchfile, 0o775)
            else:
                os.chmod(launchfile, 0o775)

        except Exception as e:
            print("ERROR: build_launch_bash: %s" % str(e))

        return launchfile
Exemple #16
0
 def do_platform(x):
     x.insert(0, ['-p', Envi().pack_system()])
     return x