edir 2.24__tar.gz → 2.25__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.
- {edir-2.24/edir.egg-info → edir-2.25}/PKG-INFO +20 -18
- {edir-2.24 → edir-2.25}/README.md +19 -17
- {edir-2.24 → edir-2.25/edir.egg-info}/PKG-INFO +20 -18
- {edir-2.24 → edir-2.25}/edir.py +78 -54
- {edir-2.24 → edir-2.25}/.flake8 +0 -0
- {edir-2.24 → edir-2.25}/.gitignore +0 -0
- {edir-2.24 → edir-2.25}/Makefile +0 -0
- {edir-2.24 → edir-2.25}/edir.egg-info/SOURCES.txt +0 -0
- {edir-2.24 → edir-2.25}/edir.egg-info/dependency_links.txt +0 -0
- {edir-2.24 → edir-2.25}/edir.egg-info/entry_points.txt +0 -0
- {edir-2.24 → edir-2.25}/edir.egg-info/requires.txt +0 -0
- {edir-2.24 → edir-2.25}/edir.egg-info/top_level.txt +0 -0
- {edir-2.24 → edir-2.25}/pyproject.toml +0 -0
- {edir-2.24 → edir-2.25}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: edir
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.25
|
|
4
4
|
Summary: Utility to rename, remove, and copy files/dirs using your editor
|
|
5
5
|
Author-email: Mark Blakeney <mark.blakeney@bullet-systems.net>
|
|
6
6
|
License: GPLv3
|
|
@@ -57,9 +57,9 @@ the following ways:
|
|
|
57
57
|
3 ./c
|
|
58
58
|
4 ./d
|
|
59
59
|
```
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
But `edir` presents these as:
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
```
|
|
64
64
|
1 ./a
|
|
65
65
|
2 ./b
|
|
@@ -213,14 +213,14 @@ the following ways:
|
|
|
213
213
|
1. Deleted files are removed and all renamed files and directories
|
|
214
214
|
are renamed to temporaries. The temporaries are made on the same
|
|
215
215
|
file-system as the target.
|
|
216
|
-
|
|
216
|
+
|
|
217
217
|
2. Empty deleted directories are removed.
|
|
218
|
-
|
|
218
|
+
|
|
219
219
|
3. Renamed temporary files and directories are renamed to their
|
|
220
220
|
target name. Any required copies are created.
|
|
221
|
-
|
|
221
|
+
|
|
222
222
|
4. Remaining deleted directories are removed.
|
|
223
|
-
|
|
223
|
+
|
|
224
224
|
In simple terms, remember that files are processed before
|
|
225
225
|
directories so you can rename files into a different directory and
|
|
226
226
|
then delete the original directory, all in one edit. However in
|
|
@@ -277,16 +277,16 @@ option](#command-default-options) so you are always prompted.
|
|
|
277
277
|
After a preview of pending changes is shown a prompt is presented for
|
|
278
278
|
the user to enter a single key:
|
|
279
279
|
|
|
280
|
-
`(P)roceed, (E)dit, (R)estart, (Q)uit: [p/e/r/q]?`
|
|
280
|
+
`(P)roceed, (E)dit, (R)estart, (Q)uit[default]: [p/e/r/q]?`
|
|
281
281
|
|
|
282
282
|
where:
|
|
283
283
|
|
|
284
|
-
|Option |Key|Action
|
|
285
|
-
|--- |---|---
|
|
286
|
-
|`Proceed`|`p`|Proceed with the path changes.
|
|
287
|
-
|`Edit` |`e`|Edit the path list again, as it is was last edited.
|
|
288
|
-
|`Restart`|`r`|Restart editing the path list again, as it originally began
|
|
289
|
-
|`Quit` |`q`|Quit immediately without making any changes.
|
|
284
|
+
|Option |Key|Action |
|
|
285
|
+
|--- |---|--- |
|
|
286
|
+
|`Proceed`|`p`|Proceed with the path changes. |
|
|
287
|
+
|`Edit` |`e`|Edit the path list again, as it is was last edited. |
|
|
288
|
+
|`Restart`|`r`|Restart editing the path list again, as it originally began. |
|
|
289
|
+
|`Quit` |`q`|Quit immediately without making any changes. This is the default if no key is entered.|
|
|
290
290
|
|
|
291
291
|
## Installation or Upgrade
|
|
292
292
|
|
|
@@ -331,7 +331,7 @@ are ignored. Type `edir -h` to see all [supported
|
|
|
331
331
|
options](#command-line-options).
|
|
332
332
|
|
|
333
333
|
The options `--interactive`, `--all`, `--recurse`, `--quiet`,
|
|
334
|
-
`--no-git`, `--trash`, `--suffix`, `--no-color`,
|
|
334
|
+
`--no-git`, `--trash`, `--suffix`, `--no-color`, `--no-invert-color`,
|
|
335
335
|
`--group-dirs-first/last`, `--trash-program` are sensible candidates to
|
|
336
336
|
consider setting as default. If you set these then "on-the-fly" negation
|
|
337
337
|
options `-I`, `-A`, `-R`, `-Q`, `-g`, `-T`, `-Z` are also provided to
|
|
@@ -370,8 +370,8 @@ Type `edir -h` to view the usage summary:
|
|
|
370
370
|
|
|
371
371
|
```
|
|
372
372
|
usage: edir [-h] [-i] [-I] [-a] [-A] [-r] [-R] [-q] [-Q] [-G] [-g] [-t]
|
|
373
|
-
[-T] [--trash-program TRASH_PROGRAM] [-c] [-d] [-F | -D]
|
|
374
|
-
[-N] [-M] [-S] [-E] [-X] [-Y] [-Z] [--suffix SUFFIX] [-V]
|
|
373
|
+
[-T] [--trash-program TRASH_PROGRAM] [-c] [-C] [-d] [-F | -D]
|
|
374
|
+
[-L] [-N] [-M] [-S] [-E] [-X] [-Y] [-Z] [--suffix SUFFIX] [-V]
|
|
375
375
|
[args ...]
|
|
376
376
|
|
|
377
377
|
Program to rename, remove, or copy files and directories using your editor.
|
|
@@ -399,6 +399,8 @@ options:
|
|
|
399
399
|
--trash-program TRASH_PROGRAM
|
|
400
400
|
trash program to use, default="trash-put"
|
|
401
401
|
-c, --no-color do not color rename/remove/copy messages
|
|
402
|
+
-C, --no-invert-color
|
|
403
|
+
do not invert the color to highlight error messages
|
|
402
404
|
-d, --dirnames edit given directory names directly, not their
|
|
403
405
|
contents
|
|
404
406
|
-F, --files only show/edit files
|
|
@@ -413,7 +415,7 @@ options:
|
|
|
413
415
|
-Y, --group-dirs-last
|
|
414
416
|
group directories last (including when sorted)
|
|
415
417
|
-Z, --no-group-dirs negate the options to group directories
|
|
416
|
-
--suffix SUFFIX specify suffix for editor file, default=".sh"
|
|
418
|
+
--suffix SUFFIX specify suffix for temp editor file, default=".sh"
|
|
417
419
|
-V, --version show edir version
|
|
418
420
|
|
|
419
421
|
Note you can set default starting options in $HOME/.config/edir-
|
|
@@ -43,9 +43,9 @@ the following ways:
|
|
|
43
43
|
3 ./c
|
|
44
44
|
4 ./d
|
|
45
45
|
```
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
But `edir` presents these as:
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
```
|
|
50
50
|
1 ./a
|
|
51
51
|
2 ./b
|
|
@@ -199,14 +199,14 @@ the following ways:
|
|
|
199
199
|
1. Deleted files are removed and all renamed files and directories
|
|
200
200
|
are renamed to temporaries. The temporaries are made on the same
|
|
201
201
|
file-system as the target.
|
|
202
|
-
|
|
202
|
+
|
|
203
203
|
2. Empty deleted directories are removed.
|
|
204
|
-
|
|
204
|
+
|
|
205
205
|
3. Renamed temporary files and directories are renamed to their
|
|
206
206
|
target name. Any required copies are created.
|
|
207
|
-
|
|
207
|
+
|
|
208
208
|
4. Remaining deleted directories are removed.
|
|
209
|
-
|
|
209
|
+
|
|
210
210
|
In simple terms, remember that files are processed before
|
|
211
211
|
directories so you can rename files into a different directory and
|
|
212
212
|
then delete the original directory, all in one edit. However in
|
|
@@ -263,16 +263,16 @@ option](#command-default-options) so you are always prompted.
|
|
|
263
263
|
After a preview of pending changes is shown a prompt is presented for
|
|
264
264
|
the user to enter a single key:
|
|
265
265
|
|
|
266
|
-
`(P)roceed, (E)dit, (R)estart, (Q)uit: [p/e/r/q]?`
|
|
266
|
+
`(P)roceed, (E)dit, (R)estart, (Q)uit[default]: [p/e/r/q]?`
|
|
267
267
|
|
|
268
268
|
where:
|
|
269
269
|
|
|
270
|
-
|Option |Key|Action
|
|
271
|
-
|--- |---|---
|
|
272
|
-
|`Proceed`|`p`|Proceed with the path changes.
|
|
273
|
-
|`Edit` |`e`|Edit the path list again, as it is was last edited.
|
|
274
|
-
|`Restart`|`r`|Restart editing the path list again, as it originally began
|
|
275
|
-
|`Quit` |`q`|Quit immediately without making any changes.
|
|
270
|
+
|Option |Key|Action |
|
|
271
|
+
|--- |---|--- |
|
|
272
|
+
|`Proceed`|`p`|Proceed with the path changes. |
|
|
273
|
+
|`Edit` |`e`|Edit the path list again, as it is was last edited. |
|
|
274
|
+
|`Restart`|`r`|Restart editing the path list again, as it originally began. |
|
|
275
|
+
|`Quit` |`q`|Quit immediately without making any changes. This is the default if no key is entered.|
|
|
276
276
|
|
|
277
277
|
## Installation or Upgrade
|
|
278
278
|
|
|
@@ -317,7 +317,7 @@ are ignored. Type `edir -h` to see all [supported
|
|
|
317
317
|
options](#command-line-options).
|
|
318
318
|
|
|
319
319
|
The options `--interactive`, `--all`, `--recurse`, `--quiet`,
|
|
320
|
-
`--no-git`, `--trash`, `--suffix`, `--no-color`,
|
|
320
|
+
`--no-git`, `--trash`, `--suffix`, `--no-color`, `--no-invert-color`,
|
|
321
321
|
`--group-dirs-first/last`, `--trash-program` are sensible candidates to
|
|
322
322
|
consider setting as default. If you set these then "on-the-fly" negation
|
|
323
323
|
options `-I`, `-A`, `-R`, `-Q`, `-g`, `-T`, `-Z` are also provided to
|
|
@@ -356,8 +356,8 @@ Type `edir -h` to view the usage summary:
|
|
|
356
356
|
|
|
357
357
|
```
|
|
358
358
|
usage: edir [-h] [-i] [-I] [-a] [-A] [-r] [-R] [-q] [-Q] [-G] [-g] [-t]
|
|
359
|
-
[-T] [--trash-program TRASH_PROGRAM] [-c] [-d] [-F | -D]
|
|
360
|
-
[-N] [-M] [-S] [-E] [-X] [-Y] [-Z] [--suffix SUFFIX] [-V]
|
|
359
|
+
[-T] [--trash-program TRASH_PROGRAM] [-c] [-C] [-d] [-F | -D]
|
|
360
|
+
[-L] [-N] [-M] [-S] [-E] [-X] [-Y] [-Z] [--suffix SUFFIX] [-V]
|
|
361
361
|
[args ...]
|
|
362
362
|
|
|
363
363
|
Program to rename, remove, or copy files and directories using your editor.
|
|
@@ -385,6 +385,8 @@ options:
|
|
|
385
385
|
--trash-program TRASH_PROGRAM
|
|
386
386
|
trash program to use, default="trash-put"
|
|
387
387
|
-c, --no-color do not color rename/remove/copy messages
|
|
388
|
+
-C, --no-invert-color
|
|
389
|
+
do not invert the color to highlight error messages
|
|
388
390
|
-d, --dirnames edit given directory names directly, not their
|
|
389
391
|
contents
|
|
390
392
|
-F, --files only show/edit files
|
|
@@ -399,7 +401,7 @@ options:
|
|
|
399
401
|
-Y, --group-dirs-last
|
|
400
402
|
group directories last (including when sorted)
|
|
401
403
|
-Z, --no-group-dirs negate the options to group directories
|
|
402
|
-
--suffix SUFFIX specify suffix for editor file, default=".sh"
|
|
404
|
+
--suffix SUFFIX specify suffix for temp editor file, default=".sh"
|
|
403
405
|
-V, --version show edir version
|
|
404
406
|
|
|
405
407
|
Note you can set default starting options in $HOME/.config/edir-
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: edir
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.25
|
|
4
4
|
Summary: Utility to rename, remove, and copy files/dirs using your editor
|
|
5
5
|
Author-email: Mark Blakeney <mark.blakeney@bullet-systems.net>
|
|
6
6
|
License: GPLv3
|
|
@@ -57,9 +57,9 @@ the following ways:
|
|
|
57
57
|
3 ./c
|
|
58
58
|
4 ./d
|
|
59
59
|
```
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
But `edir` presents these as:
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
```
|
|
64
64
|
1 ./a
|
|
65
65
|
2 ./b
|
|
@@ -213,14 +213,14 @@ the following ways:
|
|
|
213
213
|
1. Deleted files are removed and all renamed files and directories
|
|
214
214
|
are renamed to temporaries. The temporaries are made on the same
|
|
215
215
|
file-system as the target.
|
|
216
|
-
|
|
216
|
+
|
|
217
217
|
2. Empty deleted directories are removed.
|
|
218
|
-
|
|
218
|
+
|
|
219
219
|
3. Renamed temporary files and directories are renamed to their
|
|
220
220
|
target name. Any required copies are created.
|
|
221
|
-
|
|
221
|
+
|
|
222
222
|
4. Remaining deleted directories are removed.
|
|
223
|
-
|
|
223
|
+
|
|
224
224
|
In simple terms, remember that files are processed before
|
|
225
225
|
directories so you can rename files into a different directory and
|
|
226
226
|
then delete the original directory, all in one edit. However in
|
|
@@ -277,16 +277,16 @@ option](#command-default-options) so you are always prompted.
|
|
|
277
277
|
After a preview of pending changes is shown a prompt is presented for
|
|
278
278
|
the user to enter a single key:
|
|
279
279
|
|
|
280
|
-
`(P)roceed, (E)dit, (R)estart, (Q)uit: [p/e/r/q]?`
|
|
280
|
+
`(P)roceed, (E)dit, (R)estart, (Q)uit[default]: [p/e/r/q]?`
|
|
281
281
|
|
|
282
282
|
where:
|
|
283
283
|
|
|
284
|
-
|Option |Key|Action
|
|
285
|
-
|--- |---|---
|
|
286
|
-
|`Proceed`|`p`|Proceed with the path changes.
|
|
287
|
-
|`Edit` |`e`|Edit the path list again, as it is was last edited.
|
|
288
|
-
|`Restart`|`r`|Restart editing the path list again, as it originally began
|
|
289
|
-
|`Quit` |`q`|Quit immediately without making any changes.
|
|
284
|
+
|Option |Key|Action |
|
|
285
|
+
|--- |---|--- |
|
|
286
|
+
|`Proceed`|`p`|Proceed with the path changes. |
|
|
287
|
+
|`Edit` |`e`|Edit the path list again, as it is was last edited. |
|
|
288
|
+
|`Restart`|`r`|Restart editing the path list again, as it originally began. |
|
|
289
|
+
|`Quit` |`q`|Quit immediately without making any changes. This is the default if no key is entered.|
|
|
290
290
|
|
|
291
291
|
## Installation or Upgrade
|
|
292
292
|
|
|
@@ -331,7 +331,7 @@ are ignored. Type `edir -h` to see all [supported
|
|
|
331
331
|
options](#command-line-options).
|
|
332
332
|
|
|
333
333
|
The options `--interactive`, `--all`, `--recurse`, `--quiet`,
|
|
334
|
-
`--no-git`, `--trash`, `--suffix`, `--no-color`,
|
|
334
|
+
`--no-git`, `--trash`, `--suffix`, `--no-color`, `--no-invert-color`,
|
|
335
335
|
`--group-dirs-first/last`, `--trash-program` are sensible candidates to
|
|
336
336
|
consider setting as default. If you set these then "on-the-fly" negation
|
|
337
337
|
options `-I`, `-A`, `-R`, `-Q`, `-g`, `-T`, `-Z` are also provided to
|
|
@@ -370,8 +370,8 @@ Type `edir -h` to view the usage summary:
|
|
|
370
370
|
|
|
371
371
|
```
|
|
372
372
|
usage: edir [-h] [-i] [-I] [-a] [-A] [-r] [-R] [-q] [-Q] [-G] [-g] [-t]
|
|
373
|
-
[-T] [--trash-program TRASH_PROGRAM] [-c] [-d] [-F | -D]
|
|
374
|
-
[-N] [-M] [-S] [-E] [-X] [-Y] [-Z] [--suffix SUFFIX] [-V]
|
|
373
|
+
[-T] [--trash-program TRASH_PROGRAM] [-c] [-C] [-d] [-F | -D]
|
|
374
|
+
[-L] [-N] [-M] [-S] [-E] [-X] [-Y] [-Z] [--suffix SUFFIX] [-V]
|
|
375
375
|
[args ...]
|
|
376
376
|
|
|
377
377
|
Program to rename, remove, or copy files and directories using your editor.
|
|
@@ -399,6 +399,8 @@ options:
|
|
|
399
399
|
--trash-program TRASH_PROGRAM
|
|
400
400
|
trash program to use, default="trash-put"
|
|
401
401
|
-c, --no-color do not color rename/remove/copy messages
|
|
402
|
+
-C, --no-invert-color
|
|
403
|
+
do not invert the color to highlight error messages
|
|
402
404
|
-d, --dirnames edit given directory names directly, not their
|
|
403
405
|
contents
|
|
404
406
|
-F, --files only show/edit files
|
|
@@ -413,7 +415,7 @@ options:
|
|
|
413
415
|
-Y, --group-dirs-last
|
|
414
416
|
group directories last (including when sorted)
|
|
415
417
|
-Z, --no-group-dirs negate the options to group directories
|
|
416
|
-
--suffix SUFFIX specify suffix for editor file, default=".sh"
|
|
418
|
+
--suffix SUFFIX specify suffix for temp editor file, default=".sh"
|
|
417
419
|
-V, --version show edir version
|
|
418
420
|
|
|
419
421
|
Note you can set default starting options in $HOME/.config/edir-
|
{edir-2.24 → edir-2.25}/edir.py
RENAMED
|
@@ -30,18 +30,19 @@ SUFFIX = '.sh'
|
|
|
30
30
|
# The temp dir we will use in the dir of each target move
|
|
31
31
|
TEMPDIR = '.tmp-' + PROG
|
|
32
32
|
|
|
33
|
-
# Define ANSI escape sequences for colors
|
|
34
|
-
|
|
35
|
-
COLOR_green = '\033[32m'
|
|
36
|
-
COLOR_yellow = '\033[33m'
|
|
37
|
-
COLOR_reset = '\033[39m'
|
|
38
|
-
|
|
33
|
+
# Define action verbs and ANSI escape sequences for action colors
|
|
34
|
+
# Refer https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
|
39
35
|
ACTIONS = {
|
|
40
|
-
'remove': (
|
|
41
|
-
|
|
42
|
-
'copy': (
|
|
36
|
+
'remove': (('\033[31m', '\033[30;41m'), # Red
|
|
37
|
+
('Removing', 'Remove', 'Removed')),
|
|
38
|
+
'copy': (('\033[32m', '\033[30;42m'), # Green
|
|
39
|
+
('Copying', 'Copy', 'Copied')),
|
|
40
|
+
'rename': (('\033[33m', '\033[30;43m'), # Yellow
|
|
41
|
+
('Renaming', 'Rename', 'Renamed')),
|
|
43
42
|
}
|
|
44
43
|
|
|
44
|
+
COLOR_reset = '\033[39;49m'
|
|
45
|
+
|
|
45
46
|
args = argparse.Namespace()
|
|
46
47
|
gitfiles = set()
|
|
47
48
|
counts = [0, 0]
|
|
@@ -53,12 +54,26 @@ def get_default_editor() -> str:
|
|
|
53
54
|
from platform import system
|
|
54
55
|
return EDITORS.get(system(), EDITORS['default'])
|
|
55
56
|
|
|
57
|
+
def editfile(filename: Path) -> None:
|
|
58
|
+
'Run the editor command'
|
|
59
|
+
# Use explicit user defined editor or choose system default
|
|
60
|
+
editor = os.getenv(EDITOR) or os.getenv('EDITOR') or get_default_editor()
|
|
61
|
+
editcmd = shlex.split(editor) + [str(filename)]
|
|
62
|
+
|
|
63
|
+
# Run the editor ..
|
|
64
|
+
with open('/dev/tty') as tty:
|
|
65
|
+
res = subprocess.run(editcmd, stdin=tty)
|
|
66
|
+
|
|
67
|
+
# Check if editor returned error
|
|
68
|
+
if res.returncode != 0:
|
|
69
|
+
sys.exit(f'ERROR: {editor} returned error {res.returncode}')
|
|
70
|
+
|
|
56
71
|
def log(action: str, msg: str, error: Optional[str] = None, *,
|
|
57
72
|
prompt: bool = False) -> None:
|
|
58
73
|
'Output message with appropriate color'
|
|
59
74
|
counts[bool(error)] += 1
|
|
60
75
|
|
|
61
|
-
|
|
76
|
+
colors, tense = ACTIONS[action]
|
|
62
77
|
|
|
63
78
|
if error:
|
|
64
79
|
out = sys.stderr
|
|
@@ -69,10 +84,11 @@ def log(action: str, msg: str, error: Optional[str] = None, *,
|
|
|
69
84
|
out = sys.stdout
|
|
70
85
|
msg = f'{tense[0] if prompt else tense[2]} {msg}'
|
|
71
86
|
|
|
72
|
-
if args.no_color:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
87
|
+
if not args.no_color:
|
|
88
|
+
msg = colors[bool(error and not args.no_invert_color)] \
|
|
89
|
+
+ msg + COLOR_reset
|
|
90
|
+
|
|
91
|
+
print(msg, file=out)
|
|
76
92
|
|
|
77
93
|
def run(cmd: str) -> Tuple[str, str]:
|
|
78
94
|
'Run given command and return (stdout, stderr) strings'
|
|
@@ -121,14 +137,23 @@ def remove(path: Path, git: bool = False, trash: bool = False,
|
|
|
121
137
|
except Exception as e:
|
|
122
138
|
return str(e)
|
|
123
139
|
|
|
124
|
-
def rename(pathsrc: Path, pathdest: Path, is_git: bool = False) ->
|
|
140
|
+
def rename(pathsrc: Path, pathdest: Path, is_git: bool = False) -> str:
|
|
125
141
|
'Rename given pathsrc to pathdest'
|
|
126
142
|
if is_git:
|
|
127
143
|
out, err = run(f'git mv -f "{pathsrc}" "{pathdest}"')
|
|
128
144
|
if err:
|
|
129
|
-
|
|
145
|
+
err = f'git mv error: {err}'
|
|
130
146
|
else:
|
|
131
|
-
|
|
147
|
+
try:
|
|
148
|
+
shutil.move(str(pathsrc), str(pathdest))
|
|
149
|
+
except Exception as e:
|
|
150
|
+
# Remove any trailing colon and specific file since we may
|
|
151
|
+
# be renaming a temp file.
|
|
152
|
+
err = str(e).split(':')[0]
|
|
153
|
+
else:
|
|
154
|
+
err = ''
|
|
155
|
+
|
|
156
|
+
return err
|
|
132
157
|
|
|
133
158
|
def create_prompt(options: str) -> str:
|
|
134
159
|
'Create a string of options + keys for user to choose from'
|
|
@@ -151,7 +176,11 @@ class Fpath:
|
|
|
151
176
|
self.temppath = None
|
|
152
177
|
self.note = ''
|
|
153
178
|
self.copies: List[Path] = []
|
|
154
|
-
|
|
179
|
+
try:
|
|
180
|
+
self.is_dir = path.is_dir()
|
|
181
|
+
except Exception as e:
|
|
182
|
+
sys.exit(f'ERROR: Can not read {path}: {e}')
|
|
183
|
+
|
|
155
184
|
self.appdash = '/' if self.is_dir else ''
|
|
156
185
|
self.diagrepr = str(self.path)
|
|
157
186
|
self.is_git = self.diagrepr in gitfiles
|
|
@@ -163,16 +192,18 @@ class Fpath:
|
|
|
163
192
|
self.diagrepr += '/'
|
|
164
193
|
|
|
165
194
|
@staticmethod
|
|
166
|
-
def inc_path(path: Path) ->
|
|
195
|
+
def inc_path(path: Path) -> Path:
|
|
167
196
|
'Find next unique file name'
|
|
168
197
|
# Iterate forever, there can only be a finite number of existing
|
|
169
198
|
# paths
|
|
170
199
|
name = path.name
|
|
171
200
|
for c in itertools.count():
|
|
172
201
|
if not path.is_symlink() and not path.exists():
|
|
173
|
-
|
|
202
|
+
break
|
|
174
203
|
path = path.with_name(name + ('~' if c <= 0 else f'~{c}'))
|
|
175
204
|
|
|
205
|
+
return path
|
|
206
|
+
|
|
176
207
|
def copy(self, pathdest: Path) -> Optional[str]:
|
|
177
208
|
'Copy given pathsrc to pathdest'
|
|
178
209
|
func = shutil.copytree if self.is_dir else shutil.copy2
|
|
@@ -181,31 +212,32 @@ class Fpath:
|
|
|
181
212
|
except Exception as e:
|
|
182
213
|
return str(e)
|
|
183
214
|
|
|
184
|
-
def rename_temp(self) ->
|
|
215
|
+
def rename_temp(self) -> Optional[str]:
|
|
185
216
|
'Move this path to a temp place in advance of final move'
|
|
186
217
|
if not self.newpath:
|
|
187
|
-
return
|
|
218
|
+
return None
|
|
188
219
|
tempdir = self.newpath.parent / TEMPDIR
|
|
189
220
|
try:
|
|
190
221
|
tempdir.mkdir(parents=True, exist_ok=True)
|
|
191
|
-
except Exception:
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
self.temppath = self.inc_path(tempdir / self.newpath.name)
|
|
196
|
-
if self.temppath:
|
|
197
|
-
self.tempdirs.add(tempdir)
|
|
198
|
-
rename(self.path, self.temppath, self.is_git)
|
|
222
|
+
except Exception as e:
|
|
223
|
+
# Remove any trailing colon and specific file since we are
|
|
224
|
+
# renaming a temp file.
|
|
225
|
+
return str(e).split(':')[0]
|
|
199
226
|
|
|
200
|
-
|
|
227
|
+
self.tempdirs.add(tempdir)
|
|
228
|
+
temppath = self.inc_path(tempdir / self.newpath.name)
|
|
229
|
+
err = rename(self.path, temppath, self.is_git)
|
|
230
|
+
if not err:
|
|
231
|
+
self.temppath = temppath
|
|
232
|
+
|
|
233
|
+
return err
|
|
234
|
+
|
|
235
|
+
def restore_temp(self) -> Optional[str]:
|
|
201
236
|
'Restore temp path to final destination'
|
|
202
237
|
if not self.temppath or not self.newpath:
|
|
203
|
-
return
|
|
238
|
+
return None
|
|
204
239
|
self.newpath = self.inc_path(self.newpath)
|
|
205
|
-
|
|
206
|
-
rename(self.temppath, self.newpath, self.is_git)
|
|
207
|
-
return True
|
|
208
|
-
return False
|
|
240
|
+
return rename(self.temppath, self.newpath, self.is_git)
|
|
209
241
|
|
|
210
242
|
def sort_name(self) -> str:
|
|
211
243
|
'Return name for sort'
|
|
@@ -326,7 +358,7 @@ class Fpath:
|
|
|
326
358
|
newpath = Path(pathstr)
|
|
327
359
|
|
|
328
360
|
if path.newpath:
|
|
329
|
-
if newpath != path.path:
|
|
361
|
+
if newpath != path.path and newpath not in path.copies:
|
|
330
362
|
path.copies.append(newpath)
|
|
331
363
|
else:
|
|
332
364
|
path.newpath = newpath
|
|
@@ -387,20 +419,6 @@ class Fpath:
|
|
|
387
419
|
else:
|
|
388
420
|
print('Invalid answer.')
|
|
389
421
|
|
|
390
|
-
def editfile(filename: Path) -> None:
|
|
391
|
-
'Run the editor command'
|
|
392
|
-
# Use explicit user defined editor or choose system default
|
|
393
|
-
editor = os.getenv(EDITOR) or os.getenv('EDITOR') or get_default_editor()
|
|
394
|
-
editcmd = shlex.split(editor) + [str(filename)]
|
|
395
|
-
|
|
396
|
-
# Run the editor ..
|
|
397
|
-
with open('/dev/tty') as tty:
|
|
398
|
-
res = subprocess.run(editcmd, stdin=tty)
|
|
399
|
-
|
|
400
|
-
# Check if editor returned error
|
|
401
|
-
if res.returncode != 0:
|
|
402
|
-
sys.exit(f'ERROR: {editor} returned error {res.returncode}')
|
|
403
|
-
|
|
404
422
|
def main() -> int:
|
|
405
423
|
'Main code'
|
|
406
424
|
global args
|
|
@@ -444,6 +462,8 @@ def main() -> int:
|
|
|
444
462
|
help='trash program to use, default="%(default)s"')
|
|
445
463
|
opt.add_argument('-c', '--no-color', action='store_true',
|
|
446
464
|
help='do not color rename/remove/copy messages')
|
|
465
|
+
opt.add_argument('-C', '--no-invert-color', action='store_true',
|
|
466
|
+
help='do not invert the color to highlight error messages')
|
|
447
467
|
opt.add_argument('-d', '--dirnames', action='store_true',
|
|
448
468
|
help='edit given directory names directly, not their contents')
|
|
449
469
|
grp = opt.add_mutually_exclusive_group()
|
|
@@ -566,7 +586,10 @@ def main() -> int:
|
|
|
566
586
|
for p in paths:
|
|
567
587
|
if p.newpath:
|
|
568
588
|
if p.newpath != p.path:
|
|
569
|
-
p.rename_temp()
|
|
589
|
+
err = p.rename_temp()
|
|
590
|
+
if err:
|
|
591
|
+
log('rename',
|
|
592
|
+
f'"{p.diagrepr}" to "{p.newpath}{p.appdash}"', err)
|
|
570
593
|
elif not p.is_dir:
|
|
571
594
|
err = remove(p.path, p.is_git, args.trash)
|
|
572
595
|
log('remove', f'"{p.diagrepr}"', err)
|
|
@@ -582,8 +605,9 @@ def main() -> int:
|
|
|
582
605
|
# Pass 3. Rename all temp files and dirs to final target, and make
|
|
583
606
|
# copies.
|
|
584
607
|
for p in paths:
|
|
585
|
-
|
|
586
|
-
|
|
608
|
+
err = p.restore_temp()
|
|
609
|
+
if err is not None:
|
|
610
|
+
log('rename', f'"{p.diagrepr}" to "{p.newpath}{p.appdash}"', err)
|
|
587
611
|
|
|
588
612
|
for c in p.copies:
|
|
589
613
|
err = p.copy(c)
|
{edir-2.24 → edir-2.25}/.flake8
RENAMED
|
File without changes
|
|
File without changes
|
{edir-2.24 → edir-2.25}/Makefile
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|