Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# to update i18n .mo files (and merge .pot file into .po files) run on Linux:
# python setup.py build_i18n -m''

__VERSION__ = '6.2'
__VERSION__ = '6.3'

PROGRAM_VERSION = __VERSION__
prefix = sys.prefix
Expand Down
5 changes: 2 additions & 3 deletions update-station
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,15 @@ def check():
Function that checks for updates.
"""
while True:
sleep(20)
sleep(60)
if not repository_is_syncing():
if not Data.stop_pkg_refreshing:
if not updating():
GLib.idle_add(update_tray)
else:
print('True')
GLib.idle_add(Data.system_tray.tray_icon().set_visible, False)
# Wait for an hour to look for update
sleep(600)
sleep(3600)


def check_now():
Expand Down
133 changes: 72 additions & 61 deletions update_station/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,14 @@ def on_reboot(*args) -> None:
Gtk.main_quit()


def get_detail() -> None:
def get_detail(*args) -> None:
"""
Get the details of the upgrade failure.
:return:
"""
Popen(f'sudo -u {Data.username} xdg-open {Data.home}/update.failed', shell=True)


def get_packages_to_reinstall() -> list:
"""
Get packages to reinstall on kernel upgrade.
:return: The list of packages to reinstall.
"""
packages = read_file(f'../src/pkg_to_reinstall').replace('\n', ' ')
return run_command(f'pkg query "%n" {packages}').stdout.splitlines()


def run_command(command: str, check: bool = False) -> CompletedProcess:
"""
Run a shell command and optionally check for errors.
Expand All @@ -76,11 +67,7 @@ def check_for_update() -> bool:
return False
elif 'UPGRADED:' in upgrade_text:
return True
elif ' INSTALLED:' in upgrade_text:
return True
elif 'REINSTALLED:' in upgrade_text:
return True
elif 'REMOVED:' in upgrade_text:
elif 'DOWNGRADED:' in upgrade_text:
return True
else:
return False
Expand Down Expand Up @@ -153,10 +140,42 @@ def get_pkg_upgrade(option: str = '') -> str:
return upgrade_verbose


def get_packages_list_by_upgrade_type(upgrade_type: str, update_pkg: str, update_pkg_list: list) -> list:
"""
Get the list of packages by the upgrade type.
:param upgrade_type: The upgrade type: REMOVED, UPGRADED, INSTALLED, REINSTALLED, DOWNGRADED.
:param update_pkg: The upgrade data.
:param update_pkg_list: The list of the upgrade data.
:return: The list of packages.
"""
package_list = []
stop = False
if f'{upgrade_type}:' in update_pkg:
for line in update_pkg_list:
if f'{upgrade_type}:' in line:
stop = True
elif stop is True and line == '':
break
elif stop is True:
package_list.append(line.strip())
return package_list

def get_pkg_upgrade_data() -> dict:
"""
Get the upgrade data from pkg.
:return: The upgrade data.
This function is used to get the upgrade data from pkg.
:return: Returns a dictionary with the following keys:
- system_upgrade: True if the system is upgrading else False.
- remove: The list of packages to remove.
- number_to_remove: The number of packages to remove.
- upgrade: The list of packages to upgrade.
- number_to_upgrade: The number of packages to upgrade.
- upgrade: The list of packages to upgrade.
- number_to_upgrade: The number of packages to upgrade.
- install: The list of packages to install.
- number_to_install: The number of packages to install.
- reinstall: The list of packages to reinstall.
- number_to_reinstall: The number of packages to reinstall.
- total_of_packages: The total number of packages to upgrade.
"""
option = ''
system_upgrade = False
Expand All @@ -166,54 +185,46 @@ def get_pkg_upgrade_data() -> dict:
option = 'f'
update_pkg = get_pkg_upgrade(option)
update_pkg_list = update_pkg.splitlines()
pkg_to_remove = []
pkg_to_upgrade = []
pkg_to_install = []
pkg_to_reinstall = []
stop = False
if 'REMOVED:' in update_pkg:
for line in update_pkg_list:
if 'REMOVED:' in line:
stop = True
elif stop is True and line == '':
stop = False
break
elif stop is True:
pkg_to_remove.append(line.strip())
if 'UPGRADED:' in update_pkg:
for line in update_pkg_list:
if 'UPGRADED:' in line:
stop = True
elif stop is True and line == '':
stop = False
break
elif stop is True:
pkg_to_upgrade.append(line.strip())
if ' INSTALLED:' in update_pkg:
for line in update_pkg_list:
if ' INSTALLED:' in line:
stop = True
elif stop is True and line == '':
stop = False
break
elif stop is True:
pkg_to_install.append(line.strip())
if 'REINSTALLED:' in update_pkg:
for line in update_pkg_list:
if 'REINSTALLED:' in line:
stop = True
elif stop is True and line == '':
break
elif stop is True:
pkg_to_reinstall.append(line.strip())
pkg_dictionary = {
pkg_to_upgrade = get_packages_list_by_upgrade_type(
'UPGRADED', update_pkg, update_pkg_list
)
pkg_to_downgrade = get_packages_list_by_upgrade_type(
'DOWNGRADED', update_pkg, update_pkg_list
)
pkg_to_install = get_packages_list_by_upgrade_type(
' INSTALLED', update_pkg, update_pkg_list
)
pkg_to_reinstall = get_packages_list_by_upgrade_type(
'REINSTALLED', update_pkg, update_pkg_list
)
pkg_to_remove = get_packages_list_by_upgrade_type(
'REMOVED', update_pkg, update_pkg_list
)
total_of_packages = len(pkg_to_upgrade)
total_of_packages += (len(pkg_to_downgrade)
+ len(pkg_to_install)
+ len(pkg_to_reinstall)
+ len(pkg_to_remove))
return {
'system_upgrade': system_upgrade,
'remove': pkg_to_remove,
'upgrade': pkg_to_upgrade,
'number_to_upgrade': len(pkg_to_upgrade),
'downgrade': pkg_to_downgrade,
'number_to_downgrade': len(pkg_to_downgrade),
'install': pkg_to_install,
'reinstall': pkg_to_reinstall
'number_to_install': len(pkg_to_install),
'reinstall': pkg_to_reinstall,
'number_to_reinstall': len(pkg_to_reinstall),
'remove': pkg_to_remove,
'number_to_remove': len(pkg_to_remove),
'total_of_packages': (
len(pkg_to_upgrade)
+ len(pkg_to_downgrade)
+ len(pkg_to_install)
+ len(pkg_to_reinstall)
+ len(pkg_to_remove)
)
}
return pkg_dictionary


def is_major_upgrade_available() -> bool:
Expand Down
2 changes: 0 additions & 2 deletions update_station/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Data:
second_update: Boolean that indicates if the update-station should do 2 update.
stop_pkg_refreshing: Boolean that indicates if the update-station should stop refreshing the packages.
system_tray: Object that contains the system tray of the update-station.
total_packages: Integer that indicates the total number of packages that are that will be updated.
update_started: Boolean that indicates if the application has started updating the system.
username: String that indicates the username of the user that is running the update-station.
"""
Expand All @@ -35,6 +34,5 @@ class Data:
second_update: bool = False
stop_pkg_refreshing: bool = False
system_tray = None
total_packages: int = 0
update_started: bool = False
username: str = os.environ.get('SUDO_USER') if 'SUDO_USER' in os.environ else getpass.getuser()
Loading