1010import time
1111import stat
1212import shutil
13- import tempfile
1413import platform
14+ import getpass
1515
16+ # NOTE: Some of the unused imports might be used/imported by others.
17+ # Handle once test-cases are back up and running.
1618from gitdb .util import (
17- make_sha ,
18- LockedFD ,
19- file_contents_ro ,
20- LazyMixin ,
21- to_hex_sha ,
22- to_bin_sha
23- )
24-
25- # Import the user database on unix based systems
26- if os .name == "posix" :
27- import pwd
28-
19+ make_sha ,
20+ LockedFD ,
21+ file_contents_ro ,
22+ LazyMixin ,
23+ to_hex_sha ,
24+ to_bin_sha
25+ )
26+
2927__all__ = ("stream_copy" ,"join_path" ,"to_native_path_windows" ,"to_native_path_linux" ,
3028"join_path_native" ,"Stats" ,"IndexFileSHA1Writer" ,"Iterable" ,"IterableList" ,
3129"BlockingLockFile" ,"LockFile" ,'Actor' ,'get_user_id' ,'assure_directory_exists' ,
@@ -116,19 +114,8 @@ def assure_directory_exists(path, is_file=False):
116114return False
117115
118116def get_user_id ():
119- """:return: string identifying the currently active system user as name@node
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- if os .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- if username == ukn and hasattr (os ,'getlogin' ):
129- username = os .getlogin ()
130- # END get username from login
131- return "%s@%s" % (username ,platform .node ())
117+ """:return: string identifying the currently active system user as name@node"""
118+ return "%s@%s" % (getpass .getuser (),platform .node ())
132119
133120#} END utilities
134121
@@ -492,7 +479,7 @@ def _obtain_lock_or_raise(self):
492479try :
493480fd = os .open (lock_file ,os .O_WRONLY | os .O_CREAT | os .O_EXCL ,0 )
494481os .close (fd )
495- except OSError , e :
482+ except OSError as e :
496483raise IOError (str (e ))
497484
498485self ._owns_lock = True
@@ -514,7 +501,7 @@ def _release_lock(self):
514501# on bloody windows, the file needs write permissions to be removable.
515502# Why ...
516503if os .name == 'nt' :
517- os .chmod (lfp ,0777 )
504+ os .chmod (lfp ,int ( " 0777" , 8 ) )
518505# END handle win32
519506os .remove (lfp )
520507except OSError :
@@ -593,9 +580,6 @@ def __new__(cls, id_attr, prefix=''):
593580def __init__ (self ,id_attr ,prefix = '' ):
594581self ._id_attr = id_attr
595582self ._prefix = prefix
596- if not isinstance (id_attr ,basestring ):
597- raise ValueError ("First parameter must be a string identifying the name-property. Extend the list after initialization" )
598- # END help debugging !
599583
600584def __contains__ (self ,attr ):
601585# first try identy match for performance