#!/usr/bin/env python

import argparse, uuid
from os import path

copyright_tmpl = \
"""/* Copyright (C) 2012-2018 HiPro IT Solutions Private Limited,
 * Chennai. All rights reserved.
 *
 * This program and the accompanying materials are made available
 * under the terms described in the LICENSE file which accompanies
 * this distribution. If the LICENSE file was not attached to this
 * distribution or for further clarifications, please contact
 * legal@hipro.co.in. */
"""

header_incl_tmpl = \
"""
#ifndef HIPRO_THITTAM__%(uuid)s
#define HIPRO_THITTAM__%(uuid)s


#endif // HIPRO_THITTAM__%(uuid)s
"""

editor_var_tmpl = """\n/*\n  Local Variables:
  mode: c++
  indent-tabs-mode: nil
  End:
*/
"""

def h_create (file_handle):
    file_handle.write (copyright_tmpl)
    file_handle.write (header_incl_tmpl %
                       ({'uuid': str(uuid.uuid1()).replace('-','_'),}))
    file_handle.write (editor_var_tmpl)
    file_handle.close ()

def src_create (file_handle):
    file_handle.write (copyright_tmpl)
    file_handle.write (editor_var_tmpl)
    file_handle.close ()

def main():
    parser = argparse.ArgumentParser (
        prog="stool", description="C++ source and header file generation tool")
    parser.add_argument ("-f", "--file-name",
                         help="C++ header/source file name",
                         type=argparse.FileType('w'), required=True)
    args = vars(parser.parse_args ())

    _file = args['file_name']
    file_name, extn = path.splitext(_file.name)
    if extn in ('.h', '.hpp'):
        h_create (_file)
    else:
        src_create (_file)

if __name__ == "__main__":
    main ()

# Local Variables:
# mode: python
# indent-tabs-mode: nil
# tab-width: 4
# End:
