[Mpuls-commits] r4775 - in base/trunk: mpulsweb/commands/db mpulsweb.egg-info

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Mar 11 11:06:56 CET 2011


Author: torsten
Date: 2011-03-11 11:06:55 +0100 (Fri, 11 Mar 2011)
New Revision: 4775

Modified:
   base/trunk/mpulsweb.egg-info/PKG-INFO
   base/trunk/mpulsweb.egg-info/SOURCES.txt
   base/trunk/mpulsweb/commands/db/common.py
Log:
Updated script to create databases


Modified: base/trunk/mpulsweb/commands/db/common.py
===================================================================
--- base/trunk/mpulsweb/commands/db/common.py	2011-03-11 10:06:03 UTC (rev 4774)
+++ base/trunk/mpulsweb/commands/db/common.py	2011-03-11 10:06:55 UTC (rev 4775)
@@ -9,6 +9,17 @@
 
 DIRS = [os.path.join(os.path.dirname(os.path.abspath(__file__)), 'scripts')]
 
+def build_commandline(options, cmd='psql'):
+    params = ['host', 'port', 'username']
+    cmdline = []
+    cmdline.append(cmd)
+    for p in params:
+        o = options.get(p)
+        if o:
+            cmdline.append('--%s=%s' % (p, o))
+    return " ".join(cmdline)
+
+
 def get_path(filename, dir=None):
     #print  pylons.config.get('pylons.paths').get('static_files')
     for ROOT in DIRS[::-1]:
@@ -50,35 +61,25 @@
 
 def check_connection(options, args=None):
     # Just connect to the database. Imideatly cloes connection
-    cmd_line = "psql --host=%s --port=%s --username=%s -c '\q'" % (options.get('host'), 
-                                                      options.get('port'), 
-                                                      options.get('user'))
+    cmd_line = "%s -c '\q'" % build_commandline(options)
     args = shlex.split(cmd_line)
     retcode = subprocess.check_call(args)
     return int(retcode) == 0 
 
 def check_mpulscluster(options, args=None):
     # Just connect to the database. Imideatly cloes connection
-    cmd_line = "psql --host=%s --port=%s --username=%s -c '\q' mpuls_maintenance" % (options.get('host'), 
-                                                      options.get('port'), 
-                                                      options.get('user'))
+    cmd_line = "%s -c '\q' mpuls_maintenance" % build_commandline(options)
     return exec_command(cmd_line)
 
 def check_mpulsdb(options, args=None):
     # Just connect to the database. Imideatly cloes connection
     dbname = "ka_%s_db" % args[0] 
-    cmd_line = "psql --host=%s --port=%s --username=%s -c '\q' %s" % (options.get('host'), 
-                                                      options.get('port'), 
-                                                      options.get('user'),
-                                                      dbname)
+    cmd_line = "%s -c '\q' %s" % (build_commandline(options), dbname)
     return exec_command(cmd_line)
 
 def init_cluster(options):
     # Just connect to the database. Imideatly cloes connection
-    cmd_line = "psql --host=%s --port=%s --username=%s -c '\i %s'" % (options.get('host'), 
-                                                      options.get('port'), 
-                                                      options.get('user'),
-                                                      get_path('mpuls-init-cluster.sql'))
+    cmd_line = "%s -f %s" % (build_commandline(options), get_path('mpuls-init-cluster.sql'))
     return exec_command(cmd_line)
 
 def create_db(options, dbname):
@@ -87,10 +88,7 @@
     print "Creating db %s ... " % dbname,
     sql_tmpl = Template(open(get_path('mpuls-create-db.sql')).read())
     sql = sql_tmpl.substitute(d)
-    cmd_line = "psql --host=%s --port=%s --username=%s -t mpuls_maintenance -c '%s';" % (options.get('host'), 
-                                                    options.get('port'), 
-                                                    options.get('user'),
-                                                    sql)
+    cmd_line = "%s -t mpuls_maintenance -c '%s';" % (build_commandline(options), sql)
     ret = exec_command(cmd_line, stdout="/dev/null")
     if ret:
         print "OK"
@@ -127,12 +125,7 @@
                 sql_l.append('\i %s' % get_path(script.strip(), 'install'))
                 infile.write("\n".join(sql_l))
                 infile.seek(0)
-                cmd_line = "psql --host=%s --port=%s --username=%s ka_%s_db" % (options.get('host'), 
-                                                                options.get('port'), 
-                                                                options.get('user'),
-                                                                dbname
-                                                                )
-
+                cmd_line = "%s ka_%s_db" % (build_commandline(options), dbname)
                 ret = exec_command(cmd_line, stdin=infile, stdout='/dev/null', stderr=outfile)
                 outfile.seek(0)
                 errors = outfile.read()
@@ -166,16 +159,11 @@
     # 1. Drop database
     dbnamel = "ka_%s_db" % dbname
     print "Dropping db %s ... " % dbnamel,
-    cmd_line = "dropdb --host=%s --port=%s --username=%s %s" % (options.get('host'), 
-                                                    options.get('port'), 
-                                                    options.get('user'),
-                                                    dbnamel)
+    cmd_line = "%s %s" % (build_commandline(options, 'dropdb'), dbnamel)
     retcode = exec_command(cmd_line)
     if not retcode: return retcode
     # 2. Drop users
-    cmd_line = "psql --host=%s --port=%s --username=%s -c 'select rolname from pg_roles'" % (options.get('host'), 
-                                                    options.get('port'), 
-                                                    options.get('user'))
+    cmd_line = "%s -c 'select rolname from pg_roles'" % (build_commandline(options))
     users = tempfile.TemporaryFile()
     ret = exec_command(cmd_line, stdout=users)
     r = re.compile('.*ka_%s_.*' % dbname) 
@@ -196,10 +184,7 @@
 
 def drop_user(options, username):
     print "Dropping user %s ... " % username,
-    cmd_line = "dropuser --host=%s --port=%s --username=%s %s" % (options.get('host'), 
-                                                    options.get('port'), 
-                                                    options.get('user'),
-                                                    username)
+    cmd_line = "%s %s" % (build_commandline(options, cmd='dropuser'), username)
     ret = exec_command(cmd_line)
     if ret:
         print "Ok"
@@ -214,14 +199,13 @@
     print "Initiate db %s ... " % dbname,
     sql_tmpl = Template(open(get_path('mpuls-init-db.sql')).read())
     sql = sql_tmpl.substitute(d)
-    cmd_line = """psql --host=%s --port=%s --username=%s -t mpuls_maintenance -c "%s";""" % (options.get('host'), 
-                                                    options.get('port'), 
-                                                    options.get('user'),
-                                                    sql)
+    cmd_line = """%s -t mpuls_maintenance -c "%s";""" % (build_commandline(options), sql)
     pw = None
     tmp = tempfile.TemporaryFile()
+    ret = None
+    pfile = '/tmp/passwords.txt'
     try:
-        pw = open('passwords.txt', 'a')
+        pw = open(pfile, 'a')
         ret = exec_command(cmd_line, stdout=tmp)
         tmp.seek(0)
         pw.write("%s    %s\n" % (dbname, tmp.read()))
@@ -232,7 +216,7 @@
             pw.close
 
     if ret:
-        print "Ok"
+        print "Ok. Password under %s" % pfile
         return ret
     else:
         print "Failed"
@@ -253,16 +237,16 @@
 
         def __add_options(self):
             self.parser.add_option('--user', 
-                              default='postgres', 
+                              default=None, 
                               help='Connect to the database with the given user [default: %default]')
             self.parser.add_option('--password', 
                               default=None, 
                               help='Connect to the database with the given password [default: %default]')
             self.parser.add_option('--host', 
-                              default='localhost', 
+                              default=None, 
                               help='Connect to the database on the the given host [default: %default]')
             self.parser.add_option('--port', 
-                              default='5432',
+                              default=None,
                               help='Connect to the database on the the given port [default: %default]')
             self.parser.add_option('--script-dir', 
                               default=None,

Modified: base/trunk/mpulsweb.egg-info/PKG-INFO
===================================================================
--- base/trunk/mpulsweb.egg-info/PKG-INFO	2011-03-11 10:06:03 UTC (rev 4774)
+++ base/trunk/mpulsweb.egg-info/PKG-INFO	2011-03-11 10:06:55 UTC (rev 4775)
@@ -1,6 +1,6 @@
 Metadata-Version: 1.0
 Name: mpulsweb
-Version: 2.0.0-predev-r4614
+Version: 2.0.0-predev-r4770
 Summary: mpuls ist ein Web-Applikations-Rahmen zur Verwaltung                  von elektronischen Fallakten (Schwerpunkt Sozialinformatik)
 Home-page: http://wald.intevation.org/projects/mpuls/
 Author: Intevation GmbH

Modified: base/trunk/mpulsweb.egg-info/SOURCES.txt
===================================================================
--- base/trunk/mpulsweb.egg-info/SOURCES.txt	2011-03-11 10:06:03 UTC (rev 4774)
+++ base/trunk/mpulsweb.egg-info/SOURCES.txt	2011-03-11 10:06:55 UTC (rev 4775)
@@ -13,6 +13,7 @@
 setup.py
 contrib/apache/apache-site-proxy.conf
 contrib/apache/apache-site-wsgi.conf
+contrib/apache/check_connection.wsgi
 contrib/apache/mpuls.wsgi
 docs/index.txt
 ez_setup/README.txt
@@ -1243,6 +1244,7 @@
 mpulsweb/templates/casebundle/editor.mako
 mpulsweb/templates/casebundle/standin.mako
 mpulsweb/templates/casebundle/dialogs/confirm_anonymize.mako
+mpulsweb/templates/casebundle/dialogs/download_formletter.mako
 mpulsweb/templates/casebundle/dialogs/error.mako
 mpulsweb/templates/casebundle/dialogs/success_anonymize.mako
 mpulsweb/templates/casebundle/dialogs/success_delete_admin.mako



More information about the Mpuls-commits mailing list