|
22 | 22 | to_bin_sha |
23 | 23 | ) |
24 | 24 |
|
| 25 | +# Import the user database on unix based systems |
| 26 | +ifos.name=="posix": |
| 27 | +importpwd |
| 28 | + |
25 | 29 | __all__= ("stream_copy","join_path","to_native_path_windows","to_native_path_linux", |
26 | 30 | "join_path_native","Stats","IndexFileSHA1Writer","Iterable","IterableList", |
27 | 31 | "BlockingLockFile","LockFile",'Actor','get_user_id','assure_directory_exists', |
@@ -113,12 +117,17 @@ def assure_directory_exists(path, is_file=False): |
113 | 117 |
|
114 | 118 | defget_user_id(): |
115 | 119 | """:return: string identifying the currently active system user as name@node |
116 | | - :note: user can be set with the 'USER' environment variable, usually set on windows""" |
117 | | -ukn='UNKNOWN' |
118 | | -username=os.environ.get('USER',os.environ.get('USERNAME',ukn)) |
119 | | -ifusername==uknandhasattr(os,'getlogin'): |
120 | | -username=os.getlogin() |
121 | | -# END get username from login |
| 120 | + :note: user can be set with the 'USER' environment variable, usually set on windows |
| 121 | + :note: on unix based systems you can use the password database |
| 122 | + to get the login name of the effective process user""" |
| 123 | +ifos.name=="posix": |
| 124 | +username=pwd.getpwuid(os.geteuid()).pw_name |
| 125 | +else: |
| 126 | +ukn='UNKNOWN' |
| 127 | +username=os.environ.get('USER',os.environ.get('USERNAME',ukn)) |
| 128 | +ifusername==uknandhasattr(os,'getlogin'): |
| 129 | +username=os.getlogin() |
| 130 | +# END get username from login |
122 | 131 | return"%s@%s"% (username,platform.node()) |
123 | 132 |
|
124 | 133 | #} END utilities |
|