Update some scripts with better pipeable behavior.

This commit is contained in:
voussoir 2020-12-06 15:02:56 -08:00
parent 4b8f8f6c77
commit 81fc944d10
4 changed files with 36 additions and 24 deletions

15
delete.py Normal file
View file

@ -0,0 +1,15 @@
import os
import shutil
import sys
from voussoirkit import pipeable
from voussoirkit import winglob
for pattern in pipeable.go(skip_blank=True):
for name in winglob.glob(pattern):
if os.path.isfile(name):
pipeable.output(name)
os.remove(name)
elif os.path.isdir(name):
pipeable.output(name)
shutil.rmtree(name)

View file

@ -1,10 +0,0 @@
import os
from voussoirkit import pipeable
for line in pipeable.go():
if os.path.isfile(line):
print('Deleting', line)
os.remove(line)
else:
print('Not a file', line)

View file

@ -1,9 +1,12 @@
import os
import send2trash import send2trash
import sys import sys
from voussoirkit import pipeable
from voussoirkit import winglob from voussoirkit import winglob
for pattern in sys.argv[1:]: for pattern in pipeable.go(skip_blank=True):
for file in winglob.glob(pattern): for name in winglob.glob(pattern):
print(file) name = os.path.abspath(name)
send2trash.send2trash(file) pipeable.output(name)
send2trash.send2trash(name)

14
size.py
View file

@ -1,16 +1,20 @@
import sys import sys
from voussoirkit import spinal
from voussoirkit import pathclass from voussoirkit import pathclass
from voussoirkit import pipeable
from voussoirkit import spinal
paths = sys.argv[1:] @pipeable.ctrlc_return1
paths = [pathclass.Path(p) for p in paths] def main(argv):
total = 0 total = 0
for path in paths: for path in pipeable.go():
path = pathclass.Path(path)
if path.is_file: if path.is_file:
total += path.size total += path.size
elif path.is_dir: elif path.is_dir:
total += spinal.get_dir_size(path) total += spinal.get_dir_size(path)
print(total) print(total)
if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:]))