1
0
mirror of https://github.com/Tygs/0bin.git synced 2023-08-10 21:13:00 +03:00

Add a script to remove paste, either from URL of from ID

This commit is contained in:
Shir0kamii 2015-09-10 23:14:18 +02:00
parent 11ff63d931
commit c33de9c0dc
2 changed files with 43 additions and 0 deletions

View File

@ -48,6 +48,7 @@ setup(
entry_points = {
'console_scripts': [
'zerobin = zerobin.routes:main',
'remove_paste = zerobin.remove_paste:main',
]
}

42
zerobin/remove_paste.py Normal file
View File

@ -0,0 +1,42 @@
from zerobin.paste import Paste
from clize import run
import re
paste_url = re.compile('/paste/(?P<paste_id>.*)#(?P<key>.*)')
def unpack_paste(paste):
"""Take either the ID or the URL of a paste, and return its ID"""
try_url = paste_url.search(paste)
if try_url:
return try_url.group('paste_id')
return paste
def remove_paste(*paste_list, quiet:'q'=False):
"""
Remove pastes, given its ID or its URL
paste_list: Liste of paste, given by ID or URL
quiet: Don't print anything
"""
for paste_uuid in map(unpack_paste, paste_list):
try:
Paste.load(paste_uuid).delete()
except ValueError:
if not quiet:
print('Paste {} doesn\'t exist'.format(paste_uuid))
else:
if not quiet:
print('Paste {} is removed'.format(paste_uuid))
def main():
run(remove_paste)
if __name__ == "__main__":
main()