Skip to content

Commit 6f55c17

Browse files
committed
Replaced ordered dict with standard version; used logging module
All performance tests still print to stderr, but do so in a py3 compatible way
1 parent 1b9d3b9 commit 6f55c17

21 files changed

+122
-1616
lines changed

‎doc/source/conf.py

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
# absolute, like shown here.
2222
#sys.path.append(os.path.abspath('.'))
2323
sys.path.insert(0, os.path.abspath('../..'))
24-
print sys.path
2524

2625
# General configuration
2726
# ---------------------

‎git/cmd.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import os
88
import sys
9+
import logging
910
from util import (
1011
LazyMixin,
1112
stream_copy
@@ -22,6 +23,8 @@
2223
'with_exceptions', 'as_process',
2324
'output_stream')
2425

26+
log = logging.getLogger('git.cmd')
27+
2528
__all__ = ('Git', )
2629

2730

@@ -334,7 +337,7 @@ def execute(self, command,
334337
If you add additional keyword arguments to the signature of this method,
335338
you must update the execute_kwargs tuple housed in this module."""
336339
if self.GIT_PYTHON_TRACE and (self.GIT_PYTHON_TRACE != 'full' or as_process):
337-
print(' '.join(command))
340+
log.info(' '.join(command))
338341

339342
# Allow the user to have the command executed in their working dir.
340343
if with_keep_cwd or self._working_dir is None:
@@ -389,11 +392,11 @@ def execute(self, command,
389392
if self.GIT_PYTHON_TRACE == 'full':
390393
cmdstr = " ".join(command)
391394
if stderr_value:
392-
print("%s -> %d; stdout: '%s'; stderr: '%s'" % (cmdstr, status, stdout_value, stderr_value))
395+
log.info("%s -> %d; stdout: '%s'; stderr: '%s'", cmdstr, status, stdout_value, stderr_value)
393396
elif stdout_value:
394-
print("%s -> %d; stdout: '%s'" % (cmdstr, status, stdout_value))
397+
log.info("%s -> %d; stdout: '%s'", cmdstr, status, stdout_value)
395398
else:
396-
print("%s -> %d" % (cmdstr, status))
399+
log.info("%s -> %d", cmdstr, status)
397400
# END handle debug printing
398401

399402
if with_exceptions and status != 0:

‎git/config.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99
import re
1010
import ConfigParser as cp
1111
import inspect
12+
import logging
1213

1314
from git.odict import OrderedDict
1415
from git.util import LockFile
1516

1617
__all__ = ('GitConfigParser', 'SectionConstraint')
1718

1819

20+
log = logging.getLogger('git.config')
21+
22+
1923
class MetaParserBuilder(type):
2024

2125
"""Utlity class wrapping base-class methods into decorators that assure read-only properties"""
@@ -186,8 +190,8 @@ def __del__(self):
186190
try:
187191
try:
188192
self.write()
189-
except IOError as e:
190-
print("Exception during destruction of GitConfigParser: %s" % str(e))
193+
except IOError:
194+
log.error("Exception during destruction of GitConfigParser", exc_info=True)
191195
finally:
192196
self._lock._release_lock()
193197

‎git/objects/commit.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
altzone
3232
)
3333
import os
34-
import sys
34+
import logging
35+
36+
log = logging.getLogger('git.objects.commit')
3537

3638
__all__ = ('Commit', )
3739

@@ -473,16 +475,16 @@ def _deserialize(self, stream):
473475
try:
474476
self.author.name = self.author.name.decode(self.encoding)
475477
except UnicodeDecodeError:
476-
print >> sys.stderr, "Failed to decode author name '%s' using encoding %s" % (
477-
self.author.name, self.encoding)
478+
log.error("Failed to decode author name '%s' using encoding %s", self.author.name, self.encoding,
479+
exc_info=True)
478480
# END handle author's encoding
479481

480482
# decode committer name
481483
try:
482484
self.committer.name = self.committer.name.decode(self.encoding)
483485
except UnicodeDecodeError:
484-
print >> sys.stderr, "Failed to decode committer name '%s' using encoding %s" % (
485-
self.committer.name, self.encoding)
486+
log.error("Failed to decode committer name '%s' using encoding %s", self.committer.name, self.encoding,
487+
exc_info=True)
486488
# END handle author's encoding
487489

488490
# a stream from our data simply gives us the plain message
@@ -491,7 +493,7 @@ def _deserialize(self, stream):
491493
try:
492494
self.message = self.message.decode(self.encoding)
493495
except UnicodeDecodeError:
494-
print >> sys.stderr, "Failed to decode message '%s' using encoding %s" % (self.message, self.encoding)
496+
log.error("Failed to decode message '%s' using encoding %s", self.message, self.encoding, exc_info=True)
495497
# END exception handling
496498
return self
497499

‎git/objects/submodule/base.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727
import git
2828

2929
import os
30-
import sys
30+
import logging
3131

3232
__all__ = ["Submodule", "UpdateProgress"]
3333

3434

35+
log = logging.getLogger('git.objects.submodule.base')
36+
37+
3538
class UpdateProgress(RemoteProgress):
3639

3740
"""Class providing detailed progress information to the caller who should
@@ -408,7 +411,7 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
408411
mrepo.head.set_reference(local_branch, logmsg="submodule: attaching head to %s" % local_branch)
409412
mrepo.head.ref.set_tracking_branch(remote_branch)
410413
except IndexError:
411-
print >> sys.stderr, "Warning: Failed to checkout tracking branch %s" % self.branch_path
414+
log.warn("Failed to checkout tracking branch %s", self.branch_path)
412415
# END handle tracking branch
413416

414417
# NOTE: Have to write the repo config file as well, otherwise
@@ -437,11 +440,10 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
437440
binsha = rcommit.binsha
438441
hexsha = rcommit.hexsha
439442
else:
440-
print >> sys.stderr, "%s a tracking branch was not set for local branch '%s'" % (
441-
msg_base, mrepo.head.ref)
443+
log.error("%s a tracking branch was not set for local branch '%s'", msg_base, mrepo.head.ref)
442444
# END handle remote ref
443445
else:
444-
print >> sys.stderr, "%s there was no local tracking branch" % msg_base
446+
log.error("%s there was no local tracking branch", msg_base)
445447
# END handle detached head
446448
# END handle to_latest_revision option
447449

‎git/objects/submodule/root.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
from git.exc import InvalidGitRepositoryError
66
import git
77

8-
import sys
8+
import logging
99

1010
__all__ = ["RootModule", "RootUpdateProgress"]
1111

12+
log = logging.getLogger('git.objects.submodule.root')
13+
1214

1315
class RootUpdateProgress(UpdateProgress):
1416

@@ -247,8 +249,8 @@ def update(self, previous_commit=None, recursive=True, force_remove=False, init=
247249
# this way, it will be checked out in the next step
248250
# This will change the submodule relative to us, so
249251
# the user will be able to commit the change easily
250-
print >> sys.stderr, "WARNING: Current sha %s was not contained in the tracking\
251-
branch at the new remote, setting it the the remote's tracking branch" % sm.hexsha
252+
log.warn("Current sha %s was not contained in the tracking\
253+
branch at the new remote, setting it the the remote's tracking branch", sm.hexsha)
252254
sm.binsha = rref.commit.binsha
253255
# END reset binsha
254256

0 commit comments

Comments
 (0)