Ticket #2947: management_import_patch.diff
File management_import_patch.diff, 2.0 KB (added by , 18 years ago) |
---|
-
django/core/management.py
429 429 get_sql_all.help_doc = "Prints the CREATE TABLE, initial-data and CREATE INDEX SQL statements for the given model module name(s)." 430 430 get_sql_all.args = APP_ARGS 431 431 432 def _find_module_with_dots(name, paths=None): 433 """Like imp.find_module, but supports module names with zero or more dots.""" 434 import imp 435 dotindex = name.find('.') 436 if dotindex == -1: 437 return imp.find_module(name, paths) 438 else: 439 parent_name = name[:dotindex] 440 parent_path = imp.find_module(parent_name, paths)[1] 441 return _find_module_with_dots(name[dotindex+1:], [parent_path]) 442 443 def _module_exists(modulename): 444 try: 445 _find_module_with_dots(modulename) 446 return True 447 except ImportError: 448 return False 449 450 451 def _import_module_if_it_exists(modname, *args, **kwargs): 452 try: 453 return __import__(modname, *args, **kwargs) 454 except ImportError, e: 455 if _module_exists(modname): 456 # the module exists and yet raised an ImportError. Why? 457 raise e 458 else: 459 # it's okay if the module doesn't exist 460 return False 461 432 462 def syncdb(verbosity=1, interactive=True): 433 463 "Creates the database tables for all apps in INSTALLED_APPS whose tables haven't already been created." 434 464 from django.db import connection, transaction, models, get_creation_module … … 444 474 # Import the 'management' module within each installed app, to register 445 475 # dispatcher events. 446 476 for app_name in settings.INSTALLED_APPS: 447 try: 448 __import__(app_name + '.management', '', '', ['']) 449 except ImportError: 450 pass 451 477 modname = app_name + '.management' 478 _import_module_if_it_exists(modname) 479 452 480 data_types = get_creation_module().DATA_TYPES 453 481 454 482 cursor = connection.cursor()