Update filepull's usage of pathclass and pipeable.

This commit is contained in:
voussoir 2021-12-07 12:46:45 -08:00
parent 205c74d47c
commit 9cec1d8e2f
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -6,16 +6,17 @@ import os
import sys import sys
from voussoirkit import interactive from voussoirkit import interactive
from voussoirkit import pathclass
from voussoirkit import pipeable
from voussoirkit import spinal from voussoirkit import spinal
def filepull(pull_from='.', autoyes=False): def filepull(pull_from='.', autoyes=False):
files = list(spinal.walk(pull_from)) start = pathclass.Path(pull_from)
cwd = os.getcwd() files = [file for d in start.listdir_directories() for file in d.walk_files()]
files = [f for f in files if os.path.split(f.absolute_path)[0] != cwd]
if len(files) == 0: if len(files) == 0:
print('No files to move') pipeable.stderr('No files to move')
return return 1
duplicate_count = {} duplicate_count = {}
for f in files: for f in files:
@ -33,16 +34,18 @@ def filepull(pull_from='.', autoyes=False):
raise Exception('duplicate names:\n' + '\n'.join(duplicates)) raise Exception('duplicate names:\n' + '\n'.join(duplicates))
for f in files: for f in files:
print(f.basename) pipeable.stdout(f.basename)
if autoyes or interactive.getpermission(f'Move {len(files)} files?'): if autoyes or interactive.getpermission(f'Move {len(files)} files?'):
for f in files: for f in files:
local = os.path.join('.', f.basename) local = os.path.join('.', f.basename)
os.rename(f, local) os.rename(f, local)
return 0
else:
return 1
def filepull_argparse(args): def filepull_argparse(args):
filepull(pull_from=args.pull_from, autoyes=args.autoyes) return filepull(pull_from=args.pull_from, autoyes=args.autoyes)
return 0
def main(argv): def main(argv):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()