util.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. '''
  2. (C) 2019 Raryel C. Souza
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. '''
  14. import platform
  15. import os
  16. import subprocess
  17. import socket
  18. class MyUtil(object):
  19. @staticmethod
  20. def open_file(path):
  21. if platform.system() == "Windows":
  22. os.startfile(path)
  23. elif platform.system() == "Darwin":
  24. subprocess.Popen(["open", path])
  25. else:
  26. subprocess.Popen(["xdg-open", path])
  27. @staticmethod
  28. def is_internet_connected():
  29. try:
  30. # connect to the host -- tells us if the host is actually
  31. # reachable
  32. s = socket.create_connection(("www.google.com", 80), 2)
  33. s.close()
  34. return True
  35. except OSError:
  36. pass
  37. return False
  38. @staticmethod
  39. def percentage(currentval, maxval):
  40. return 100 * currentval / float(maxval)