]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/helpers.py
username/userfullname: use struct names
[bup.git] / lib / bup / helpers.py
index b88fabf2df5ea59fe1421fe59ab714cfbddfaba9..d66b5f17dad32a23331876e3ff58ac2477964388 100644 (file)
@@ -99,6 +99,13 @@ def partition(predicate, stream):
     return (leading_matches(), rest())
 
 
+def merge_dict(*xs):
+    result = {}
+    for x in xs:
+        result.update(x)
+    return result
+
+
 def lines_until_sentinel(f, sentinel, ex_type):
     # sentinel must end with \n and must contain only one \n
     while True:
@@ -435,7 +442,7 @@ def username():
     global _username
     if not _username:
         uid = os.getuid()
-        _username = pwd_from_uid(uid)[0] or 'user%d' % uid
+        _username = pwd_from_uid(uid).pw_name or b'user%d' % uid
     return _username
 
 
@@ -447,9 +454,9 @@ def userfullname():
         uid = os.getuid()
         entry = pwd_from_uid(uid)
         if entry:
-            _userfullname = entry[4].split(',')[0] or entry[0]
+            _userfullname = entry.pw_gecos.split(b',')[0] or entry.pw_name
         if not _userfullname:
-            _userfullname = 'user%d' % uid
+            _userfullname = b'user%d' % uid
     return _userfullname
 
 
@@ -831,7 +838,7 @@ if _mincore:
         if chunk_count < 1:
             chunk_count = 1
         result = bytearray(page_count)
-        for ci in xrange(chunk_count):
+        for ci in compat.range(chunk_count):
             pos = _fmincore_chunk_size * ci;
             msize = min(_fmincore_chunk_size, st.st_size - pos)
             try:
@@ -962,7 +969,7 @@ def columnate(l, prefix):
     while len(l) % ncols:
         l.append('')
     rows = len(l) // ncols
-    for s in range(0, len(l), rows):
+    for s in compat.range(0, len(l), rows):
         cols.append(l[s:s+rows])
     out = ''
     for row in zip(*cols):
@@ -1174,7 +1181,7 @@ else:
         return x
 
 
-_some_invalid_save_parts_rx = re.compile(r'[[ ~^:?*\\]|\.\.|//|@{')
+_some_invalid_save_parts_rx = re.compile(r'[\[ ~^:?*\\]|\.\.|//|@{')
 
 def valid_save_name(name):
     # Enforce a superset of the restrictions in git-check-ref-format(1)