Skip to content

Commit 536fa12

Browse files
committed
Merge ok
2 parents b86bc2c + 73ce7c4 commit 536fa12

File tree

2 files changed

+63
-8
lines changed

2 files changed

+63
-8
lines changed

README.rst

+10-6
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ to `moderate the pastebin content`_ as they have no way to decrypt it.
1212

1313
It's an Python implementation of the `zerobin project`_, created by sebsauvage, under the `WTFPL licence`_.
1414

15-
For now tested with IE9, and the last opera, safari, chrome and FF.
15+
To run zerobin, download zerobin.pyz from the latest release_ then:
1616

17-
There is a `good doc <http://readthedocs.org/docs/0bin/en/latest/>`_,
18-
but in short::
17+
::
1918

20-
pip install zerobin
21-
zerobin
19+
python zerobin.pyz
20+
21+
0bin requires Python 3.7 or higher.
22+
23+
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.
24+
25+
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.
2226

23-
0bin runs on Python 3.7+.
2427

2528
How it works
2629
=============
@@ -70,6 +73,7 @@ Known issues
7073
.. _node.js: http://nodejs.org/
7174
.. _is not worth it: http://stackoverflow.com/questions/201705/how-many-random-elements-before-md5-produces-collisions
7275
.. _WTFPL licence: http://en.wikipedia.org/wiki/WTFPL
76+
.. _release: https://github.com/Tygs/0bin/releases
7377

7478
Contributing
7579
=============

zerobin/cli.py

+53-2
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,64 @@ def set_admin_password(password):
158158
settings.ADMIN_PASSWORD_FILE.write_bytes(hash_password(password))
159159

160160

161+
def clean_expired_pastes(
162+
*, dry_run=False, verbose=False, config_dir="", data_dir="",
163+
):
164+
""" Clean expired file pastes and empty paste directories
165+
166+
This features delete files from the data dir, make sure it's safe.
167+
168+
Use "dry_run" and "verbose" options to check first
169+
"""
170+
171+
ensure_app_context(config_dir=config_dir, data_dir=data_dir)
172+
173+
print("Deleting expired pastes...")
174+
i = 0
175+
for p in Paste.iter_all():
176+
if p.has_expired:
177+
if not dry_run:
178+
p.delete()
179+
if verbose:
180+
print(p.path, "has expired")
181+
i += 1
182+
if dry_run:
183+
print(f"{i} pastes would have been deleted")
184+
else:
185+
print(f"{i} pastes deleted")
186+
187+
print("Deleting empty paste directories...")
188+
i = 0
189+
for p in settings.DATA_DIR.rglob("*"):
190+
try:
191+
if p.is_dir() and not next(p.iterdir(), None):
192+
if not dry_run:
193+
p.rmdir()
194+
if verbose:
195+
print(p, "is empty")
196+
i += 1
197+
except OSError as e:
198+
print(f'Error while processing "{p}: {e}')
199+
if dry_run:
200+
print(f"{i} directories would have been deleted")
201+
else:
202+
print(f"{i} directories deleted")
203+
print("Done")
204+
205+
161206
def main():
162-
subcommands = [runserver, delete_paste, infos, set_admin_password]
207+
subcommands = [
208+
runserver,
209+
delete_paste,
210+
infos,
211+
set_admin_password,
212+
clean_expired_pastes,
213+
]
163214
subcommand_names = [
164215
clize.util.name_py2cli(name)
165216
for name in clize.util.dict_from_names(subcommands).keys()
166217
]
167218
if len(sys.argv) < 2 or sys.argv[1] not in subcommand_names:
168219
sys.argv.insert(1, subcommand_names[0])
169-
clize.run(runserver, delete_paste, infos, set_admin_password)
220+
clize.run(runserver, delete_paste, infos, set_admin_password, clean_expired_pastes)
170221

0 commit comments

Comments
 (0)