Skip to content

Instantly share code, notes, and snippets.

@dboyliao
Last active March 9, 2019 04:33
Show Gist options
  • Select an option

  • Save dboyliao/7aa298bdf60719751edb5568b0df4d89 to your computer and use it in GitHub Desktop.

Select an option

Save dboyliao/7aa298bdf60719751edb5568b0df4d89 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# a python copy of thanos JS (https://thanosjs.org/)
from __future__ import print_function
import importlib
import os
import random
import sys
def _try_import(pkg):
try:
importlib.import_module(pkg)
except ImportError:
print('%s is missing' % pkg)
def _main(path):
stones = ['power', 'reality', 'mind', 'space', 'time', 'soul']
for stone in stones:
_try_import(stone)
path = os.path.expanduser(path)
for dirpath, _, fnames in os.walk(path):
for fname in fnames:
fpath = os.path.join(dirpath, fname)
name, _ = os.path.splitext(fname)
if random.random() < 0.5 and name not in stones and name != 'thanos':
print('for the balance of the universe, remove %s' % fpath)
os.remove(fpath)
def _help():
print("""\
# this will reduce the size of your working directory approximately down to 50%
# by removing files. You've been warned :)
How to use it:
% touch {power,reality,mind,space,time,soul}.py
% python thanos.py snap-finger --with-gloves
""")
if __name__ == '__main__':
if set(sys.argv).issuperset(['snap-finger', '--with-gloves']):
_main('.')
else:
_help()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment