From c33de9c0dc43c711767687a0fda7338c5cfb3231 Mon Sep 17 00:00:00 2001 From: Shir0kamii Date: Thu, 10 Sep 2015 23:14:18 +0200 Subject: [PATCH] Add a script to remove paste, either from URL of from ID --- setup.py | 1 + zerobin/remove_paste.py | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 zerobin/remove_paste.py diff --git a/setup.py b/setup.py index 5973c0f..66f4174 100644 --- a/setup.py +++ b/setup.py @@ -48,6 +48,7 @@ setup( entry_points = { 'console_scripts': [ 'zerobin = zerobin.routes:main', + 'remove_paste = zerobin.remove_paste:main', ] } diff --git a/zerobin/remove_paste.py b/zerobin/remove_paste.py new file mode 100644 index 0000000..489f18b --- /dev/null +++ b/zerobin/remove_paste.py @@ -0,0 +1,42 @@ +from zerobin.paste import Paste +from clize import run +import re + +paste_url = re.compile('/paste/(?P.*)#(?P.*)') + +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()