Skip to content

Commit

Permalink
Update check
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-p committed Apr 19, 2022
1 parent e47bd74 commit ca698e9
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 21 deletions.
6 changes: 5 additions & 1 deletion AdmDialogs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The Admin4 Project
# (c) 2013-2014 Andreas Pflug
# (c) 2013-2022 Andreas Pflug
#
# Licensed under the Apache License,
# see LICENSE.TXT for conditions of usage
Expand Down Expand Up @@ -183,21 +183,25 @@ def Go(self):
self.Proxy=adm.proxy
self['UpdateCheckPeriod'].Append( [ (1, xlt("daily")), (7, xlt('weekly')), (30, xlt('monthly')), (0, xlt('never')) ] )
self.UpdateCheckPeriod=adm.updateCheckPeriod
self.AllowPrereleases=adm.allowPrereleases


def Save(self):
adm.confirmDeletes=self.ConfirmDeletes
adm.updateCheckPeriod=self.UpdateCheckPeriod
adm.allowPrereleases=self.AllowPrereleases
adm.proxy=self.Proxy
adm.config.Write("ConfirmDeletes", adm.confirmDeletes)
adm.config.Write("UpdateCheckPeriod", adm.updateCheckPeriod)
adm.config.Write("AllowPrereleases", adm.allowPrereleases)
adm.config.Write("Proxy", adm.proxy)
return True

@staticmethod
def Init():
adm.confirmDeletes=adm.config.Read("ConfirmDeletes", True)
adm.updateCheckPeriod=adm.config.Read("UpdateCheckPeriod", 7)
adm.allowPrereleases=adm.config.Read("AllowPrereleases", False)
adm.proxy=adm.config.Read("Proxy")


Expand Down
14 changes: 13 additions & 1 deletion Preferences.xrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@
<object class="sizeritem">
<object class="whComboBox" name="UpdateCheckPeriod"/>
</object>
<object class="sizeritem">
<object class="wxStaticText">
<label>Allow Prereleases</label>
</object>
<flag>wxALIGN_CENTRE_VERTICAL</flag>
</object>
<object class="sizeritem">
<object class="wxCheckBox" name="AllowPrereleases">
<label></label>
<checked>1</checked>
</object>
</object>
<object class="sizeritem">
<object class="wxStaticText">
<label>Proxy</label>
Expand All @@ -47,4 +59,4 @@
</object>
</object>
</object>
</resource>
</resource>
75 changes: 63 additions & 12 deletions Update.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,101 @@
from xmlhelp import Document as XmlDocument
import time, threading, subprocess

try:
import Crypto.PublicKey.RSA, Crypto.Hash.SHA, Crypto.Signature.PKCS1_v1_5
except:
Crypto=None
Crypto=None

onlineTimeout=5
FORCE_UPDATECHECK=False # used while developing

class UpdateThread(threading.Thread):

def __init__(self, frame):
self.frame=frame
threading.Thread.__init__(self)


def OnUpdate(self, _evt=None):
lines=[]
lines.append(xlt("New version: %s") % adm.updateInfo.release['tag_name'])
lines.append(adm.updateInfo.release['body'].replace('\r', ''))
lines.append(xlt("Please visit the releases website at"))
lines.append(admVersion.RELEASE_URL)
dlg=wx.MessageDialog(self.frame, "\n".join(lines), caption=xlt("Update available"))
dlg.ShowModal()

def run(self):
# currently no update check
return

update=OnlineUpdate()
update=GithubUpdateCheck()
if update.IsValid():
adm.updateInfo=update
if update.UpdateAvailable():
wx.CallAfter(self.frame.OnUpdate)
wx.CallAfter(self.OnUpdate)
elif update.exception:
wx.CallAfter(wx.MessageBox,
xlt("Connection error while trying to retrieve update information from the update server.\nCheck network connectivity and proxy settings!"),
xlt("Communication error"), wx.ICON_EXCLAMATION)




def CheckAutoUpdate(frame):
if adm.updateCheckPeriod:
if not admVersion.revDate:
return
lastUpdate=adm.config.Read('LastUpdateCheck', 0)
if not lastUpdate or lastUpdate+adm.updateCheckPeriod*24*60*60 < time.time():
if FORCE_UPDATECHECK or not lastUpdate or lastUpdate+adm.updateCheckPeriod*24*60*60 < time.time():
thread=UpdateThread(frame)
thread.start()

class GithubUpdateCheck():
def __init__(self):
self.info=None
self.release=None
try:
response=requests.get(admVersion.RELEASE_CHECK_URL, timeout=onlineTimeout, proxies=adm.GetProxies())
self.info=response.json()
except Exception as ex:
self.exception = ex
self.message=xlt("Online update check failed.\n\nError reported:\n %s") % str(ex)
return
adm.config.Write('LastUpdateCheck', time.time())

def IsValid(self):
return self.info != None

def UpdateAvailable(self):
if self.info:
localVersion=admVersion.version
localMainVersion=localVersion[:localVersion.find('rc')]
localRC=(localVersion!=localMainVersion)
for release in self.info:
if not adm.allowPrereleases and release.get('prerelease'):
continue
if True:
upstreamVersion=release['tag_name']
upstreamMainVersion=upstreamVersion[:upstreamVersion.find(('rc'))]
upstreamRC=(upstreamVersion!=upstreamMainVersion)

if localMainVersion > upstreamMainVersion: # strange: local version is newer
return False
elif localMainVersion == upstreamMainVersion:
if not localRC: # already release
return False
if upstreamRC:
if localVersion >= upstreamVersion:
return False
self.release=release
return True

return False


#################################################################
# deprecated

def HttpGet(url, timeout=onlineTimeout):
# We're verifying all contents ourself using the admin4 public key
response=requests.get(url, timeout=timeout, proxies=adm.GetProxies(), verify=False)
response.raise_for_status()
return response


class OnlineUpdate:
startupCwd=os.getcwd()

Expand Down
6 changes: 3 additions & 3 deletions UpdateDlg.xrc
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,19 @@
<object class="wxButton" name="Cancel">
<label>Cancel</label>
</object>
<flag>wxLEFT|wxRIGHT|wxALIGN_RIGHT</flag>
<flag>wxLEFT|wxRIGHT</flag>
<border>10</border>
</object>
<object class="sizeritem">
<object class="wxButton" name="Ok">
<label>Ok</label>
</object>
<flag>wxALIGN_RIGHT</flag>
<flag></flag>
</object>
</object>
<flag>wxTOP|wxBOTTOM|wxLEFT|wxRIGHT|wxGROW</flag>
<border>10</border>
</object>
</object>
</object>
</resource>
</resource>
1 change: 1 addition & 0 deletions adm.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

confirmDeletes=True
updateCheckPeriod=7
allowPrereleases=False
proxy=None

config=None
Expand Down
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The Admin4 Project
# (c) 2013-2014 Andreas Pflug
# (c) 2013-2022 Andreas Pflug
#
# Licensed under the Apache License,
# see LICENSE.TXT for conditions of usage
Expand Down
10 changes: 7 additions & 3 deletions version.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,19 @@ def __eq__(self, cmp):
def __ne__(self, cmp):
return self.fullver() != cmp.fullver()

version=Version(version)



requiredAdmVersion=Version(requiredAdmVersion)
libVersion=Version("3.0.0")

appName="Admin4"
description="4th generation\nAdministration Tool\n\nHelp and manual: http://www.admin4.org/docs"
RELEASE_CHECK_URL="https://api.github.com/repos/andreas-p/admin4/releases"
RELEASE_URL="https://github.com/andreas-p/admin4/releases"

description="""4th generation Administration Tool
Help and manual: http://www.admin4.org/docs
Releases: %s""" % RELEASE_URL
vendor="PSE"
vendorDisplay="PSE Consulting"
copyright="(c) 2013-2022 PSE Consulting Andreas Pflug"
Expand Down

0 comments on commit ca698e9

Please sign in to comment.