Skip to content

Commit 39f948f

Browse files
committed
auto update support
1 parent 46e5414 commit 39f948f

File tree

148 files changed

+182
-28
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+182
-28
lines changed

README.md

+1-1

data/launcher/config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
modules:
22
goagent: {auto_start: 1, current_version: 3.1.38, ignore_version: 3.1.38}
33
launcher: {current_version: 1.0.5, ignore_version: 1.0.5}
4-
update: {check_update: 1, last_path: /, node_id: '0',
5-
uuid: 0}
4+
update: {check_update: 1, last_path: /media/release/XX-Net/launcher/1.0.5, node_id: !!python/long '8796754053427',
5+
uuid: f4f82660-3426-4785-a9d3-cb82fe9a7d88}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

goagent/3.1.38/local/proxy.ini renamed to goagent/3.1.39/local/proxy.ini

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ enable = 0
8181
type = HTTP
8282
host = 127.0.0.1
8383
port = 8888
84+
user =
85+
passwd =
8486

8587
[control]
8688
enable = 1
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

goagent/3.1.38/web_ui/deploy.html renamed to goagent/3.1.39/web_ui/deploy.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<h2>部署GAE服务端</h2>
77
<form id="form-goagent-deploy">
8-
<input type="text" class="input-small" placeholder="appids" id="gae_appid">
8+
<input type="text" class="input-large" placeholder="appids" id="gae_appid">
99
<input type="text" class="input-middle" placeholder="E-mail" id="gae_email" >
1010
<input type="password" class="input-small" placeholder="password" id="gae_passwd">
1111
<br>
File renamed without changes.
File renamed without changes.

launcher/1.0.5/setup.py

-23
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

launcher/1.0.6/setup.py

+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
import sys
5+
6+
current_path = os.path.dirname(os.path.abspath(__file__))
7+
python_path = os.path.abspath( os.path.join(current_path, os.pardir, os.pardir, 'python27', '1.0'))
8+
noarch_lib = os.path.abspath( os.path.join(python_path, 'lib', 'noarch'))
9+
sys.path.append(noarch_lib)
10+
11+
import urllib2
12+
import time
13+
import subprocess
14+
import logging
15+
import re
16+
import zipfile
17+
import config
18+
import shutil
19+
20+
opener = urllib2.build_opener()
21+
22+
root_path = os.path.abspath( os.path.join(current_path, os.pardir, os.pardir))
23+
download_path = os.path.abspath( os.path.join(root_path, 'data', 'downloads'))
24+
25+
xxnet_unzip_path = ""
26+
27+
28+
def get_XXNet():
29+
global xxnet_unzip_path
30+
def download_file(url, file):
31+
try:
32+
logging.info("download %s to %s", url, file)
33+
req = opener.open(url)
34+
CHUNK = 16 * 1024
35+
with open(file, 'wb') as fp:
36+
while True:
37+
chunk = req.read(CHUNK)
38+
if not chunk: break
39+
fp.write(chunk)
40+
return True
41+
except:
42+
logging.info("download %s to %s fail", url, file)
43+
return False
44+
45+
def get_xxnet_url_version(readme_file):
46+
47+
try:
48+
fd = open(readme_file, "r")
49+
lines = fd.readlines()
50+
p = re.compile(r'https://codeload.github.com/XX-net/XX-Net/zip/([0-9]+)\.([0-9]+)\.([0-9]+)')
51+
for line in lines:
52+
m = p.match(line)
53+
if m:
54+
version = m.group(1) + "." + m.group(2) + "." + m.group(3)
55+
return m.group(0), version
56+
except Exception as e:
57+
logging.exception("xxnet_version fail:%s", e)
58+
raise "get_version_fail:" % readme_file
59+
60+
readme_url = "https://raw.githubusercontent.com/XX-net/XX-Net/master/README.md"
61+
readme_targe = os.path.join(download_path, "README.md")
62+
if not os.path.isdir(download_path):
63+
os.mkdir(download_path)
64+
if not download_file(readme_url, readme_targe):
65+
raise "get README fail:" % readme_url
66+
xxnet_url, xxnet_version = get_xxnet_url_version(readme_targe)
67+
xxnet_unzip_path = os.path.join(download_path, "XX-Net-%s" % xxnet_version)
68+
xxnet_zip_file = os.path.join(download_path, "XX-Net-%s.zip" % xxnet_version)
69+
70+
71+
if not download_file(xxnet_url, xxnet_zip_file):
72+
raise "download xxnet zip fail:" % download_path
73+
74+
with zipfile.ZipFile(xxnet_zip_file, "r") as dz:
75+
dz.extractall(download_path)
76+
dz.close()
77+
78+
79+
80+
def get_new_new_config():
81+
global xxnet_unzip_path
82+
import yaml
83+
data_path = os.path.abspath( os.path.join(xxnet_unzip_path, 'data', 'launcher', 'config.yaml'))
84+
try:
85+
new_config = yaml.load(file(data_path, 'r'))
86+
return new_config
87+
except yaml.YAMLError, exc:
88+
print "Error in configuration file:", exc
89+
90+
def process_data_files():
91+
new_config = get_new_new_config()
92+
config.load()
93+
config.config["modules"]["goagent"]["current_version"] = new_config["modules"]["goagent"]["current_version"]
94+
config.config["modules"]["launcher"]["current_version"] = new_config["modules"]["launcher"]["current_version"]
95+
config.save()
96+
97+
def install_xxnet_files():
98+
99+
def sha1_file(filename):
100+
import hashlib
101+
102+
BLOCKSIZE = 65536
103+
hasher = hashlib.sha1()
104+
try:
105+
with open(filename, 'rb') as afile:
106+
buf = afile.read(BLOCKSIZE)
107+
while len(buf) > 0:
108+
hasher.update(buf)
109+
buf = afile.read(BLOCKSIZE)
110+
return hasher.hexdigest()
111+
except:
112+
return False
113+
pass
114+
115+
for root, subdirs, files in os.walk(xxnet_unzip_path):
116+
#print "root:", root
117+
relate_path = root[len(xxnet_unzip_path)+1:]
118+
for subdir in subdirs:
119+
120+
target_path = os.path.join(root_path, relate_path, subdir)
121+
if not os.path.isdir(target_path):
122+
logging.info("mkdir %s", target_path)
123+
os.mkdir(target_path)
124+
125+
for filename in files:
126+
if relate_path == os.path.join("data", "goagent") and filename == "config.ini":
127+
continue
128+
if relate_path == os.path.join("data", "launcher") and filename == "config.yaml":
129+
continue
130+
src_file = os.path.join(root, filename)
131+
dst_file = os.path.join(root_path, relate_path, filename)
132+
if not os.path.isfile(dst_file) or sha1_file(src_file) != sha1_file(dst_file):
133+
shutil.copy(src_file, dst_file)
134+
logging.info("copy %s => %s", src_file, dst_file)
135+
136+
137+
def update_environment():
138+
get_XXNet()
139+
process_data_files()
140+
install_xxnet_files()
141+
142+
def wait_xxnet_exit():
143+
144+
def http_request(url, method="GET"):
145+
proxy_handler = urllib2.ProxyHandler({})
146+
opener = urllib2.build_opener(proxy_handler)
147+
try:
148+
req = opener.open(url)
149+
return req
150+
except Exception as e:
151+
#logging.exception("web_control http_request:%s fail:%s", url, e)
152+
return False
153+
154+
for i in range(20):
155+
if http_request("http://127.0.0.1:8085/quit") == False:
156+
return True
157+
time.sleep(1)
158+
return False
159+
160+
def run_new_start_script():
161+
162+
current_path = os.path.dirname(os.path.abspath(__file__))
163+
start_sript = os.path.abspath( os.path.join(current_path, os.pardir, "start.py"))
164+
subprocess.Popen([sys.executable, start_sript], shell=False)
165+
166+
def main():
167+
wait_xxnet_exit()
168+
update_environment()
169+
170+
time.sleep(2)
171+
logging.info("setup start run new launcher")
172+
run_new_start_script()
173+
174+
if __name__ == "__main__":
175+
main()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

launcher/1.0.5/web_ui/config.html renamed to launcher/1.0.6/web_ui/config.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
<br><br>
3-
<h4 >登录后启动:
3+
<h4 >开机自动启动:
44
<div class="pull-right">
55
<input id="auto_start" type="checkbox" checked>
66
</div>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)