delayed-rm 2.6.0__tar.gz → 2.8.0__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.
@@ -1,13 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: delayed_rm
3
- Version: 2.6.0
3
+ Version: 2.8.0
4
4
  Summary: Ever wish you had a few minutes to undo an rm? Now you do!
5
- Home-page: https://github.com/zwimer/delayed_rm
6
5
  License: GPL
7
6
  Project-URL: Homepage, https://github.com/zwimer/delayed_rm
8
7
  Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.8
10
- Requires-Python: >=3.8
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Requires-Python: >=3.10
11
10
  Description-Content-Type: text/markdown
12
11
  License-File: LICENSE
13
12
 
@@ -1,8 +1,7 @@
1
- from __future__ import annotations
1
+ from collections.abc import Callable
2
2
  from collections import defaultdict
3
3
  from tempfile import gettempdir
4
4
  from datetime import datetime
5
- from typing import Callable
6
5
  from pathlib import Path
7
6
  import subprocess
8
7
  import argparse
@@ -13,7 +12,7 @@ import sys
13
12
  import os
14
13
 
15
14
 
16
- __version__ = "2.6.0"
15
+ __version__ = "2.8.0"
17
16
 
18
17
 
19
18
  #
@@ -128,36 +127,43 @@ def delayed_rm(paths: list[Path], delay: int, rf: bool) -> bool:
128
127
  where: dict[str, set[Path]] = defaultdict(set)
129
128
  full_where: dict[Path, Path] = {}
130
129
  # Delete files
131
- for p in paths:
132
- # Select an output directory that an item of name p.name does not exist
133
- outd: Path
134
- if len(out_dirs) != len(where[p.name]):
135
- outd = next(iter(out_dirs - where[p.name]))
136
- else:
137
- outd = _mkdir(base / str(len(out_dirs)))
138
- out_dirs.add(outd)
139
- # Move file into the temp directory
140
- try:
141
- new: Path = outd / p.name
130
+ ctrlc = False
131
+ edited = False
132
+ try:
133
+ for p in paths:
134
+ # Select an output directory that an item of name p.name does not exist
135
+ outd: Path
136
+ if len(out_dirs) != len(where[p.name]):
137
+ outd = next(iter(out_dirs - where[p.name]))
138
+ else:
139
+ outd = _mkdir(base / str(len(out_dirs)))
140
+ out_dirs.add(outd)
141
+ # Move file into the temp directory
142
142
  try:
143
- p.rename(new)
144
- except OSError:
145
- copyf = lambda src, dst: shutil.copy2(src, dst, follow_symlinks=False)
146
- if p.is_dir():
147
- shutil.copytree(p, new, copy_function=copyf, symlinks=False)
148
- shutil.rmtree(p)
149
- else:
150
- copyf(p, new)
151
- p.unlink()
152
- full_where[p] = new
153
- where[p.name].add(outd)
154
- success.append(p)
155
- except OSError as e:
156
- failed.append(p)
157
- _eprint(e)
143
+ new: Path = outd / p.name
144
+ try:
145
+ p.rename(new)
146
+ except OSError:
147
+ copyf = lambda src, dst: shutil.copy2(src, dst, follow_symlinks=False)
148
+ if p.is_dir():
149
+ shutil.copytree(p, new, copy_function=copyf, symlinks=False)
150
+ edited = True
151
+ shutil.rmtree(p)
152
+ else:
153
+ copyf(p, new)
154
+ edited = True
155
+ p.unlink()
156
+ success.append(p)
157
+ full_where[p] = new
158
+ where[p.name].add(outd)
159
+ except OSError as e:
160
+ failed.append(p)
161
+ _eprint(e)
162
+ except KeyboardInterrupt:
163
+ ctrlc = True
158
164
  # Inform user of failures
159
165
  failed_plus: list[str] = [str(i) for i in failed]
160
- if len(failed) > 0:
166
+ if len(failed) > 0 and not ctrlc:
161
167
  _eprint("failed to rm:\n " + "\n ".join(failed_plus))
162
168
  # Log result
163
169
  success_plus: list[str] = [f"{i} ---> {full_where[i]}" for i in success]
@@ -167,7 +173,7 @@ def delayed_rm(paths: list[Path], delay: int, rf: bool) -> bool:
167
173
  + "\n "
168
174
  + "\n".join(
169
175
  (
170
- f"Delay: {delay}",
176
+ ("Interrupted by: SIGINT\n" if ctrlc else "") + f"Delay: {delay}",
171
177
  f"rf: {rf}",
172
178
  f"Storage Directory: {base}",
173
179
  f"Succeeded:{fmt(success_plus)}",
@@ -176,10 +182,14 @@ def delayed_rm(paths: list[Path], delay: int, rf: bool) -> bool:
176
182
  ).replace("\n", "\n ")
177
183
  + "\n\n"
178
184
  )
179
- with log_f.open("a") as f:
180
- f.write(msg)
185
+ try:
186
+ with log_f.open("a") as f:
187
+ f.write(msg)
188
+ except OSError:
189
+ print(msg)
190
+ raise
181
191
  # Delay rm and die
182
- if not success:
192
+ if not edited:
183
193
  shutil.rmtree(base)
184
194
  else:
185
195
  subprocess.Popen( # pylint: disable=consider-using-with
@@ -188,7 +198,7 @@ def delayed_rm(paths: list[Path], delay: int, rf: bool) -> bool:
188
198
  stdout=subprocess.DEVNULL,
189
199
  stderr=subprocess.DEVNULL,
190
200
  )
191
- return not failed
201
+ return not failed and not ctrlc
192
202
 
193
203
 
194
204
  def delayed_rm_raw(delay: int, log: bool, r: bool, f: bool, paths: list[Path]) -> bool:
@@ -1,13 +1,12 @@
1
1
  Metadata-Version: 2.1
2
- Name: delayed-rm
3
- Version: 2.6.0
2
+ Name: delayed_rm
3
+ Version: 2.8.0
4
4
  Summary: Ever wish you had a few minutes to undo an rm? Now you do!
5
- Home-page: https://github.com/zwimer/delayed_rm
6
5
  License: GPL
7
6
  Project-URL: Homepage, https://github.com/zwimer/delayed_rm
8
7
  Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.8
10
- Requires-Python: >=3.8
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Requires-Python: >=3.10
11
10
  Description-Content-Type: text/markdown
12
11
  License-File: LICENSE
13
12
 
@@ -1,7 +1,6 @@
1
1
  LICENSE
2
2
  README.md
3
3
  pyproject.toml
4
- setup.cfg
5
4
  delayed_rm/__init__.py
6
5
  delayed_rm/delayed_rm.py
7
6
  delayed_rm/py.typed
@@ -6,12 +6,12 @@ build-backend = "setuptools.build_meta"
6
6
  name = "delayed_rm"
7
7
  classifiers = [
8
8
  "Programming Language :: Python :: 3",
9
- "Programming Language :: Python :: 3.8",
9
+ "Programming Language :: Python :: 3.10",
10
10
  ]
11
11
  license = {text = "GPL"}
12
12
  description = "Ever wish you had a few minutes to undo an rm? Now you do!"
13
13
  urls = {Homepage = "https://github.com/zwimer/delayed_rm"}
14
- requires-python = ">= 3.8"
14
+ requires-python = ">= 3.10"
15
15
  dynamic = ["version"]
16
16
 
17
17
  [project.readme]
@@ -38,7 +38,7 @@ version = {attr = "delayed_rm.__version__"}
38
38
 
39
39
  [tool.black]
40
40
  line-length = 120
41
- target-version = ["py38"]
41
+ target-version = ["py310"]
42
42
 
43
43
  [tool.ruff]
44
44
  ignore=["E731","E741"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -1,28 +0,0 @@
1
- [metadata]
2
- name = delayed_rm
3
- version = attr: delayed_rm.__version__
4
- url = https://github.com/zwimer/delayed_rm
5
- classifiers =
6
- Programming Language :: Python :: 3
7
- Programming Language :: Python :: 3.8
8
- license = GPL
9
- license_files = LICENSE
10
- description = Ever wish you had a few minutes to undo an rm? Now you do!
11
- long_description = file: README.md
12
- long_description_content_type = text/markdown
13
-
14
- [options]
15
- python_requires = >= 3.8
16
- packages = find:
17
-
18
- [options.package_data]
19
- delayed_rm = py.typed
20
-
21
- [options.entry_points]
22
- console_scripts =
23
- delayed_rm = delayed_rm:cli
24
-
25
- [egg_info]
26
- tag_build =
27
- tag_date = 0
28
-
File without changes
File without changes