From 262db62265eecd9e9630f24857f38bfa7c754558 Mon Sep 17 00:00:00 2001 From: ksamuel Date: Sat, 15 Aug 2020 14:40:26 +0200 Subject: [PATCH 1/7] Add command to remove expired pastes --- zerobin/cli.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/zerobin/cli.py b/zerobin/cli.py index 504366b..fb3bc0a 100644 --- a/zerobin/cli.py +++ b/zerobin/cli.py @@ -158,13 +158,62 @@ def set_admin_password(password): settings.ADMIN_PASSWORD_FILE.write_bytes(hash_password(password)) +def clean_expired_pastes(*, dry_run=False, verbose=False): + """ 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() + + 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(): - subcommands = [runserver, delete_paste, infos, set_admin_password] + subcommands = [ + runserver, + delete_paste, + infos, + set_admin_password, + clean_expired_pastes, + ] subcommand_names = [ clize.util.name_py2cli(name) for name in clize.util.dict_from_names(subcommands).keys() ] if len(sys.argv) < 2 or sys.argv[1] not in subcommand_names: 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) From b73ce9684fc1e7439bc0899fe392446f745ef1d9 Mon Sep 17 00:00:00 2001 From: ksamuel Date: Sat, 15 Aug 2020 14:45:52 +0200 Subject: [PATCH 2/7] Tweak command to remove expired pastes --- zerobin/cli.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/zerobin/cli.py b/zerobin/cli.py index fb3bc0a..13670a3 100644 --- a/zerobin/cli.py +++ b/zerobin/cli.py @@ -158,7 +158,9 @@ def set_admin_password(password): settings.ADMIN_PASSWORD_FILE.write_bytes(hash_password(password)) -def clean_expired_pastes(*, dry_run=False, verbose=False): +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. @@ -166,7 +168,7 @@ def clean_expired_pastes(*, dry_run=False, verbose=False): Use "dry_run" and "verbose" options to check first """ - ensure_app_context() + ensure_app_context(config_dir=config_dir, data_dir=data_dir) print("Deleting expired pastes...") i = 0 From 6951d3da5638282ef40659318c1b80e8507ddc0f Mon Sep 17 00:00:00 2001 From: ksamuel Date: Sat, 15 Aug 2020 14:47:17 +0200 Subject: [PATCH 3/7] Fix README rst typo --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index d57f9fa..f2103fb 100644 --- a/README.rst +++ b/README.rst @@ -69,7 +69,7 @@ Known issues .. _zerobin project: https://github.com/sebsauvage/ZeroBin/ .. _node.js: http://nodejs.org/ .. _is not worth it: http://stackoverflow.com/questions/201705/how-many-random-elements-before-md5-produces-collisions -.. _WTF licence: http://en.wikipedia.org/wiki/WTFPL +.. _WTFPL licence: http://en.wikipedia.org/wiki/WTFPL Contributing ============= From 183150a6b027b3ce20799f0eaa28a52a31fa3ff7 Mon Sep 17 00:00:00 2001 From: ksamuel Date: Tue, 18 Aug 2020 14:41:46 +0200 Subject: [PATCH 4/7] Release v1.0.1 --- zerobin/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zerobin/__init__.py b/zerobin/__init__.py index 5c09490..01f979d 100644 --- a/zerobin/__init__.py +++ b/zerobin/__init__.py @@ -1,5 +1,5 @@ from pathlib import Path -__version__ = "1.0.0" +__version__ = "1.0.1" ROOT_DIR = Path(__file__).absolute().parent From 5b515f4c353856ef1ce6975a7075b2c375314d5f Mon Sep 17 00:00:00 2001 From: ksamuel Date: Wed, 19 Aug 2020 11:59:04 +0200 Subject: [PATCH 5/7] Bump version --- zerobin/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zerobin/__init__.py b/zerobin/__init__.py index 01f979d..f04b8d8 100644 --- a/zerobin/__init__.py +++ b/zerobin/__init__.py @@ -1,5 +1,5 @@ from pathlib import Path -__version__ = "1.0.1" +__version__ = "1.0.2" ROOT_DIR = Path(__file__).absolute().parent From 6c64f28643150ccbbdc8bdcd9ef2ad5eee883d24 Mon Sep 17 00:00:00 2001 From: ksamuel Date: Wed, 19 Aug 2020 12:38:50 +0200 Subject: [PATCH 6/7] Update README to demonstrate pyz --- README.rst | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index f2103fb..b5abc69 100644 --- a/README.rst +++ b/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`_. -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 `_, -but in short:: +:: - pip install zerobin - zerobin + python zerobin.pyz + +0bin requires Python 3.7 or higher. + +You may need to type `py -3.7 zerobin.pyz` on Windows, or `python3.7 zerobin.pyz` on Mac/Linux, depending on your configuration. + +If you are familiar with the Python ecosystem, you can also `python -m pip install zerobin --user` and run `python -m zerobin` for the same effect. -0bin runs on Python 3.7+. How it works ============= @@ -70,6 +73,7 @@ Known issues .. _node.js: http://nodejs.org/ .. _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 +.. _release: https://github.com/Tygs/0bin/releases Contributing ============= From a9b2f53e65783250f5eae50ee4ce606dad5f1560 Mon Sep 17 00:00:00 2001 From: ksamuel Date: Wed, 19 Aug 2020 12:41:39 +0200 Subject: [PATCH 7/7] Fix inline code block in README --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index b5abc69..f3db271 100644 --- a/README.rst +++ b/README.rst @@ -20,9 +20,9 @@ To run zerobin, download zerobin.pyz from the latest release_ then: 0bin requires Python 3.7 or higher. -You may need to type `py -3.7 zerobin.pyz` on Windows, or `python3.7 zerobin.pyz` on Mac/Linux, depending on your configuration. +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 `python -m pip install zerobin --user` and run `python -m zerobin` for the same effect. +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. How it works