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.
- {delayed_rm-2.6.0 → delayed_rm-2.7.0}/PKG-INFO +1 -1
- {delayed_rm-2.6.0 → delayed_rm-2.7.0}/delayed_rm/delayed_rm.py +44 -33
- {delayed_rm-2.6.0 → delayed_rm-2.7.0}/delayed_rm.egg-info/PKG-INFO +2 -2
- {delayed_rm-2.6.0 → delayed_rm-2.7.0}/LICENSE +0 -0
- {delayed_rm-2.6.0 → delayed_rm-2.7.0}/README.md +0 -0
- {delayed_rm-2.6.0 → delayed_rm-2.7.0}/delayed_rm/__init__.py +0 -0
- {delayed_rm-2.6.0 → delayed_rm-2.7.0}/delayed_rm/py.typed +0 -0
- {delayed_rm-2.6.0 → delayed_rm-2.7.0}/delayed_rm.egg-info/SOURCES.txt +0 -0
- {delayed_rm-2.6.0 → delayed_rm-2.7.0}/delayed_rm.egg-info/dependency_links.txt +0 -0
- {delayed_rm-2.6.0 → delayed_rm-2.7.0}/delayed_rm.egg-info/entry_points.txt +0 -0
- {delayed_rm-2.6.0 → delayed_rm-2.7.0}/delayed_rm.egg-info/top_level.txt +0 -0
- {delayed_rm-2.6.0 → delayed_rm-2.7.0}/pyproject.toml +0 -0
- {delayed_rm-2.6.0 → delayed_rm-2.7.0}/setup.cfg +0 -0
|
@@ -13,7 +13,7 @@ import sys
|
|
|
13
13
|
import os
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
__version__ = "2.
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
shutil.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
180
|
-
|
|
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
|
|
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:
|
|
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
|