This commit is contained in:
caandt 2025-01-03 13:30:46 -05:00
parent 6b93e2178b
commit 7bd08eb44c
2 changed files with 58 additions and 14 deletions

View file

@ -11,9 +11,7 @@
env.NIX_LDFLAGS = "-lXcursor"; env.NIX_LDFLAGS = "-lXcursor";
}); });
ki = super.ki.overrideAttrs (old: { ki = super.ki.overrideAttrs (old: {
postInstall = '' patches = old.patches ++ [./ki.diff];
patch $out/bin/ki < ${./ki.diff}
'';
}); });
}) })
]; ];

View file

@ -1,11 +1,57 @@
--- a/bin/ki diff --git a/ki/__init__.py b/ki/__init__.py
+++ b/bin/ki index 3f29c1a..1d5c101 100644
@@ -1,6 +1,8 @@ --- a/ki/__init__.py
import re +++ b/ki/__init__.py
import sys @@ -405,7 +405,7 @@ def parse_note(parser: Lark, transformer: NoteTransformer, delta: Delta) -> Deck
from ki import ki deck=deck,
+import ki.maybes as M; M.empty_kirepo = lambda root: (M.F.mksubdir(root, M.Path(M.KI)), M.F.mksubdir(M.EmptyDir(root), M.Path(M.MEDIA))) model=flatnote.model,
+import pathlib as P; PTD = P.Path.__truediv__; P.Path.__truediv__ = lambda a, b: P.Path('/dev/null') if '.gitattributes' in str(PTD(a, b)) else PTD(a, b) tags=flatnote.tags,
if __name__ == "__main__": - fields=flatnote.fields,
sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0]) + fields={k: v.rstrip() for k, v in flatnote.fields.items()},
sys.exit(ki()) )
@@ -1510,14 +1510,15 @@ def _pull2(kirepo: KiRepo, col: Collection) -> Collection:
@ki.command()
+@click.option('-f', '--force', is_flag=True)
@beartype
-def push() -> None:
+def push(force: bool) -> None:
"""Push commits from the currrent ki repository into an Anki collection."""
- _push()
+ _push(force)
@beartype
-def _push() -> PushResult:
+def _push(force: bool = False) -> PushResult:
"""Execute a push op."""
# pylint: disable=too-many-locals
# Check that we are inside a ki repository, and load collection.
@@ -1527,7 +1528,10 @@ def _push() -> PushResult:
hashes: List[str] = kirepo.hashes_file.read_text(encoding=UTF8).split("\n")
hashes = list(filter(lambda l: l != "", hashes))
if md5sum not in hashes[-1]:
- raise UpdatesRejectedError(kirepo.col_file)
+ if force:
+ echo('overwriting...')
+ else:
+ raise UpdatesRejectedError(kirepo.col_file)
head_kirepo: KiRepo = cp_ki(M.head_ki(kirepo), f"{HEAD_SUFFIX}-{md5sum}")
remote_root: EmptyDir = F.mksubdir(F.mkdtemp(), REMOTE_SUFFIX / md5sum)
diff --git a/ki/maybes.py b/ki/maybes.py
index 38c5573..45458f5 100644
--- a/ki/maybes.py
+++ b/ki/maybes.py
@@ -470,8 +470,6 @@ def empty_kirepo(root: EmptyDir) -> Tuple[EmptyDir, EmptyDir]:
"""Initialize subdirs for a ki repo."""
kidir = F.mksubdir(root, Path(KI))
mediadir = F.mksubdir(EmptyDir(root), Path(MEDIA))
- workflowsdir = F.mksubdir(EmptyDir(root), Path(".github/workflows"))
- _ = F.copyfile(F.chk(Path(__file__).parent / "jekyll-gh-pages.yml"), F.chk(workflowsdir / "jekyll-gh-pages.yml.example"))
return kidir, mediadir