Update closest_photodb to take starting path argument.
This commit is contained in:
parent
399d27bb44
commit
26d5ff5730
5 changed files with 10 additions and 8 deletions
|
@ -1953,21 +1953,20 @@ class PhotoDB(
|
||||||
self.sql.commit()
|
self.sql.commit()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def closest_photodb(cls, *args, **kwargs):
|
def closest_photodb(cls, path, *args, **kwargs):
|
||||||
'''
|
'''
|
||||||
Starting from the cwd and climbing upwards towards the filesystem root,
|
Starting from the cwd and climbing upwards towards the filesystem root,
|
||||||
look for an existing Etiquette data directory and return the PhotoDB
|
look for an existing Etiquette data directory and return the PhotoDB
|
||||||
object. If none exists, raise exceptions.NoClosestPhotoDB.
|
object. If none exists, raise exceptions.NoClosestPhotoDB.
|
||||||
'''
|
'''
|
||||||
cwd = pathclass.cwd()
|
starting = path
|
||||||
|
|
||||||
path = cwd
|
|
||||||
while True:
|
while True:
|
||||||
if path.with_child(constants.DEFAULT_DATADIR).is_dir:
|
if path.with_child(constants.DEFAULT_DATADIR).is_dir:
|
||||||
break
|
break
|
||||||
parent = path.parent
|
parent = path.parent
|
||||||
if path == parent:
|
if path == parent:
|
||||||
raise exceptions.NoClosestPhotoDB(cwd.absolute_path)
|
raise exceptions.NoClosestPhotoDB(starting.absolute_path)
|
||||||
path = parent
|
path = parent
|
||||||
|
|
||||||
path = path.with_child(constants.DEFAULT_DATADIR)
|
path = path.with_child(constants.DEFAULT_DATADIR)
|
||||||
|
|
|
@ -30,7 +30,7 @@ def find_photodb():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# If this raises, main will catch it.
|
# If this raises, main will catch it.
|
||||||
photodb = etiquette.photodb.PhotoDB.closest_photodb(log_level=LOG_LEVEL)
|
photodb = etiquette.photodb.PhotoDB.closest_photodb(cwd, log_level=LOG_LEVEL)
|
||||||
photodbs[cwd] = photodb
|
photodbs[cwd] = photodb
|
||||||
return photodb
|
return photodb
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ def etiquette_flask_launch(
|
||||||
site.localhost_only = True
|
site.localhost_only = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
backend.common.init_photodb(log_level=LOG_LEVEL)
|
backend.common.init_photodb(path=pathclass.cwd(), log_level=LOG_LEVEL)
|
||||||
except etiquette.exceptions.NoClosestPhotoDB as exc:
|
except etiquette.exceptions.NoClosestPhotoDB as exc:
|
||||||
pipeable.stderr(exc.error_message)
|
pipeable.stderr(exc.error_message)
|
||||||
pipeable.stderr('Try `etiquette_cli.py init` to create the database.')
|
pipeable.stderr('Try `etiquette_cli.py init` to create the database.')
|
||||||
|
|
|
@ -6,6 +6,8 @@ gunicorn etiquette_flask_prod:site --bind "0.0.0.0:PORT" --access-logfile "-"
|
||||||
'''
|
'''
|
||||||
import werkzeug.middleware.proxy_fix
|
import werkzeug.middleware.proxy_fix
|
||||||
|
|
||||||
|
from voussoirkit import pathclass
|
||||||
|
|
||||||
import backend
|
import backend
|
||||||
|
|
||||||
backend.site.wsgi_app = werkzeug.middleware.proxy_fix.ProxyFix(backend.site.wsgi_app)
|
backend.site.wsgi_app = werkzeug.middleware.proxy_fix.ProxyFix(backend.site.wsgi_app)
|
||||||
|
@ -13,4 +15,4 @@ backend.site.wsgi_app = werkzeug.middleware.proxy_fix.ProxyFix(backend.site.wsgi
|
||||||
site = backend.site
|
site = backend.site
|
||||||
site.debug = False
|
site.debug = False
|
||||||
|
|
||||||
backend.common.init_photodb()
|
backend.common.init_photodb(path=pathclass.cwd())
|
||||||
|
|
|
@ -10,6 +10,7 @@ import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from voussoirkit import interactive
|
from voussoirkit import interactive
|
||||||
|
from voussoirkit import pathclass
|
||||||
from voussoirkit import pipeable
|
from voussoirkit import pipeable
|
||||||
from voussoirkit import vlogging
|
from voussoirkit import vlogging
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@ def erepl_argparse(args):
|
||||||
global P
|
global P
|
||||||
|
|
||||||
try:
|
try:
|
||||||
P = etiquette.photodb.PhotoDB.closest_photodb(log_level=LOG_LEVEL)
|
P = etiquette.photodb.PhotoDB.closest_photodb(pathclass.cwd(), log_level=LOG_LEVEL)
|
||||||
except etiquette.exceptions.NoClosestPhotoDB as exc:
|
except etiquette.exceptions.NoClosestPhotoDB as exc:
|
||||||
pipeable.stderr(exc.error_message)
|
pipeable.stderr(exc.error_message)
|
||||||
pipeable.stderr('Try `etiquette_cli.py init` to create the database.')
|
pipeable.stderr('Try `etiquette_cli.py init` to create the database.')
|
||||||
|
|
Loading…
Reference in a new issue