#!/usr/bin/env python

import os
import os.path


def set_noterc():
    noterc = os.path.expanduser('~/.noterc')
    editor = os.getenv('EDITOR', default='nano')
    noterc_tpl = ('[DEFAULT]\n'
                  'data = ~/.note/\n'
                  'dateformat = Y-m-d H:M\n'
                  'editor = {0}\n').format(editor)

    if not os.path.exists(noterc):
        with open(noterc, 'w') as f:
            f.write(noterc_tpl)
    else:
        print("File '~/.noterc' already exists.")


def set_note_dir():
    notedir = os.path.expanduser('~/.note')
    data_tpl = '[]'

    if not os.path.exists(notedir):
        os.mkdir(notedir)

        with open(os.path.join(notedir, 'data.json'), 'w') as f:
            f.write(data_tpl)
        with open(os.path.join(notedir, 'trash.json'), 'w') as f:
            f.write(data_tpl)
        with open(os.path.join(notedir, 'revisions.json'), 'w') as f:
            f.write(data_tpl)
    else:
        print("Directory '~/.note' already exists.")


if __name__ == '__main__':
    set_noterc()
    set_note_dir()
