Example #1
0
    def _main(self, request):
        if request.path == '/__main__':
            tmpl = os.path.join(_HERE, 'templates', 'main.mako')
            with open(tmpl) as f:
                tmpl = Template(f.read())

            return tmpl.render(appviews=self.appviews,
                               libraries=self.libraries)

        if request.path == '/__main__/add' and request.method == 'POST':
            def _name2path(name):
                # MORE CHARS
                path = name.lower()
                path = path.replace(' ', '')
                return '/' + path

            data = {}
            name = data['name'] = request.POST['name']
            data['root'] = _name2path(data['name'])
            data['description'] = request.POST['description']
            rbr = _DEFAULT_APP % data
            code = _DEFAULT_CODE
            location = os.path.join(_APPS, name)
            os.mkdir(location)
            appview = AppView(wsgiapp=self, location=location,
                              rbr=rbr, code=code, name=name)
            appview.generate()
            self.appviews.append((appview.get_root(), appview))
            self.appviews.sort(by_len)
            # XXX
            url = 'http://%s%s/__editor__' % (request.environ['HTTP_HOST'],
                                        appview.get_root())
            return HTTPFound(location=url)

        if request.path == '/__main__/addlib' and request.method == 'POST':
            # loading a new lib
            name = request.POST['name']
            file_ = request.POST['file']
            if hasattr(file_, 'file'):
                code = file_.file.read()
            else:
                code = ''
            self.libraries.append(VirtualModule(name, code))
            # XXX
            url = 'http://%s/__lib__/%s' % (request.environ['HTTP_HOST'], name)
            return HTTPFound(location=url)

        return self._404()
Example #2
0
    def _load_apps(self):
        appviews = []
        # provided RBRs
        #for rbr in self.rbrs:
        #    appview = AppView(self, rbr)
        #    appview.generate()
        #    appviews.append((appview.get_root(), appview))

        # disk-based RBRs
        for path in os.listdir(self.appdir):
            full = os.path.join(self.appdir, path)
            if not os.path.isdir(full):
                continue
            appview = AppView(self, full, name=path)
            appview.generate()
            appviews.append((appview.get_root(), appview))

        appviews.sort(by_len)
        return appviews
    def _load_apps(self):
        appviews = []
        # provided RBRs
        #for rbr in self.rbrs:
        #    appview = AppView(self, rbr)
        #    appview.generate()
        #    appviews.append((appview.get_root(), appview))

        # disk-based RBRs
        for path in os.listdir(self.appdir):
            full = os.path.join(self.appdir, path)
            if not os.path.isdir(full):
                continue
            appview = AppView(self, full, name=path)
            appview.generate()
            appviews.append((appview.get_root(), appview))

        appviews.sort(by_len)
        return appviews
    def _main(self, request):
        if request.path == '/__main__':
            tmpl = os.path.join(_HERE, 'templates', 'main.mako')
            with open(tmpl) as f:
                tmpl = Template(f.read())

            return tmpl.render(appviews=self.appviews,
                               libraries=self.libraries)

        if request.path == '/__main__/add' and request.method == 'POST':

            def _name2path(name):
                # MORE CHARS
                path = name.lower()
                path = path.replace(' ', '')
                return '/' + path

            data = {}
            name = data['name'] = request.POST['name']
            data['root'] = _name2path(data['name'])
            data['description'] = request.POST['description']
            rbr = _DEFAULT_APP % data
            code = _DEFAULT_CODE
            location = os.path.join(_APPS, name)
            os.mkdir(location)
            appview = AppView(wsgiapp=self,
                              location=location,
                              rbr=rbr,
                              code=code,
                              name=name)
            appview.generate()
            self.appviews.append((appview.get_root(), appview))
            self.appviews.sort(by_len)
            # XXX
            url = 'http://%s%s/__editor__' % (request.environ['HTTP_HOST'],
                                              appview.get_root())
            return HTTPFound(location=url)

        if request.path == '/__main__/addlib' and request.method == 'POST':
            # loading a new lib
            name = request.POST['name']
            file_ = request.POST['file']
            if hasattr(file_, 'file'):
                code = file_.file.read()
            else:
                code = ''
            self.libraries.append(VirtualModule(name, code))
            # XXX
            url = 'http://%s/__lib__/%s' % (request.environ['HTTP_HOST'], name)
            return HTTPFound(location=url)

        return self._404()