Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def generate_new_name(self):
"""
Generates name for new profile.
That is 'New Profile X', where X is number that makes name unique.
"""
i = 1
new_name = _("New Profile %s") % (i,)
filename = os.path.join(get_profiles_path(), new_name + ".sccprofile")
while os.path.exists(filename):
i += 1
new_name = _("New Profile %s") % (i,)
filename = os.path.join(get_profiles_path(), new_name + ".sccprofile")
return new_name
def convert_old_profiles(self):
"""
Checks all available profiles and automatically converts anything with
version 1.3 or lower.
"""
from scc.parser import ActionParser
to_convert = {}
for name in os.listdir(get_profiles_path()):
if name.endswith("~"):
# Ignore backups - https://github.com/kozec/sc-controller/issues/440
continue
try:
p = Profile(ActionParser())
p.load(os.path.join(get_profiles_path(), name))
except:
# Just ignore invalid profiles here
continue
if p.original_version < 1.4:
to_convert[name] = p
if to_convert:
log.warning("Auto-converting old profile files to version 1.4. This should take only moment.")
log.warning("All files are modified in-place, but backup files are created. Feel free to remove them later.")
for name in to_convert:
def _save_osk_profile(self, profile):
"""
Saves on-screen keyboard profile and calls daemon.reconfigure()
Used by methods that are changing it.
"""
profile.save(os.path.join(get_profiles_path(),
OSDKeyboard.OSK_PROF_NAME + ".sccprofile"))
self.app.dm.reconfigure()
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
def new_profile(self, profile, name):
filename = os.path.join(get_profiles_path(), name + ".sccprofile")
self.current_file = Gio.File.new_for_path(filename)
self.save_profile(self.current_file, profile)
controller = self.profile_switchers[0].get_controller()
if controller:
controller.set_profile(filename)
else:
self.dm.set_profile(filename)
self.profile_switchers[0].set_profile(name, create=True)
def _save_osk_profile(self, profile):
"""
Saves on-screen keyboard profile and calls daemon.reconfigure()
Used by methods that are changing it.
"""
profile.save(os.path.join(get_profiles_path(),
OSDKeyboard.OSK_PROF_NAME + ".sccprofile"))
self.app.dm.reconfigure()
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
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
def generate_new_name(self):
"""
Generates name for new profile.
That is 'New Profile X', where X is number that makes name unique.
"""
i = 1
new_name = _("New Profile %s") % (i,)
filename = os.path.join(get_profiles_path(), new_name + ".sccprofile")
while os.path.exists(filename):
i += 1
new_name = _("New Profile %s") % (i,)
filename = os.path.join(get_profiles_path(), new_name + ".sccprofile")
return new_name