Skip to content

Commit

Permalink
UPD(index) preserve db by default ,
Browse files Browse the repository at this point in the history
-  Uncouple --source from -overwrite.
- drop PROMNESIA_INDEX_POLICY env-var.
  • Loading branch information
ankostis committed Mar 3, 2021
1 parent 0775abb commit 48aa904
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 34 deletions.
4 changes: 3 additions & 1 deletion doc/GUIDE.org
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ Also see [[https://github.com/karlicoss/promnesia/issues/172][issues/172]].

** partial update

(experimental) Set env variable =PROMNESIA_INDEX_POLICY=update=.
Only index sources given in =promnesia index --sources SOURCE [SOURCE] ...=
(or all sources, if no =--sources= given), unless =--overwrite= is given,
in which case all existing visits are removed from db prior to indexing.

** exclude files from =auto= indexer

Expand Down
42 changes: 9 additions & 33 deletions src/promnesia/__main__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import argparse
import os
import logging
import inspect
import os
import sys
from typing import List, Tuple, Optional, Dict, Sequence, Iterable, Iterator, Union
from pathlib import Path
Expand Down Expand Up @@ -303,24 +301,15 @@ def main() -> None:
nargs="+",
type=_ordinal_or_name,
metavar="SOURCE",
help="Source names (or their 0-indexed position) to index."
" If missing, db is recreated empty and all sources are indexed.",
help="Source names (or their 0-indexed position) to index.",
)
overwrite = ep.add_mutually_exclusive_group()
overwrite.add_argument(
'--update',
ep.add_argument(
'--overwrite',
required=False,
action="store_const",
const=True,
dest="overwrite_db",
help="Keep existing visits in db and merge new ones collected."
" If neither is given, --update assumed when --sources given (the default)"
", unless PROMNESIA_INDEX_POLICY=(update|overwrite) env-var defined"
", which takes precendance."
" Conflicts with --update.%(default)0.0s"
action="store_true",
help="Empty db before populating it with newly indexed visits."
" If interrupted, db is left untouched."
)
overwrite.add_argument('--overwrite', required=False, action="store_const", const=False, dest="overwrite_db",
help="The opposite of --update: recreate db with newly indexed visits%(default)0.0s")

sp = subp.add_parser('serve', help='Serve a link database', formatter_class=F) # type: ignore
server.setup_parser(sp)
Expand All @@ -342,7 +331,7 @@ def main() -> None:
help='Promnesia source to index as (see https://github.com/karlicoss/promnesia/tree/master/src/promnesia/sources for the full list)',
)
ap.add_argument('--sources', required=False, action="extend", nargs="+", type=_ordinal_or_name,
help="Subset of source(s) to run (name or 0-indexed position); use `promnisia --dry` to view sources")
help="Source names (or their 0-indexed position) to index.")
ap.add_argument('params', nargs='*', help='Optional extra params for the indexer')

isp = subp.add_parser('install-server', help='Install server as a systemd service (for autostart)', formatter_class=F)
Expand Down Expand Up @@ -376,19 +365,6 @@ def main() -> None:
p.print_help(sys.stderr)
sys.exit(1)

overwrite_policy_var = os.environ.get("PROMNESIA_INDEX_POLICY")
if overwrite_policy_var:
overwrite_policy_var = overwrite_policy_var.lower()
if overwrite_policy_var not in ("update", "overwrite"):
print(
f"Invalid value for PROMNESIA_INDEX_POLICY env-var: {overwrite_policy_var}"
"\n Must be one of (update | overwrite).",
file=sys.stderr)
sys.exit(2)
args.overwrite_db = overwrite_policy_var == "overwrite"
if args.overwrite_db is None:
args.overwrite_db = not bool(args.sources)

logger.info("CLI args: %s", args)

# TODO maybe, it's better for server to compute intermediate represetnation?
Expand All @@ -401,7 +377,7 @@ def main() -> None:
config_file=args.config,
dry=args.dry,
sources_subset=args.sources,
overwrite_db=args.overwrite_db,
overwrite_db=args.overwrite,
)
elif args.mode == 'serve':
server.run(args)
Expand All @@ -415,7 +391,7 @@ def main() -> None:
config_file=args.config,
name=args.name,
sources_subset=args.sources,
overwrite_db=args.overwrite_db,
overwrite_db=args.overwrite,
)
elif args.mode == 'install-server': # todo rename to 'autostart' or something?
install_server.install(args)
Expand Down

0 comments on commit 48aa904

Please sign in to comment.