query: Move 'versions' command to a function
This commit is contained in:
parent
2440d49731
commit
b646d650d4
2 changed files with 33 additions and 29 deletions
|
|
@ -81,32 +81,7 @@ class Query:
|
|||
|
||||
def query(self, cmd, *args):
|
||||
if cmd == 'versions':
|
||||
|
||||
# Returns the list of indexed versions in the following format:
|
||||
# topmenu submenu tag
|
||||
# Example: v3 v3.1 v3.1-rc10
|
||||
versions = OrderedDict()
|
||||
|
||||
for line in self.scriptLines('list-tags', '-h'):
|
||||
taginfo = decode(line).split(' ')
|
||||
num = len(taginfo)
|
||||
topmenu, submenu = 'FIXME', 'FIXME'
|
||||
|
||||
if num == 1:
|
||||
tag, = taginfo
|
||||
elif num == 2:
|
||||
submenu,tag = taginfo
|
||||
elif num ==3:
|
||||
topmenu,submenu,tag = taginfo
|
||||
|
||||
if self.db.vers.exists(tag):
|
||||
if topmenu not in versions:
|
||||
versions[topmenu] = OrderedDict()
|
||||
if submenu not in versions[topmenu]:
|
||||
versions[topmenu][submenu] = []
|
||||
versions[topmenu][submenu].append(tag)
|
||||
|
||||
return versions
|
||||
return self.get_versions()
|
||||
|
||||
elif cmd == 'latest':
|
||||
return self.get_latest_tag()
|
||||
|
|
@ -247,6 +222,35 @@ class Query:
|
|||
else:
|
||||
return 'Unknown subcommand: ' + cmd + '\n'
|
||||
|
||||
# Returns the list of indexed versions in the following format:
|
||||
# topmenu submenu tag
|
||||
# Example: v3 v3.1 v3.1-rc10
|
||||
def get_versions(self):
|
||||
versions = OrderedDict()
|
||||
|
||||
for line in self.scriptLines('list-tags', '-h'):
|
||||
taginfo = decode(line).split(' ')
|
||||
num = len(taginfo)
|
||||
topmenu, submenu = 'FIXME', 'FIXME'
|
||||
|
||||
if num == 1:
|
||||
tag, = taginfo
|
||||
elif num == 2:
|
||||
submenu, tag = taginfo
|
||||
elif num == 3:
|
||||
topmenu, submenu, tag = taginfo
|
||||
else:
|
||||
raise Exception("unexpected number of fields in taginfo")
|
||||
|
||||
if self.db.vers.exists(tag):
|
||||
if topmenu not in versions:
|
||||
versions[topmenu] = OrderedDict()
|
||||
if submenu not in versions[topmenu]:
|
||||
versions[topmenu][submenu] = []
|
||||
versions[topmenu][submenu].append(tag)
|
||||
|
||||
return versions
|
||||
|
||||
# Returns identifier search results
|
||||
def search_ident(self, version, ident, family):
|
||||
# DT bindings compatible strings are handled differently
|
||||
|
|
|
|||
|
|
@ -401,7 +401,7 @@ def get_projects(basedir: str) -> list[ProjectEntry]:
|
|||
# Used to render version list in the sidebar
|
||||
VersionEntry = namedtuple('VersionEntry', 'version, url')
|
||||
|
||||
# Takes result of Query.query('version') and prepares it for the sidebar template.
|
||||
# Takes result of Query.get_versions() and prepares it for the sidebar template.
|
||||
# Returns an OrderedDict with version information and optionally a triple with
|
||||
# (major, minor, version) of current_version. The triple is useful, because sometimes
|
||||
# the major or minor of a version (in this context) is a custom string (ex. FIXME).
|
||||
|
|
@ -433,12 +433,12 @@ def get_versions(versions: OrderedDict[str, OrderedDict[str, str]],
|
|||
def get_versions_cached(q, ctx, project):
|
||||
with ctx.versions_cache_lock:
|
||||
if project not in ctx.versions_cache:
|
||||
ctx.versions_cache[project] = (time.time(), q.query('versions'))
|
||||
ctx.versions_cache[project] = (time.time(), q.get_versions())
|
||||
cached_versions = ctx.versions_cache[project]
|
||||
else:
|
||||
cached_versions = ctx.versions_cache[project]
|
||||
if time.time()-cached_versions[0] > VERSION_CACHE_DURATION_SECONDS:
|
||||
ctx.versions_cache[project] = (time.time(), q.query('versions'))
|
||||
ctx.versions_cache[project] = (time.time(), q.get_versions())
|
||||
cached_versions = ctx.versions_cache[project]
|
||||
|
||||
return cached_versions[1]
|
||||
|
|
|
|||
Loading…
Reference in a new issue