# Path: djangojames/db/utils.py
# def dump_db(database_config, outputpath='/tmp/'):
#     db_engine = _get_engine(database_config)
#     database_config['OUTPUT_FILE'] = os.path.join(outputpath, get_dumpdb_name())
#     #from fabric.api import local
#     
#     if db_engine in ['postgresql_psycopg2', 'postgresql']:     
#         cmd = 'pg_dump -U postgres %(NAME)s > %(OUTPUT_FILE)s' % database_config
#     elif db_engine == 'mysql':
#         
#         if database_config['HOST']:
#             database_config['HOST'] = '--host %s' % database_config['HOST']
#         cmd = '/usr/bin/mysqldump %(NAME)s %(HOST)s -u %(USER)s -p%(PASSWORD)s >  %(OUTPUT_FILE)s' % database_config
#     else:
#         raise NotImplementedError, "This database backend is not yet supported: %s" % db_engine    
# 
#     print cmd
#     call(cmd, shell=True)


from django.core.management.base import NoArgsCommand
from optparse import make_option
from djangojames.db.utils import dump_db
        from django.db.utils import DEFAULT_DB_ALIAS
        from django.conf import settings
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#


class Command(NoArgsCommand):
    help = "Dumps the project db"
    flag = __name__

    option_list = NoArgsCommand.option_list + (
        make_option('--outputpath',
            help='a directory to write the dump to'),  
    )

    def handle_noargs(self, **options): 
        
        db = options.get('database', DEFAULT_DB_ALIAS)
        outputpath = options.get('outputpath', settings.PROJECT_ROOT) 
        
        if outputpath is None:
            outputpath = settings.PROJECT_ROOT
        
        database_config = settings.DATABASES[db]       
        

# Path: djangojames/db/utils.py
# def dump_db(database_config, outputpath='/tmp/'):
#     db_engine = _get_engine(database_config)
#     database_config['OUTPUT_FILE'] = os.path.join(outputpath, get_dumpdb_name())
#     #from fabric.api import local
#     
#     if db_engine in ['postgresql_psycopg2', 'postgresql']:     
#         cmd = 'pg_dump -U postgres %(NAME)s > %(OUTPUT_FILE)s' % database_config
#     elif db_engine == 'mysql':
#         
#         if database_config['HOST']:
#             database_config['HOST'] = '--host %s' % database_config['HOST']
#         cmd = '/usr/bin/mysqldump %(NAME)s %(HOST)s -u %(USER)s -p%(PASSWORD)s >  %(OUTPUT_FILE)s' % database_config
#     else:
#         raise NotImplementedError, "This database backend is not yet supported: %s" % db_engine    
# 
#     print cmd
#     call(cmd, shell=True)


# Path: djangojames/management/commands/dumpdb.py
from django.core.management.base import NoArgsCommand
from optparse import make_option
from djangojames.db.utils import dump_db
        from django.db.utils import DEFAULT_DB_ALIAS
        from django.conf import settings

# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#


class Command(NoArgsCommand):
    help = "Dumps the project db"
    flag = __name__

    option_list = NoArgsCommand.option_list + (
        make_option('--outputpath',
            help='a directory to write the dump to'),  
    )

    def handle_noargs(self, **options): 
        
        db = options.get('database', DEFAULT_DB_ALIAS)
        outputpath = options.get('outputpath', settings.PROJECT_ROOT) 
        
        if outputpath is None:
            outputpath = settings.PROJECT_ROOT
        
        database_config = settings.DATABASES[db]       
        

        dump_db(database_config, outputpath)