-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjetbrains-eap-autoupdater.py
94 lines (80 loc) · 2.78 KB
/
jetbrains-eap-autoupdater.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
# coding: utf-8
from urllib2 import urlopen
from re import search, IGNORECASE
from glob import glob
from os import path, rename, chdir, waitpid, mkdir, environ
from subprocess import Popen
from shutil import rmtree
from sys import exit
PF86DIR=environ['ProgramFiles']
if '86' in PF86DIR:
PFDIR=PF86DIR[:-6]
else:
PFDIR=PF86DIR
JBDIR=path.join(PF86DIR, 'JetBrains')
DWDIR=path.join(JBDIR, '.downloads')
if not path.exists(JBDIR):
mkdir(JBDIR)
if not path.exists(DWDIR):
mkdir(DWDIR)
chdir(JBDIR)
for IDENAME, CHECKURLS in (
('PhpStorm', ['http://confluence.jetbrains.net/display/WI/Web+IDE+EAP']),
('PyCharm', ['http://confluence.jetbrains.net/display/PYH/JetBrains+PyCharm+Preview', 'http://www.jetbrains.com/pycharm/download/']),
('ideaIC', ['http://confluence.jetbrains.net/display/IDEADEV/IDEA+X+EAP']),
):
print 'checking for updates for', IDENAME
dists = []
for d in glob(path.join(JBDIR, IDENAME+'*')):
version_file = d + r'/version.txt'
if not path.exists(version_file):
continue
f = open(version_file, 'r')
version = f.read().strip()
f.close()
dists.append((version, d))
dists = dict(dists)
print 'installed', IDENAME+'s', dists.keys()
for CHECKURL in CHECKURLS:
f = urlopen(CHECKURL)
m = search('href="([^"]+'+IDENAME+'[^"]+[.]exe)"', f.read(), flags=IGNORECASE)
if not m is None:
last_url = m.group(1)
print 'last '+IDENAME+':', last_url
f.close()
break
def already_installed(dists, last_url):
for build in dists.keys():
if build in last_url:
return True
return False
if not already_installed(dists, last_url):
version = outname = last_url.split('/')[-1]
chdir(DWDIR)
try:
if not path.exists(outname):
Popen([path.join(PF86DIR, 'GnuWin32', 'bin', 'wget'), '-O', outname + '.tmp', '--continue', last_url]).communicate()
rename(outname + '.tmp', outname)
else:
print 'already downloaded'
finally:
chdir(JBDIR)
newdir = IDENAME+'EAP'
olddir = newdir + '.old'
rmtree(olddir, True)
if path.exists(newdir):
rename(newdir, olddir)
mkdir(newdir)
chdir(newdir)
Popen([path.join(PFDIR, '7-Zip', '7z.exe'), 'x', path.join(DWDIR, outname)]).communicate()
f = open('version.txt', 'w')
f.write(version)
f.close()
chdir('..')
rmtree(olddir, True)
# @TODO: запускать только если уже была запущена
# Popen([newdir + '/bin/'+IDENAME+'.exe'])
print 'all done'
else:
print 'up-to-date'
rmtree(DWDIR, True)