tools: add os-export

This commit is contained in:
Yanyan Jiang 2020-02-02 21:11:18 +08:00
parent a0a9f839e9
commit 3c0f9709eb
2 changed files with 26 additions and 12 deletions

1
tools/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/export

View File

@ -3,6 +3,7 @@ from pathlib import Path
import re, shutil
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,6 +48,7 @@ def list_filter(path, xs):
return True
return False
def files():
for abspath in AM_HOME.rglob('*'):
if abspath.is_file():
path = abspath.relative_to(AM_HOME)
@ -50,8 +56,15 @@ for abspath in AM_HOME.rglob('*'):
white = list_filter(path_str, WHITE_LIST)
black = list_filter(path_str, BLACK_LIST)
if white and not black:
print(path)
yield abspath, path
export_dir = AM_HOME / 'scripts' / 'export'
print(export_dir)
shutil.rmtree(export_dir)
try:
shutil.rmtree(EXPORT_DIR)
except:
pass
for abspath, relpath in files():
src = abspath
dst = EXPORT_DIR / relpath
dst.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(src, dst)