예제 #1
0
def get_output_directory(view_or_root, return_setting=False):
    # not supported using texify or the simple builder
    if using_texify_or_simple():
        if return_setting:
            return (None, None)
        else:
            return None

    root = get_root(view_or_root)

    output_directory = get_directive(view_or_root, 'output_directory')

    if (output_directory is None or output_directory == '') and (
            root is not None and view_or_root != root):
        output_directory = get_directive(root, 'output_directory')

    if output_directory is not None and output_directory != '':
        out_dir = resolve_to_absolute_path(
            root, output_directory, _get_root_directory(root)
        )

        if return_setting:
            return (out_dir, output_directory)
        else:
            return out_dir

    view = sublime.active_window().active_view()
    output_directory = view.settings().get('output_directory')

    if output_directory is not None and output_directory != '':
        out_dir = resolve_to_absolute_path(
            root,
            output_directory,
            _get_root_directory(get_project_file_name(view))
        )

        if return_setting:
            return (out_dir, output_directory)
        else:
            return out_dir

    settings = sublime.load_settings('LaTeXTools.sublime-settings')
    output_directory = settings.get('output_directory')

    if output_directory is not None and output_directory != '':
        out_dir = resolve_to_absolute_path(
            root, output_directory, _get_root_directory(root)
        )

        if return_setting:
            return (out_dir, output_directory)
        else:
            return out_dir

    if return_setting:
        return (None, None)
    else:
        return None
예제 #2
0
def get_output_directory(view_or_root, return_setting=False):
    # not supported using texify or the simple builder
    if using_texify_or_simple():
        if return_setting:
            return (None, None)
        else:
            return None

    root = get_root(view_or_root)

    output_directory = get_directive(view_or_root, 'output_directory')

    if (output_directory is None or output_directory
            == '') and (root is not None and view_or_root != root):
        output_directory = get_directive(root, 'output_directory')

    if output_directory is not None and output_directory != '':
        out_dir = resolve_to_absolute_path(root, output_directory,
                                           _get_root_directory(root))

        if return_setting:
            return (out_dir, output_directory)
        else:
            return out_dir

    view = sublime.active_window().active_view()
    output_directory = view.settings().get('output_directory')

    if output_directory is not None and output_directory != '':
        out_dir = resolve_to_absolute_path(
            root, output_directory,
            _get_root_directory(get_project_file_name(view)))

        if return_setting:
            return (out_dir, output_directory)
        else:
            return out_dir

    settings = sublime.load_settings('LaTeXTools.sublime-settings')
    output_directory = settings.get('output_directory')

    if output_directory is not None and output_directory != '':
        out_dir = resolve_to_absolute_path(root, output_directory,
                                           _get_root_directory(root))

        if return_setting:
            return (out_dir, output_directory)
        else:
            return out_dir

    if return_setting:
        return (None, None)
    else:
        return None
예제 #3
0
def get_aux_directory(view_or_root, return_setting=False):
    # not supported using texify or the simple builder
    if not using_miktex() or using_texify_or_simple():
        if return_setting:
            return (None, None)
        else:
            return None

    root = get_root(view_or_root)

    aux_directory = None
    if root is not None:
        aux_directory = get_directive(root, 'aux_directory')

    if aux_directory is not None and aux_directory != '':
        aux_dir = resolve_to_absolute_path(
            root, aux_directory, _get_root_directory(root)
        )

        if return_setting:
            return (aux_dir, aux_directory)
        else:
            return aux_dir

    view = sublime.active_window().active_view()
    aux_directory = view.settings().get('aux_directory')

    if aux_directory is not None and aux_directory != '':
        aux_dir = resolve_to_absolute_path(
            root,
            aux_directory,
            _get_root_directory(get_project_file_name(view))
        )

        if return_setting:
            return (aux_dir, aux_directory)
        else:
            return aux_dir

    settings = sublime.load_settings('LaTeXTools.sublime-settings')
    aux_directory = settings.get('aux_directory')

    if aux_directory is not None and aux_directory != '':
        aux_dir = resolve_to_absolute_path(
            root, aux_directory, _get_root_directory(root)
        )

        if return_setting:
            return (aux_dir, aux_directory)
        else:
            return aux_dir

    return get_output_directory(root, return_setting)
예제 #4
0
def get_aux_directory(view_or_root, return_setting=False):
    # not supported using texify or the simple builder
    if not using_miktex() or using_texify_or_simple():
        if return_setting:
            return (None, None)
        else:
            return None

    root = get_root(view_or_root)

    aux_directory = None
    if root is not None:
        aux_directory = get_directive(root, 'aux_directory')

    if aux_directory is not None and aux_directory != '':
        aux_dir = resolve_to_absolute_path(root, aux_directory,
                                           _get_root_directory(root))

        if return_setting:
            return (aux_dir, aux_directory)
        else:
            return aux_dir

    view = sublime.active_window().active_view()
    aux_directory = view.settings().get('aux_directory')

    if aux_directory is not None and aux_directory != '':
        aux_dir = resolve_to_absolute_path(
            root, aux_directory,
            _get_root_directory(get_project_file_name(view)))

        if return_setting:
            return (aux_dir, aux_directory)
        else:
            return aux_dir

    settings = sublime.load_settings('LaTeXTools.sublime-settings')
    aux_directory = settings.get('aux_directory')

    if aux_directory is not None and aux_directory != '':
        aux_dir = resolve_to_absolute_path(root, aux_directory,
                                           _get_root_directory(root))

        if return_setting:
            return (aux_dir, aux_directory)
        else:
            return aux_dir

    return get_output_directory(root, return_setting)
예제 #5
0
def get_tex_root_from_settings(view):
    root = view.settings().get('TEXroot', None)

    if root is not None:
        if os.path.isabs(root):
            if os.path.isfile(root):
                return root
        else:
            proj_file = get_project_file_name(view)

            if proj_file:
                project_dir = os.path.dirname(proj_file)
                root_path = os.path.normpath(os.path.join(project_dir, root))
                if os.path.isfile(root_path):
                    return root_path

    return root
예제 #6
0
def get_tex_root_from_settings(view):
	root = view.settings().get('TEXroot', None)

	if root is not None:
		if os.path.isabs(root):
			if os.path.isfile(root):
				return root
		else:
			proj_file = get_project_file_name(view)

			if proj_file:
				project_dir = os.path.dirname(proj_file)
				root_path = os.path.normpath(os.path.join(project_dir, root))
				if os.path.isfile(root_path):
					return root_path

	return root
예제 #7
0
	def run(self, select=False):
		select = False if select not in (True, False) else select
		view = self.view = self.window.active_view()
		if not select:
			window_settings = self.WINDOWS.get(self.window.id(), {})
			build_system = window_settings.get('build_system')

			if build_system:
				build_variant = window_settings.get('build_variant', '')
				self.run_build(build_system, build_variant)
				return

		# no previously selected build system or select is True
		# find all .sublime-build files
		if _ST3:
			sublime_build_files = sublime.find_resources('*.sublime-build')
			project_settings = self.window.project_data()
		else:
			sublime_build_files = glob.glob(os.path.join(
				sublime.packages_path(), '*', '*.sublime-build'
			))
			project_file_name = get_project_file_name(view)
			if project_file_name is not None:
				try:
					project_settings = \
						parse_json_with_comments(project_file_name)
				except:
					print('Error parsing project file')
					traceback.print_exc()
					project_settings = {}
			else:
				project_settings = {}

		builders = []
		for i, build_system in enumerate(
			project_settings.get('build_systems', [])
		):
			if (
				'selector' not in build_system or
				view.score_selector(0, project_settings['selector']) > 0
			):
				try:
					build_system['name']
				except:
					print('Could not determine name for build system {0}'.format(
						build_system
					))
					continue

				build_system['index'] = i
				builders.append(build_system)

		for filename in sublime_build_files:
			try:
				sublime_build = parse_json_with_comments(filename)
			except:
				print(u'Error parsing file {0}'.format(filename))
				continue

			if (
				'selector' not in sublime_build or
				view.score_selector(0, sublime_build['selector']) > 0
			):
				sublime_build['file'] = filename.replace(
					sublime.packages_path(), 'Packages', 1
				).replace(os.path.sep, '/')

				sublime_build['name'] = os.path.splitext(
					os.path.basename(sublime_build['file'])
				)[0]

				builders.append(sublime_build)

		formatted_entries = []
		build_system_variants = []
		for builder in builders:
			build_system_name = builder['name']
			build_system_internal_name = builder.get(
				'index', builder.get('file')
			)

			formatted_entries.append(build_system_name)
			build_system_variants.append((build_system_internal_name, ''))

			for variant in builder.get('variants', []):
				try:
					formatted_entries.append(
						"{0} - {1}".format(
							build_system_name,
							variant['name']
						)
					)
				except KeyError:
					continue

				build_system_variants.append(
					(build_system_internal_name, variant['name'])
				)

		entries = len(formatted_entries)
		if entries == 0:
			self.window.run_command('build')
		elif entries == 1:
			build_system, build_variant = build_system_variants[0]
			self.WINDOWS[self.window.id()] = {
				'build_system': build_system,
				'build_variant': build_variant
			}
			self.run_build(build_system, build_variant)
		else:
			def on_done(index):
				# cancel
				if index == -1:
					return

				build_system, build_variant = build_system_variants[index]
				self.WINDOWS[self.window.id()] = {
					'build_system': build_system,
					'build_variant': build_variant
				}
				self.run_build(build_system, build_variant)

			self.window.show_quick_panel(formatted_entries, on_done)
예제 #8
0
    def run(self, select=False):
        select = False if select not in (True, False) else select
        view = self.view = self.window.active_view()
        if not select:
            window_settings = self.WINDOWS.get(self.window.id(), {})
            build_system = window_settings.get('build_system')

            if build_system:
                build_variant = window_settings.get('build_variant', '')
                self.run_build(build_system, build_variant)
                return

        # no previously selected build system or select is True
        # find all .sublime-build files
        if _ST3:
            sublime_build_files = sublime.find_resources('*.sublime-build')
            project_settings = self.window.project_data() or {}
        else:
            sublime_build_files = glob.glob(
                os.path.join(sublime.packages_path(), '*', '*.sublime-build'))
            project_file_name = get_project_file_name(view)
            if project_file_name is not None:
                try:
                    project_settings = \
                     parse_json_with_comments(project_file_name)
                except:
                    print('Error parsing project file')
                    traceback.print_exc()
                    project_settings = {}
            else:
                project_settings = {}

        builders = []
        for i, build_system in enumerate(
                project_settings.get('build_systems', [])):
            if ('selector' not in build_system or view.score_selector(
                    0, project_settings.get('selector', 'text.tex.latex')) >
                    0):
                try:
                    build_system['name']
                except:
                    print(
                        'Could not determine name for build system {0}'.format(
                            build_system))
                    continue

                build_system['index'] = i
                builders.append(build_system)

        for filename in sublime_build_files:
            try:
                sublime_build = parse_json_with_comments(filename)
            except:
                print(u'Error parsing file {0}'.format(filename))
                continue

            if ('selector' not in sublime_build
                    or view.score_selector(0, sublime_build['selector']) > 0):
                sublime_build['file'] = filename.replace(
                    sublime.packages_path(), 'Packages',
                    1).replace(os.path.sep, '/')

                sublime_build['name'] = os.path.splitext(
                    os.path.basename(sublime_build['file']))[0]

                builders.append(sublime_build)

        formatted_entries = []
        build_system_variants = []
        for builder in builders:
            build_system_name = builder['name']
            build_system_internal_name = builder.get('index',
                                                     builder.get('file'))

            formatted_entries.append(build_system_name)
            build_system_variants.append((build_system_internal_name, ''))

            for variant in builder.get('variants', []):
                try:
                    formatted_entries.append("{0} - {1}".format(
                        build_system_name, variant['name']))
                except KeyError:
                    continue

                build_system_variants.append(
                    (build_system_internal_name, variant['name']))

        entries = len(formatted_entries)
        if entries == 0:
            self.window.run_command('build')
        elif entries == 1:
            build_system, build_variant = build_system_variants[0]
            self.WINDOWS[self.window.id()] = {
                'build_system': build_system,
                'build_variant': build_variant
            }
            self.run_build(build_system, build_variant)
        else:

            def on_done(index):
                # cancel
                if index == -1:
                    return

                build_system, build_variant = build_system_variants[index]
                self.WINDOWS[self.window.id()] = {
                    'build_system': build_system,
                    'build_variant': build_variant
                }
                self.run_build(build_system, build_variant)

            self.window.show_quick_panel(formatted_entries, on_done)