-
Notifications
You must be signed in to change notification settings - Fork 0
/
tortoisegit.py
126 lines (103 loc) · 4.25 KB
/
tortoisegit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#
# Simple TortoiseSVN-like Git plugin for the Windows Shell
# Published under the GNU GPL, v2 or later.
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
# Copyright (C) 2007 Henry Ludemann <misc@hl.id.au>
# Copyright (C) 2007 TK Soh <teekaysoh@gmail.com>
#
import os
import sys
import _winreg
if hasattr(sys, "frozen") and sys.frozen == 'dll':
import win32traceutil
# specify version string, otherwise 'git --version' will be used:
version = ''
import tortoisegit.version
tortoisegit.version.remember_version(version)
# shell extension classes
from tortoisegit.contextmenu import ContextMenuExtension
from tortoisegit.iconoverlay import ChangedOverlay, AddedOverlay, UnchangedOverlay
bin_path = os.path.dirname(os.path.join(os.getcwd(), sys.argv[0]))
print "bin path = ", bin_path
def check_tortoise_overlays():
# TortoiseOverlays must be installed, and we must be able to write there.
try:
hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
r"Software\TortoiseOverlays", 0,
_winreg.KEY_ALL_ACCESS)
except WindowsError:
print "TortoiseOverlays is not installed."
sys.exit(1)
# TortoiseGit registry setup
def register_tortoise_path(unregister=False):
key = r"Software\TortoiseGit"
cat = _winreg.HKEY_LOCAL_MACHINE
if (unregister):
_winreg.DeleteKey(cat, key)
print "TortoiseGit unregistered"
else:
_winreg.SetValue(cat, key, _winreg.REG_SZ, bin_path)
print "TortoiseGit registered"
# for COM registration via py2exe
def DllRegisterServer():
check_tortoise_overlays()
RegisterServer(ContextMenuExtension)
RegisterServer(ChangedOverlay)
RegisterServer(AddedOverlay)
RegisterServer(UnchangedOverlay)
register_tortoise_path()
# for COM registration via py2exe
def DllUnregisterServer():
UnregisterServer(ContextMenuExtension)
UnregisterServer(ChangedOverlay)
UnregisterServer(AddedOverlay)
UnregisterServer(UnchangedOverlay)
register_tortoise_path(unregister=True)
def RegisterServer(cls):
#import mercurial
#git_path = os.path.dirname(os.path.dirname(mercurial.__file__))
# Add the appropriate shell extension registry keys
for category, keyname, values in cls.registry_keys:
hkey = _winreg.CreateKey(category, keyname)
for (name, val) in values:
# todo: handle ints?
_winreg.SetValueEx(hkey, name, 0, _winreg.REG_SZ, val)
# register the extension on Approved list
try:
apath = r'SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved'
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, apath, 0, _winreg.KEY_WRITE)
_winreg.SetValueEx(key, cls._reg_clsid_, 0, _winreg.REG_SZ, 'TortoiseGit')
except:
pass
print cls._reg_desc_, "registration complete."
def UnregisterServer(cls):
for category, keyname, values in cls.registry_keys:
hkey = _winreg.OpenKey(category, keyname, 0, _winreg.KEY_ALL_ACCESS)
for (name, val) in values:
# todo: handle ints?
try:
_winreg.DeleteValue(hkey, name)
except WindowsError, exc:
print "Failed to remove registry key %s: %s" % (keyname, exc)
# unregister the extension from Approved list
try:
apath = r'SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved'
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, apath, 0, _winreg.KEY_WRITE)
_winreg.DeleteValue(key, cls._reg_clsid_)
except:
pass
print cls._reg_desc_, "unregistration complete."
if __name__=='__main__':
check_tortoise_overlays()
from win32com.server import register
register.UseCommandLine(ContextMenuExtension,
finalize_register = lambda: RegisterServer(ContextMenuExtension),
finalize_unregister = lambda: UnregisterServer(ContextMenuExtension))
for cls in (ChangedOverlay, AddedOverlay, UnchangedOverlay):
register.UseCommandLine(cls,
finalize_register = lambda: RegisterServer(cls),
finalize_unregister = lambda: UnregisterServer(cls))
if "--unregister" in sys.argv[1:]:
register_tortoise_path(unregister=True)
else:
register_tortoise_path()