You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.0 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. #! /usr/bin/env python
  2. import os
  3. import sys
  4. import locale
  5. import subprocess
  6. def remove_empty_items(array):
  7. return [x for x in array if x != '']
  8. def remove_spaces(string):
  9. return string.replace(' ', '')
  10. def string_to_array(string, char=' '):
  11. return string.split(char)
  12. def preferredencoding():
  13. try:
  14. pref = locale.getpreferredencoding()
  15. u'TEST'.encode(pref)
  16. except:
  17. pref = 'UTF-8'
  18. return pref
  19. def get_encoding():
  20. if sys.version_info >= (3, 0):
  21. return None
  22. if sys.platform == 'win32':
  23. # Refer to http://stackoverflow.com/a/9951851/35070
  24. return preferredencoding()
  25. return None
  26. def encode_list(data_list, encoding):
  27. return [x.encode(encoding, 'ignore') for x in data_list]
  28. def video_is_dash(video):
  29. return "DASH" in video
  30. def have_dash_audio(audio):
  31. return audio != "NO SOUND"
  32. def remove_file(filename):
  33. os.remove(filename)
  34. def get_path_seperator():
  35. return '\\' if os.name == 'nt' else '/'
  36. def fix_path(path):
  37. if path != '' and path[-1:] != get_path_seperator():
  38. path += get_path_seperator()
  39. return path
  40. def get_HOME():
  41. return os.path.expanduser("~")
  42. def add_PATH(path):
  43. os.environ["PATH"] += os.pathsep + path
  44. def abs_path(path):
  45. path_list = path.split(get_path_seperator())
  46. for i in range(len(path_list)):
  47. if path_list[i] == '~':
  48. path_list[i] = get_HOME()
  49. return get_path_seperator().join(path_list)
  50. def file_exist(filename):
  51. return os.path.exists(filename)
  52. def get_os_type():
  53. return os.name
  54. def get_filesize(path):
  55. return os.path.getsize(path)
  56. def makedir(path):
  57. os.makedirs(path)
  58. def icon_path(icon_path, file_path):
  59. L = len(icon_path)
  60. file_path = os.path.abspath(file_path).split(get_path_seperator())
  61. for index, item in reversed(list(enumerate(icon_path))):
  62. file_path[index - L] = item
  63. return get_path_seperator().join(file_path)
  64. def get_filename(path):
  65. return path.split(get_path_seperator())[-1]
  66. def open_dir(path):
  67. if os.name == 'nt':
  68. os.startfile(path)
  69. else:
  70. subprocess.call(('xdg-open', path))