Optimize get last package
This commit is contained in:
parent
5f30d588dc
commit
e10aa66da4
18
App.py
18
App.py
@ -18,38 +18,38 @@ api.add_resource(
|
|||||||
BrowseRepo,
|
BrowseRepo,
|
||||||
'/', # Retrieve available repos
|
'/', # Retrieve available repos
|
||||||
'/<string:repo_name>', # Retrieve data from <repo_name>
|
'/<string:repo_name>', # Retrieve data from <repo_name>
|
||||||
'/<string:repo_name>/<string:package_name>', # Retrieve data from <repo_name> about <package_name>
|
'/<string:repo_name>/<string:package_name>', # Retrieve data from <repo_name> about <package_name>
|
||||||
)
|
)
|
||||||
|
|
||||||
api.add_resource(
|
api.add_resource(
|
||||||
BrowseRepoVersion,
|
BrowseRepoVersion,
|
||||||
'/<string:repo_name>/<string:package_name>/<int:version_major>',
|
'/<string:repo_name>/<string:package_name>/<int:version_major>',
|
||||||
# Retrieve data version <package_name> from default <repo_name>
|
# Retrieve data version <package_name> from <repo_name>
|
||||||
'/<string:repo_name>/<string:package_name>/<int:version_major>/<int:version_minor>',
|
'/<string:repo_name>/<string:package_name>/<int:version_major>/<int:version_minor>',
|
||||||
# Retrieve data version <package_name> from default <repo_name>
|
# Retrieve data version <package_name> from <repo_name>
|
||||||
'/<string:repo_name>/<string:package_name>/<int:version_major>/<int:version_minor>/<int:version_release>',
|
'/<string:repo_name>/<string:package_name>/<int:version_major>/<int:version_minor>/<int:version_release>',
|
||||||
# Retrieve data version <package_name> from default <repo_name>
|
# Retrieve data version <package_name> from <repo_name>
|
||||||
)
|
)
|
||||||
|
|
||||||
api.add_resource(
|
api.add_resource(
|
||||||
InfoLastPackage,
|
InfoLastPackage,
|
||||||
'/<string:repo_name>/<string:package_name>/last', # Download last version <package_name> from default <repo_name>
|
'/<string:repo_name>/<string:package_name>/last', # Info for last version <package_name> from <repo_name>
|
||||||
)
|
)
|
||||||
|
|
||||||
api.add_resource(
|
api.add_resource(
|
||||||
DownloadLastPackage,
|
DownloadLastPackage,
|
||||||
'/download/<string:repo_name>/<string:package_name>/last',
|
'/download/<string:repo_name>/<string:package_name>/last',
|
||||||
# Download last version <package_name> from default <repo_name>
|
# Download last version <package_name> from <repo_name>
|
||||||
)
|
)
|
||||||
|
|
||||||
api.add_resource(
|
api.add_resource(
|
||||||
DownloadPackageVersion,
|
DownloadPackageVersion,
|
||||||
'/download/<string:repo_name>/<string:package_name>/<int:version_major>',
|
'/download/<string:repo_name>/<string:package_name>/<int:version_major>',
|
||||||
# Download version <package_name> from default <repo_name>
|
# Download version <package_name> from <repo_name>
|
||||||
'/download/<string:repo_name>/<string:package_name>/<int:version_major>/<int:version_minor>',
|
'/download/<string:repo_name>/<string:package_name>/<int:version_major>/<int:version_minor>',
|
||||||
# Download version <package_name> from default <repo_name>
|
# Download version <package_name> from <repo_name>
|
||||||
'/download/<string:repo_name>/<string:package_name>/<int:version_major>/<int:version_minor>/<int:version_release>',
|
'/download/<string:repo_name>/<string:package_name>/<int:version_major>/<int:version_minor>/<int:version_release>',
|
||||||
# Download version <package_name> from default <repo_name>
|
# Download version <package_name> from <repo_name>
|
||||||
)
|
)
|
||||||
|
|
||||||
api.add_resource(
|
api.add_resource(
|
||||||
|
@ -43,6 +43,7 @@ class PackageVersioning(FileSystemEventHandler):
|
|||||||
def __init__(self, repos_json_conf, prefix_url_download="/download"):
|
def __init__(self, repos_json_conf, prefix_url_download="/download"):
|
||||||
self.__repos_public = {}
|
self.__repos_public = {}
|
||||||
self.__repos_private = {}
|
self.__repos_private = {}
|
||||||
|
self.__repos_last = {}
|
||||||
self.__repos_json_conf = repos_json_conf
|
self.__repos_json_conf = repos_json_conf
|
||||||
self.__repos_obs = []
|
self.__repos_obs = []
|
||||||
self.__prefix_url_download = prefix_url_download
|
self.__prefix_url_download = prefix_url_download
|
||||||
@ -59,6 +60,8 @@ class PackageVersioning(FileSystemEventHandler):
|
|||||||
"directory_path": os.path.abspath(directory_path),
|
"directory_path": os.path.abspath(directory_path),
|
||||||
"package_finder": PackageFinder(regex_package_name)
|
"package_finder": PackageFinder(regex_package_name)
|
||||||
}
|
}
|
||||||
|
repo_last= {}
|
||||||
|
list_package_name = []
|
||||||
|
|
||||||
for filename in repo_private['package_finder'].find_packages(directory_path):
|
for filename in repo_private['package_finder'].find_packages(directory_path):
|
||||||
package_path = os.path.join(directory_path, filename)
|
package_path = os.path.join(directory_path, filename)
|
||||||
@ -92,6 +95,7 @@ class PackageVersioning(FileSystemEventHandler):
|
|||||||
|
|
||||||
if package_name not in repo_public:
|
if package_name not in repo_public:
|
||||||
repo_public[package_name] = {}
|
repo_public[package_name] = {}
|
||||||
|
list_package_name.append(package_name)
|
||||||
else:
|
else:
|
||||||
if str(version) in repo_public[package_name]:
|
if str(version) in repo_public[package_name]:
|
||||||
raise Exception("Conflict name package {} version {} ! Version already exist !"
|
raise Exception("Conflict name package {} version {} ! Version already exist !"
|
||||||
@ -112,9 +116,9 @@ class PackageVersioning(FileSystemEventHandler):
|
|||||||
|
|
||||||
self.__repos_public[repo_name] = repo_public
|
self.__repos_public[repo_name] = repo_public
|
||||||
self.__repos_private[repo_name] = repo_private
|
self.__repos_private[repo_name] = repo_private
|
||||||
print(self.__repos_public)
|
for p in list_package_name:
|
||||||
print(self.__repos_private)
|
repo_last[p] = self.__get_last_version_package(package_name, repo_name)
|
||||||
|
self.__repos_last[repo_name] = repo_last
|
||||||
|
|
||||||
def get_all_packages(self, package_name=None, repo_name=None):
|
def get_all_packages(self, package_name=None, repo_name=None):
|
||||||
repo_name, repo_public, _ = self.__get_repo(repo_name)
|
repo_name, repo_public, _ = self.__get_repo(repo_name)
|
||||||
@ -126,7 +130,7 @@ class PackageVersioning(FileSystemEventHandler):
|
|||||||
print(repo_public)
|
print(repo_public)
|
||||||
raise PackageDoNotExist
|
raise PackageDoNotExist
|
||||||
|
|
||||||
def get_last_version_package(self, package_name, repo_name):
|
def __get_last_version_package(self, package_name, repo_name):
|
||||||
_, repo_public, _ = self.__get_repo(repo_name)
|
_, repo_public, _ = self.__get_repo(repo_name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -142,6 +146,9 @@ class PackageVersioning(FileSystemEventHandler):
|
|||||||
|
|
||||||
return package[str(last_version)]
|
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_path_package(self, filename, repo_name):
|
def get_path_package(self, filename, repo_name):
|
||||||
_, _, repo_private = self.__get_repo(repo_name)
|
_, _, repo_private = self.__get_repo(repo_name)
|
||||||
if not repo_private[repo_name]['package_finder'].is_valid_filename(filename):
|
if not repo_private[repo_name]['package_finder'].is_valid_filename(filename):
|
||||||
|
Reference in New Issue
Block a user