Skip to content

Commit

Permalink
added GitHub check frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
kwindrem committed May 17, 2024
1 parent d094454 commit 74af30e
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 46 deletions.
10 changes: 6 additions & 4 deletions FileSets/VersionIndependent/PageSettingsPackageManager.qml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ MbPage {
MbItemOptions
{
id: autoDownload
description: qsTr ("Automatic GitHub downloads")
description: qsTr ("GitHub check frequency")
bind: Utils.path (settingsPrefix, "/GitHubAutoDownload")
possibleValues:
[
MbOption { description: "On"; value: 1 },
MbOption { description: "Once"; value: 2 },
MbOption { description: "Off"; value: 0 }
MbOption { description: "Once"; value: 99 },
MbOption { description: "Every 10 minutes"; value: 1 },
MbOption { description: "Hourly"; value: 2 },
MbOption { description: "Daily"; value: 3 },
MbOption { description: "Never"; value: 0 }
]
writeAccessLevel: User.AccessInstaller
}
Expand Down
81 changes: 41 additions & 40 deletions PackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@

AUTO_DOWNLOADS_OFF = 0
NORMAL_DOWNLOAD = 1
ONE_DOWNLOAD = 2
HOURLY_DOWNLOAD = 2
DAILY_DOWNLOAD = 3
ONE_DOWNLOAD = 99

# /Settings/PackageManager/AutoInstall
# 0 - no automatic install
Expand Down Expand Up @@ -2148,7 +2150,9 @@ def UpdateVersionsAndFlags (self, doConflictChecks=False, doScriptPreChecks=Fals
# slow refresh also controls GitHub version expiration

FAST_GITHUB_REFRESH = 0.25
SLOW_GITHUB_REFRESH = 600.0
NORMAL_GITHUB_REFRESH = 600.0 # 10 minutes
HOURLY_GITHUB_REFRESH = 60.0 * 60.0
DAILY_GITHUB_REFRESH = HOURLY_GITHUB_REFRESH * 24.0

class UpdateGitHubVersionClass (threading.Thread):

Expand Down Expand Up @@ -2264,18 +2268,23 @@ def run (self):
packageListLength = 0

while self.threadRunning:
downloadMode = DbusIf.GetAutoDownloadMode ()

# do initial refreshes quickly
if forcedRefresh:
delay = FAST_GITHUB_REFRESH
# no packages set arbitrary, long delay
# won't actually be used because some message will be pushed to the queue
# but this prevents divide by zero
elif packageListLength == 0:
delay = SLOW_GITHUB_REFRESH
# otherwise set delay to complete scan of all versions in the slow refresh period
# otherwise set delay to complete scan of all versions in the selected refresh period
# this prevents GitHub versions from going undefined if refreshes are happening
else:
delay = SLOW_GITHUB_REFRESH / packageListLength
if downloadMode == NORMAL_DOWNLOAD:
delay = NORMAL_GITHUB_REFRESH
elif downloadMode == HOURLY_DOWNLOAD:
delay = HOURLY_GITHUB_REFRESH
else:
delay = DAILY_GITHUB_REFRESH
# this prevents divide by zero - value not actually used
if packageListLength != 0:
delay /= packageListLength
# queue gets STOP and REFRESH commands or priority package name
# empty queue signals it's time for a background update
# queue timeout is used to pace background updates
Expand Down Expand Up @@ -2338,18 +2347,16 @@ def run (self):
if source != 'GUI':
doUpdate = True
# for GUI - refresh if no version or last refresh more than 30 seconds ago
# prevents unnecessary network traffic when navigating PackageManager menus
elif package.GitHubVersion == "" or time.time () > package.lastGitHubRefresh + 30:
doUpdate = True
else:
logging.error ("can't fetch GitHub version - " + packageName + " not in package list")
DbusIf.UNLOCK ("UpdateGitHubVersion run 1")

doBackground = forcedRefresh or DbusIf.GetAutoDownloadMode () != AUTO_DOWNLOADS_OFF
# insure background updates will begin with fisrt package when they start again
if not doBackground:
gitHubVersionPackageIndex = 0
doBackground = forcedRefresh or downloadMode != AUTO_DOWNLOADS_OFF
# no priority update - do background update
elif not doUpdate:
if not doUpdate and doBackground:
DbusIf.LOCK ("UpdateGitHubVersion run 2")
packageListLength = len (PackageClass.PackageList)
# empty package list - no refreshes possible
Expand All @@ -2361,10 +2368,7 @@ def run (self):
packageName = package.PackageName
user = package.GitHubUser
branch = package.GitHubBranch
# refresh if no version or last refresh more than 30 seconds ago
# prevents unnecessary network traffic when navigating PackageManager menus
if package.GitHubVersion == "" or time.time () > package.lastGitHubRefresh + 30:
doUpdate = True
doUpdate = True
gitHubVersionPackageIndex += 1
# reached end of list - all package Git Hub versions have been refreshed
if gitHubVersionPackageIndex >= packageListLength:
Expand Down Expand Up @@ -3651,7 +3655,7 @@ def run (self):
# persistent storage for mainLoop
packageIndex = 0
noActionCount = 0
currentDownloadMode = AUTO_DOWNLOADS_OFF
lastDownloadMode = AUTO_DOWNLOADS_OFF
bootInstall = False
DeferredGuiEditAcknowledgement = None
lastTimeSync = 0
Expand All @@ -3677,7 +3681,7 @@ def mainLoop ():
global noActionCount
global packageIndex
global noActionCount
global currentDownloadMode
global lastDownloadMode
global bootInstall
global lastTimeSync
startTime = time.time()
Expand Down Expand Up @@ -3710,15 +3714,16 @@ def mainLoop ():
actionMessage = ""
bootReinstallFile="/etc/venus/REINSTALL_PACKAGES"

# default values - changed below based on states
currentDownloadMode = DbusIf.GetAutoDownloadMode ()
emptyPackageList = False
scanForActions = True
checkPackages = True
autoInstall = False
autoDownload = False

# hold off all package processing if package list is empty
if len (PackageClass.PackageList) == 0:
emptyPackageList = True
scanForActions = False
checkPackages = False
packageIndex = 0

# if boot-time reinstall has been requiested by reinstallMods
Expand All @@ -3729,32 +3734,29 @@ def mainLoop ():
bootInstall = True
packageIndex = 0
logging.warning ("starting boot-time reinstall")
currentDownloadMode = AUTO_DOWNLOADS_OFF
autoInstall = True
elif WaitForGitHubVersions:
currentDownloadMode = AUTO_DOWNLOADS_OFF
scanForActions = False
checkPackages = False

# don't look for new actions if uninstalling all packages or uninstalling SetupHelper
elif MediaScan.AutoUninstall or SetupHelperUninstall:
currentDownloadMode = AUTO_DOWNLOADS_OFF

pass
# not doing something special - use dbus values
else:
autoDownload = currentDownloadMode != AUTO_DOWNLOADS_OFF
autoInstall = DbusIf.GetAutoInstall ()
# save mode before chaning so changes can be detected below
lastDownloadMode = currentDownloadMode
currentDownloadMode = DbusIf.GetAutoDownloadMode ()

# download mode changed
# restart at beginning of list and request GitHub version refresh
if currentDownloadMode != lastDownloadMode \
and ( currentDownloadMode == ONE_DOWNLOAD or lastDownloadMode == AUTO_DOWNLOADS_OFF ):
# restart at beginning of list and refresh all GitHub versions
if currentDownloadMode != lastDownloadMode and currentDownloadMode != AUTO_DOWNLOADS_OFF:
packageIndex = 0
scanForActions = False
checkPackages = False
UpdateGitHubVersion.SetPriorityGitHubVersion ('REFRESH')
# save mode so changes can be detected on next pass
lastDownloadMode = currentDownloadMode

# make sure a new scan starts at beginning of list
if not scanForActions:
if not checkPackages:
packageIndex = 0
# process one package per pass of mainloop
else:
Expand Down Expand Up @@ -3783,8 +3785,7 @@ def mainLoop ():

# disallow operations on this package if anything is pending
packageOperationOk = not package.DownloadPending and not package.InstallPending
if packageOperationOk and currentDownloadMode != AUTO_DOWNLOADS_OFF \
and DownloadGitHub.DownloadVersionCheck (package):
if packageOperationOk and autoDownload and DownloadGitHub.DownloadVersionCheck (package):
# don't allow install if download is needed - even if it has not started yet
packageOperationOk = False
actionMessage = "downloading " + packageName + " ..."
Expand All @@ -3810,7 +3811,7 @@ def mainLoop ():
actionMessage = "installing " + packageName + " ..."
PushAction ( command='install' + ':' + packageName, source='AUTO' )
DbusIf.UNLOCK ("mainLoop 1")
# end if scanForActions
# end if checkPackages

DbusIf.LOCK ("mainLoop 2")
actionsPending = False
Expand All @@ -3822,7 +3823,7 @@ def mainLoop ():
if package.DownloadPending or package.InstallPending:
actionsPending = True
# clear GitHub version if not refreshed in 10 minutes
elif package.GitHubVersion != "" and package.lastGitHubRefresh > 0 and time.time () > package.lastGitHubRefresh + SLOW_GITHUB_REFRESH + 10:
elif package.GitHubVersion != "" and package.lastGitHubRefresh > 0 and time.time () > package.lastGitHubRefresh + NORMAL_GITHUB_REFRESH + 10:
package.SetGitHubVersion ("")

if package.ActionNeeded == REBOOT_NEEDED:
Expand Down
2 changes: 1 addition & 1 deletion blindInstall/SetupHelperVersion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v8.2
v8.3
4 changes: 4 additions & 0 deletions changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v8.3:
added GitHub check frequency: 10 minutes, hourly, daily
reduces network bandwidth

v8.2:
fixed: auto downloads can happen even when off (introduced in v8.1)

Expand Down
Binary file modified venus-data-UninstallPackages.tgz
Binary file not shown.
Binary file modified venus-data.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v8.2
v8.3

1 comment on commit 74af30e

@kwindrem
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prior to v8.3, you had a choice of checking for GuiHub updates once every 10 minutes, or not at all. Some users on limited data plans asked for reduced frequency of checking. So now you can select "Daily" and "Hourly" check rates as well.

The "Once" selection is still available which checks all package GitHub versions once then switches to None.

In addition to the automatic version checks, entering PackageManager's Active packages menu will refresh all GutHub versions so that you have up to date infomation for manual downloads. The selected package GitHub version is also updated when switching between packages in PackageManager's Package edit menu, again so the information is up to date.

Checks for GutHub version changes are spread out so that all package versions are updated in the selected period. For example with 8 packages and Hourly selected one package version check is made every 7.5 minutes. If you have only two packages, then one package is checked every 30 minutes.

Faster rates mean that updates will happen closer to the time GitHub was updated which is handy if you are waiting for an update. But otherwise, has no advantage.

Please sign in to comment.