- # In windows case, the USERNAME environment variable has to be set
- if is_windows():
- if not 'USERNAME' in os.environ:
- raise Exception('USERNAME environment variable not set')
- return os.environ['USERNAME']
- else: # linux
- import pwd
- return pwd.getpwuid(os.getuid())[0]
-
-def _lsb_release(args):
- '''Get system information with lsb_release.
-
- :param args str: The arguments to give to lsb_release.
- :return: The distribution.
- :rtype: str
- '''
- try:
- path = '/usr/local/bin:/usr/bin:/bin'
- lsb_path = os.getenv("LSB_PATH")
- if lsb_path is not None:
- path = lsb_path + ":" + path
-
- from subprocess import Popen, PIPE
- res = Popen(['lsb_release', args], env={'PATH': path}, stdout=PIPE).communicate()[0][:-1]
- # in case of python3, convert byte to str
- if isinstance(res, bytes):
- res = res.decode()
- return res
- except OSError:
- sys.stderr.write(_(u"lsb_release not installed\n"))
- sys.stderr.write(_(u"You can define $LSB_PATH to give the path to lsb_release\n"))
- sys.exit(-1)
+ try :
+ if is_windows():
+ # In windows case, the USERNAME environment variable has to be set
+ user_name=os.environ['USERNAME']
+ else: # linux
+ import pwd
+ user_name=pwd.getpwuid(os.getuid())[0]
+ except :
+ user_name="Unknown"
+ return user_name