wpsync 1.17.2__tar.gz → 1.18.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {wpsync-1.17.2 → wpsync-1.18.2}/PKG-INFO +2 -1
- {wpsync-1.17.2 → wpsync-1.18.2}/README.md +1 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/pyproject.toml +6 -1
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/cli.py +101 -15
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/pull.py +5 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/push.py +5 -0
- wpsync-1.18.2/src/wpsync/shell.py +76 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/sync.py +24 -4
- {wpsync-1.17.2 → wpsync-1.18.2}/.gitignore +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/LICENSE +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/build_backend/versioning.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/__init__.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/__main__.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/config.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/documents.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/editors.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/markup/__init__.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/markup/dom.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/markup/markdown.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/media.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/posts.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/state.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/storage.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/trash.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/wordpress/__init__.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/wordpress/autop.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/wordpress/client.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/wordpress/content.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/src/wpsync/wordpress/remote.py +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/version.json +0 -0
- {wpsync-1.17.2 → wpsync-1.18.2}/website/README.md +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: wpsync
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.18.2
|
|
4
4
|
Summary: Manage blog posts as local Markdown files
|
|
5
5
|
Project-URL: Homepage, https://wpsync.dev
|
|
6
6
|
Project-URL: Changelog, https://github.com/ediril/wpsync/blob/main/CHANGELOG.md
|
|
@@ -79,6 +79,7 @@ header, and its images go in `content/images/`.
|
|
|
79
79
|
|
|
80
80
|
```console
|
|
81
81
|
wpsync profiles # list profiles; * marks the current one
|
|
82
|
+
wpsync cd myblog # go to a profile's folder (after wpsync setup)
|
|
82
83
|
wpsync ls # local posts, without contacting the blog
|
|
83
84
|
wpsync show hello # one post's details and issues
|
|
84
85
|
wpsync create -o # start a new private post and open it
|
|
@@ -56,6 +56,7 @@ header, and its images go in `content/images/`.
|
|
|
56
56
|
|
|
57
57
|
```console
|
|
58
58
|
wpsync profiles # list profiles; * marks the current one
|
|
59
|
+
wpsync cd myblog # go to a profile's folder (after wpsync setup)
|
|
59
60
|
wpsync ls # local posts, without contacting the blog
|
|
60
61
|
wpsync show hello # one post's details and issues
|
|
61
62
|
wpsync create -o # start a new private post and open it
|
|
@@ -35,7 +35,12 @@ Repository = "https://github.com/ediril/wpsync.git"
|
|
|
35
35
|
wpsync = "wpsync.cli:main"
|
|
36
36
|
|
|
37
37
|
[dependency-groups]
|
|
38
|
-
dev = [
|
|
38
|
+
dev = [
|
|
39
|
+
"pip>=26.3,<27",
|
|
40
|
+
"pytest>=8,<10",
|
|
41
|
+
"ruff>=0.12,<1",
|
|
42
|
+
"twine>=6,<7",
|
|
43
|
+
]
|
|
39
44
|
|
|
40
45
|
[tool.hatch.version]
|
|
41
46
|
source = "code"
|
|
@@ -10,6 +10,7 @@ import time
|
|
|
10
10
|
import unicodedata
|
|
11
11
|
from collections import Counter
|
|
12
12
|
from collections.abc import Callable, Mapping, Sequence
|
|
13
|
+
from dataclasses import dataclass
|
|
13
14
|
from datetime import UTC, datetime
|
|
14
15
|
from pathlib import Path, PurePosixPath
|
|
15
16
|
from typing import TextIO
|
|
@@ -43,6 +44,12 @@ from wpsync.editors import Editor, EditorError, editor_command, launch
|
|
|
43
44
|
from wpsync.posts import Post, PostStatus, PostSummary, RemoteState
|
|
44
45
|
from wpsync.pull import Puller
|
|
45
46
|
from wpsync.push import Pusher
|
|
47
|
+
from wpsync.shell import (
|
|
48
|
+
ShellSetupError,
|
|
49
|
+
home_relative,
|
|
50
|
+
install_shell_function,
|
|
51
|
+
startup_file,
|
|
52
|
+
)
|
|
46
53
|
from wpsync.state import (
|
|
47
54
|
PostRecord,
|
|
48
55
|
StateError,
|
|
@@ -60,6 +67,7 @@ COMMANDS = (
|
|
|
60
67
|
"map",
|
|
61
68
|
"remove",
|
|
62
69
|
"root",
|
|
70
|
+
"cd",
|
|
63
71
|
"profile",
|
|
64
72
|
"profiles",
|
|
65
73
|
"editor",
|
|
@@ -73,6 +81,7 @@ COMMANDS = (
|
|
|
73
81
|
"delete",
|
|
74
82
|
"trash",
|
|
75
83
|
"restore",
|
|
84
|
+
"setup",
|
|
76
85
|
)
|
|
77
86
|
PROFILE_AWARE_COMMANDS = frozenset(
|
|
78
87
|
{
|
|
@@ -110,19 +119,25 @@ LEGEND = (
|
|
|
110
119
|
("~ ", "on both sides; push updates the post"),
|
|
111
120
|
(" r", "on WordPress only; push keeps it"),
|
|
112
121
|
("- r", "on WordPress only; push -p deletes it"),
|
|
113
|
-
(" x ", "private; push skips it"),
|
|
122
|
+
(" x ", "private, or public and dated later; push skips it"),
|
|
114
123
|
("l", "local only"),
|
|
115
124
|
("r", "on WordPress only"),
|
|
116
125
|
(" ", "blank side column: on both sides"),
|
|
117
126
|
("?", "conflict; push asks first, or cannot send it"),
|
|
118
127
|
("=", "unchanged"),
|
|
119
|
-
("x", "private"),
|
|
128
|
+
("x", "private, or dated later"),
|
|
120
129
|
("/", "folder"),
|
|
121
130
|
)
|
|
122
|
-
|
|
131
|
+
EXCLUDED = (Action.PRIVATE, Action.SCHEDULED)
|
|
132
|
+
"""What push skips, shown in diff's exclusion slot."""
|
|
133
|
+
HIDDEN_HINTS = {
|
|
134
|
+
Action.PRIVATE: ("private", "-x"),
|
|
135
|
+
Action.SCHEDULED: ("scheduled", "-x"),
|
|
136
|
+
Action.KEPT: ("remote-only", "-a"),
|
|
137
|
+
}
|
|
123
138
|
LS_LEGEND = (
|
|
124
139
|
("*", "Public: push publishes it (blank means private)"),
|
|
125
|
-
("*Jan 1, 2029", "Public
|
|
140
|
+
("*Jan 1, 2029", "Public, dated later: push publishes it from that date"),
|
|
126
141
|
)
|
|
127
142
|
|
|
128
143
|
|
|
@@ -294,6 +309,18 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
294
309
|
)
|
|
295
310
|
_profile_argument(root)
|
|
296
311
|
|
|
312
|
+
cd = subparsers.add_parser(
|
|
313
|
+
"cd",
|
|
314
|
+
help="change to a profile's local folder (needs 'wpsync setup')",
|
|
315
|
+
usage="wpsync cd [PROFILE]",
|
|
316
|
+
description=(
|
|
317
|
+
"Change the shell's directory to a profile's local folder. A program "
|
|
318
|
+
"cannot change its shell's directory, so this works through the "
|
|
319
|
+
"shell function that 'wpsync setup' installs."
|
|
320
|
+
),
|
|
321
|
+
)
|
|
322
|
+
_profile_argument(cd)
|
|
323
|
+
|
|
297
324
|
profile = subparsers.add_parser(
|
|
298
325
|
"profile",
|
|
299
326
|
help="show the current or named profile",
|
|
@@ -428,7 +455,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
428
455
|
"-x",
|
|
429
456
|
"--excluded",
|
|
430
457
|
action="store_true",
|
|
431
|
-
help="also show private posts, which push skips",
|
|
458
|
+
help="also show private and later-dated posts, which push skips",
|
|
432
459
|
)
|
|
433
460
|
diff.add_argument(
|
|
434
461
|
"-p",
|
|
@@ -516,6 +543,16 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
516
543
|
pull.add_argument(
|
|
517
544
|
"-y", "--yes", action="store_true", help="answer yes to every question"
|
|
518
545
|
)
|
|
546
|
+
|
|
547
|
+
subparsers.add_parser(
|
|
548
|
+
"setup",
|
|
549
|
+
help="enable 'wpsync cd' in your zsh or bash startup file",
|
|
550
|
+
description=(
|
|
551
|
+
"Add a small wpsync shell function to ~/.zshrc or ~/.bashrc, "
|
|
552
|
+
"chosen from $SHELL, so 'wpsync cd PROFILE' changes directory. "
|
|
553
|
+
"Running it again updates the function in place."
|
|
554
|
+
),
|
|
555
|
+
)
|
|
519
556
|
return parser
|
|
520
557
|
|
|
521
558
|
|
|
@@ -643,6 +680,30 @@ def _root(arguments: argparse.Namespace, session: _Session) -> str:
|
|
|
643
680
|
return os.fspath(profile.local_root)
|
|
644
681
|
|
|
645
682
|
|
|
683
|
+
def _cd(arguments: argparse.Namespace, session: _Session) -> str:
|
|
684
|
+
raise ConfigurationError(
|
|
685
|
+
"cd needs the shell function; run 'wpsync setup', then open a new terminal"
|
|
686
|
+
)
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
def _setup(arguments: argparse.Namespace, session: _Session) -> str:
|
|
690
|
+
try:
|
|
691
|
+
path = startup_file(session.environ)
|
|
692
|
+
replaced = install_shell_function(path)
|
|
693
|
+
except ShellSetupError as error:
|
|
694
|
+
raise ConfigurationError(str(error)) from error
|
|
695
|
+
except OSError as error:
|
|
696
|
+
raise ConfigurationError(f"could not update {path}: {error}") from error
|
|
697
|
+
home = Path(session.environ.get("HOME") or Path.home())
|
|
698
|
+
shown = home_relative(path, home)
|
|
699
|
+
action = "Updated" if replaced else "Added"
|
|
700
|
+
return (
|
|
701
|
+
f"{action} the wpsync shell function in {shown}.\n"
|
|
702
|
+
f"Open a new terminal, or run: source {shown}\n"
|
|
703
|
+
"Then 'wpsync cd PROFILE' changes to that profile's local folder."
|
|
704
|
+
)
|
|
705
|
+
|
|
706
|
+
|
|
646
707
|
def _profile(arguments: argparse.Namespace, session: _Session) -> str:
|
|
647
708
|
configuration = session.store.load()
|
|
648
709
|
if arguments.profile_prefix is None and arguments.profile_name is None:
|
|
@@ -943,6 +1004,7 @@ def _diff(arguments: argparse.Namespace, session: _Session) -> str:
|
|
|
943
1004
|
remote,
|
|
944
1005
|
root=root,
|
|
945
1006
|
media=read_media(root, profile.api_root),
|
|
1007
|
+
now=datetime.now(UTC),
|
|
946
1008
|
prune=arguments.prune,
|
|
947
1009
|
)
|
|
948
1010
|
finally:
|
|
@@ -954,8 +1016,8 @@ def _diff(arguments: argparse.Namespace, session: _Session) -> str:
|
|
|
954
1016
|
for entry in result.entries:
|
|
955
1017
|
visible = (
|
|
956
1018
|
arguments.all
|
|
957
|
-
or entry.action not in (Action.UNCHANGED,
|
|
958
|
-
or (entry.action
|
|
1019
|
+
or entry.action not in (Action.UNCHANGED, *EXCLUDED, Action.KEPT)
|
|
1020
|
+
or (entry.action in EXCLUDED and arguments.excluded)
|
|
959
1021
|
)
|
|
960
1022
|
if visible:
|
|
961
1023
|
shown.append(entry)
|
|
@@ -1014,9 +1076,9 @@ def _status_line(
|
|
|
1014
1076
|
entry_action: Action, entry_presence: str, name: str, depth: int, color: bool
|
|
1015
1077
|
) -> str:
|
|
1016
1078
|
"""Action, exclusion, and presence slots, as HLSync shows them."""
|
|
1017
|
-
|
|
1018
|
-
action = " " if
|
|
1019
|
-
exclusion = "x" if
|
|
1079
|
+
excluded = entry_action in EXCLUDED
|
|
1080
|
+
action = " " if excluded else entry_action.value
|
|
1081
|
+
exclusion = "x" if excluded else " "
|
|
1020
1082
|
presence = entry_presence or " "
|
|
1021
1083
|
status = f"{action}{exclusion} {presence}"
|
|
1022
1084
|
if not color:
|
|
@@ -1281,7 +1343,15 @@ class _Progress:
|
|
|
1281
1343
|
return ask
|
|
1282
1344
|
|
|
1283
1345
|
|
|
1284
|
-
|
|
1346
|
+
@dataclass(frozen=True)
|
|
1347
|
+
class _Transferred:
|
|
1348
|
+
"""What push or pull prints, and whether a post failed, which exits 1."""
|
|
1349
|
+
|
|
1350
|
+
summary: str
|
|
1351
|
+
failed: bool
|
|
1352
|
+
|
|
1353
|
+
|
|
1354
|
+
def _pull(arguments: argparse.Namespace, session: _Session) -> _Transferred:
|
|
1285
1355
|
profile, base = _profile_root(arguments, session)
|
|
1286
1356
|
root = profile.local_root
|
|
1287
1357
|
yes = arguments.yes
|
|
@@ -1331,7 +1401,7 @@ def _pull(arguments: argparse.Namespace, session: _Session) -> str:
|
|
|
1331
1401
|
summary = result.summary()
|
|
1332
1402
|
if result.declined and not yes:
|
|
1333
1403
|
summary += " Rerun with --yes to accept the skipped changes."
|
|
1334
|
-
return summary
|
|
1404
|
+
return _Transferred(summary, failed=result.failed > 0)
|
|
1335
1405
|
|
|
1336
1406
|
|
|
1337
1407
|
def _follow_files(
|
|
@@ -1349,7 +1419,7 @@ def _follow_files(
|
|
|
1349
1419
|
)
|
|
1350
1420
|
|
|
1351
1421
|
|
|
1352
|
-
def _push(arguments: argparse.Namespace, session: _Session) ->
|
|
1422
|
+
def _push(arguments: argparse.Namespace, session: _Session) -> _Transferred:
|
|
1353
1423
|
profile, base = _profile_root(arguments, session)
|
|
1354
1424
|
root = profile.local_root
|
|
1355
1425
|
documents = scan_documents(root)
|
|
@@ -1374,9 +1444,19 @@ def _push(arguments: argparse.Namespace, session: _Session) -> str:
|
|
|
1374
1444
|
media = read_media(root, profile.api_root)
|
|
1375
1445
|
progress = _Progress(session)
|
|
1376
1446
|
try:
|
|
1377
|
-
plan = compare(
|
|
1447
|
+
plan = compare(
|
|
1448
|
+
selection,
|
|
1449
|
+
lazy,
|
|
1450
|
+
root=root,
|
|
1451
|
+
media=media,
|
|
1452
|
+
now=datetime.now(UTC),
|
|
1453
|
+
prune=arguments.prune,
|
|
1454
|
+
)
|
|
1378
1455
|
for note in plan.notes:
|
|
1379
1456
|
session.status(f"Note: {note}")
|
|
1457
|
+
for entry in plan.entries:
|
|
1458
|
+
if entry.action is Action.SCHEDULED:
|
|
1459
|
+
session.status(f"Note: {display_path(entry.path)} {entry.reason}.")
|
|
1380
1460
|
sending = [entry for entry in plan.entries if entry.step is not None]
|
|
1381
1461
|
images = {image.path for entry in sending for image in entry.images}
|
|
1382
1462
|
if sending:
|
|
@@ -1405,7 +1485,8 @@ def _push(arguments: argparse.Namespace, session: _Session) -> str:
|
|
|
1405
1485
|
summary = result.summary()
|
|
1406
1486
|
if result.declined and not arguments.yes:
|
|
1407
1487
|
summary += " Rerun with --yes to accept the skipped changes."
|
|
1408
|
-
|
|
1488
|
+
notes = [f"Note: {note}" for note in result.notes]
|
|
1489
|
+
return _Transferred("\n".join([summary, *notes]), failed=result.failed > 0)
|
|
1409
1490
|
|
|
1410
1491
|
|
|
1411
1492
|
HANDLERS = {
|
|
@@ -1413,6 +1494,7 @@ HANDLERS = {
|
|
|
1413
1494
|
"map": _map,
|
|
1414
1495
|
"remove": _remove,
|
|
1415
1496
|
"root": _root,
|
|
1497
|
+
"cd": _cd,
|
|
1416
1498
|
"profile": _profile,
|
|
1417
1499
|
"profiles": _profiles,
|
|
1418
1500
|
"editor": _editor,
|
|
@@ -1426,6 +1508,7 @@ HANDLERS = {
|
|
|
1426
1508
|
"delete": _delete,
|
|
1427
1509
|
"trash": _trash,
|
|
1428
1510
|
"restore": _restore,
|
|
1511
|
+
"setup": _setup,
|
|
1429
1512
|
}
|
|
1430
1513
|
|
|
1431
1514
|
|
|
@@ -1471,6 +1554,9 @@ def run(
|
|
|
1471
1554
|
) as error:
|
|
1472
1555
|
print(f"wpsync: error: {error}", file=stderr)
|
|
1473
1556
|
return 1
|
|
1557
|
+
if isinstance(message, _Transferred):
|
|
1558
|
+
print(message.summary, file=stdout)
|
|
1559
|
+
return 1 if message.failed else 0
|
|
1474
1560
|
print(message, file=stdout)
|
|
1475
1561
|
return 0
|
|
1476
1562
|
|
|
@@ -59,6 +59,11 @@ class PullResult:
|
|
|
59
59
|
deleted_locally: list[str] = field(default_factory=list)
|
|
60
60
|
deleted_remotely: list[str] = field(default_factory=list)
|
|
61
61
|
|
|
62
|
+
@property
|
|
63
|
+
def failed(self) -> int:
|
|
64
|
+
"""Skipped posts that could not be pulled, as opposed to declined ones."""
|
|
65
|
+
return self.skipped - self.declined
|
|
66
|
+
|
|
62
67
|
def summary(self) -> str:
|
|
63
68
|
tail = ""
|
|
64
69
|
if self.missing_files:
|
|
@@ -68,6 +68,11 @@ class PushResult:
|
|
|
68
68
|
notes: list[str] = field(default_factory=list)
|
|
69
69
|
"""What WordPress did differently from what was sent."""
|
|
70
70
|
|
|
71
|
+
@property
|
|
72
|
+
def failed(self) -> int:
|
|
73
|
+
"""Skipped posts that could not be sent, as opposed to declined ones."""
|
|
74
|
+
return self.skipped - self.declined
|
|
75
|
+
|
|
71
76
|
def summary(self) -> str:
|
|
72
77
|
skipped = f"; {self.skipped} skipped" if self.skipped else ""
|
|
73
78
|
if not self.changes:
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Shell startup integration that lets 'wpsync cd' change directory."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import stat
|
|
7
|
+
from collections.abc import Mapping
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from wpsync.storage import write_text_atomic
|
|
11
|
+
|
|
12
|
+
BEGIN = "# >>> wpsync shell setup >>>"
|
|
13
|
+
END = "# <<< wpsync shell setup <<<"
|
|
14
|
+
|
|
15
|
+
# A program cannot change its parent shell's directory, so 'cd' is handled by
|
|
16
|
+
# this function; every other command passes through to the wpsync program.
|
|
17
|
+
BLOCK = f"""{BEGIN}
|
|
18
|
+
# Lets 'wpsync cd [PROFILE]' change to a profile's local folder.
|
|
19
|
+
wpsync() {{
|
|
20
|
+
if [ "$1" = cd ]; then
|
|
21
|
+
shift
|
|
22
|
+
local dir
|
|
23
|
+
dir="$(command wpsync root "$@")" && cd "$dir"
|
|
24
|
+
else
|
|
25
|
+
command wpsync "$@"
|
|
26
|
+
fi
|
|
27
|
+
}}
|
|
28
|
+
{END}
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
STARTUP_FILES = {"zsh": ".zshrc", "bash": ".bashrc"}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ShellSetupError(RuntimeError):
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def startup_file(environ: Mapping[str, str]) -> Path:
|
|
39
|
+
"""Return the interactive startup file of the user's login shell."""
|
|
40
|
+
shell = Path(environ.get("SHELL", "")).name
|
|
41
|
+
if shell not in STARTUP_FILES:
|
|
42
|
+
named = shell or "unknown"
|
|
43
|
+
raise ShellSetupError(f"setup supports zsh and bash, not '{named}'")
|
|
44
|
+
home = Path(environ.get("HOME") or Path.home())
|
|
45
|
+
directory = Path(environ.get("ZDOTDIR") or home) if shell == "zsh" else home
|
|
46
|
+
return directory / STARTUP_FILES[shell]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def install_shell_function(path: Path) -> bool:
|
|
50
|
+
"""Write the shell function block; return True if it replaced an older one."""
|
|
51
|
+
# Write through a symlink so dotfile managers keep their link.
|
|
52
|
+
target = path.resolve() if path.is_symlink() else path
|
|
53
|
+
try:
|
|
54
|
+
existing = target.read_text(encoding="utf-8")
|
|
55
|
+
mode = stat.S_IMODE(target.stat().st_mode)
|
|
56
|
+
except FileNotFoundError:
|
|
57
|
+
existing, mode = "", 0o644
|
|
58
|
+
start, end = existing.find(BEGIN), existing.find(END)
|
|
59
|
+
if start != -1 and end > start:
|
|
60
|
+
rest = existing[end + len(END) :]
|
|
61
|
+
updated = existing[:start] + BLOCK + rest.removeprefix("\n")
|
|
62
|
+
replaced = True
|
|
63
|
+
else:
|
|
64
|
+
separator = "" if not existing else "\n" if existing.endswith("\n") else "\n\n"
|
|
65
|
+
updated = existing + separator + BLOCK
|
|
66
|
+
replaced = False
|
|
67
|
+
write_text_atomic(target, updated, mode=mode)
|
|
68
|
+
return replaced
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def home_relative(path: Path, home: Path) -> str:
|
|
72
|
+
"""Show a startup file path with the home directory as '~'."""
|
|
73
|
+
try:
|
|
74
|
+
return f"~/{path.relative_to(home).as_posix()}"
|
|
75
|
+
except ValueError:
|
|
76
|
+
return os.fspath(path)
|
|
@@ -5,6 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
import difflib
|
|
6
6
|
from collections.abc import Sequence
|
|
7
7
|
from dataclasses import dataclass, replace
|
|
8
|
+
from datetime import datetime
|
|
8
9
|
from enum import StrEnum
|
|
9
10
|
from pathlib import Path, PurePosixPath
|
|
10
11
|
from typing import Generic, Protocol, TypeVar
|
|
@@ -15,6 +16,7 @@ from wpsync.documents import (
|
|
|
15
16
|
LocalDocument,
|
|
16
17
|
body_checksum,
|
|
17
18
|
fields_checksum,
|
|
19
|
+
format_date,
|
|
18
20
|
)
|
|
19
21
|
from wpsync.markup.markdown import image_sources
|
|
20
22
|
from wpsync.media import file_checksum, image_path, post_images
|
|
@@ -151,6 +153,8 @@ class Action(StrEnum):
|
|
|
151
153
|
UNCHANGED = "="
|
|
152
154
|
PRIVATE = "x"
|
|
153
155
|
"""Excluded: push skips a private post."""
|
|
156
|
+
SCHEDULED = "s"
|
|
157
|
+
"""Excluded: push holds a public post until its date."""
|
|
154
158
|
KEPT = " "
|
|
155
159
|
"""Deleted locally, but push keeps the post without -p."""
|
|
156
160
|
|
|
@@ -198,7 +202,8 @@ class DiffEntry:
|
|
|
198
202
|
step: PushStep | DeleteStep | None = None
|
|
199
203
|
"""None when a push leaves the post alone."""
|
|
200
204
|
reason: str = ""
|
|
201
|
-
"""Why push
|
|
205
|
+
"""Why push does not send the post: a conflict it has no question for, or
|
|
206
|
+
the date a scheduled post waits for."""
|
|
202
207
|
images: tuple[ImageUpload, ...] = ()
|
|
203
208
|
"""The images the post shows that push uploads with it."""
|
|
204
209
|
|
|
@@ -246,13 +251,16 @@ def compare(
|
|
|
246
251
|
*,
|
|
247
252
|
root: Path,
|
|
248
253
|
media: list[MediaRecord],
|
|
254
|
+
now: datetime,
|
|
249
255
|
prune: bool = False,
|
|
250
256
|
) -> Diff:
|
|
251
257
|
"""Classify the selected posts, contacting the remote only when needed.
|
|
252
258
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
259
|
+
A public post dated after now is held, so it reaches the blog with the
|
|
260
|
+
first push on or after its date. The images the sent posts show are listed
|
|
261
|
+
too: a new or replaced image is uploaded, so a post that shows one changes
|
|
262
|
+
even if its file did not. With prune, a post whose file was deleted is
|
|
263
|
+
deleted from the blog.
|
|
256
264
|
"""
|
|
257
265
|
entries: list[DiffEntry] = []
|
|
258
266
|
changed: dict[str, tuple[LocalDocument, list[str]]] = {}
|
|
@@ -268,6 +276,18 @@ def compare(
|
|
|
268
276
|
if post_id is not None:
|
|
269
277
|
present.add(post_id)
|
|
270
278
|
record = selection.records.get(post_id) if post_id else None
|
|
279
|
+
date = document.document.post.date
|
|
280
|
+
if not private and date is not None and date > now:
|
|
281
|
+
entries.append(
|
|
282
|
+
DiffEntry(
|
|
283
|
+
Action.SCHEDULED,
|
|
284
|
+
"" if record else "l",
|
|
285
|
+
post_id,
|
|
286
|
+
path,
|
|
287
|
+
reason=f"waits until {format_date(date)}",
|
|
288
|
+
)
|
|
289
|
+
)
|
|
290
|
+
continue
|
|
271
291
|
if private and record is None:
|
|
272
292
|
entries.append(DiffEntry(Action.PRIVATE, "l", post_id, path))
|
|
273
293
|
continue
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|