1import os 2 3from variety.Util import Util 4 5DEFAULT_PROFILE_PATH = "~/.config/variety/" 6 7__profile_path = DEFAULT_PROFILE_PATH 8 9 10def set_profile_path(profile_path): 11 if not profile_path: 12 profile_path = DEFAULT_PROFILE_PATH 13 14 # if just a name is passed instead of a full path, put it under ~/.config/variety-profiles 15 if not "/" in profile_path: 16 profile_path = "~/.config/variety-profiles/{}".format(profile_path) 17 18 # make sure profile path has a trailing slash 19 if not profile_path.endswith("/"): 20 profile_path += "/" 21 22 global __profile_path 23 __profile_path = profile_path 24 25 26def get_profile_path(expanded=True): 27 global __profile_path 28 return os.path.expanduser(__profile_path) if expanded else __profile_path 29 30 31def get_profile_short_name(): 32 return os.path.basename(get_profile_path()[:-1]) 33 34 35def get_profile_wm_class(): 36 return "Variety" + ("" if is_default_profile() else " (Profile: {})".format(get_profile_path())) 37 38 39def is_default_profile(): 40 """ 41 Are we using the default profile or a custom profile? 42 """ 43 return os.path.normpath(get_profile_path()) == os.path.normpath( 44 os.path.expanduser(DEFAULT_PROFILE_PATH) 45 ) 46 47 48def get_profile_id(): 49 """ 50 Returns a dbus-and-filename-friendly identificator of the profile path 51 """ 52 return Util.md5(os.path.normpath(get_profile_path()))[:10] 53 54 55def get_desktop_file_name(): 56 if is_default_profile(): 57 return "variety.desktop" 58 else: 59 return "variety-{}-{}.desktop".format(get_profile_short_name(), get_profile_id()) 60 61 62def get_autostart_file_path(): 63 return os.path.join(os.path.expanduser("~/.config/autostart"), get_desktop_file_name()) 64