''' (C) 2019 Raryel C. Souza This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ''' import platform import os import subprocess import socket class MyUtil(object): @staticmethod def open_file(path): if platform.system() == "Windows": os.startfile(path) elif platform.system() == "Darwin": subprocess.Popen(["open", path]) else: subprocess.Popen(["xdg-open", path]) @staticmethod def is_internet_connected(): try: # connect to the host -- tells us if the host is actually # reachable s = socket.create_connection(("www.google.com", 80), 2) s.close() return True except OSError: pass return False @staticmethod def percentage(currentval, maxval): return 100 * currentval / float(maxval)