diff options
| author | Antony Lesuisse <lesuisse@gmail.com> | 2014-05-29 18:33:04 +0200 |
|---|---|---|
| committer | Antony Lesuisse <lesuisse@gmail.com> | 2014-05-29 18:33:04 +0200 |
| commit | d4624fa826a5e9542782f2c53c8ba2c766d093bc (patch) | |
| tree | be214779eb6d1f17157aa48e72fbcbf95405e38b /openerpcommand/drop.py | |
| parent | 045ecc603e67911a5390c812cb6b5b123d9c190e (diff) | |
[IMP] repository cleanup
- move packaging stuff to setup
- remove historical stuff
- remove oe, odoo-cmd-fme will be merged with the convered commands
- add an odoo.py script to run odo and boostrap it
- simplify README
- prepare to move documentation to the github wiki
Diffstat (limited to 'openerpcommand/drop.py')
| -rw-r--r-- | openerpcommand/drop.py | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/openerpcommand/drop.py b/openerpcommand/drop.py deleted file mode 100644 index b64442716de..00000000000 --- a/openerpcommand/drop.py +++ /dev/null @@ -1,50 +0,0 @@ -""" -Drop a database. -""" - -import common - -# TODO turn template1 in a parameter -# This should be exposed from openerp (currently in -# openerp/service/web_services.py). -def drop_database(database_name): - import openerp - openerp.netsvc.init_logger() - db = openerp.sql_db.db_connect('template1') - cr = db.cursor() - cr.autocommit(True) # avoid transaction block - try: - # TODO option for doing this. - # Try to terminate all other connections that might prevent - # dropping the database - - # PostgreSQL 9.2 renamed pg_stat_activity.procpid to pid: - # http://www.postgresql.org/docs/9.2/static/release-9-2.html#AEN110389 - pid_col = 'pid' if cr._cnx.server_version >= 90200 else 'procpid' - try: - cr.execute("""SELECT pg_terminate_backend(%(pid_col)s) - FROM pg_stat_activity - WHERE datname = %%s AND - %(pid_col)s != pg_backend_pid()""" % {'pid_col': pid_col}, - (database_name,)) - except Exception: - pass - - try: - cr.execute('DROP DATABASE "%s"' % database_name, log_exceptions=False) - except Exception, e: - print "Can't drop %s" % (database_name,) - finally: - cr.close() - -def run(args): - assert args.database - drop_database(args.database) - -def add_parser(subparsers): - parser = subparsers.add_parser('drop', - description='Drop a database.') - parser.add_argument('-d', '--database', metavar='DATABASE', - **common.required_or_default('DATABASE', 'the database to create')) - - parser.set_defaults(run=run) |
