all repos — py-vite @ 21dde9f4a1adc9bcb62c8418b824e72504d2bd34

the original vite, written in python

refactor: switch to pathlib
icyphox icyph0x@protonmail.com
Fri, 16 Mar 2018 09:27:24 +0530
commit

21dde9f4a1adc9bcb62c8418b824e72504d2bd34

parent

a996e2b650d7706b066473c8dc0af4d6808226a0

1 files changed, 15 insertions(+), 9 deletions(-)

jump to
M vite.pyvite.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()