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 sys
from voussoirkit import pipeable
from voussoirkit import winglob
for pattern in sys.argv[1:]:
for file in winglob.glob(pattern):
print(file)
send2trash.send2trash(file)
for pattern in pipeable.go(skip_blank=True):
for name in winglob.glob(pattern):
name = os.path.abspath(name)
pipeable.output(name)
send2trash.send2trash(name)

18
size.py
View file

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