File: conf_create

package info (click to toggle)
lmod 8.7.60-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 63,008 kB
  • sloc: sh: 6,266; makefile: 2,837; ansic: 1,513; tcl: 1,382; python: 1,050; csh: 112
file content (95 lines) | stat: -rwxr-xr-x 3,103 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
# -*- python -*-
#
# Git Version: @git@

#-----------------------------------------------------------------------
# XALT: A tool that tracks users jobs and environments on a cluster.
# Copyright (C) 2013-2014 University of Texas at Austin
# Copyright (C) 2013-2014 University of Tennessee
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser  General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307 USA
#-----------------------------------------------------------------------

from __future__ import print_function
import os, sys, re, getpass, base64

try:
  import configparser
except:
  import ConfigParser as configparser

dirNm, execName = os.path.split(sys.argv[0])
sys.path.insert(1,os.path.abspath(os.path.join(dirNm, "../libexec")))
sys.path.insert(1,os.path.realpath(os.path.join(dirNm, "../site")))

import argparse

class CmdLineOptions(object):
  def __init__(self):
    pass

  def execute(self):
    parser = argparse.ArgumentParser()
    parser.add_argument("--dbhost",  dest='dbhost',  action="store",  help="db host")
    parser.add_argument("--dbuser",  dest='dbuser',  action="store",  help="db user")
    parser.add_argument("--passwd",  dest='passwd',  action="store",  help="password")
    parser.add_argument("--dbname",  dest='dbname',  action="store",  help="name of db")

    args = parser.parse_args()

    return args
class CreateConf(object):
  def __init__(self, args):
    self.__host   = args.dbhost
    self.__user   = args.dbuser
    self.__passwd = args.passwd
    self.__db     = args.dbname

  def __readFromUser(self):
    if (not self.__host):   self.__host   = raw_input("Database host: ")
    if (not self.__user):   self.__user   = raw_input("Database user: ")
    if (not self.__passwd): self.__passwd = getpass.getpass("Database pass: ")
    if (not self.__db):     self.__db     = raw_input("Database name: ")

  def __writeConfig(self):
    config = configparser.ConfigParser()
    config.add_section("MYSQL")
    config.set("MYSQL","HOST",self.__host)
    config.set("MYSQL","USER",self.__user)
    config.set("MYSQL","PASSWD",base64.b64encode(self.__passwd.encode()).decode())
    config.set("MYSQL","DB",self.__db)

    fn = self.__db + "_db.conf"

    f = open(fn,"w")
    config.write(f)
    f.close()

  def create(self):

    self.__readFromUser()
    self.__writeConfig()



def main():
  args = CmdLineOptions().execute()
  createConf = CreateConf(args)
  createConf.create()


if ( __name__ == '__main__'): main()