Update filepull's usage of pathclass and pipeable.
This commit is contained in:
parent
205c74d47c
commit
9cec1d8e2f
1 changed files with 11 additions and 8 deletions
19
filepull.py
19
filepull.py
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue