diff --git a/src/fileLoaders.py b/src/fileLoaders.py index a1fc3ac..ea80abe 100644 --- a/src/fileLoaders.py +++ b/src/fileLoaders.py @@ -10,7 +10,7 @@ class BaseLoader: - def getTextForName(self, query_name): + def getTextForName(self, query_name, subdir): # The URIs of all candidates rq_name = query_name + '.rq' sparql_name = query_name + '.sparql' @@ -24,7 +24,7 @@ def getTextForName(self, query_name): ] for queryFullName, queryType in candidates: - queryText = self._getText(queryFullName) + queryText = self._getText(queryFullName, subdir) if queryText: if (queryType == qType['JSON']): queryText = json.loads(queryText) @@ -50,9 +50,10 @@ def getLicenceURL(self): class GithubLoader(BaseLoader): - def __init__(self, user, repo, sha, prov): + def __init__(self, user, repo, subdir, sha, prov): self.user = user self.repo = repo + self.subdir = subdir self.sha = sha self.prov = prov gh = Github(static.ACCESS_TOKEN) @@ -65,6 +66,8 @@ def __init__(self, user, repo, sha, prov): def fetchFiles(self): api_repo_content_uri = static.GITHUB_API_BASE_URL + self.user + '/' + self.repo + '/contents' + if self.subdir: + api_repo_content_uri += '/' + str(self.subdir) params = { 'ref': 'master' if self.sha is None else self.sha } @@ -84,17 +87,20 @@ def getRawRepoUri(self): raw_repo_uri += '/{}/'.format(self.sha) return raw_repo_uri - def getTextFor(self, fileItem): + def getTextFor(self, fileItem, subdir=None): raw_query_uri = fileItem['download_url'] - resp = self._getText(raw_query_uri) + resp = self._getText(raw_query_uri, subdir) # Add query URI as used entity by the logged activity if self.prov is not None: self.prov.add_used_entity(raw_query_uri) return resp - def _getText(self, query_name): + def _getText(self, query_name, subdir=None): query_uri = self.getRawRepoUri() + query_name + if subdir: + query_uri = self.getRawRepoUri() + subdir + '/' + query_name + print("Requesting query at " + str(query_uri)) req = requests.get(query_uri, headers={'Authorization': 'token {}'.format(static.ACCESS_TOKEN)}) if req.status_code == 200: return req.text diff --git a/src/server.py b/src/server.py index eb46cd8..5cec898 100644 --- a/src/server.py +++ b/src/server.py @@ -32,11 +32,15 @@ def query_local(query_name): @app.route('/api///', methods=['GET', 'POST']) +@app.route('/api////', methods=['GET', 'POST']) @app.route('/api///.', methods=['GET', 'POST']) +@app.route('/api////.', methods=['GET', 'POST']) @app.route('/api///commit//', methods=['GET', 'POST']) +@app.route('/api////commit//', methods=['GET', 'POST']) @app.route('/api///commit//.', methods=['GET', 'POST']) -def query(user, repo, query_name, sha=None, content=None): - glogger.info("-----> Executing call name at /{}/{}/{} on commit {}".format(user, repo, query_name, sha)) +@app.route('/api////commit//.', methods=['GET', 'POST']) +def query(user, repo, query_name, subdir=None, sha=None, content=None): + glogger.info("-----> Executing call name at /{}/{}/{}/{} on commit {}".format(user, repo, subdir, query_name, sha)) glogger.debug("Request accept header: " + request.headers["Accept"]) requestArgs = request.args @@ -44,7 +48,7 @@ def query(user, repo, query_name, sha=None, content=None): requestUrl = request.url formData = request.form - query_response, status, headers = utils.dispatch_query(user, repo, query_name, + query_response, status, headers = utils.dispatch_query(user, repo, query_name, subdir, sha=sha, content=content, requestArgs=requestArgs, acceptHeader=acceptHeader, requestUrl=requestUrl, formData=formData) @@ -66,19 +70,24 @@ def swagger_spec_local(): @app.route('/api//', strict_slashes=False) +@app.route('/api///', strict_slashes=False) @app.route('/api///api-docs') @app.route('/api///commit/') @app.route('/api///commit//api-docs') -def api_docs(user, repo, sha=None): - return render_template('api-docs.html', user=user, repo=repo, sha=sha) +@app.route('/api////commit/') +@app.route('/api////commit//api-docs') +def api_docs(user, repo, subdir=None, sha=None): + return render_template('api-docs.html', user=user, repo=repo, subdir=subdir, sha=sha) @app.route('/api///spec', methods=['GET']) +@app.route('/api////spec', methods=['GET']) @app.route('/api///commit//spec') -def swagger_spec(user, repo, sha=None, content=None): - glogger.info("-----> Generating swagger spec for /{}/{} on commit {}".format(user, repo, sha)) +@app.route('/api////commit//spec') +def swagger_spec(user, repo, subdir=None, sha=None, content=None): + glogger.info("-----> Generating swagger spec for /{}/{} on commit {}".format(user, repo, subdir, sha)) - swag = utils.build_swagger_spec(user, repo, sha, static.SERVER_NAME) + swag = utils.build_swagger_spec(user, repo, subdir, sha, static.SERVER_NAME) if 'text/turtle' in request.headers['Accept']: resp_spec = make_response(utils.turtleize(swag)) @@ -89,9 +98,15 @@ def swagger_spec(user, repo, sha=None, content=None): resp_spec.headers['Cache-Control'] = static.CACHE_CONTROL_POLICY # Caching JSON specs for 15 minutes - glogger.info("-----> API spec generation for /{}/{} on commit {} complete".format(user, repo, sha)) + glogger.info("-----> API spec generation for /{}/{} on commit {} complete".format(user, repo, subdir, sha)) return resp_spec if __name__ == '__main__': - app.run(host=static.DEFAULT_HOST, port=static.DEFAULT_PORT, debug=static.LOG_DEBUG_MODE) + print("foo") + print("bar") + print("LOG DEBUG MODE is: " + str(static.LOG_DEBUG_MODE)) + print("API KEY: " + str(static.ACCESS_TOKEN)) + glogger.debug("yo") + app.run(host=static.DEFAULT_HOST, port=static.DEFAULT_PORT, debug=True) + glogger.debug("YO") diff --git a/src/swagger.py b/src/swagger.py index 91ad563..2b40f58 100644 --- a/src/swagger.py +++ b/src/swagger.py @@ -103,9 +103,9 @@ def get_path_for_item(item): return item_path -def build_spec(user, repo, sha=None, prov=None, extraMetadata=[]): +def build_spec(user, repo, subdir, sha=None, prov=None, extraMetadata=[]): """Build grlc specification for the given github user / repo.""" - loader = grlc.utils.getLoader(user, repo, sha=sha, prov=prov) + loader = grlc.utils.getLoader(user, repo, subdir, sha=sha, prov=prov) files = loader.fetchFiles() raw_repo_uri = loader.getRawRepoUri() diff --git a/src/templates/api-docs.html b/src/templates/api-docs.html index f54b01c..c6a2740 100644 --- a/src/templates/api-docs.html +++ b/src/templates/api-docs.html @@ -89,7 +89,7 @@