query: Move 'type' command to a function
This commit is contained in:
parent
b646d650d4
commit
9bc76f0d8d
2 changed files with 12 additions and 11 deletions
|
|
@ -87,17 +87,9 @@ class Query:
|
|||
return self.get_latest_tag()
|
||||
|
||||
elif cmd == 'type':
|
||||
|
||||
# Returns the type (blob or tree) associated to
|
||||
# the given path. Example:
|
||||
# > ./query.py type v3.1-rc10 /Makefile
|
||||
# blob
|
||||
# > ./query.py type v3.1-rc10 /arch
|
||||
# tree
|
||||
|
||||
version = args[0]
|
||||
path = args[1]
|
||||
return decode(self.script('get-type', version, path)).strip()
|
||||
return self.get_file_type(version, path)
|
||||
|
||||
elif cmd == 'exist':
|
||||
version = args[0]
|
||||
|
|
@ -251,6 +243,15 @@ class Query:
|
|||
|
||||
return versions
|
||||
|
||||
# Returns the type (blob or tree) associated to
|
||||
# the given path. Example:
|
||||
# > ./query.py type v3.1-rc10 /Makefile
|
||||
# blob
|
||||
# > ./query.py type v3.1-rc10 /arch
|
||||
# tree
|
||||
def get_file_type(self, version, path):
|
||||
return decode(self.script('get-type', version, path)).strip()
|
||||
|
||||
# Returns identifier search results
|
||||
def search_ident(self, version, ident, family):
|
||||
# DT bindings compatible strings are handled differently
|
||||
|
|
|
|||
|
|
@ -469,7 +469,7 @@ def get_layout_template_context(q: Query, ctx: RequestContext, get_url_with_new_
|
|||
|
||||
# Generate raw source response
|
||||
def generate_raw_source(resp, query, project, version, path):
|
||||
type = query.query('type', version, path)
|
||||
type = query.get_file_type(version, path)
|
||||
if type != 'blob':
|
||||
raise ElixirProjectError('File not found', 'This file does not exist.',
|
||||
query=query, project=project, version=version)
|
||||
|
|
@ -597,7 +597,7 @@ def generate_source_page(ctx: RequestContext, q: Query,
|
|||
status = falcon.HTTP_OK
|
||||
source_base_url = get_source_base_url(project, version)
|
||||
|
||||
type = q.query('type', version, path)
|
||||
type = q.get_file_type(version, path)
|
||||
|
||||
# Generate breadcrumbs
|
||||
path_split = path.split('/')[1:]
|
||||
|
|
|
|||
Loading…
Reference in a new issue