forked from outlyerapp/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwordpress.py
More file actions
executable file
·85 lines (68 loc) · 2.48 KB
/
wordpress.py
File metadata and controls
executable file
·85 lines (68 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
78
79
80
81
82
83
84
#!/usr/bin/env python
import os
import sys
import subprocess
tmp_space = "/tmp/"
def main():
if len(sys.argv) == 2:
url = sys.argv[1]
else:
print 'No URL specified to check'
sys.exit(1)
cmd = "wget -O " + tmp_space + "/index.html http://wordpress.org/download/"
try:
wget_process = subprocess.call(cmd, shell=True)
except:
print "Could not get http://wordpress.org/download/"
sys.exit(1)
version = ""
f = open(tmp_space + 'index.html', 'r')
for line in f.readlines():
if line.startswith(' <p class="intro">The latest stable release of WordPress'):
try:
left_paren = line.index('(')
except:
os.remove(tmp_space + 'index.html')
print "Did not find left paren in http://wordpress.org/download/"
sys.exit(1)
try:
right_paren = line.index(')')
except:
os.remove(tmp_space + 'index.html')
print "Did not find right paren in http://wordpress.org/download/"
sys.exit(1)
version = line[left_paren+1:right_paren]
f.close()
if version == "":
os.remove(tmp_space + 'index.html')
print "Could not ascertain current version number on wordpress.org"
sys.exit(1)
version = version[8:]
os.remove(tmp_space + 'index.html')
cmd = "wget -O " + tmp_space + "index.html " + url
wget_proc = subprocess.call(cmd, shell=True)
url_line = ""
f = open(tmp_space + 'index.html','r')
for line in f.readlines():
if line.startswith('<meta name="generator" content="WordPress'):
try:
left_paren = line.index('WordPress')
except:
os.remove(tmp_space + 'index.html')
print "Left paren on %s not found." % url
sys.exit(1)
try:
right_paren = line.index('/>')
except:
os.remove(tmp_space + 'index.html')
print "Right paren on %s not found." % url
sys.exit(1)
url_line = line[left_paren+10:right_paren-2]
os.remove(tmp_space + 'index.html')
if version == url_line:
print "Latest Wordpress Version %s is running on %s" % (version, url)
sys.exit(0)
else:
print "Latest Wordpress Version is %s. %s version cannot be determined." % (version, url)
sys.exit(1)
main()