Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit598cd1d

Browse files
committed
Simplified get_user_id() and fixed possible python3 compatiblity issue.
Changed motivated bygitpython-developers#52
1 parentfbd0968 commit598cd1d

File tree

1 file changed

+15
-31
lines changed

1 file changed

+15
-31
lines changed

‎git/util.py

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,20 @@
1010
importtime
1111
importstat
1212
importshutil
13-
importtempfile
1413
importplatform
14+
importgetpass
1515

16+
# NOTE: Some of the unused imports might be used/imported by others.
17+
# Handle once test-cases are back up and running.
1618
fromgitdb.utilimport (
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-
ifos.name=="posix":
27-
importpwd
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):
116114
returnFalse
117115

118116
defget_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-
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
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):
492479
try:
493480
fd=os.open(lock_file,os.O_WRONLY|os.O_CREAT|os.O_EXCL,0)
494481
os.close(fd)
495-
exceptOSError,e:
482+
exceptOSErrorase:
496483
raiseIOError(str(e))
497484

498485
self._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 ...
516503
ifos.name=='nt':
517-
os.chmod(lfp,0777)
504+
os.chmod(lfp,int("0777",8))
518505
# END handle win32
519506
os.remove(lfp)
520507
exceptOSError:
@@ -593,9 +580,6 @@ def __new__(cls, id_attr, prefix=''):
593580
def__init__(self,id_attr,prefix=''):
594581
self._id_attr=id_attr
595582
self._prefix=prefix
596-
ifnotisinstance(id_attr,basestring):
597-
raiseValueError("First parameter must be a string identifying the name-property. Extend the list after initialization")
598-
# END help debugging !
599583

600584
def__contains__(self,attr):
601585
# first try identy match for performance

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp