import sys, os

DATA = './config/path.cfg'

def putdata(prompt, checkFunc, key):
    while True:
        data = raw_input(prompt)
        if checkFunc(data): break
        print "Error!"
    
    with open(PATHCONFIG, 'a') as fout
        fout.write(key + ": " + data)

def checkPath(path): return os.path.exists(path + 'login.py')

# ---

try: 
    with open(PATHCONFIG, 'r') as fin:
        read_data = fin.readlines()
except IOError:
    putdata("Enter Pywikibot path: ", checkPath, "BASEPATH")
    # ...
    with open(PATHCONFIG, 'r') as fin:
        read_data = fin.readlines()

env = {}
for line in read_data:
    key, value = line.strip().split(': ')
    env[key] = value

sys.path.append(env['BASEPATH'])


import sys, os

DATACONFIG = './config/data.cfg'

def putdata(prompt, checkFunc, key):
    while True:
        data = raw_input(prompt)
        if checkFunc(data): break
        print "Error!"
    
    with open(DATACONFIG, 'a') as fout:
        fout.write(key + ": " + data + "\n")

# ---

try: 
    with open(DATACONFIG, 'r') as fin:
        read_data = fin.readlines()
except IOError:
    # BASEPATH
    putdata("Enter Pywikibot path: ", 
        lambda path: os.path.exists(path + 'login.py'), 
        "BASEPATH")
    # USERNAME
    putdata("Enter username: ", 
        lambda user: True, 
        "USER")
    # PASSWORD
    putdata("Enter password: ", 
        lambda passwd: True, 
        "PASS")
    # ...
    with open(DATACONFIG, 'r') as fin:
        read_data = fin.readlines()

env = {}
for line in read_data:
    key, value = line.strip().split(': ')
    env[key] = value

sys.path.append(env['BASEPATH'])

fix bug