refactor: switch to pathlib
icyphox icyph0x@protonmail.com
Fri, 16 Mar 2018 09:27:24 +0530
1 files changed,
15 insertions(+),
9 deletions(-)
jump to
M
vite.py
→
vite.py
@@ -5,8 +5,8 @@
import markdown2 import sys import argparse -import os import errno +import pathlib parser = argparse.ArgumentParser(description='A simple and mnml static site generator.') parser.add_argument('action', choices=['new'], help='Create a new project.')@@ -19,11 +19,17 @@
args = parser.parse_args() project_path = args.path[0] -try: - os.makedirs(project_path) - os.makedirs(project_path + '/pages') - os.makedirs(project_path + '/build') - print('Created project directory at %s.' % (project_path)) -except OSError as e: - if e.errno != errno.EEXIST: - raise +def create_dirs(path): + try: + pathlib.Path(path + '/pages').mkdir(parents=True, exist_ok=False) + pathlib.Path(path + '/build').mkdir(exist_ok=False) + except FileExistsError as e: + if e.errno != errno.EEXIST: + raise + +def main(): + create_dirs(project_path) + + +if __name__ == "__main__": + main()