[PATCH 2 of 2] setup-db: perform an initial repository scan as stated by the docs (issue #302)

Thomas De Schampheleire thomas.de_schampheleire at nokia.com
Tue May 1 20:13:19 UTC 2018


# HG changeset patch
# User Thomas De Schampheleire <thomas.de_schampheleire at nokia.com>
# Date 1525204743 -7200
#      Tue May 01 21:59:03 2018 +0200
# Node ID 2f02cdea28f702aa10b0a8bb47e23b305fde9b30
# Parent  ab5ae5d0e2ba5b8189ce0040237e3a3ce3d3fe44
setup-db: perform an initial repository scan as stated by the docs (issue #302)

The documentation as well as the prompt text inside setup-db itself state
that the repository root location will be scanned automatically for existing
repositories.
However, this is not actually the case. Only exception is when the
'initial_repo_scan' is set to True in the ini file; in that case the scan is
done on each start of Kallithea.

Add a call to the repo-scan gearbox command from the setup-db command.
Directly calling into the corresponding kallithea methods is not possible,
as the configuration is not fully loaded (i.e. database and caching is not
set up). Changing the user workflow to require an explicit call to repo-scan
is also possible but less user-friendly.

It may be fragile to hook into gearbox like this, if desired we could go
round using 'subprocess'.

In order to get access to the configuration file, we save the 'args' inside
the Command object from BasePasterCommand.

diff --git a/kallithea/lib/paster_commands/common.py b/kallithea/lib/paster_commands/common.py
--- a/kallithea/lib/paster_commands/common.py
+++ b/kallithea/lib/paster_commands/common.py
@@ -67,6 +67,7 @@ class BasePasterCommand(gearbox.command.
 
         If needed by the command, read config file and initialize database before running.
         """
+        self.args = args
         if self.takes_config_file:
             path_to_ini_file = os.path.realpath(args.config_file)
             self.config = paste.deploy.appconfig('config:' + path_to_ini_file)
diff --git a/kallithea/lib/paster_commands/setup_db.py b/kallithea/lib/paster_commands/setup_db.py
--- a/kallithea/lib/paster_commands/setup_db.py
+++ b/kallithea/lib/paster_commands/setup_db.py
@@ -19,6 +19,7 @@ Databaset setup gearbox command for Kall
 """
 
 
+import gearbox
 import os
 import sys
 import paste.deploy
@@ -103,4 +104,7 @@ class Command(BasePasterCommand):
         dbmanage.populate_default_permissions()
         Session().commit()
 
+        # initial repository scan
+        gearbox.main.GearBox().run(['repo-scan', '-c', self.args.config_file])
+
         print 'Database set up successfully.'


More information about the kallithea-general mailing list