delayed-rm 2.6.0__tar.gz → 2.7.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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: delayed_rm
3
- Version: 2.6.0
3
+ Version: 2.7.0
4
4
  Summary: Ever wish you had a few minutes to undo an rm? Now you do!
5
5
  Home-page: https://github.com/zwimer/delayed_rm
6
6
  License: GPL
@@ -13,7 +13,7 @@ import sys
13
13
  import os
14
14
 
15
15
 
16
- __version__ = "2.6.0"
16
+ __version__ = "2.7.0"
17
17
 
18
18
 
19
19
  #
@@ -128,36 +128,43 @@ def delayed_rm(paths: list[Path], delay: int, rf: bool) -> bool:
128
128
  where: dict[str, set[Path]] = defaultdict(set)
129
129
  full_where: dict[Path, Path] = {}
130
130
  # 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
131
+ ctrlc = False
132
+ edited = False
133
+ try:
134
+ for p in paths:
135
+ # Select an output directory that an item of name p.name does not exist
136
+ outd: Path
137
+ if len(out_dirs) != len(where[p.name]):
138
+ outd = next(iter(out_dirs - where[p.name]))
139
+ else:
140
+ outd = _mkdir(base / str(len(out_dirs)))
141
+ out_dirs.add(outd)
142
+ # Move file into the temp directory
142
143
  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)
144
+ new: Path = outd / p.name
145
+ try:
146
+ p.rename(new)
147
+ except OSError:
148
+ copyf = lambda src, dst: shutil.copy2(src, dst, follow_symlinks=False)
149
+ if p.is_dir():
150
+ shutil.copytree(p, new, copy_function=copyf, symlinks=False)
151
+ edited = True
152
+ shutil.rmtree(p)
153
+ else:
154
+ copyf(p, new)
155
+ edited = True
156
+ p.unlink()
157
+ success.append(p)
158
+ full_where[p] = new
159
+ where[p.name].add(outd)
160
+ except OSError as e:
161
+ failed.append(p)
162
+ _eprint(e)
163
+ except KeyboardInterrupt:
164
+ ctrlc = True
158
165
  # Inform user of failures
159
166
  failed_plus: list[str] = [str(i) for i in failed]
160
- if len(failed) > 0:
167
+ if len(failed) > 0 and not ctrlc:
161
168
  _eprint("failed to rm:\n " + "\n ".join(failed_plus))
162
169
  # Log result
163
170
  success_plus: list[str] = [f"{i} ---> {full_where[i]}" for i in success]
@@ -167,7 +174,7 @@ def delayed_rm(paths: list[Path], delay: int, rf: bool) -> bool:
167
174
  + "\n "
168
175
  + "\n".join(
169
176
  (
170
- f"Delay: {delay}",
177
+ ("Interrupted by: SIGINT\n" if ctrlc else "") + f"Delay: {delay}",
171
178
  f"rf: {rf}",
172
179
  f"Storage Directory: {base}",
173
180
  f"Succeeded:{fmt(success_plus)}",
@@ -176,10 +183,14 @@ def delayed_rm(paths: list[Path], delay: int, rf: bool) -> bool:
176
183
  ).replace("\n", "\n ")
177
184
  + "\n\n"
178
185
  )
179
- with log_f.open("a") as f:
180
- f.write(msg)
186
+ try:
187
+ with log_f.open("a") as f:
188
+ f.write(msg)
189
+ except OSError:
190
+ print(msg)
191
+ raise
181
192
  # Delay rm and die
182
- if not success:
193
+ if not edited:
183
194
  shutil.rmtree(base)
184
195
  else:
185
196
  subprocess.Popen( # pylint: disable=consider-using-with
@@ -188,7 +199,7 @@ def delayed_rm(paths: list[Path], delay: int, rf: bool) -> bool:
188
199
  stdout=subprocess.DEVNULL,
189
200
  stderr=subprocess.DEVNULL,
190
201
  )
191
- return not failed
202
+ return not failed and not ctrlc
192
203
 
193
204
 
194
205
  def delayed_rm_raw(delay: int, log: bool, r: bool, f: bool, paths: list[Path]) -> bool:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
- Name: delayed-rm
3
- Version: 2.6.0
2
+ Name: delayed_rm
3
+ Version: 2.7.0
4
4
  Summary: Ever wish you had a few minutes to undo an rm? Now you do!
5
5
  Home-page: https://github.com/zwimer/delayed_rm
6
6
  License: GPL
File without changes
File without changes
File without changes
File without changes