mirror of
https://github.com/Tygs/0bin.git
synced 2023-08-10 21:13:00 +03:00
Merge ok
This commit is contained in:
commit
536fa12975
16
README.rst
16
README.rst
@ -12,15 +12,18 @@ to `moderate the pastebin content`_ as they have no way to decrypt it.
|
|||||||
|
|
||||||
It's an Python implementation of the `zerobin project`_, created by sebsauvage, under the `WTFPL licence`_.
|
It's an Python implementation of the `zerobin project`_, created by sebsauvage, under the `WTFPL licence`_.
|
||||||
|
|
||||||
For now tested with IE9, and the last opera, safari, chrome and FF.
|
To run zerobin, download zerobin.pyz from the latest release_ then:
|
||||||
|
|
||||||
There is a `good doc <http://readthedocs.org/docs/0bin/en/latest/>`_,
|
::
|
||||||
but in short::
|
|
||||||
|
|
||||||
pip install zerobin
|
python zerobin.pyz
|
||||||
zerobin
|
|
||||||
|
0bin requires Python 3.7 or higher.
|
||||||
|
|
||||||
|
You may need to type :code:`py -3.7 zerobin.pyz` on Windows, or :code:`python3.7 zerobin.pyz` on Mac/Linux, depending on your configuration.
|
||||||
|
|
||||||
|
If you are familiar with the Python ecosystem, you can also :code:`python -m pip install zerobin --user` and run :code:`python -m zerobin` for the same effect.
|
||||||
|
|
||||||
0bin runs on Python 3.7+.
|
|
||||||
|
|
||||||
How it works
|
How it works
|
||||||
=============
|
=============
|
||||||
@ -70,6 +73,7 @@ Known issues
|
|||||||
.. _node.js: http://nodejs.org/
|
.. _node.js: http://nodejs.org/
|
||||||
.. _is not worth it: http://stackoverflow.com/questions/201705/how-many-random-elements-before-md5-produces-collisions
|
.. _is not worth it: http://stackoverflow.com/questions/201705/how-many-random-elements-before-md5-produces-collisions
|
||||||
.. _WTFPL licence: http://en.wikipedia.org/wiki/WTFPL
|
.. _WTFPL licence: http://en.wikipedia.org/wiki/WTFPL
|
||||||
|
.. _release: https://github.com/Tygs/0bin/releases
|
||||||
|
|
||||||
Contributing
|
Contributing
|
||||||
=============
|
=============
|
||||||
|
@ -158,13 +158,64 @@ def set_admin_password(password):
|
|||||||
settings.ADMIN_PASSWORD_FILE.write_bytes(hash_password(password))
|
settings.ADMIN_PASSWORD_FILE.write_bytes(hash_password(password))
|
||||||
|
|
||||||
|
|
||||||
|
def clean_expired_pastes(
|
||||||
|
*, dry_run=False, verbose=False, config_dir="", data_dir="",
|
||||||
|
):
|
||||||
|
""" Clean expired file pastes and empty paste directories
|
||||||
|
|
||||||
|
This features delete files from the data dir, make sure it's safe.
|
||||||
|
|
||||||
|
Use "dry_run" and "verbose" options to check first
|
||||||
|
"""
|
||||||
|
|
||||||
|
ensure_app_context(config_dir=config_dir, data_dir=data_dir)
|
||||||
|
|
||||||
|
print("Deleting expired pastes...")
|
||||||
|
i = 0
|
||||||
|
for p in Paste.iter_all():
|
||||||
|
if p.has_expired:
|
||||||
|
if not dry_run:
|
||||||
|
p.delete()
|
||||||
|
if verbose:
|
||||||
|
print(p.path, "has expired")
|
||||||
|
i += 1
|
||||||
|
if dry_run:
|
||||||
|
print(f"{i} pastes would have been deleted")
|
||||||
|
else:
|
||||||
|
print(f"{i} pastes deleted")
|
||||||
|
|
||||||
|
print("Deleting empty paste directories...")
|
||||||
|
i = 0
|
||||||
|
for p in settings.DATA_DIR.rglob("*"):
|
||||||
|
try:
|
||||||
|
if p.is_dir() and not next(p.iterdir(), None):
|
||||||
|
if not dry_run:
|
||||||
|
p.rmdir()
|
||||||
|
if verbose:
|
||||||
|
print(p, "is empty")
|
||||||
|
i += 1
|
||||||
|
except OSError as e:
|
||||||
|
print(f'Error while processing "{p}: {e}')
|
||||||
|
if dry_run:
|
||||||
|
print(f"{i} directories would have been deleted")
|
||||||
|
else:
|
||||||
|
print(f"{i} directories deleted")
|
||||||
|
print("Done")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
subcommands = [runserver, delete_paste, infos, set_admin_password]
|
subcommands = [
|
||||||
|
runserver,
|
||||||
|
delete_paste,
|
||||||
|
infos,
|
||||||
|
set_admin_password,
|
||||||
|
clean_expired_pastes,
|
||||||
|
]
|
||||||
subcommand_names = [
|
subcommand_names = [
|
||||||
clize.util.name_py2cli(name)
|
clize.util.name_py2cli(name)
|
||||||
for name in clize.util.dict_from_names(subcommands).keys()
|
for name in clize.util.dict_from_names(subcommands).keys()
|
||||||
]
|
]
|
||||||
if len(sys.argv) < 2 or sys.argv[1] not in subcommand_names:
|
if len(sys.argv) < 2 or sys.argv[1] not in subcommand_names:
|
||||||
sys.argv.insert(1, subcommand_names[0])
|
sys.argv.insert(1, subcommand_names[0])
|
||||||
clize.run(runserver, delete_paste, infos, set_admin_password)
|
clize.run(runserver, delete_paste, infos, set_admin_password, clean_expired_pastes)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user