Skip to content
This repository was archived by the owner on May 22, 2019. It is now read-only.

fix support for python 2.5.x #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions tracext/git/PyGIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@
import cStringIO
import codecs

def terminate(process):
"""
Kills a process, useful on 2.5 where subprocess.Popens don't have a
terminate method.


Used here because we're stuck on 2.5 and don't have Popen.terminate
goodness.
"""

def terminate_win(process):
import win32process
return win32process.TerminateProcess(process._handle, -1)

def terminate_nix(process):
import signal
return os.kill(process.pid, signal.SIGTERM)

terminate_default = terminate_nix

handlers = {
"win32": terminate_win,
"linux2": terminate_nix
}

return handlers.get(sys.platform, terminate_default)(process)

__all__ = ["git_version", "GitError", "GitErrorSha", "Storage", "StorageFactory"]

class GitError(Exception):
Expand Down Expand Up @@ -61,7 +88,8 @@ def __execute(self, git_cmd, *cmd_args):

#print >>sys.stderr, "DEBUG:", git_cmd, cmd_args

p = self.__pipe(git_cmd, *cmd_args, stdout=PIPE, stderr=PIPE)
kwds = dict(stdout=PIPE,stderr=PIPE)
p = self.__pipe(git_cmd, *cmd_args, **kwds)

stdout_data, stderr_data = p.communicate()
#TODO, do something with p.returncode, e.g. raise exception
Expand All @@ -72,7 +100,8 @@ def cat_file_batch(self):
return self.__pipe('cat-file', '--batch', stdin=PIPE, stdout=PIPE)

def log_pipe(self, *cmd_args):
return self.__pipe('log', *cmd_args, stdout=PIPE)
kwds = dict(stdout=PIPE)
return self.__pipe('log', *cmd_args, **kwds)

def __getattr__(self, name):
if name[0] == '_' or name in ['cat_file_batch', 'log_pipe']:
Expand Down Expand Up @@ -741,7 +770,7 @@ def name_status_gen():
except ValueError:
break
f.close()
p[0].terminate()
terminate(p[0])
p[0].wait()
p[:] = []
while True: yield None
Expand All @@ -757,7 +786,7 @@ def historian(path):

if p:
p[0].stdout.close()
p[0].terminate()
terminate(p[0])
p[0].wait()

def last_change(self, sha, path, historian=None):
Expand Down
1 change: 1 addition & 0 deletions tracext/git/git_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# See COPYING for distribution information

from __future__ import with_statement
from trac.core import *
from trac.util import TracError, shorten_line
from trac.util.datefmt import FixedOffset, to_timestamp, format_datetime
Expand Down