Skip to content

Commit

Permalink
Merge pull request #24 from ghostbsd/issue-18
Browse files Browse the repository at this point in the history
Added the code to warn user about upgrade
  • Loading branch information
vic-thacker authored Jun 26, 2021
2 parents 8722a60 + c99aeee commit 2151d2d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# ,,python setup.py build_i18n -m''

# silence pyflakes, __VERSION__ is properly assigned below...
__VERSION__ = '1.2'
__VERSION__ = '1.3'

# for line in open('gbinstall', 'r').readlines():
# if (line.startswith('__VERSION__')):
Expand Down
58 changes: 55 additions & 3 deletions software-station
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import pwd
import os
from time import sleep


from software_station_pkg import (
search_packages,
available_package_origin,
Expand All @@ -50,7 +49,8 @@ from software_station_pkg import (
fetch_packages,
network_stat,
repo_online,
sync_with_repository
sync_with_repository,
start_update_station
)

from software_station_xpm import xpmPackageCategory
Expand Down Expand Up @@ -306,6 +306,7 @@ class TableWindow(Gtk.Window):
self.pkg_statistic.set_text('<small>Syncing statistic</small>')
self.pkg_statistic.set_use_markup(True)
self.network = network_stat()
self.need_upgrade = False
if self.network == 'UP':
self.online = repo_online()
else:
Expand All @@ -314,7 +315,8 @@ class TableWindow(Gtk.Window):
if self.online is True:
msg = 'syncing with the repository'
GLib.idle_add(self.update_progress, self.progress, 0.1, msg)
sync_with_repository()
if sync_with_repository() == 'UPGRADE':
self.need_upgrade = True
sleep(1)
msg = 'syncing available packages'
GLib.idle_add(self.update_progress, self.progress, 0.2, msg)
Expand Down Expand Up @@ -345,6 +347,8 @@ class TableWindow(Gtk.Window):
GLib.idle_add(self.unlock_ui)
if self.online is False:
GLib.idle_add(self.confirm_offline)
elif self.need_upgrade is True:
GLib.idle_add(self.confirm_upgrade)

def hide_window(self, button, window):
window.hide()
Expand All @@ -353,6 +357,7 @@ class TableWindow(Gtk.Window):
window = Gtk.Window()
window.set_title("Software Station")
window.connect("delete-event", Gtk.main_quit)
window.set_keep_above(True)
window.set_size_request(200, 80)
box1 = Gtk.VBox(homogeneous=False, spacing=0)
window.add(box1)
Expand Down Expand Up @@ -382,6 +387,53 @@ class TableWindow(Gtk.Window):
hBox.pack_end(close_button, False, False, 5)
window.show_all()

def start_upgrade(self, button):
start_update_station()
Gtk.main_quit()

def confirm_upgrade(self):
window = Gtk.Window()
window.set_title("Upgrade Needed")
window.connect("delete-event", Gtk.main_quit)
window.set_keep_above(True)
window.set_size_request(200, 80)
vBox = Gtk.VBox(homogeneous=False, spacing=0)
window.add(vBox)
vBox.show()
hBox = Gtk.HBox(homogeneous=False, spacing=0)
hBox.show()
vBox.pack_start(hBox, False, False, 10)
title = "<b>Warning this system need to be upgraded!</b>"
title_label = Gtk.Label(label=title)
title_label.set_use_markup(True)
title_label.set_justify(Gtk.Justification.CENTER)
hBox.pack_start(title_label, True, True, 10)
hBox = Gtk.HBox(homogeneous=False, spacing=0)
hBox.show()
vBox.pack_start(hBox, False, False, 5)
msg = "Installing software without upgrading could harm this installation.\n" \
"Would you like to upgrade now?"
msg_label = Gtk.Label(label=msg)
hBox.pack_start(msg_label, True, True, 20)
hBox = Gtk.HBox(homogeneous=False, spacing=0)
hBox.show()
vBox.pack_end(hBox, False, False, 5)
offline_button = Gtk.Button()
offline_button.set_label("Yes")
apply_img = Gtk.Image()
apply_img.set_from_icon_name('gtk-yes', 1)
offline_button.set_image(apply_img)
offline_button.connect("clicked", self.start_upgrade)
hBox.pack_end(offline_button, False, False, 5)
close_button = Gtk.Button()
close_button.set_label("No")
apply_img = Gtk.Image()
apply_img.set_from_icon_name('gtk-no', 1)
close_button.set_image(apply_img)
close_button.connect("clicked", self.hide_window, window)
hBox.pack_end(close_button, False, False, 5)
window.show_all()

def unlock_ui(self):
self.origin_treeview.set_sensitive(True)
self.pkgtreeview.set_sensitive(True)
Expand Down
23 changes: 20 additions & 3 deletions software_station_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,26 @@ def repo_online():


def sync_with_repository():
cmd = "pkg update -f"
pkg_out = run(cmd, shell=True)
return True if pkg_out.returncode == 0 else False
cmd = "yes | pkg update -f"
pkg_out = run(
cmd,
shell=True,
stdout=PIPE,
universal_newlines=True,
encoding='utf-8'
)
if pkg_out.returncode == 0:
if 'Newer FreeBSD version' in pkg_out.stdout:
return 'UPGRADE'
return 'SYNCED'
else:
return 'FAILLED'


def start_update_station():
cmd = "update-station check-now"
update_station = Popen(cmd, shell=True)
return True if update_station.returncode == 0 else False


def available_package_origin():
Expand Down

0 comments on commit 2151d2d

Please sign in to comment.