def load_save_settings(settings_file): """Context manager to load and save settings.""" if not settings_file: settings_file = suricate.get_variable('suricate_settings_file_base_name') settings = sublime.load_settings(settings_file) if not settings: message = 'Settings file "%s" not found!' % settings_file sublime.error_message(message) raise Exception(message) # Do not try/catch, don't save if fails. yield settings sublime.save_settings(settings_file)
def remove(): display_list = [] extension = suricate.get_variable('suricate_profile_extension') current = _get_current_profile_set() for profile in current: settings = sublime.load_settings(profile + extension) description = settings.get('description', 'No description provided') display_list.append([profile, description]) if not display_list: sublime.error_message('Sorry, you don\'t have any active profile.') return def on_done(picked): current.remove(picked[0]) _set_and_save_profiles(current) sublime_wrapper.show_quick_panel(sorted(display_list), on_done)
def to_buffer(): title = 'Profiles' text = '%s\n%s\n\n' % (title, '=' * len(title)) extension = suricate.get_variable('suricate_profile_extension') current = _get_current_profile_set() your_profile = 'Your profile: [%s]' % ', '.join(sorted(current)) profiles = [[your_profile, current]] + [[x, [x]] for x in find_profiles()] for name, profile_names in profiles: profile_files = [x + extension for x in profile_names] text += '### %s\n\n' % name commands = command_parser.parse_profiles(profile_files) text += print_commands(commands) + '\n\n' sublime_wrapper.flush_to_buffer( text, name=title, scratch=True, syntax='Markdown')
def _set_and_save_profiles(value): variable_name = 'suricate_settings_file_base_name' settings_file_base_name = suricate.get_variable(variable_name) settings = sublime.load_settings(settings_file_base_name) settings.set('profiles', list(value)) sublime.save_settings(settings_file_base_name)
def find_profiles(): extension = suricate.get_variable('suricate_profile_extension') lst = sublime.find_resources('*' + extension) return set(x.rsplit('/', 1)[-1][:-len(extension)] for x in lst)