def create_user(no_utf8=False):
curr_user = os.geteuid();
target = pwd.getpwnam('postgres')
try:
os.seteuid(target.pw_uid)
m = hashlib.md5()
m.update(DB_PASSWORD)
m.update(DB_USER)
command = """CREATE USER %s PASSWORD 'md5%s'""" % (DB_USER, m.hexdigest())
subprocess.check_call(['psql', '-c', command])
if no_utf8:
command = """CREATE DATABASE %s OWNER %s""" % (DB_NAME, DB_USER)
else:
command = """CREATE DATABASE %s OWNER %s ENCODING 'UTF8'""" % (DB_NAME, DB_USER)
subprocess.check_call(['psql', '-c', command])
os.seteuid(curr_user)
except Exception, e:
raise SystemExit(str(e))
return target
评论列表
文章目录