This is an automated email from the git hooks/post-receive script.
praiskup pushed a commit to branch master in repository copr/copr.
The following commit(s) were added to refs/heads/master by this push: new fc6855f frontend: dump whooshee version when updating indexes fc6855f is described below
commit fc6855f3dc98585ca86d1a47aa3325f6ea6bd322 Author: Jakub Kadlcik frostyx@email.cz AuthorDate: Mon Aug 26 13:33:34 2019 +0200
frontend: dump whooshee version when updating indexes
Once we have information about what whooshee version we used for generating indexes, then we can update our provision playbooks to rebuild them only if the version changed.
Merges: #946 --- frontend/coprs_frontend/commands/update_indexes.py | 4 ++- .../commands/update_indexes_required.py | 14 ++++++++ frontend/coprs_frontend/coprs/whoosheers.py | 38 ++++++++++++++++++++++ frontend/coprs_frontend/manage.py | 7 ++-- 4 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/frontend/coprs_frontend/commands/update_indexes.py b/frontend/coprs_frontend/commands/update_indexes.py index 03279fc..e9da805 100644 --- a/frontend/coprs_frontend/commands/update_indexes.py +++ b/frontend/coprs_frontend/commands/update_indexes.py @@ -1,7 +1,7 @@ from flask_script import Command from flask_whooshee import Whooshee from coprs import app -from coprs.whoosheers import CoprWhoosheer +from coprs.whoosheers import CoprWhoosheer, WhoosheeStamp from coprs.logic import coprs_logic
@@ -26,3 +26,5 @@ class UpdateIndexesCommand(Command): for copr in coprs_logic.CoprsLogic.get_all(): CoprWhoosheer.insert_copr(writer, copr) writer.commit(optimize=True) + + WhoosheeStamp.store() diff --git a/frontend/coprs_frontend/commands/update_indexes_required.py b/frontend/coprs_frontend/commands/update_indexes_required.py new file mode 100644 index 0000000..209b31d --- /dev/null +++ b/frontend/coprs_frontend/commands/update_indexes_required.py @@ -0,0 +1,14 @@ +import sys +from flask_script import Command +from coprs.whoosheers import WhoosheeStamp + + +class UpdateIndexesRequiredCommand(Command): + """ + Is whooshee indexes rebuild required? + """ + + def run(self): + valid = WhoosheeStamp.is_valid() + print("no" if valid else "yes") + sys.exit(int(not valid)) diff --git a/frontend/coprs_frontend/coprs/whoosheers.py b/frontend/coprs_frontend/coprs/whoosheers.py index 930bd65..9ab6d70 100644 --- a/frontend/coprs_frontend/coprs/whoosheers.py +++ b/frontend/coprs_frontend/coprs/whoosheers.py @@ -1,8 +1,11 @@ +import os import whoosh import time
+from subprocess import Popen, PIPE from flask_whooshee import AbstractWhoosheer
+from coprs import app from coprs import models from coprs import whooshee from coprs import db @@ -110,3 +113,38 @@ class CoprWhoosheer(AbstractWhoosheer): WHERE copr.id = {1} """.format(int(time.time()), copr_id) ) + + +class WhoosheeStamp(object): + """ + When a whooshee package is updated, it is often needed to rebuild + indexes. This class manages a stamp file containing whooshee packages + versions and decides whether they are still up-to-date or not. + """ + + PATH = os.path.join(app.config["WHOOSHEE_DIR"], "whooshee-version") + + @classmethod + def current(cls): + packages = ["python3-flask-whooshee", "python3-whoosh"] + cmd = ["rpm", "-q", "--qf", "%{NAME}-%{VERSION}\n"] + packages + process = Popen(cmd, stdout=PIPE, stderr=PIPE) + out, err = process.communicate() + return out.decode("utf-8").rstrip() + + @classmethod + def store(cls): + with open(cls.PATH, "w") as f: + f.write(cls.current()) + + @classmethod + def read(cls): + try: + with open(cls.PATH, "r") as f: + return f.read().rstrip() + except OSError: + return None + + @classmethod + def is_valid(cls): + return cls.read() == cls.current() diff --git a/frontend/coprs_frontend/manage.py b/frontend/coprs_frontend/manage.py index 2f0d585..455e3c5 100755 --- a/frontend/coprs_frontend/manage.py +++ b/frontend/coprs_frontend/manage.py @@ -29,11 +29,14 @@ commands = { "add_user": "AddUserCommand", "dump_user": "DumpUserCommand",
+ # Whooshee indexes + "update_indexes": "UpdateIndexesCommand", + "update_indexes_quick": "UpdateIndexesQuickCommand", + "update_indexes_required": "UpdateIndexesRequiredCommand", + # Other "get_admins": "GetAdminsCommand", "fail_build": "FailBuildCommand", - "update_indexes": "UpdateIndexesCommand", - "update_indexes_quick": "UpdateIndexesQuickCommand", "rawhide_to_release": "RawhideToReleaseCommand", "backend_rawhide_to_release": "BackendRawhideToReleaseCommand", "update_graphs": "UpdateGraphsDataCommand",
copr-commits@lists.fedorahosted.org