manage.py :  » ERP » frePPLe » frepple-0.8.0 » contrib » installer » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » ERP » frePPLe 
frePPLe » frepple 0.8.0 » contrib » installer » manage.py
#
# Copyright (C) 2007 by Johan De Taeye
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#

# file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/tags/0.8.0/contrib/installer/manage.py $
# revision : $LastChangedRevision: 1075 $  $LastChangedBy: jdetaeye $
# date : $LastChangedDate: 2009-10-10 13:31:38 +0200 (Sat, 10 Oct 2009) $

import sys, os, os.path
from stat import S_ISDIR,ST_MODE

from django.core.management import execute_manager,call_command

# Environment settings (which are used in the Django settings file and need
# to be updated BEFORE importing the settings)
os.environ['DJANGO_SETTINGS_MODULE'] = 'freppledb.settings'
os.environ['FREPPLE_APP'] = os.path.split(sys.path[0])[0]

# Sys.path contains the zip file with all packages. We need to put the
# freppledb subdirectory from the zip-file separately on the path because
# our django applications never refer to the project name.
sys.path = [ os.path.join(sys.path[0],'freppledb'), sys.path[0] ]

# Default command is to run the web server
if len(sys.argv) <= 1:
  sys.argv.append('frepple_runserver')

# Import django settings
from django.conf import settings

# Override the debugging settings
settings.DEBUG = False
settings.TEMPLATE_DEBUG = False

# Update the directories where fixtures are searched
settings.FIXTURE_DIRS = (
  os.path.join(settings.FREPPLE_APP,'fixtures','input').replace('\\','/'),
  os.path.join(settings.FREPPLE_APP,'fixtures','common').replace('\\','/'),
)

# Update the template dirs
settings.TEMPLATE_DIRS = (
    # Always use forward slashes, even on Windows.
    os.path.join(settings.FREPPLE_APP,'templates2').replace('\\','/'),
    os.path.join(settings.FREPPLE_APP,'templates1').replace('\\','/'),
    settings.FREPPLE_HOME.replace('\\','/'),
)

# Create the database if it doesn't exist yet
noDatabaseSchema = False
if settings.DATABASE_ENGINE == 'sqlite3':
  # Verify if the sqlite database file exists
  if not os.path.isfile(settings.DATABASE_NAME):
    noDatabaseSchema = True
elif settings.DATABASE_ENGINE not in ['postgresql_psycopg2', 'mysql', 'oracle']:
    print 'Aborting: Unknown database engine %s' % settings.DATABASE_ENGINE
    raw_input("Hit any key to continue...")
    sys.exit(1)
else:
  # PostgreSQL, Oracle or MySQL database:
  # Try connecting and check for a table called 'plan'.
  from django.db import connection,transaction
  try: cursor = connection.cursor()
  except Exception, e:
    print "Aborting: Can't connect to the database"
    print "   %s" % e
    raw_input("Hit any key to continue...")
    sys.exit(1)
  try: cursor.execute("SELECT name FROM plan")
  except: noDatabaseSchema = True
  transaction.commit_unless_managed()

if noDatabaseSchema:
  print "\nDatabase schema %s doesn't exist." % settings.DATABASE_NAME
  confirm = raw_input("Do you want to create it now? (yes/no): ")
  while confirm not in ('yes', 'no'):
    confirm = raw_input('Please enter either "yes" or "no": ')
  if confirm == 'yes':
    # Create the database
    print "\nCreating database scheme"
    call_command('syncdb', verbosity=1)

# Execute the command
import freppledb.settings
execute_manager(freppledb.settings, sys.argv)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.