Esempio n. 1
0
 def import_plugin(self):
     path = QFileDialog.getOpenFileName(
         dir=self.config['history']['last_open_folder'], filter='*.txt')[0]
     logger.debug(f'Selected path: {path}')
     if path:
         name = path.split('/')[-1]
         p = Plugin(name=name, path=path)
         self.session.add(p)
         self.session.commit()
         self.update_mpc_plugin_list()
         self.import_plugin_files(p)
Esempio n. 2
0
    def post(self):
        secret = self.request.get('secret', '')
        is_update = False
        if len(secret):
            plugins = Plugin.query(Plugin.secret == secret).fetch()
            if len(plugins) == 0:
                send_upload_form(
                    self, "No plugin could be found that matches that "
                    "secret.")
                return
            else:
                plugin = plugins[0]
            is_update = True
        else:
            plugin = Plugin()
        plugin.zip_url = 'http://' + os.environ['HTTP_HOST'] + '/serve/' + str(
            self.get_uploads('zip')[0].key())
        zip_data = urllib2.urlopen(plugin.zip_url).read()
        if not read_plugin_info(plugin, zip_data):
            send_upload_form(
                self, "We couldn't find a valid info.json file in your "
                "zip.")
            return

        console_key = self.request.get('console_key', None)

        plugin.secret = base64.b64encode(os.urandom(128))
        plugin.notes = self.request.get('notes', '')

        admin = users.is_current_user_admin() or \
            (console_key and console_key_is_valid(console_key))
        if admin:
            existing = Plugin.by_name(plugin.name)
            if existing:
                plugin.downloads += existing.downloads
                plugin.put()
                existing.disable()
                existing.downloads = 0
                existing.put()
        plugin.put()
        if admin:
            plugin.enable()

        if console_key is not None:
            self.response.write({"success": True})
        else:
            approval_msg = " It'll be public after it's been approved." if not is_update else ""
            message = "Your plugin was uploaded!" + approval_msg
            self.response.write(
                template("uploaded.html", {
                    "message": message,
                    "plugin": plugin
                }))