|
@@ -14,6 +14,7 @@ def parse_args():
|
|
|
parser.add_argument('--docs-dir', action='append', nargs=2, dest='docs_dirs', default=None)
|
|
|
parser.add_argument('--existing', choices=('skip', 'overwrite'), default='overwrite')
|
|
|
parser.add_argument('--source-root', required=True)
|
|
|
+ parser.add_argument('--src-dir', action='append', nargs='*', dest='src_dirs', default=None)
|
|
|
parser.add_argument('files', nargs='*')
|
|
|
return parser.parse_args(pcf.get_args(sys.argv[1:]))
|
|
|
|
|
@@ -28,16 +29,15 @@ def makedirs(dirname):
|
|
|
raise
|
|
|
|
|
|
|
|
|
-def copy_file(src, dst, overwrite, orig_path, generated=False):
|
|
|
+def copy_file(src, dst, overwrite=False, orig_path=None, generated=False):
|
|
|
if os.path.exists(dst) and not overwrite:
|
|
|
return
|
|
|
|
|
|
makedirs(os.path.dirname(dst))
|
|
|
|
|
|
with open(src, 'r') as fsrc, open(dst, 'w') as fdst:
|
|
|
- # FIXME(snermolaev): uncomment lines below when yfm is ready
|
|
|
- # if src.endswith('.md'):
|
|
|
- # fdst.write('---\n{}\n\n---\n'.format('generated: true' if generated else 'vcsPath: {}'.format(orig_path)))
|
|
|
+ # if (orig_path or generated) and src.endswith('.md'):
|
|
|
+ # fdst.write('---\n{}\n\n---\n'.format('generated: true' if generated else 'vcsPath: {}'.format(orig_path)))
|
|
|
shutil.copyfileobj(fsrc, fdst)
|
|
|
|
|
|
|
|
@@ -55,11 +55,11 @@ def main():
|
|
|
if args.docs_dirs:
|
|
|
for item in args.docs_dirs:
|
|
|
assert len(item) == 2
|
|
|
- docs_dir, docs_dir_namespace = item[0], item[1]
|
|
|
+ docs_dir, nm = item[0], item[1]
|
|
|
assert not os.path.isabs(docs_dir)
|
|
|
- if docs_dir_namespace and docs_dir_namespace != '.':
|
|
|
- assert not os.path.isabs(docs_dir_namespace)
|
|
|
- dst = os.path.join(dest_dir, docs_dir_namespace)
|
|
|
+ if nm and nm != '.':
|
|
|
+ assert not os.path.isabs(nm)
|
|
|
+ dst = os.path.join(dest_dir, nm)
|
|
|
else:
|
|
|
dst = dest_dir
|
|
|
|
|
@@ -72,7 +72,33 @@ def main():
|
|
|
file_src = os.path.join(root, f)
|
|
|
assert file_src.startswith(source_root)
|
|
|
file_dst = os.path.join(dst, os.path.relpath(root, abs_docs_dir), f)
|
|
|
- copy_file(file_src, file_dst, is_overwrite_existing, file_src[len(source_root):])
|
|
|
+ copy_file(file_src, file_dst, overwrite=is_overwrite_existing, orig_path=file_src[len(source_root):])
|
|
|
+
|
|
|
+ if args.src_dirs:
|
|
|
+ for item in args.src_dirs:
|
|
|
+ assert len(item) > 1
|
|
|
+ src_dir, nm = os.path.normpath(item[0]), item[1]
|
|
|
+ assert os.path.isabs(src_dir)
|
|
|
+ if nm and nm != '.':
|
|
|
+ assert not os.path.isabs(nm)
|
|
|
+ dst = os.path.join(dest_dir, nm)
|
|
|
+ else:
|
|
|
+ dst = dest_dir
|
|
|
+
|
|
|
+ if src_dir.startswith(source_root):
|
|
|
+ root = source_root
|
|
|
+ is_from_source_root = True
|
|
|
+ else:
|
|
|
+ assert src_dir.startswith(build_root)
|
|
|
+ root = build_root
|
|
|
+ is_from_source_root = False
|
|
|
+
|
|
|
+ for f in item[2:]:
|
|
|
+ file_src = os.path.normpath(f)
|
|
|
+ assert file_src.startswith(root)
|
|
|
+ rel_path = file_src[len(root):] if is_from_source_root else None
|
|
|
+ file_dst = os.path.join(dst, file_src[len(src_dir):])
|
|
|
+ copy_file(file_src, file_dst, overwrite=is_overwrite_existing, orig_path=rel_path)
|
|
|
|
|
|
if args.bin_dir:
|
|
|
assert len(args.bin_dir) > 1
|
|
@@ -88,7 +114,7 @@ def main():
|
|
|
assert os.path.isfile(file_src)
|
|
|
assert file_src.startswith(bin_dir)
|
|
|
file_dst = os.path.join(dst, file_src[len(bin_dir):])
|
|
|
- copy_file(file_src, file_dst, is_overwrite_existing, None, generated=True)
|
|
|
+ copy_file(file_src, file_dst, overwrite=is_overwrite_existing, orig_path=None)
|
|
|
|
|
|
for src in args.files:
|
|
|
generated = False
|
|
@@ -98,7 +124,7 @@ def main():
|
|
|
if file_src.startswith(source_root):
|
|
|
rel_path = file_src[len(source_root):]
|
|
|
elif file_src.startswith(build_root):
|
|
|
- generated = True
|
|
|
+ # generated = True
|
|
|
rel_path = file_src[len(build_root):]
|
|
|
else:
|
|
|
raise Exception('Unexpected file path [{}].'.format(file_src))
|