示例#1
0
文件: __init__.py 项目: dcoles/ivle
    def populate(self, req, ctx):
        self.plugin_styles[Plugin] = ['log.css']
        self.plugin_scripts = {
                'ivle.webapp.filesystem.browser': ['browser.js'],
                Plugin: ['log.js'],
                }
        self.scripts_init = ['log_init']

        svnlogservice_path = os.path.join(req.config['paths']['share'],
                                          'services/svnlogservice')

        user_jail_dir = os.path.join(req.config['paths']['jails']['mounts'],
                                     req.user.login)
        (out, err) = ivle.interpret.execute_raw(req.config,
                                                req.user,
                                                user_jail_dir,
                                                '/home',
                                                svnlogservice_path,
                                                [self.path]
                                                )
        assert not err

        response = json.loads(out)
        if 'error' in response:
            if response['error'] == 'notfound':
                raise NotFound()
            else:
                raise AssertionError('Unknown error from svnlogservice: %s' %
                                     response['error'])

        # No error. We must be safe.
        ctx['format_datetime'] = ivle.date.make_date_nice
        ctx['format_datetime_short'] = ivle.date.format_datetime_for_paragraph

        ctx['path'] = self.path
        ctx['url'] = req.make_path(os.path.join('svnlog', self.path))
        ctx['diffurl'] = req.make_path(os.path.join('diff', self.path))
        ctx['title'] = os.path.normpath(self.path).rsplit('/', 1)[-1]
        self.extra_breadcrumbs = make_path_breadcrumbs(req, self.subpath)
        self.extra_breadcrumbs.append(SubversionLogBreadcrumb())

        sr = ivle.svn.revision_from_string(
                   req.get_fieldstorage().getfirst("r"))
        ctx['revno'] = sr.number if sr and \
                       sr.kind == pysvn.opt_revision_kind.number else None
        ctx['logs'] = response['logs']

        # Create URLs for each of the versioned files.
        # XXX: This scheme only works for stuff/!
        for log in ctx['logs']:
            for pathaction in log['paths']:
                pathaction.append(req.make_path(os.path.join('files',
                                  ivle.util.split_path(req.path)[0],
                                  pathaction[0][1:])) + '?r=%d' % log['revno'])
示例#2
0
文件: __init__.py 项目: dcoles/ivle
    def populate(self, req, ctx):
        if len(self.path) == 0:
            # If no path specified, default to the user's home directory
            redirectPath = req.make_path(os.path.join('files', req.user.login))
            req.throw_redirect(redirectPath)

        # Set request attributes
        self.plugin_styles[Plugin] = ['browser.css',
                                      'listing.css',
                                      'editor.css']
        self.plugin_scripts[Plugin] = ['browser.js',
                                       'listing.js',
                                       'editor.js',
                                       'specialhome.js']
        self.plugin_scripts['+external/codemirror'] = ['js/codemirror.js']
        self.scripts_init = ["browser_init"]

        # Start writing data

        # TODO: Set this properly. We can't get into the jail from server-side
        # code at the moment, so we can't determine this.
        isdir = False

        revision = ivle.svn.revision_from_string(
                         req.get_fieldstorage().getfirst('r'))
        try:
            revno = revision.number
        except:
            revno = None

        ctx['isdir'] = isdir
        ctx['revno'] = revno

        self.extra_breadcrumbs = make_path_breadcrumbs(req, self.subpath,revno)

        self.gen_actions(req, ctx)

        # The page title should contain the name of the file being browsed
        ctx['title'] = os.path.normpath(self.path).rsplit('/', 1)[-1]

        ctx['fileservice_action'] = req.make_path(os.path.join("fileservice",
                                                               self.path))
        ctx['filename'] = cgi.escape(self.path)

        # Media URL for CodeMirror
        ctx['codemirrorpath'] = media_url(req, '+external/codemirror', '')
示例#3
0
文件: __init__.py 项目: dcoles/ivle
    def populate(self, req, ctx):
        self.plugin_styles[Plugin] = ['diff.css']

        revfields = req.get_fieldstorage().getlist("r")
        if len(revfields) > 2:
            raise BadRequest('A maximum of two revisions can be given.')

        revs = [revfield.value for revfield in revfields]

        jail_dir = os.path.join(req.config['paths']['jails']['mounts'],
                                req.user.login)
        (out, err) = ivle.interpret.execute_raw(req.config, req.user, jail_dir,
                            '/home', os.path.join(req.config['paths']['share'],
                                                  'services/diffservice'),
                            [self.path] + revs
                            )
        assert not err

        response = json.loads(out)
        if 'error' in response:
            if response['error'] == 'notfound':
                raise NotFound()
            else:
                raise AssertionError('Unknown error from diffservice: %s' %
                                     response['error'])

        # No error. We must be safe.
        diff = response['diff']

        # Split up the udiff into individual files
        diff_matcher = re.compile(
            r'^Index: (.*)\n\=+\n((?:[^I].*\n)*)',re.MULTILINE
        )

        ctx['title'] = os.path.normpath(self.path).rsplit('/', 1)[-1]
        self.extra_breadcrumbs = make_path_breadcrumbs(req, self.subpath)
        self.extra_breadcrumbs.append(SubversionDiffBreadcrumb())

        # Create a dict with (name, HTMLdiff) pairs for each non-empty diff.
        ctx['files'] = dict([(fd[0], genshi.XML(htmlfy_diff(fd[1])))
                             for fd in diff_matcher.findall(diff)
                             if fd[1]])