Contents
import os
import tarfile

def recursive_files(dir_name='.', ignore=None):
    for dir_name,subdirs,files in os.walk(dir_name):
        if ignore and os.path.basename(dir_name) in ignore: 
            continue

        for file_name in files:
            if ignore and file_name in ignore:
                continue

            yield os.path.join(dir_name, file_name)

def make_tar_file(dir_name='.', tar_file_name='tarfile.tar', ignore=None):
    tar = tarfile.open(tar_file_name, 'w')

    for file_name in recursive_files(dir_name, ignore):
        print(file_name)
        tar.add(file_name)

    tar.close()

home_dir = os.path.expanduser("~")
os.chdir(home_dir)
    
print('Creating homework archive as .tar file')
dir_name = 'lab-cognition-perception/homeworks'
tar_file_name = 'Psych46Homeworks.tar'
ignore = {'.ipynb_checkpoints', '__pycache__', tar_file_name}
make_tar_file(dir_name, tar_file_name, ignore)
print('Done.')
print("")

print('Creating lab archive as .tar file')
dir_name = 'lab-cognition-perception/labs'
tar_file_name = 'Psych46Labs.tar'
ignore = {'.ipynb_checkpoints', '__pycache__', tar_file_name}
make_tar_file(dir_name, tar_file_name, ignore)
print('Done.')