-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditfile.py
More file actions
executable file
·77 lines (66 loc) · 2.48 KB
/
Copy patheditfile.py
File metadata and controls
executable file
·77 lines (66 loc) · 2.48 KB
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
#!/usr/bin/env python
"""Helper script for the feature provided by the IncludeEditLink setting."""
editor = 'Vim'
editorCommands = {
'Emacs':
'gnuclient +%(line)s "%(filename)s"',
'Geany':
'geany -l %(line)s "%(filename)s"',
'Geany (Windows)':
r'start %%ProgramFiles%%\Geany\Geany.exe -l %(line)s "%(filename)s"',
'gedit':
'gedit +%(line)s "%(filename)s"',
'jEdit':
'jedit "%(filename)s" +line:%(line)s',
'jedit (Windows)':
'start %%ProgramFiles%%\\jEdit\jedit.jar "%(filename)s" +line:%(line)s',
'Kate':
'kate -u -l %(line)s "%(filename)s"',
'Komodo':
'komodo -l %(line)s "%(filename)s"',
'Komodo Edit 5 (Windows)':
r'start %%ProgramFiles%%\"ActiveState Komodo Edit 5"\komodo.exe -l %(line)s "%(filename)s"',
'Komodo IDE 5 (Windows)':
r'start %%ProgramFiles%%\"ActiveState Komodo IDE 5"\komodo.exe -l %(line)s "%(filename)s"',
'KWrite':
'kwrite --line %(line)s "%(filename)s"',
'Notepad++ (Windows)':
r'start %%ProgramFiles%%\Notepad++\notepad++.exe -n%(line)s "%(filename)s"',
'PSPad (Windows)':
r'start %%ProgramFiles%%\PSPad\PSPad.exe -%(line)s "%(filename)s"',
'SciTE':
'scite "%(filename)s" -goto:%(line)s',
'SciTE (Windows)':
r'start %%ProgramFiles%%\SciTE\SciTE.exe "%(filename)s" -goto:%(line)s',
'Vim':
'gvim +%(line)s "%(filename)s"',
}
defaultCommand = editor + ' +%(line)s "%(filename)s"'
import os, sys
try:
from email import message_from_file
except ImportError:
from rfc822 import Message as message_from_file
def transform(params):
"""Transform EditFile paramters.
As an example, if you are under Windows and your edit file
has a Unix filename, then it is transformed to a Samba path.
"""
filename = params['filename']
if os.sep == '\\' and filename.startswith('/'):
filename = os.path.normpath(filename[1:])
hostname = params['hostname'].split(':', 1)[0]
sambapath = r'\\%s\root' % hostname
filename = os.path.join(sambapath, filename)
params['filename'] = filename
return params
def openFile(params):
"""Open editor with file specified in parameters."""
command = editorCommands.get(editor, defaultCommand) % transform(params)
print command
os.system(command)
def parseFile(filename):
"""Parse the WebKit EditFile."""
openFile(message_from_file(open(filename)))
if __name__ == '__main__':
parseFile(sys.argv[1])