import yaml, argparse, pathlib from datetime import datetime import utils if __name__ == "__main__": p = argparse.ArgumentParser(description='creates new content files') p.add_argument('filepath', metavar='filepath', type=str, help='path for new file') args = p.parse_args() file = pathlib.Path(args.filepath) type = file.parent.name conf = utils.load_conf() atypes = utils.get_files_in_subdir(conf['template'], 'archetypes', 'md') if atypes is None: print('no archetypes in template') exit(1) if type not in atypes.keys(): ## can relax this later print('directory of the new file must match an archetype') exit(1) with open(atypes[type]) as fp: archetype = fp.read() #### process str if needed #### file.parent.mkdir(parents=True, exist_ok=True) with open(file, 'w') as fp: fp.write(archetype)