-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-sublime.py
More file actions
executable file
·113 lines (95 loc) · 3.04 KB
/
Copy pathinstall-sublime.py
File metadata and controls
executable file
·113 lines (95 loc) · 3.04 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
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
#!/usr/bin/env python
#Installs sublime text on Ubuntu 12.04
#installation includes
# *an option to download the tar.bz2 file
# *creation of sublime.default file
# *fake sublime default text editor
#
#Author Ivan Dominic Bagui <baguio.ivan@gmail.com>
#
import sys, subprocess, urllib2, os, fileinput
file_name=None
def downloadSublime():
global file_name
url = "http://c758482.r82.cf2.rackcdn.com/Sublime%20Text%202.0.1%20x64.tar.bz2"
file_name = "~/Downloads/"+url.split('/')[-1]
u = urllib2.urlopen(url)
f = open(file_name, 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, file_size)
file_size_dl = 0
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += len(buffer)
f.write(buffer)
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
status = status + chr(8)*(len(status)+1)
print status,
f.close()
#edit the defaults list and set sublime as default text editor
#replaces gedit only
def setSublimeAsDefault():
print "Making Sublime Text 2 as default text editor"
def_ = "/usr/share/applications/defaults.list"
#if gedit is in line, replace it with sublime
def updatedLine(line):
line.replace("gedit", "sublime")
for line in fileinput.input(def_, inplace=1):
print "%s" % (updatedLine(line)),
#main installation stuff
#filename - filename (file location) of tar.bz2 file
def installSublime(filename):
print "Now installing Sublime Text 2..."
#desktop entry for sublime
sublime_desktop = """[Desktop Entry]
Version=1.0
Name=Sublime Text 2
# Only KDE 4 seems to use GenericName, so we reuse the KDE strings.
# From Ubuntu's language-pack-kde-XX-base packages, version 9.04-20090413.
GenericName=Text Editor
Exec=sublime
Terminal=false
Icon=/opt/Sublime Text 2/Icon/48x48/sublime_text.png
Type=Application
Categories=TextEditor;IDE;Development
X-Ayatana-Desktop-Shortcuts=NewWindow
[NewWindow Shortcut Group]
Name=New Window
Exec=sublime -n
TargetEnvironment=Unity"""
print "Decompressing file"
subprocess.call(["tar", "xf",filename])
print "Moving directory to /opt"
subprocess.call(["sudo","mv","Sublime Text 2","/opt/"])
print "Creating symbolic link"
subprocess.call(["sudo","ln","-s","/opt/Sublime Text 2/sublime_text","/usr/bin/sublime"])
print "Creating Desktop entry"
desk = open("sublime.desktop",'w')
desk.write(sublime_desktop)
desk.close()
subprocess.call(["sudo","mv","sublime.desktop","/usr/share/applications/sublime.desktop"])
setSublimeAsDefault()
print "Everything is done!"
def main():
try:
filename = sys.argv[1]
except:
print "File location of Sublime Text tar.bz2 not found"
while (True):
i = raw_input("Would you like to download? (y/n)")
if i == 'n':
print "Please specify file location of Sublime Text tar.bz2 file"
sys.exit(0)
else:
downloadSublime()
installSublime(file_name)
installSublime(filename)
if __name__ == "__main__":
if not os.geteuid()==0:
print "Please run this script as root"
sys.exit(0)
main()