Skip to content

Commit c33de9c

Browse files
committed
Add a script to remove paste, either from URL of from ID
1 parent 11ff63d commit c33de9c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
entry_points = {
4949
'console_scripts': [
5050
'zerobin = zerobin.routes:main',
51+
'remove_paste = zerobin.remove_paste:main',
5152
]
5253
}
5354

zerobin/remove_paste.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from zerobin.paste import Paste
2+
from clize import run
3+
import re
4+
5+
paste_url = re.compile('/paste/(?P<paste_id>.*)#(?P<key>.*)')
6+
7+
def unpack_paste(paste):
8+
"""Take either the ID or the URL of a paste, and return its ID"""
9+
10+
try_url = paste_url.search(paste)
11+
12+
if try_url:
13+
return try_url.group('paste_id')
14+
return paste
15+
16+
17+
def remove_paste(*paste_list, quiet:'q'=False):
18+
"""
19+
Remove pastes, given its ID or its URL
20+
21+
paste_list: Liste of paste, given by ID or URL
22+
23+
quiet: Don't print anything
24+
"""
25+
26+
for paste_uuid in map(unpack_paste, paste_list):
27+
try:
28+
Paste.load(paste_uuid).delete()
29+
30+
except ValueError:
31+
if not quiet:
32+
print('Paste {} doesn\'t exist'.format(paste_uuid))
33+
34+
else:
35+
if not quiet:
36+
print('Paste {} is removed'.format(paste_uuid))
37+
38+
def main():
39+
run(remove_paste)
40+
41+
if __name__ == "__main__":
42+
main()

0 commit comments

Comments
 (0)