def test_for_update(): try: if not updates.is_up_to_date(): if ask_user_for_update(): run_updater() exit(0) except Exception as e: logging.error("Can't check for updates: " + str(e))
def update_updater(): try: logging.info('Begging updating.') if not updater_updates.is_up_to_date(): thread = updater_updates.UpdaterUpdater() thread.start() return thread else: return None except Exception as e: logging.error("Can't update updater: " + str(e))
def send_mac_os_notification(message: str): """Send macOS push notification.""" logging.debug('Sending macos push notification') if not osinfo.is_mac_os(): logging.error('Trying to send macOS notification not from macOS!') raise OSError('MacOS notifications can be sent only from MacOS!') if appinfo.APP_ICON is not None: os.system( 'terminal-notifier -title "{}" -subtitle "" -message "{}" -appIcon "{}"' .format(appinfo.APP_NAME, message, appinfo.APP_ICON)) else: os.system( 'terminal-notifier -title "{}" -subtitle "" -message "{}"'.format( appinfo.APP_NAME, message))
def run_daemon_if_it_is_not_running(): if not os.path.exists(appinfo.PID_FILE): run_daemon() else: try: f = open(appinfo.PID_FILE, 'r') pid = int(f.read().strip()) f.close() if not psutil.pid_exists(pid): run_daemon() except Exception as e: logging.error("Can't check pid file of daemon: " + str(e)) run_daemon()
def send_linux_notification(message: str): """Send linux libnotify notification.""" logging.debug('Sending linux libnotify notification') if not osinfo.is_linux(): logging.error('Trying to send linux notification not from linux!') raise OSError( 'Linux libnotify notifications can be sent only from linux-based OS!' ) if appinfo.APP_ICON is not None: os.system( 'notify-send "{}" "{}" --icon="{}" --expire-time=30000'.format( appinfo.APP_NAME, message, os.path.abspath(appinfo.APP_ICON))) else: os.system('notify-send "{}" "{}" --expire-time=30000'.format( appinfo.APP_NAME, message))
def delete(name: str): """Remove url from sites list. NameError - if than name not exists. """ logging.info('Deleting website ' + name) sites = get_sites_dict() if name not in sites.keys(): logging.error('Name not exists') raise NameError('Name not exists.') del sites[name] save_sites_list(sites)
def send_windows_notification(message: str): """Send windows 10 toast notification.""" logging.debug('Sending windows 10 toast notification') if not osinfo.is_win(): logging.error('Trying to send win10 notification not from win10!') raise OSError( 'Windows toast notifications can be sent only from Windows 10!') import win10toast toaster = win10toast.ToastNotifier() toaster.show_toast(appinfo.APP_NAME, message, icon_path=appinfo.APP_ICON, duration=5, threaded=True)
def add(name: str, url: str, settings: dict, favourite: bool = False, favicon: str = files.get_media_folder_path() + '/logo.ico'): """Add url to sites list. Generate settings dictionary by `build_settings` method. NameError - if than name already exists. """ logging.info('Adding new website ' + name + '<' + url + '>') sites = get_sites_dict() if name in sites.keys(): logging.error('Name already exists') raise NameError('Name already exists.') sites[name] = {'url': url, 'settings': settings, 'favourite': favourite, 'favicon': favicon} save_sites_list(sites)
def rename(old_name: str, new_name: str): """Rename url in sites list. NameError - if new name already exists or old name not exists. """ logging.info('Renaming website ' + old_name + ' to ' + new_name) sites = get_sites_dict() if old_name not in sites.keys(): logging.error('old name not exists') raise NameError('Old name not exists.') if new_name in sites.keys(): logging.error('New name already exists') raise NameError('New name already exists.') sites[new_name] = sites.pop(old_name) save_sites_list(sites)
def run_daemon(): try: run('daemon') except Exception as e: print("EXCEPTION - " + str(e)) logging.error("Can't start daemon: ")