#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Language Version: 3.4.x
# Last Modified: 2015-06-04 11:45:15

"""
用于设置数据库信息等系统环境变量，以便settings使用
runserver ip:port
sys.argv[3][0] : dbname
sys.argv[3][1] : user
sys.argv[3][2] : password
sys.argv[3][3] : host
sys.argv[3][4] : port

runserver
sys.argv[2][0] : dbname
sys.argv[2][1] : user
sys.argv[2][2] : password
sys.argv[2][3] : host
sys.argv[2][4] : port
"""

__all__ = []
__author__ = "刘飞 (email:13701242710@163.com)"
__version__ = "1.0.1"

"""
if len(sys.argv) > 2 :
    if len(sys.argv[2].split('.')) == 4 :
        if len(sys.argv) != 4:
            raise BaseException("Sorry, argv for 4.")
        else:
            if len(sys.argv[3].split(',')) != 5:
                raise BaseException("Sorry,db argv for 5.")
        dbname,user,password,host,port=sys.argv[3].split(',')
    else:
        if len(sys.argv) != 3:
            raise BaseException("Sorry, argv for 4.")
        else:
            if len(sys.argv[2].split(',')) != 5:
                raise BaseException("Sorry,db argv for 5.")
        dbname,user,password,host,port=sys.argv[2].split(',')
else:
    raise BaseException("Sorry, argv for 4.")
"""
import os
import json
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
dbinfo = dict(dbname = input('Database name:'),user=input('User:'),password=input('Password:'),host=input('Host:'),port=input('Port:'))
with open(os.path.join(BASE_DIR,'dbinfo/setinfo.json'),'w') as f:
    f.write(json.dumps(dbinfo))

