forked from omaha-consulting/omaha-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
63 lines (52 loc) · 2.17 KB
/
util.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
# Copyright (C) 2011 Crystalnix <[email protected]>
# This file is part of omaha-server.
# omaha-server is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# omaha-server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with omaha-server. If not, see <http://www.gnu.org/licenses/>.
import os, json
from config import Config
def getPathToUpdate(versionTo, versionFrom = None):
res = '{0}/{1}'.format(Config.bitpopDirectory, versionTo)
if versionFrom is None or versionFrom == '':
return res + '/' + Config.installerName
return res + '/' + versionFrom + '/' + Config.installerName
def getUpdateURL(versionTo, versionFrom = None):
return Config.insecureDomain + '/' + getPathToUpdate(versionTo, versionFrom)
def getUpdateURLMac(dmg_path):
return Config.insecureDomain + '/' + Config.bitpopDirectory + '/mac/' + dmg_path
def loadJsonAndCheckIfLatestKeyExists(filename):
latestExists = True
jsonInfo = None
jsonFile = None
if os.path.exists(filename) and os.path.isfile(filename):
try:
jsonFile = open(filename, "r")
except:
latestExists = False
if latestExists:
try:
jsonInfo = json.load(jsonFile)
except:
latestExists = False
finally:
jsonFile.close()
if type(jsonInfo) != type({}) or not jsonInfo.has_key("latest"):
latestExists = False
else:
latestExists = False
return { 'jsonData': jsonInfo, 'latestExists': latestExists }
def versionCompare(v1, v2):
v1s = v1.split('.')
v2s = v2.split('.')
for x, y in zip(v1s, v2s):
if int(x) < int(y): return -1;
if int(x) > int(y): return 1;
return 0