Skip to content

Instantly share code, notes, and snippets.

@alevene
Created January 15, 2020 21:40
Show Gist options
  • Select an option

  • Save alevene/41b0f2b3eec2626b806e9d69c392a524 to your computer and use it in GitHub Desktop.

Select an option

Save alevene/41b0f2b3eec2626b806e9d69c392a524 to your computer and use it in GitHub Desktop.
Print all DAGs except...
import os
import sys
def print_all_dag_files(except_list):
root_dir = '/Users/alex.levene/workspace/airflow-dags/'
exclude_dirs = ['.buildkite', '.idea', '.mine', 'common']
keep_dirs = ['airflow_config']
ignores = []
for dir_name, subdir_list, file_list in os.walk(root_dir):
short_dir_name = dir_name.replace(root_dir, '').split('/')[0]
if short_dir_name in (exclude_dirs + keep_dirs):
continue
for fname in file_list:
if fname.endswith('.py'):
full_fname = os.path.join(dir_name.replace(root_dir, ''), fname)
if full_fname in except_list:
continue
ignores.append(full_fname)
[print('{}/.*'.format(f)) for f in exclude_dirs]
for ignore in sorted(ignores):
print(ignore)
if __name__ == '__main__':
# pass list of filenames
# Ex: python3 dag_ignore.py sqooperduper/zenpayroll.py athena_schema/__init__.py
file_args = sys.argv[1:]
print_all_dag_files(file_args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment