コード例 #1
0
def open_in_editor(request):
    from django.conf import settings

    template = request.REQUEST['template']
    line = request.REQUEST.get('line', 0)
    column = request.REQUEST.get('column', 0)

    # Get template path
    path = get_template_path(template)
    print 'opening template: ' + path

    # Call command for opening this file
    if hasattr(settings, 'TEMPLATE_PREPROCESSOR_OPEN_IN_EDITOR_COMMAND'):
        settings.TEMPLATE_PREPROCESSOR_OPEN_IN_EDITOR_COMMAND(
            path, line, column)
    else:
        # By default, open this file in GVim, in a new tab.
        subprocess.Popen(["/usr/bin/gvim"])
        #subprocess.Popen(["/usr/bin/gvim", "--remote-tab", path ])
        time.sleep(0.4)
        subprocess.Popen(
            ["/usr/bin/gvim", "--remote-send",
             "<ESC>:tabe %s<ENTER>" % path])
        subprocess.Popen([
            "/usr/bin/gvim", "--remote-send",
            "<ESC>:%s<ENTER>%s|" % (line, column)
        ])

    return HttpResponse('[{ "result": "ok" }]',
                        mimetype="application/javascript")
コード例 #2
0
    def _build_compile_queue(self,
                             languages,
                             all_templates=True,
                             single_template=None):
        """
        Build a list of all the templates to be compiled.
        """
        # Create compile queue
        queue = set()  # Use a set, avoid duplication of records.

        if self.verbosity >= 2:
            print 'Building queue'

        for lang in languages:
            # Now compile all templates to the cache directory
            for dir, t in template_iterator():
                input_path = os.path.normpath(os.path.join(dir, t))
                output_path = self._make_output_path(lang, t)

                # Compile this template if:
                if (
                        # We are compiling *everything*
                        all_templates or

                        # Or this is the only template that we want to compile
                    (single_template and t in single_template) or

                        # Or we are compiling changed files
                    (
                        not single_template and (

                            # Compiled file does not exist
                            not os.path.exists(output_path) or

                            # Compiled file has been marked for recompilation
                            os.path.exists(output_path + '-c-recompile') or

                            # Compiled file is outdated
                            os.path.getmtime(output_path) <
                            os.path.getmtime(input_path)))):

                    queue.add((lang, t, input_path, output_path))

                    # When this file has to be compiled, and other files depend
                    # on this template also compile the other templates.
                    if os.path.exists(output_path + '-c-used-by'):
                        for t2 in open(output_path + '-c-used-by',
                                       'r').read().split('\n'):
                            if t2:
                                try:
                                    queue.add(
                                        (lang, t2, get_template_path(t2),
                                         self._make_output_path(lang, t2)))
                                except TemplateDoesNotExist, e:
                                    pass  # Reference to non-existing template
コード例 #3
0
    def _build_compile_queue(self, languages, all_templates=True, single_template=None):
        """
        Build a list of all the templates to be compiled.
        """
        # Create compile queue
        queue = set() # Use a set, avoid duplication of records.

        if self.verbosity >= 2:
            print 'Building queue'

        for lang in languages:
            # Now compile all templates to the cache directory
            for dir, t in template_iterator():
                input_path = os.path.normpath(os.path.join(dir, t))
                output_path = self._make_output_path(lang, t)

                # Compile this template if:
                if (
                        # We are compiling *everything*
                        all_templates or

                        # Or this is the only template that we want to compile
                        (single_template and t in single_template) or

                        # Or we are compiling changed files
                        (not single_template and (

                            # Compiled file does not exist
                            not os.path.exists(output_path) or

                            # Compiled file has been marked for recompilation
                            os.path.exists(output_path + '-c-recompile') or

                            # Compiled file is outdated
                            os.path.getmtime(output_path) < os.path.getmtime(input_path))

                        )):

                    queue.add( (lang, t, input_path, output_path) )

                    # When this file has to be compiled, and other files depend
                    # on this template also compile the other templates.
                    if os.path.exists(output_path + '-c-used-by'):
                        for t2 in open(output_path + '-c-used-by', 'r').read().split('\n'):
                            if t2:
                                try:
                                    queue.add( (lang, t2, get_template_path(t2), self._make_output_path(lang, t2)) )
                                except TemplateDoesNotExist, e:
                                    pass # Reference to non-existing template
コード例 #4
0
def open_in_editor(request):
    from django.conf import settings

    template = request.REQUEST['template']
    line = request.REQUEST.get('line', 0)
    column = request.REQUEST.get('column', 0)

    # Get template path
    path = get_template_path(template)
    print 'opening template: ' + path

    # Call command for opening this file
    if hasattr(settings, 'TEMPLATE_PREPROCESSOR_OPEN_IN_EDITOR_COMMAND'):
        settings.TEMPLATE_PREPROCESSOR_OPEN_IN_EDITOR_COMMAND(path, line, column)
    else:
        # By default, open this file in GVim, in a new tab.
        subprocess.Popen(["/usr/bin/gvim"])
        #subprocess.Popen(["/usr/bin/gvim", "--remote-tab", path ])
        time.sleep(0.4)
        subprocess.Popen(["/usr/bin/gvim", "--remote-send", "<ESC>:tabe %s<ENTER>" % path ])
        subprocess.Popen(["/usr/bin/gvim", "--remote-send", "<ESC>:%s<ENTER>%s|" % (line, column)])

    return HttpResponse('[{ "result": "ok" }]', mimetype="application/javascript")