Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Next] Add automatic Downloads #676

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions lib/systemd/system/mintupdate-automation-download.service

This file was deleted.

11 changes: 0 additions & 11 deletions lib/systemd/system/mintupdate-automation-download.timer

This file was deleted.

15 changes: 9 additions & 6 deletions usr/lib/linuxmint/mintUpdate/automatic_upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
logfile = "/var/log/mintupdate.log"
power_connectfile="/sys/class/power_supply/AC/online"
log = open(logfile, "a")
log.write("\n-- Automatic Upgrade starting %s:\n" % time.strftime('%a %d %b %Y %H:%M:%S %Z'))
if only_download:
log.write("\n-- Automatic Upgrade will only be downloaded and not installed(can be changed in mintupdate settings) %s:\n" % time.strftime('%a %d %b %Y %H:%M:%S %Z'))
else:
log.write("\n-- Automatic Upgrade starting %s:\n" % time.strftime('%a %d %b %Y %H:%M:%S %Z'))
log.flush()

pkla_source = "/usr/share/linuxmint/mintupdate/automation/99-mintupdate-temporary.pkla"
Expand Down Expand Up @@ -44,7 +47,10 @@
line = line.strip()
if line and not line.startswith("#"):
arguments.append(line)

except:
import traceback
log.write("Exception occurred:\n")
log.write(traceback.format_exc())
# Run mintupdate-cli through systemd-inhibit
cmd = ["/bin/systemd-inhibit", '--why="Performing automatic updates"',
'--who="Update Manager"', "--what=shutdown", "--mode=block",
Expand All @@ -54,10 +60,7 @@
cmd.extend(arguments)
subprocess.run(cmd, stdout=log, stderr=log)

except:
import traceback
log.write("Exception occurred:\n")
log.write(traceback.format_exc())


try:
# Remove shutdown and reboot blocker
Expand Down
60 changes: 29 additions & 31 deletions usr/lib/linuxmint/mintUpdate/mintUpdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2544,14 +2544,16 @@ def open_preferences(self, widget, show_automation=False):
page = SettingsPage()
box.pack_start(page, True, True, 0)
section = page.add_section(_("Package Updates"), _("Performed as root on a daily basis"))
autoupgrade_switch = Switch(_("Apply updates automatically"))
autoupgrade_switch.content_widget.set_active(os.path.isfile(AUTOMATIONS["upgrade"][2]))
autoupgrade_switch.content_widget.connect("notify::active", self.set_auto_upgrade)
section.add_row(autoupgrade_switch)
autodownload_switch = Switch(_("Download updates automatically"))
autodownload_switch.content_widget.set_active(os.path.isfile(AUTOMATIONS["download"][0]))
autodownload_switch.content_widget.connect("notify::active", self.set_auto_download)
section.add_row(autodownload_switch)
autoupgrade_combo = ComboBox(label = _("Select what to do automatically"), options = [[0, _("Nothing")], [1,_("Only Download")], [2,_("Download and install (recommended)")]])
MidnightNerd marked this conversation as resolved.
Show resolved Hide resolved
if (os.path.isfile(AUTOMATIONS["upgrade"][2])):
active = 2
elif (os.path.isfile(AUTOMATIONS["download"][2])):
active = 1
else:
active = 0
autoupgrade_combo.content_widget.set_active(active)
autoupgrade_combo.content_widget.connect("changed", self.set_auto_upgrade)
section.add_row(autoupgrade_combo)
button = Gtk.Button(label=_("Export blacklist to /etc/mintupdate.blacklist"))
button.set_margin_start(20)
button.set_margin_end(20)
Expand Down Expand Up @@ -2595,29 +2597,25 @@ def auto_refresh_toggled(self, widget, param):
self.auto_refresh = AutomaticRefreshThread(self)
self.auto_refresh.start()

def set_auto_upgrade(self, widget, param):
exists = os.path.isfile(AUTOMATIONS["upgrade"][2])
action = None
if widget.get_active() and not exists:
action = "enable"
elif not widget.get_active() and exists:
action = "disable"
if action:
subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "upgrade", action])
if widget.get_active() != os.path.isfile(AUTOMATIONS["upgrade"][2]):
widget.set_active(not widget.get_active())

def set_auto_download(self, widget, param):
exists = os.path.isfile(AUTOMATIONS["download"][0])
action = None
if widget.get_active() and not exists:
action = "enable"
elif not widget.get_active() and exists:
action = "disable"
if action:
subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "download", action])
if widget.get_active() != os.path.isfile(AUTOMATIONS["download"][0]):
widget.set_active(not widget.get_active())
def set_auto_upgrade(self, widget):
model = widget.get_model()
upgrade_exists = exists = os.path.isfile(AUTOMATIONS["upgrade"][2])
download_exists = exists = os.path.isfile(AUTOMATIONS["download"][2])
if model[widget.get_active_iter()][0]==0:
if upgrade_exists:
subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "upgrade", "disable"])
if download_exists:
subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "download", "disable"])
elif model[widget.get_active_iter()][0]==1:
if upgrade_exists:
subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "upgrade", "disable"])
if not download_exists:
subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "download", "enable"])
elif model[widget.get_active_iter()][0]==2:
if download_exists:
subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "download", "disable"])
if not upgrade_exists:
subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "upgrade", "enable"])

def set_auto_remove(self, widget, param):
exists = os.path.isfile(AUTOMATIONS["autoremove"][2])
Expand Down
2 changes: 1 addition & 1 deletion usr/share/linuxmint/mintupdate/automation/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"upgrade": ["/etc/systemd/system/timers.target.wants/mintupdate-automation-upgrade.timer", "systemd", "/var/lib/linuxmint/mintupdate-automatic-upgrades-enabled"],
"blacklist": ["/etc/mintupdate.blacklist", "Blacklist", null],
"autoremove": ["/etc/systemd/system/timers.target.wants/mintupdate-automation-autoremove.timer", "systemd", "/var/lib/linuxmint/mintupdate-automatic-removals-enabled"],
"clean": ["/etc/apt/apt.conf.d/99_mintupdate_clean", "apt-daily config", null]
"clean": ["/etc/apt/apt.conf.d/99_mintupdate_clean", "apt-daily config", null],
"download": ["/etc/systemd/system/timers.target.wants/mintupdate-automation-upgrade.timer", "systemd", "/var/lib/linuxmint/mintupdate-automatic-downloads-enabled"]
}
Loading