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:
parent
11ff63d931
commit
c33de9c0dc
1
setup.py
1
setup.py
@ -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
42
zerobin/remove_paste.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user