-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathyed.py
executable file
·56 lines (44 loc) · 1.27 KB
/
yed.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
#!/usr/bin/env python
# -*- encoding=utf8 -*-
#
# @name_zhTW '安裝 yEd 流程圖軟體'
# @desc_zhTW 'Java 寫的流程圖軟體'
# @author '2009 Hsin Yi Chen 陳信屹 (hychen) <ossug.hychen at gmail.com>
# @ubuntu
# @license 'BSD'
import urllib
import re
import os
import sys
import datetime
def exit_script(msg):
msg = msg+"%s" % datetime.datetime.now()
print msg
open('/tmp/'+os.path.basename(__file__)+'.log','w').write(msg+'\n')
sys.exit()
host = 'http://www.yworks.com'
dwurl = host+'/en/products_download.php'
prams = {'file':'yEd3_2_0_1.sh',
'task':'accept',
'agree':'true'}
if os.getuid() != 0:
exit_script('please run as root.')
print 'starting to dowload installer..'
res = urllib.urlopen(dwurl, urllib.urlencode(prams))
respone = res.read()
if not respone:
exit_script('can not feth content of the page \
where download url exists.')
regex ='<a href="(.*)">start yEd download</a>'
real_dwurl = re.findall(regex,respone, re.M)[0]
if not real_dwurl:
exit_script('can not get download url.')
try:
filename = real_dwurl.split('/')[-1]
except IndexError:
exit_script('can not get file name.')
path = '/tmp/'+filename
if not os.path.isfile(path):
os.system("/usr/bin/env wget -c %s -O %s" % (host+real_dwurl,path))
print 'run installer'
os.system('bash '+path)