コード例 #1
0
ファイル: main.py プロジェクト: pirate42/ajenti-v
    def init(self):
        self.title = 'Website editor'
        self.icon = 'globe'
        self.category = 'Web'
        self.hidden = True

        self.manager = VHManager.get()
        self.binder = Binder(None, self)

        self.append(self.ui.inflate('vh:main-website'))
        self.find('domains').new_item = lambda c: WebsiteDomain.create('example.com')
        self.find('ports').new_item = lambda c: WebsitePort.create(80)

        def post_location_bind(object, collection, item, ui):
            ui.find('backend-params').empty()
            ui.find('backend-params').append(self.ui.inflate('vh:main-backend-params-%s' % item.backend.type))
            item.backend.__binder = Binder(item.backend, ui.find('backend-params'))
            item.backend.__binder.populate()

        def post_location_update(object, collection, item, ui):
            item.backend.__binder.update()

        self.find('locations').post_item_bind = post_location_bind
        self.find('locations').post_item_update = post_location_update

        self.find('create-location-type').labels = []
        self.find('create-location-type').values = []
        for g in sorted(ApplicationGatewayComponent.get_classes(), key=lambda x: x.title):
            self.find('create-location-type').labels.append(g.title)
            self.find('create-location-type').values.append(g.id)
コード例 #2
0
    def init(self):
        self.title = 'Website editor'
        self.icon = 'globe'
        self.category = 'Web'
        self.hidden = True

        self.manager = VHManager.get()
        self.binder = Binder(None, self)

        self.append(self.ui.inflate('vh:main-website'))
        self.find(
            'domains').new_item = lambda c: WebsiteDomain.create('example.com')
        self.find('ports').new_item = lambda c: WebsitePort.create(80)

        def post_location_bind(object, collection, item, ui):
            ui.find('backend-params').empty()
            ui.find('backend-params').append(
                self.ui.inflate('vh:main-backend-params-%s' %
                                item.backend.type))
            item.backend.__binder = Binder(item.backend,
                                           ui.find('backend-params'))
            item.backend.__binder.populate()

        def post_location_update(object, collection, item, ui):
            item.backend.__binder.update()

        self.find('locations').post_item_bind = post_location_bind
        self.find('locations').post_item_update = post_location_update

        self.find('create-location-type').labels = []
        self.find('create-location-type').values = []
        for g in sorted(ApplicationGatewayComponent.get_classes(),
                        key=lambda x: x.title):
            self.find('create-location-type').labels.append(g.title)
            self.find('create-location-type').values.append(g.id)
コード例 #3
0
ファイル: main.py プロジェクト: webrulon/ajenti-v
    def post_init(self):
        self.empty()
        self.append(self.ui.inflate('vh:main'))

        self.binder = Binder(self.manager.config, self)
        self.find('websites').new_item = lambda c: Website.create('New Website')
        self.find('domains').new_item = lambda c: WebsiteDomain.create('example.com')
        self.find('ports').new_item = lambda c: WebsitePort.create(80)
        
        extensions = BaseExtension.get_classes()

        def post_ws_bind(object, collection, item, ui):
            def create_location():
                self.binder.update()
                t = ui.find('create-location-type').value
                l = WebsiteLocation.create(template=t)
                l.backend.type = t
                item.locations.append(l)
                self.refresh()
            ui.find('create-location').on('click', create_location)

            # Extensions
            
            if hasattr(item, 'extensions'):
                for ext in item.extensions:
                    ext._ui_container.delete()

            item.extensions = []
            for ext in extensions:
                ext = ext.new(self.ui, item, config=item.extension_configs.get(ext.classname, None))
                ext._ui_container = self.ui.create('tab', children=[ext], title=ext.name)
                item.extensions.append(ext)
                ui.find('tabs').append(ext._ui_container)

            # Root creator

            ui.find('root-not-created').visible = not os.path.exists(item.root)

            def create_root():
                try:
                    os.mkdir(item.root)
                except:
                    pass
                subprocess.call(['chown', 'www-data', item.root])
                self.save()

            ui.find('create-root-directory').on('click', create_root)
            ui.find('set-path').on('click', self.save)

            # Downloader

            def download():
                url = ui.find('download-url').value
                self.save()
                tmppath = '/tmp/ajenti-v-download'
                script = 'wget "%s" -O "%s" ' % (url, tmppath)
                if url.lower().endswith('.tar.gz') or url.lower().endswith('.tgz'):
                    script += '&& tar xf "%s" -C "%s"' % (tmppath, item.root)
                elif url.lower().endswith('.zip'):
                    script += '&& unzip "%s" -d "%s"' % (tmppath, item.root)

                script += ' && chown www-data -R "%s"' % item.root
                def callback():
                    self.save()
                    self.activate()
                    if os.path.exists(tmppath):
                        os.unlink(tmppath)
                    self.context.notify('info', _('Download complete'))

                self.context.launch('terminal', command=script, callback=callback)

            ui.find('download').on('click', download)


        def post_ws_update(object, collection, item, ui):
            for ext in item.extensions:
                item.extension_configs[ext.classname] = ext.config

        def ws_delete(ws, collection):
            for ext in ws.extensions:
                try:
                    ext.on_destroy()
                except Exception, e:
                    logging.error(str(e))
            collection.remove(ws)
            self.save()