Skip to content

Commit a7efacc

Browse files
committed
Cleanup and improve error message
1 parent 113e991 commit a7efacc

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
lines changed

docs/sample_pyftpsync.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ common_config:
1717
# local: sync_root
1818
#: Remote target protocol and address
1919
remote: sftp://example.com/my_project
20-
#: Make --dry-run default (can be overridden by --execute or --no-dry-run):
20+
#: Make --dry-run default (pass `--execute` or `--no-dry-run` to override):
2121
dry_run: true
22-
#: Make --root default (can be overridden by --here):
22+
#: Make --root default (pass `--here` to override):
2323
root: true
2424
#: Return exit code 10 on skipped files:
2525
report_problems: true
@@ -30,15 +30,16 @@ tasks:
3030
show:
3131
command: tree
3232
dry_run: false
33-
files: true
3433
sort: true
34+
files: false # Pass `--files` to override
3535

3636
sync_all:
3737
command: sync
3838

3939
deploy:
4040
command: upload
41-
delete_unmatched: true
41+
delete: false
42+
delete_unmatched: false
4243
exclude: build,node_modules,.*,_*
4344

4445
deploy_force:

docs/sphinx/ug_cli.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ FTP URLs may contain credentials (*not* recommended)::
8787

8888
$ pyftpsync upload ~/temp ftp://joe:[email protected]/target/folder
8989

90-
Note that `pyftpsync` also supports prompting for passwords and storing
91-
passwords in the system keyring and ``.netrc`` files.
90+
.. note::
91+
92+
Replace ``ftp://`` with ``ftps://`` to enable TLS encryption. |br|
93+
Replace ``ftp://`` with ``sftp://`` to use the SFTP protocol.
9294

9395
.. note::
9496

@@ -97,10 +99,8 @@ passwords in the system keyring and ``.netrc`` files.
9799
If the remote target does *not* exist, but its parent folder does, the
98100
``--create-folder`` option may be passed.
99101

100-
.. note::
101-
102-
Replace ``ftp://`` with ``ftps://`` to enable TLS encryption. |br|
103-
Replace ``ftp://`` with ``sftp://`` to use the SFTP protocol.
102+
Note that `pyftpsync` also supports prompting for passwords and storing
103+
passwords in the system keyring and ``.netrc`` files (see below).
104104

105105

106106
Authentication
@@ -157,8 +157,8 @@ The ``--match`` option filters processed files using on or more patterns
157157
(using the `fnmatch syntax <https://docs.python.org/3/library/fnmatch.html#module-fnmatch>`_). |br|
158158
**Note:** These patterns are only applied to files, not directories.
159159

160-
The ``--exclude`` option is applied after `--match` and removes entries from
161-
processing. Unlike `--match`, these patterns are also applied to directories.
160+
The ``--exclude`` option is applied after ``--match`` and removes entries from
161+
processing. Unlike ``--match``, these patterns are also applied to directories.
162162

163163
Example::
164164

@@ -224,25 +224,25 @@ Example: Upload Files
224224
Upload all new and modified files from user's temp folder to an FTP server.
225225
No files are changed on the local directory::
226226

227-
$ pyftpsync upload ~/temp ftp://example.com/target/folder
227+
$ pyftpsync upload ~/temp sftp://example.com/target/folder
228228

229229
Add the ``--delete`` option to remove all files from the remote target that
230230
don't exist locally::
231231

232-
$ pyftpsync upload ~/temp ftp://example.com/target/folder --delete
232+
$ pyftpsync upload ~/temp sftp://example.com/target/folder --delete
233233

234234
Add the ``--dry-run`` option to switch to DRY-RUN mode, i.e. run in test mode
235235
without modifying files::
236236

237-
$ pyftpsync upload ~/temp ftp://example.com/target/folder --delete --dry-run
237+
$ pyftpsync upload ~/temp sftp://example.com/target/folder --delete --dry-run
238238

239239
Add one or more ``-v`` options to increase output verbosity::
240240

241-
$ pyftpsync upload ~/temp ftp://example.com/target/folder --delete -vv
241+
$ pyftpsync upload ~/temp sftp://example.com/target/folder --delete -vv
242242

243243
Mirror current directory to remote folder::
244244

245-
$ pyftpsync upload . ftp://example.com/target/folder --force --delete --resolve=local
245+
$ pyftpsync upload . sftp://example.com/target/folder --force --delete --resolve=local
246246

247247

248248
Download Files Syntax

ftpsync/cli_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
action="store_true",
6969
default=False,
7070
help="replace meta data files from different pyftpsync versions "
71-
"with current format. Existing data will be discarded.",
71+
"with current format. Existing data will be discarded",
7272
)
7373

7474
common_parser.add_argument(

ftpsync/run_command.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,14 @@ def handle_run_command(parser, cli_args):
169169
if task_name not in config["tasks"]:
170170
parser.error(
171171
f"Invalid entry `default_task: {task_name}`: "
172-
f"must also define `tasks.{task_name}` in {config_path}"
172+
f"`tasks.{task_name}` is not defined in {config_path}"
173173
)
174174

175175
else:
176176
parser.error(
177177
"No `TASK` argument was passed and no default configured: "
178-
f"please define `default_task: TASK` in {config_path}"
178+
f"choose from [{', '.join(config['tasks'])}] "
179+
f"or define `default_task: TASK` in {config_path}"
179180
)
180181

181182
if task_name not in config["tasks"]:
@@ -221,7 +222,7 @@ def handle_run_command(parser, cli_args):
221222
write("`--no-dry-run` (or `--execute`) was passed: resetting dry_run mode")
222223
else:
223224
write(
224-
"dry_run mode is configured: pass --no-dry-run (or --execute) "
225+
"Dry-run mode is configured: pass --no-dry-run (or --execute) "
225226
"to enable write operations"
226227
)
227228

tests/debug_adhoc.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@
55
import os
66
import sys
77

8+
from build.lib.ftpsync.util import get_debug_option
9+
810
sys.path.append(os.path.dirname(__file__) + "/..")
911

1012

1113
# ===============================================================================
1214
# Main
1315
# ===============================================================================
1416

17+
PYFTPSYNC_REMOTE_URL = get_debug_option(
18+
"PYFTPSYNC_DEBUG_FTP_URL", "debug", "ftp_url", "ftp://example.com/test_pyftpsync"
19+
)
20+
1521

1622
def do_sync():
1723
from ftpsync.synchronizers import BiDirSynchronizer
1824
from ftpsync.targets import make_target
1925

2026
local_target = make_target("~/test_pyftpsync_dl")
2127
# local_target = make_target("c:/tmp/test_pyftpsync")
22-
remote_target = make_target("ftp://wwwendt.de/test_pyftpsync", {"ftp_debug": False})
28+
remote_target = make_target(PYFTPSYNC_REMOTE_URL, {"ftp_debug": False})
2329
opts = {"verbose": 6, "dry_run": False, "resolve": "local"}
2430
s = BiDirSynchronizer(local_target, remote_target, opts)
2531
s.run()
@@ -31,7 +37,7 @@ def do_scan():
3137
class args: # noqa: N801
3238
""""""
3339

34-
args.target = "ftp://wwwendt.de/test_pyftpsync"
40+
args.target = PYFTPSYNC_REMOTE_URL
3541
args.list = True
3642
args.verbose = 4
3743
args.recursive = False

0 commit comments

Comments
 (0)