From 3c0f9709eb1f9ec2f9fec1af6049934d0a9b7cf5 Mon Sep 17 00:00:00 2001 From: Yanyan Jiang Date: Sun, 2 Feb 2020 21:11:18 +0800 Subject: [PATCH] tools: add os-export --- tools/.gitignore | 1 + {scripts => tools}/export-os.py | 37 ++++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 tools/.gitignore rename {scripts => tools}/export-os.py (52%) diff --git a/tools/.gitignore b/tools/.gitignore new file mode 100644 index 00000000..f81662e2 --- /dev/null +++ b/tools/.gitignore @@ -0,0 +1 @@ +/export diff --git a/scripts/export-os.py b/tools/export-os.py similarity index 52% rename from scripts/export-os.py rename to tools/export-os.py index 1313150e..32fffbe9 100755 --- a/scripts/export-os.py +++ b/tools/export-os.py @@ -2,7 +2,8 @@ from pathlib import Path import re, shutil -AM_HOME = (Path(__file__) / '../..').resolve() +AM_HOME = (Path(__file__) / '../..').resolve() +EXPORT_DIR = AM_HOME / 'tools' / 'export' WHITE_LIST = [ r'.gitignore', @@ -31,6 +32,10 @@ BLACK_LIST = [ r'klib/src/stdio.c', r'klib/src/stdlib.c', r'klib/src/string.c', + r'.o$', + r'.a$', + r'.d$', + r'mbr$', ] @@ -43,15 +48,23 @@ def list_filter(path, xs): return True return False -for abspath in AM_HOME.rglob('*'): - if abspath.is_file(): - path = abspath.relative_to(AM_HOME) - path_str = '/' + str(path) - white = list_filter(path_str, WHITE_LIST) - black = list_filter(path_str, BLACK_LIST) - if white and not black: - print(path) +def files(): + for abspath in AM_HOME.rglob('*'): + if abspath.is_file(): + path = abspath.relative_to(AM_HOME) + path_str = '/' + str(path) + white = list_filter(path_str, WHITE_LIST) + black = list_filter(path_str, BLACK_LIST) + if white and not black: + yield abspath, path + +try: + shutil.rmtree(EXPORT_DIR) +except: + pass -export_dir = AM_HOME / 'scripts' / 'export' -print(export_dir) -shutil.rmtree(export_dir) \ No newline at end of file +for abspath, relpath in files(): + src = abspath + dst = EXPORT_DIR / relpath + dst.parent.mkdir(parents=True, exist_ok=True) + shutil.copyfile(src, dst)