Add autoyes argument to filepull.
This commit is contained in:
parent
b951ace5d8
commit
d965333021
1 changed files with 9 additions and 4 deletions
|
@ -7,7 +7,7 @@ import sys
|
||||||
|
|
||||||
from voussoirkit import spinal
|
from voussoirkit import spinal
|
||||||
|
|
||||||
def filepull(pull_from='.'):
|
def filepull(pull_from='.', autoyes=False):
|
||||||
files = list(spinal.walk_generator(pull_from))
|
files = list(spinal.walk_generator(pull_from))
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
files = [f for f in files if os.path.split(f.absolute_path)[0] != cwd]
|
files = [f for f in files if os.path.split(f.absolute_path)[0] != cwd]
|
||||||
|
@ -30,19 +30,24 @@ def filepull(pull_from='.'):
|
||||||
for f in files:
|
for f in files:
|
||||||
print(f.basename)
|
print(f.basename)
|
||||||
|
|
||||||
print('Move %d files?' % len(files))
|
ok = autoyes
|
||||||
if input('> ').lower() in ['y', 'yes']:
|
if not ok:
|
||||||
|
print('Move %d files?' % len(files))
|
||||||
|
ok = input('> ').lower() in ['y', 'yes']:
|
||||||
|
|
||||||
|
if ok:
|
||||||
for f in files:
|
for f in files:
|
||||||
local = os.path.join('.', f.basename)
|
local = os.path.join('.', f.basename)
|
||||||
os.rename(f.absolute_path, local)
|
os.rename(f.absolute_path, local)
|
||||||
|
|
||||||
def filepull_argparse(args):
|
def filepull_argparse(args):
|
||||||
filepull(pull_from=args.pull_from)
|
filepull(pull_from=args.pull_from, autoyes=args.autoyes)
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
parser.add_argument('pull_from', nargs='?', default='.')
|
parser.add_argument('pull_from', nargs='?', default='.')
|
||||||
|
parser.add_argument('-y', '--yes', dest='autoyes', action='store_true')
|
||||||
parser.set_defaults(func=filepull_argparse)
|
parser.set_defaults(func=filepull_argparse)
|
||||||
|
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
Loading…
Reference in a new issue