|  | 
| 4 | 4 | # This module is part of GitPython and is released under | 
| 5 | 5 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php | 
| 6 | 6 | """Module for general utility functions""" | 
| 7 |  | -from git.util import IterableList | 
|  | 7 | +from git.util import ( | 
|  | 8 | +						IterableList,  | 
|  | 9 | +						Actor | 
|  | 10 | +					) | 
| 8 | 11 | 
 | 
| 9 | 12 | import re | 
| 10 | 13 | from collections import deque as Deque | 
| 11 |  | -import platform | 
| 12 | 14 | 
 | 
| 13 | 15 | from string import digits | 
| 14 | 16 | import time | 
| 15 | 17 | import os | 
| 16 | 18 | 
 | 
| 17 |  | -__all__ = ('get_object_type_by_name', 'get_user_id', 'parse_date', 'parse_actor_and_date',  | 
|  | 19 | +__all__ = ('get_object_type_by_name', 'parse_date', 'parse_actor_and_date',  | 
| 18 | 20 | 			'ProcessStreamAdapter', 'Traversable', 'altz_to_utctz_str', 'utctz_to_altz',  | 
| 19 |  | -			'verify_utctz') | 
|  | 21 | +			'verify_utctz', 'Actor') | 
| 20 | 22 | 
 | 
| 21 | 23 | #{ Functions | 
| 22 | 24 | 
 | 
| @@ -57,18 +59,6 @@ def get_object_type_by_name(object_type_name): | 
| 57 | 59 | 	else: | 
| 58 | 60 | 		raise ValueError("Cannot handle unknown object type: %s" % object_type_name) | 
| 59 | 61 | 
 | 
| 60 |  | - | 
| 61 |  | -def get_user_id(): | 
| 62 |  | -	""":return: string identifying the currently active system user as name@node | 
| 63 |  | -	:note: user can be set with the 'USER' environment variable, usually set on windows""" | 
| 64 |  | -	ukn = 'UNKNOWN' | 
| 65 |  | -	username = os.environ.get('USER', os.environ.get('USERNAME', ukn)) | 
| 66 |  | -	if username == ukn and hasattr(os, 'getlogin'): | 
| 67 |  | -		username = os.getlogin() | 
| 68 |  | -	# END get username from login | 
| 69 |  | -	return "%s@%s" % (username, platform.node()) | 
| 70 |  | -		 | 
| 71 |  | - | 
| 72 | 62 | def utctz_to_altz(utctz): | 
| 73 | 63 | 	"""we convert utctz to the timezone in seconds, it is the format time.altzone | 
| 74 | 64 | 	returns. Git stores it as UTC timezone which has the opposite sign as well,  | 
| @@ -193,58 +183,6 @@ def parse_actor_and_date(line): | 
| 193 | 183 | 
 | 
| 194 | 184 | 
 | 
| 195 | 185 | #{ Classes  | 
| 196 |  | - | 
| 197 |  | -class Actor(object): | 
| 198 |  | -	"""Actors hold information about a person acting on the repository. They  | 
| 199 |  | -	can be committers and authors or anything with a name and an email as  | 
| 200 |  | -	mentioned in the git log entries.""" | 
| 201 |  | -	# precompiled regex | 
| 202 |  | -	name_only_regex = re.compile( r'<(.+)>' ) | 
| 203 |  | -	name_email_regex = re.compile( r'(.*) <(.+?)>' ) | 
| 204 |  | -	 | 
| 205 |  | -	__slots__ = ('name', 'email') | 
| 206 |  | -	 | 
| 207 |  | -	def __init__(self, name, email): | 
| 208 |  | -		self.name = name | 
| 209 |  | -		self.email = email | 
| 210 |  | - | 
| 211 |  | -	def __eq__(self, other): | 
| 212 |  | -		return self.name == other.name and self.email == other.email | 
| 213 |  | -		 | 
| 214 |  | -	def __ne__(self, other): | 
| 215 |  | -		return not (self == other) | 
| 216 |  | -		 | 
| 217 |  | -	def __hash__(self): | 
| 218 |  | -		return hash((self.name, self.email)) | 
| 219 |  | - | 
| 220 |  | -	def __str__(self): | 
| 221 |  | -		return self.name | 
| 222 |  | - | 
| 223 |  | -	def __repr__(self): | 
| 224 |  | -		return '<git.Actor "%s <%s>">' % (self.name, self.email) | 
| 225 |  | - | 
| 226 |  | -	@classmethod | 
| 227 |  | -	def _from_string(cls, string): | 
| 228 |  | -		"""Create an Actor from a string. | 
| 229 |  | -		:param string: is the string, which is expected to be in regular git format | 
| 230 |  | -
 | 
| 231 |  | - | 
| 232 |  | -				 | 
| 233 |  | -		:return: Actor """ | 
| 234 |  | -		m = cls.name_email_regex.search(string) | 
| 235 |  | -		if m: | 
| 236 |  | -			name, email = m.groups() | 
| 237 |  | -			return Actor(name, email) | 
| 238 |  | -		else: | 
| 239 |  | -			m = cls.name_only_regex.search(string) | 
| 240 |  | -			if m: | 
| 241 |  | -				return Actor(m.group(1), None) | 
| 242 |  | -			else: | 
| 243 |  | -				# assume best and use the whole string as name | 
| 244 |  | -				return Actor(string, None) | 
| 245 |  | -			# END special case name | 
| 246 |  | -		# END handle name/email matching | 
| 247 |  | -	 | 
| 248 | 186 | 
 | 
| 249 | 187 | class ProcessStreamAdapter(object): | 
| 250 | 188 | 	"""Class wireing all calls to the contained Process instance. | 
|  | 
0 commit comments