Ejemplo n.º 1
0
def profile_is_default(name):
	"""
	Returns True if named profile exists in default_profiles directory, even
	if it is overrided by profile in user config directory.
	"""
	filename = "%s.sccprofile" % (name,)
	return os.path.exists(os.path.join(get_default_profiles_path(), filename))
Ejemplo n.º 2
0
def cmd_list_profiles(argv0, argv):
    """
	Lists available profiles
	
	Usage: scc list-profiles [-a]
	
	Arguments:
	  -a   Include names begining with dot
	"""
    from scc.paths import get_profiles_path, get_default_profiles_path
    paths = [get_default_profiles_path(), get_profiles_path()]
    include_hidden = "-a" in argv
    lst = set()
    for path in paths:
        try:
            for x in os.listdir(path):
                if x.endswith(".sccprofile"):
                    if not include_hidden and x.startswith("."):
                        continue
                    lst.add(x[0:-len(".sccprofile")])
        except OSError:
            pass
    for x in sorted(lst):
        print x
    return 0
Ejemplo n.º 3
0
def profile_is_default(name):
    """
	Returns True if named profile exists in default_profiles directory, even
	if it is overrided by profile in user config directory.
	"""
    filename = "%s.sccprofile" % (name, )
    return os.path.exists(os.path.join(get_default_profiles_path(), filename))
Ejemplo n.º 4
0
def cmd_list_profiles(argv0, argv):
	"""
	Lists available profiles
	
	Usage: scc list-profiles [-a]
	
	Arguments:
	  -a   Include names begining with dot
	"""
	from scc.paths import get_profiles_path, get_default_profiles_path
	paths = [ get_default_profiles_path(), get_profiles_path() ]
	include_hidden = "-a" in argv
	lst = set()
	for path in paths:
		try:
			for x in os.listdir(path):
				if x.endswith(".sccprofile"):
					if not include_hidden and x.startswith("."):
						continue
					lst.add(x[0:-len(".sccprofile")])
		except OSError:
			pass
	for x in sorted(lst):
		print x
	return 0
Ejemplo n.º 5
0
def profile_is_override(name):
	"""
	Returns True if named profile exists both in user config directory and
	default_profiles directory.
	"""
	filename = "%s.sccprofile" % (name,)
	if os.path.exists(os.path.join(get_profiles_path(), filename)):
		if os.path.exists(os.path.join(get_default_profiles_path(), filename)):
			return True
	return False
Ejemplo n.º 6
0
def profile_is_override(name):
    """
	Returns True if named profile exists both in user config directory and
	default_profiles directory.
	"""
    filename = "%s.sccprofile" % (name, )
    if os.path.exists(os.path.join(get_profiles_path(), filename)):
        if os.path.exists(os.path.join(get_default_profiles_path(), filename)):
            return True
    return False
Ejemplo n.º 7
0
	def generate(self, menuhandler):
		# TODO: Cannot load directory content asynchronously here and I'm
		# TODO: not happy about it
		rv, all_profiles = [], {}
		for d in (get_default_profiles_path(), get_profiles_path()):
			for x in os.listdir(d):
				if x.endswith(".sccprofile") and not x.startswith("."):
					all_profiles[x] = os.path.join(d, x)
		for p in sorted(all_profiles, key=lambda s: s.lower()):
			menuitem = MenuItem("generated", p[0:-11])	# strips ".sccprofile"
			menuitem.filename = all_profiles[p]
			menuitem.callback = self.callback
			rv.append(menuitem)
		return rv
Ejemplo n.º 8
0
	def generate(self, menuhandler):
		# TODO: Cannot load directory content asynchronously here and I'm
		# TODO: not happy about it
		rv, all_profiles = [], {}
		for d in (get_default_profiles_path(), get_profiles_path()):
			for x in os.listdir(d):
				if x.endswith(".sccprofile") and not x.startswith("."):
					all_profiles[x] = os.path.join(d, x)
		for p in sorted(all_profiles, key=lambda s: s.lower()):
			menuitem = MenuItem("generated", p[0:-11])	# strips ".sccprofile"
			menuitem.filename = all_profiles[p]
			menuitem.callback = self.callback
			rv.append(menuitem)
		return rv
	def save_profile(self, giofile, profile):
		"""
		Saves profile from 'profile' object into 'giofile'.
		Calls on_profile_saved when done
		"""
		# 1st check, if file is not in /usr/share.
		# When user tries to save over built-in profile in /usr/share,
		# new file with same name is created in ~/.config/scc/profiles and profile
		# is shaved into it.
		
		if giofile.get_path().startswith(get_default_profiles_path()):
			return self._save_profile_local(giofile, profile)
		
		profile.save(giofile.get_path())
		self.on_profile_saved(giofile)
Ejemplo n.º 10
0
    def save_profile(self, giofile, profile):
        """
		Saves profile from 'profile' object into 'giofile'.
		Calls on_profile_saved when done
		"""
        # 1st check, if file is not in /usr/share.
        # When user tries to save over built-in profile in /usr/share,
        # new file with same name is created in ~/.config/scc/profiles and profile
        # is shaved into it.

        if giofile.get_path().startswith(get_default_profiles_path()):
            return self._save_profile_local(giofile, profile)

        profile.save(giofile.get_path())
        self.on_profile_saved(giofile)
Ejemplo n.º 11
0
def find_profile(name):
	"""
	Returns filename for specified profile name.
	This is done by searching for name + '.sccprofile' in ~/.config/scc/profiles
	first and in /usr/share/scc/default_profiles if file is not found in first
	location.
	
	Returns None if profile cannot be found.
	"""
	filename = "%s.sccprofile" % (name,)
	for p in (get_profiles_path(), get_default_profiles_path()):
		path = os.path.join(p, filename)
		if os.path.exists(path):
			return path
	return None
Ejemplo n.º 12
0
def find_profile(name):
    """
	Returns filename for specified profile name.
	This is done by searching for name + '.sccprofile' in ~/.config/scc/profiles
	first and in /usr/share/scc/default_profiles if file is not found in first
	location.
	
	Returns None if profile cannot be found.
	"""
    filename = "%s.sccprofile" % (name, )
    for p in (get_profiles_path(), get_default_profiles_path()):
        path = os.path.join(p, filename)
        if os.path.exists(path):
            return path
    return None
Ejemplo n.º 13
0
	def load_profile_list(self):
		""" Loads lists of profiles. Uses GLib to do it on background. """
		# First list is for default profiles, 2nd for user profiles
		# Number is increased when list is loaded until it reaches 2
		data = [ None, None ]
		paths = [ get_default_profiles_path(), get_profiles_path() ]
		
		for i in (0, 1):
			f = Gio.File.new_for_path(paths[i])
			f.enumerate_children_async(
				"*.sccprofile",
				Gio.FileQueryInfoFlags.NONE,
				1, None,
				self._on_profile_list_loaded,
				data, i
			)
Ejemplo n.º 14
0
 def load_profile_list(self, category=None):
     paths = [get_default_profiles_path(), get_profiles_path()]
     self.load_user_data(paths, "*.sccprofile", category,
                         self.on_profiles_loaded)
Ejemplo n.º 15
0
 def load_profile_list(self):
     paths = [get_default_profiles_path(), get_profiles_path()]
     self._load_user_data(paths, "*.sccprofile", self.on_profiles_loaded)
Ejemplo n.º 16
0
	def load_profile_list(self, category=None):
		paths = [ get_default_profiles_path(), get_profiles_path() ]
		self.load_user_data(paths, "*.sccprofile", category, self.on_profiles_loaded)