Add /last and /<repo_name>/last
Showing last pacakge available for all repos or for specific repo
This commit is contained in:
parent
e10aa66da4
commit
d4bbab20b6
13
App.py
13
App.py
@ -5,7 +5,7 @@ from Config import CURRENT_CONFIG
|
||||
from flask import Flask
|
||||
from flask_restful import Api
|
||||
import api.Repo as repoApi
|
||||
from api.Repo import BrowseRepo, InfoLastPackage, DownloadLastPackage, DownloadPackage, DownloadPackageVersion, \
|
||||
from api.Repo import BrowseRepo, InfoLast, InfoLastRepo, InfoLastPackage, DownloadLastPackage, DownloadPackage, DownloadPackageVersion, \
|
||||
BrowseRepoVersion
|
||||
from utils.PackageVersioning import PackageVersioning
|
||||
|
||||
@ -31,6 +31,16 @@ api.add_resource(
|
||||
# Retrieve data version <package_name> from <repo_name>
|
||||
)
|
||||
|
||||
api.add_resource(
|
||||
InfoLast,
|
||||
'/last'
|
||||
)
|
||||
|
||||
api.add_resource(
|
||||
InfoLastRepo,
|
||||
'/<string:repo_name>/last'
|
||||
)
|
||||
|
||||
api.add_resource(
|
||||
InfoLastPackage,
|
||||
'/<string:repo_name>/<string:package_name>/last', # Info for last version <package_name> from <repo_name>
|
||||
@ -57,7 +67,6 @@ api.add_resource(
|
||||
'/download/<string:repo_name>/<string:filename>', # Download version <filename> from repo_name
|
||||
)
|
||||
|
||||
|
||||
@app.before_first_request
|
||||
def setup():
|
||||
repoApi.package_versioning = PackageVersioning(json.load(open(app.config['REPOS_JSON_CONFIG_PATH'])))
|
||||
|
14
api/Repo.py
14
api/Repo.py
@ -31,6 +31,20 @@ class BrowseRepoVersion(Resource):
|
||||
abort(404)
|
||||
|
||||
|
||||
class InfoLast(Resource):
|
||||
def get(self):
|
||||
try:
|
||||
return package_versioning.get_last_version_package(), 200
|
||||
except (RepoDoNotExist, PackageDoNotExist):
|
||||
abort(404)
|
||||
|
||||
class InfoLastRepo(Resource):
|
||||
def get(self, repo_name):
|
||||
try:
|
||||
return package_versioning.get_last_version_package(repo_name=repo_name), 200
|
||||
except (RepoDoNotExist, PackageDoNotExist):
|
||||
abort(404)
|
||||
|
||||
class InfoLastPackage(Resource):
|
||||
def get(self, package_name, repo_name):
|
||||
try:
|
||||
|
@ -146,8 +146,13 @@ class PackageVersioning(FileSystemEventHandler):
|
||||
|
||||
return package[str(last_version)]
|
||||
|
||||
def get_last_version_package(self, package_name, repo_name):
|
||||
return self.__repos_last[repo_name][package_name]
|
||||
def get_last_version_package(self, package_name=None, repo_name=None):
|
||||
if package_name and repo_name:
|
||||
return self.__repos_last[repo_name][package_name]
|
||||
elif repo_name :
|
||||
return self.__repos_last[repo_name]
|
||||
else :
|
||||
return self.__repos_last
|
||||
|
||||
def get_path_package(self, filename, repo_name):
|
||||
_, _, repo_private = self.__get_repo(repo_name)
|
||||
|
Reference in New Issue
Block a user