Skip to content

Instantly share code, notes, and snippets.

@godber
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save godber/64c0dbcf4ac37e48e1dc to your computer and use it in GitHub Desktop.

Select an option

Save godber/64c0dbcf4ac37e48e1dc to your computer and use it in GitHub Desktop.
import os
from glob import glob
def file_dir_glob_list(inlist=None):
"""Given a list of files, directories or globs, returns a fully expanded
list of files
"""
file_list = []
if inlist:
for item in inlist:
if os.path.isdir(item):
# If item is a directory, get all the files in the directory
file_list.append(glob(os.path.join('%s' % (item), '*')))
elif item:
# If its not a directory, then its either a glob or a file,
# globbing it will work for either
file_list.append(glob(item))
else:
file_list = file_list.append(glob('*'))
return file_list
@percurnicus
Copy link
Copy Markdown

files = []
if isinstance(inlist, list):
    if inlist:
       for item in inlist:
            files += arg_parser(item)
    else:
        files = glob('*')
elif isinstance(inlist, str):
    names = inlist.split(',')
    for name in names:
        files = files + arg_parser(name.strip())
elif inlist is None:
    files = glob('*')

image_set = ImageSet(files)

...

def cli():
    """Give pystamps ability to run from command line"""
    parser = argparse.ArgumentParser()
    parser.add_argument(
        'file', nargs='*',
        help="Input filename or glob for files with certain extensions"
        )
    args = parser.parse_args()
    pystamps(args.file)```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment