def _build_set_commands(env): """ Constructs a list of unicode strings containing shell commands to set environmental variables """ shell_name = os.path.basename(shellenv.get_user_login_shell()) if shell_name == 'fish': set_command = "set -gx %s %s" elif shell_name in set(['tcsh', 'csh']): set_command = "setenv %s %s" else: set_command = "export %s=%s" if shell_name == 'fish': unset_command = "set -e %s" elif shell_name in set(['tcsh', 'csh']): unset_command = "unset %s" else: unset_command = "unset -v %s" output = [] for key, value in env.items(): if value is None: output.append(unset_command % key) else: output.append(set_command % (key, _shell_quote(value))) return output
def test_get_login_shell(self): username = shellenv.get_user() shell = shellenv.get_user_login_shell(username) self.assertEqual(str_cls, type(username)) self.assertTrue(len(username) > 0) self.assertEqual(str_cls, type(shell)) self.assertTrue(len(shell) > 0)