[ET Trac] #2612: GetComponents assumes that $USER is defined

Roland Haas trac-noreply at einsteintoolkit.org
Wed Jun 8 15:26:49 CDT 2022


#2612: GetComponents assumes that $USER is defined

 Reporter: Roland Haas
   Status: new
Milestone: 
  Version: development version
     Type: bug
 Priority: minor
Component: GetComponents

Comment (by Roland Haas):

ugh, I did not know that. Checking… Simfactory has “workarounds”:  

```python
def GetUsername():

    if "USER" not in os.environ:
        fd = simenv.popen("whoami")
        username = fd.read().strip()
        fd.close()

    else:
        username = os.environ["USER"]

    return username
```

What’s wrong with `os.getlogin()` which is the first answer that Google finds for “Python get user name”: [https://www.geeksforgeeks.org/how-to-get-the-current-username-in-python/](https://www.geeksforgeeks.org/how-to-get-the-current-username-in-python/) and apparently part of Python since forever?  
I’ll make a pull request for simfactory as well.

--
Ticket URL: https://bitbucket.org/einsteintoolkit/tickets/issues/2612/getcomponents-assumes-that-user-is-defined
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.einsteintoolkit.org/pipermail/trac/attachments/20220608/306cde40/attachment.html 


More information about the Trac mailing list