#!/usr/local/bin/python
#coding:utf-8
import sys, os
import datetime
from django.core.management import setup_environ, DEFAULT_ACTION_MAPPING, startapp
try:
import settings # Assumed to be in the same directory.
except ImportError:
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
sys.exit(1)
project_directory = setup_environ(settings)
project_name = os.path.basename(project_directory)
os.environ['DJANGO_SETTINGS_MODULE'] = "%s.settings" % project_name
if __name__ == "__main__":
if len(sys.argv) <=1:
sys.stderr.write("run xxx.yyy.run p1 p2 p2")
sys.exit(1)
classpath = sys.argv[1].split('.')
if len(classpath) > 0:
pkg = '.'.join(classpath[:-1])
fr = classpath[-1]
else:
sys.stderr.write("path must has form of aaa.bbb")
sys.exit(1)
try:
mod = __import__( pkg, '', '', fr)
except ImportError:
sys.stderr.write("path can't be found")
sys.exit(1)
cls = getattr(mod, fr)
params = []
for i in range(0,len(sys.argv)):
if i != 1:
params.append( sys.argv[i])
cls(params)
Comments