Exemplo n.º 1
0
def directory_html(category=None, search=None, languages=None, browse=False,
                   name=None):
    languages_specified = languages != None
    if not languages_specified:
      languages = ['en']
    if category:
        plugins = list(Plugin.query(Plugin.categories == category,
                                    Plugin.approved == True))
        plugins = stable_daily_shuffle(plugins)
    elif search:
        plugins = search_plugins(search)
    elif name:
        plugin = Plugin.by_name(name)
        plugins = [plugin] if plugin else []
    else:
        plugins = []
    count = len(plugins)
    plugin_dicts = []
    for p in plugins:
        plugin = info_dict_for_plugin(p, languages)
        plugin_dicts.append(plugin)
    groups = group_plugins(plugin_dicts, languages, languages_specified)
    return template("directory.html",
                    {
                      "groups": groups,
                      "browse": browse,
                      "count": count,
                      "search": search})
Exemplo n.º 2
0
def aggregate_download_counts():
  names = set()
  for plugin in Plugin.query(Plugin.approved == False):
    names.add(plugin.name)
  for name in names:
    plugins = list(Plugin.query(Plugin.name == name))
    total = sum([plugin.downloads for plugin in plugins])
    any_approved = len([p for p in plugins if p.approved]) > 0
    if any_approved:
      for p in plugins:
        p.downloads = total if p.approved else 0
        p.put()
Exemplo n.º 3
0
def directory_html(category=None,
                   search=None,
                   languages=None,
                   browse=False,
                   name=None,
                   gae=None,
                   deep_links=False):

    if gae == None:
        gae = not browse

    new = category == 'New'
    if new: category = None

    languages_specified = languages != None
    if not languages_specified:
        languages = ['en']
    if category:
        plugins = list(
            Plugin.query(Plugin.categories == category,
                         Plugin.approved == True))
        plugins = stable_daily_shuffle(plugins)
    elif search:
        plugins = search_plugins(search)
    elif name:
        plugin = Plugin.by_name(name)
        plugins = [plugin] if plugin else []
    elif new:
        plugins = Plugin.query(
            Plugin.approved == True).order(-Plugin.added).fetch(limit=10)
    else:
        plugins = []
    count = len(plugins)
    plugin_dicts = []
    for p in plugins:
        plugin = info_dict_for_plugin(p, languages)
        plugin_dicts.append(plugin)
    groups = group_plugins(plugin_dicts, languages, languages_specified)
    return template(
        "directory.html", {
            "groups": groups,
            "browse": browse,
            "count": count,
            "search": search,
            "deep_links": deep_links,
            "new": new,
            "gae": gae
        })
Exemplo n.º 4
0
 def get(self, name):
     plugin = Plugin.by_name(name)
     if not plugin:
         self.error(404)
         return
     self.response.write(template("plugin_page.html",
                                  {"plugin": info_dict_for_plugin(plugin)}))
Exemplo n.º 5
0
def directory_html(category=None, search=None, languages=['en'], browse=False, name=None):
  if category:
    plugins = list(Plugin.query(Plugin.categories == category, Plugin.approved == True))
    plugins = stable_daily_shuffle(plugins)
  elif search:
    plugins = search_plugins(search)
  elif name:
    plugin = Plugin.by_name(name)
    plugins = [plugin] if plugin else []
  else:
    plugins = []
  plugin_dicts = []
  for p in plugins:
    plugin = info_dict_for_plugin(p, languages)
    plugin_dicts.append(plugin)
  return template("directory.html", {"plugins": plugin_dicts, "browse": browse, "search": search})
Exemplo n.º 6
0
		def get(self, name):
				plugin = Plugin.by_name(name)
				version = plugin.version if plugin else None
				if not version: version = 0
				url = blobstore.create_upload_url('/post_upload')
				self.response.write(json.dumps({"version": version,
																				"upload_url": url}))
Exemplo n.º 7
0
		def get(self, name):
				plugin = Plugin.by_name(name)
				version = plugin.version if plugin else None
				if not version: version = 0
				url = blobstore.create_upload_url('/post_upload')
				self.response.write(json.dumps({"version": version,
																				"upload_url": url}))
Exemplo n.º 8
0
	def post(self):
		plugins_by_version = json.loads(self.request.body)
		if len(plugins_by_version.keys()) > 0:
			plugins = Plugin.query(Plugin.name.IN(plugins_by_version.keys())).fetch()
			needs_update = [p.name for p in plugins if p.version and p.version > plugins_by_version[p.name]]
		else:
			needs_update = []
		self.response.write(json.dumps({"plugins": needs_update}))
Exemplo n.º 9
0
		def get(self, name):
				plugin = Plugin.by_name(name)
				if not plugin:
						self.error(404)
						return
				localhost = 'Development' in os.environ['SERVER_SOFTWARE']
				self.response.write(template("plugin_page.html",
																		 {"plugin": info_dict_for_plugin(plugin),
																			"localhost": localhost}))
Exemplo n.º 10
0
		def get(self, name):
				plugin = Plugin.by_name(name)
				if not plugin:
						self.error(404)
						return
				localhost = 'Development' in os.environ['SERVER_SOFTWARE']
				self.response.write(template("plugin_page.html",
																		 {"plugin": info_dict_for_plugin(plugin),
																			"localhost": localhost}))
Exemplo n.º 11
0
def directory_html(category=None, search=None, languages=None, browse=False, name=None, gae=None, deep_links=False):

    if gae == None:
        gae = not browse

    new = category == "New"
    if new:
        category = None

    languages_specified = languages != None
    if not languages_specified:
        languages = ["en"]
    if category:
        plugins = list(Plugin.query(Plugin.categories == category, Plugin.approved == True))
        plugins = stable_daily_shuffle(plugins)
    elif search:
        plugins = search_plugins(search)
    elif name:
        plugin = Plugin.by_name(name)
        plugins = [plugin] if plugin else []
    elif new:
        plugins = Plugin.query(Plugin.approved == True).order(-Plugin.added).fetch(limit=10)
    else:
        plugins = []
    count = len(plugins)
    plugin_dicts = []
    for p in plugins:
        plugin = info_dict_for_plugin(p, languages)
        plugin_dicts.append(plugin)
    groups = group_plugins(plugin_dicts, languages, languages_specified)
    return template(
        "directory.html",
        {
            "groups": groups,
            "browse": browse,
            "count": count,
            "search": search,
            "deep_links": deep_links,
            "new": new,
            "gae": gae,
        },
    )
Exemplo n.º 12
0
def remove_duplicates():
    plugins = list(Plugin.query().fetch())
    versions_to_keep = {}
    for plugin in plugins:
        if plugin.approved:
            if plugin.name not in versions_to_keep or plugin.added > versions_to_keep[plugin.name].added:
                versions_to_keep[plugin.name] = plugin
    for plugin in plugins:
        if plugin.approved and plugin.name in versions_to_keep and plugin != versions_to_keep[plugin.name]:
            plugin.approved = False
            plugin.put()
Exemplo n.º 13
0
def directory_html(category=None, search=None, languages=['en'], browse=False,
                   name=None):
    if category:
        plugins = list(Plugin.query(Plugin.categories == category,
                                    Plugin.approved == True))
        plugins = stable_daily_shuffle(plugins)
    elif search:
        plugins = search_plugins(search)
    elif name:
        plugin = Plugin.by_name(name)
        plugins = [plugin] if plugin else []
    else:
        plugins = []
    plugin_dicts = []
    for p in plugins:
        plugin = info_dict_for_plugin(p, languages)
        plugin_dicts.append(plugin)
    return template("directory.html",
                    {"plugins": plugin_dicts, "browse": browse,
                     "search": search})
Exemplo n.º 14
0
 def get(self):
   category = self.request.get('category')
   languages = self.request.get('languages', '').split(',') + ['en']
   plugins = []
   for p in Plugin.query(Plugin.categories == category, Plugin.approved == True):
     plugin = json.loads(p.info_json)
     plugin['displayName'] = get_localized_key(plugin, "displayName", languages, "")
     plugin['description'] = get_localized_key(plugin, "description", languages, "")
     plugin['examples'] = get_localized_key(plugin, "examples", languages, [])
     plugin['model'] = p
     plugin['install_url'] = 'install://_?' + urllib.urlencode([("zip_url", p.zip_url), ("name", p.name.encode('utf8'))])
     plugins.append(plugin)
   self.response.write(template("directory.html", {"plugins": plugins}))
Exemplo n.º 15
0
 def get(self, name):
     plugin = Plugin.by_name(name)
     existing_md5 = plugin.zip_md5 if plugin else None
     url = blobstore.create_upload_url('/post_upload')
     self.response.write(json.dumps({"md5": existing_md5,
                                     "upload_url": url}))
Exemplo n.º 16
0
def compute_categories():
    categories = set()
    for p in Plugin.query(Plugin.approved is True):
        for c in p.categories:
            categories.add(c)
    return categories
Exemplo n.º 17
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', '')

        plugin.zip_md5 = hashlib.md5(zip_data).hexdigest()

        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}))
Exemplo n.º 18
0
	def get(self, name):
		plugin = Plugin.by_name(name)
		if not plugin:
			self.error(404)
			return
		self.redirect(plugin.zip_url.encode('utf-8'))
Exemplo n.º 19
0
def compute_categories():
    categories = set()
    for p in Plugin.query():
      for c in p.categories:
        categories.add(c)
    return categories
Exemplo n.º 20
0
def compute_categories():
		categories = set()
		for p in Plugin.query(Plugin.approved == True, projection=[Plugin.categories]):
				for c in p.categories:
						categories.add(c)
		return categories
Exemplo n.º 21
0
def ensure_documents_indexed():
  for plugin in Plugin.query(Plugin.approved == True):
    search.ensure_plugin_indexed(plugin)