Ticket #2868: runscript.diff

File runscript.diff, 1.5 KB (added by adurdin@…, 8 years ago)
  • django/core/management.py

     
    11891189        code.interact()
    11901190run_shell.args = '[--plain]'
    11911191
     1192def runscript(script):
     1193    "Runs a python script in the current environment."
     1194    import os.path
     1195    script = os.path.abspath(script)
     1196    new_globals = globals().copy()
     1197    new_globals.update({"__name__": "__main__",
     1198                        "__file__": script})
     1199    try:
     1200        execfile(script, new_globals, {})
     1201    except IOError, e:
     1202        sys.stderr.write(style.ERROR("%s\n" % e))
     1203        sys.exit(1)
     1204runscript.args = '[path/to/python/script]'
     1205
    11921206def dbshell():
    11931207    "Runs the command-line client for the current DATABASE_ENGINE."
    11941208    from django.db import runshell
     
    12441258    'runfcgi': runfcgi,
    12451259    'runserver': runserver,
    12461260    'shell': run_shell,
     1261    'runscript': runscript,
    12471262    'sql': get_sql_create,
    12481263    'sqlall': get_sql_all,
    12491264    'sqlclear': get_sql_delete,
     
    13681383        except IndexError:
    13691384            parser.print_usage_and_exit()
    13701385        action_mapping[action](name, os.getcwd())
     1386    elif action == 'runscript':
     1387        if len(args) != 2:
     1388            sys.stderr.write(style.ERROR("Error: You must specify a script to run.\n"))
     1389            sys.exit(1)
     1390        script = args[1]
     1391        action_mapping[action](script)
    13711392    elif action == 'runserver':
    13721393        if len(args) < 2:
    13731394            addr = ''
Back to Top