-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_sublime_snippet.py
executable file
·109 lines (78 loc) · 3.1 KB
/
build_sublime_snippet.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
#!/usr/bin/env python
import os
import platform
import shutil
from pydiploy.version import __version__
"""
This script generate a sublime text snippet using
pydiploy/examples/django_fabfile and then copy the file in sublime text
config dir to use it directly.
"""
def copyFile(src, dest):
""" Copy file from src to dest """
try:
shutil.copy(src, dest)
except shutil.Error as e:
print('Error: %s' % e)
except IOError as e:
print('Error: %s' % e.strerror)
def install_snippet(dest_filename, app_type):
""" install snippets """
# TODO manage other os (Darwin,windoz...)
if platform.system() == "Linux":
sublime_config_dirs = [
'.config/sublime-text-3/Packages/User',
'.config/sublime-text-2/Packages/User']
for dir in sublime_config_dirs:
dir = os.path.join(os.environ['HOME'], dir)
if os.path.isdir(dir):
copyFile(dest_filename, dir)
print('Snippet for %s app installed in %s' % (app_type, dir))
def django_app():
# Django snippets
src_filename = 'pydiploy/examples/django_fabfile.py'
dest_filename = 'tools/pydiployfabfile.sublime-snippet'
source = open(src_filename, 'r')
target = open(dest_filename, 'w')
snippet_header = '<snippet>\n<content><![CDATA[\n'
snippet_footer = '\n]]></content>\n<description>Pydiploy fabfile %s</description>\n<tabTrigger>pydiployfab</tabTrigger>\n<scope>source.python</scope>\n</snippet>' % __version__
target.write(snippet_header)
target.write(source.read())
target.write(snippet_footer)
source.close()
target.close()
install_snippet(dest_filename, "django")
def simple_app():
# Simple snippets
src_filename = 'pydiploy/examples/simple_fabfile.py'
dest_filename = 'tools/pydiployfabfilesimple.sublime-snippet'
source = open(src_filename, 'r')
target = open(dest_filename, 'w')
snippet_header = '<snippet>\n<content><![CDATA[\n'
snippet_footer = '\n]]></content>\n<description>Pydiploy fabfile simple %s</description>\n<tabTrigger>pydiployfabsimple</tabTrigger>\n<scope>source.python</scope>\n</snippet>' % __version__
target.write(snippet_header)
target.write(source.read())
target.write(snippet_footer)
source.close()
target.close()
install_snippet(dest_filename, "simple")
def bottle_app():
# bottle snippets
src_filename = 'pydiploy/examples/bottle_fabfile.py'
dest_filename = 'tools/pydiployfabfilebottle.sublime-snippet'
source = open(src_filename, 'r')
target = open(dest_filename, 'w')
snippet_header = '<snippet>\n<content><![CDATA[\n'
snippet_footer = '\n]]></content>\n<description>Pydiploy fabfile bottle %s</description>\n<tabTrigger>pydiployfabbottle</tabTrigger>\n<scope>source.python</scope>\n</snippet>' % __version__
target.write(snippet_header)
target.write(source.read())
target.write(snippet_footer)
source.close()
target.close()
install_snippet(dest_filename, "bottle")
def main():
django_app()
simple_app()
bottle_app()
if __name__ == '__main__':
main()