summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRahul Nair <rahulunair@gmail.com>2016-11-10 13:07:27 -0600
committerRahul Nair <rahulunair@gmail.com>2016-11-10 15:20:24 -0600
commita2f1d7c222ca42dc1043b41a255782101c84557c (patch)
treefa4ba50e11cb2bd9080bcfbfcf092786b965fad5
parentc9b2ddcec4652858b4d9353c9aaa03dceda461ae (diff)
Fixing a bug due to getlogin() in syntribos0.3.0
The bug is due to the fact that sometimes when using os.getlogin(), Python is calling the system getlogin() function and returns a strerror "No such file or dir", thus failing to get the login name. Change-Id: I4156325d7435c69943b2bb736bd1ec7b4d060db4 Closes-Bug: #1640850
Notes
Notes (review): Code-Review+1: Khanak Nangia <khanak.nangia@intel.com> Code-Review+2: Vinay Potluri <vinaypotluri8@gmail.com> Workflow+1: Vinay Potluri <vinaypotluri8@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Thu, 10 Nov 2016 21:54:57 +0000 Reviewed-on: https://review.openstack.org/396367 Project: openstack/syntribos Branch: refs/heads/master
-rw-r--r--syntribos/utils/env.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/syntribos/utils/env.py b/syntribos/utils/env.py
index 872918a..b718532 100644
--- a/syntribos/utils/env.py
+++ b/syntribos/utils/env.py
@@ -14,6 +14,7 @@
14import datetime 14import datetime
15import logging 15import logging
16import os 16import os
17import pwd
17import shutil 18import shutil
18import sys 19import sys
19 20
@@ -42,7 +43,13 @@ def get_user_home_root():
42 global FOLDER 43 global FOLDER
43 user = os.environ.get("SUDO_USER") 44 user = os.environ.get("SUDO_USER")
44 if not user: 45 if not user:
45 user = os.getlogin() or os.environ.get("USER") 46 try:
47 user = os.environ.get("USER") or os.getlogin()
48 except OSError as e:
49 # Refer https://mail.python.org/pipermail/python-bugs-list/
50 # 2002-July/012691.html
51 LOG.error("Exception thrown in : {}".format(e))
52 user = pwd.getpwuid(os.getuid())[0]
46 home_path = "~{0}/{1}".format(user, FOLDER) 53 home_path = "~{0}/{1}".format(user, FOLDER)
47 return expand_path(home_path) 54 return expand_path(home_path)
48 55
@@ -62,6 +69,7 @@ def get_venv_root():
62 69
63def get_syntribos_root(): 70def get_syntribos_root():
64 """This determines the proper path to use as syntribos' root directory.""" 71 """This determines the proper path to use as syntribos' root directory."""
72 path = ""
65 custom_root = CONF.syntribos.custom_root 73 custom_root = CONF.syntribos.custom_root
66 74
67 if custom_root: 75 if custom_root: