Skip to content

Instantly share code, notes, and snippets.

@kmmbvnr
Created September 2, 2010 07:33
Show Gist options
  • Select an option

  • Save kmmbvnr/562005 to your computer and use it in GitHub Desktop.

Select an option

Save kmmbvnr/562005 to your computer and use it in GitHub Desktop.

Revisions

  1. kmmbvnr revised this gist Mar 7, 2011. 2 changed files with 30 additions and 38 deletions.
    Empty file added gistfile1.txt
    Empty file.
    68 changes: 30 additions & 38 deletions manage.py
    Original file line number Diff line number Diff line change
    @@ -1,54 +1,46 @@
    #!/usr/bin/env python2.6
    # -*- coding: utf-8 -*-
    from os import path
    import shutil, sys, virtualenv, subprocess
    import shutil, sys

    try:
    from ve_setup import use_virtualenv
    except ImportError:
    import urllib
    urllib.urlretrieve("http://tiny.cc/ve-setup", 've_setup.py')
    from ve_setup import use_virtualenv


    PROJECT_ROOT = path.abspath(path.dirname(__file__))
    REQUIREMENTS = path.join(PROJECT_ROOT, 'requirements.pip')

    VE_ROOT = path.join(PROJECT_ROOT, '.ve')
    VE_TIMESTAMP = path.join(VE_ROOT, 'timestamp')
    VE_ACTIVATE = path.join(VE_ROOT, 'bin', 'activate_this.py')

    envtime = path.exists(VE_ROOT) and path.getmtime(VE_ROOT) or 0
    envreqs = path.exists(VE_TIMESTAMP) and path.getmtime(VE_TIMESTAMP) or 0
    envspec = path.getmtime(REQUIREMENTS)

    def go_to_ve():
    # going into ve
    if not sys.prefix == VE_ROOT:
    if sys.platform == 'win32':
    python = path.join(VE_ROOT, 'Scripts', 'python.exe')
    else:
    python = path.join(VE_ROOT, 'bin', 'python')

    retcode = subprocess.call([python, __file__] + sys.argv[1:])
    sys.exit(retcode)

    update_ve = 'update_ve' in sys.argv
    if update_ve or envtime < envspec or envreqs < envspec:
    if update_ve:
    # install ve
    if envtime < envspec:
    if path.exists(VE_ROOT):
    shutil.rmtree(VE_ROOT)
    virtualenv.logger = virtualenv.Logger(consumers=[])
    virtualenv.create_environment(VE_ROOT, site_packages=True)

    go_to_ve()

    # check requirements
    if update_ve or envreqs < envspec:
    import pip
    pip.main(initial_args=['install', '-r', REQUIREMENTS])
    file(VE_TIMESTAMP, 'w').close()
    sys.exit(0)
    else:
    print "VirtualEnv need to be updated"
    print "Run ./manage.py update_ve"
    sys.exit(1)

    go_to_ve()

    def setup_ve():
    use_virtualenv(argv=[VE_ROOT],
    requirements="requirements.pip",
    activate=True)


    if 'update_ve' in sys.argv:
    if path.exists(VE_ROOT):
    shutil.rmtree(VE_ROOT)
    setup_ve()
    file(VE_TIMESTAMP, 'w').close()
    sys.exit(0)
    elif envreqs < envspec:
    print "VirtualEnv need to be updated"
    print "Run ./manage.py update_ve"
    sys.exit(1)


    setup_ve()


    # run django
    from django.core.management import execute_manager
  2. kmmbvnr revised this gist Sep 28, 2010. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions manage.py
    Original file line number Diff line number Diff line change
    @@ -25,8 +25,9 @@ def go_to_ve():
    retcode = subprocess.call([python, __file__] + sys.argv[1:])
    sys.exit(retcode)

    if envtime < envspec or envreqs < envspec:
    if 'update_ve' in sys.argv:
    update_ve = 'update_ve' in sys.argv
    if update_ve or envtime < envspec or envreqs < envspec:
    if update_ve:
    # install ve
    if envtime < envspec:
    if path.exists(VE_ROOT):
    @@ -37,7 +38,7 @@ def go_to_ve():
    go_to_ve()

    # check requirements
    if envreqs < envspec:
    if update_ve or envreqs < envspec:
    import pip
    pip.main(initial_args=['install', '-r', REQUIREMENTS])
    file(VE_TIMESTAMP, 'w').close()
  3. kmmbvnr revised this gist Sep 22, 2010. 1 changed file with 34 additions and 22 deletions.
    56 changes: 34 additions & 22 deletions manage.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    #!/usr/bin/env python
    #!/usr/bin/env python2.6
    # -*- coding: utf-8 -*-
    from os import path
    import shutil, sys, virtualenv, subprocess

    @@ -13,29 +14,40 @@
    envreqs = path.exists(VE_TIMESTAMP) and path.getmtime(VE_TIMESTAMP) or 0
    envspec = path.getmtime(REQUIREMENTS)

    # install ve
    if envtime < envspec:
    if path.exists(VE_ROOT):
    shutil.rmtree(VE_ROOT)
    virtualenv.logger = virtualenv.Logger(consumers=[])
    virtualenv.create_environment(VE_ROOT, site_packages=True)

    # going into ve
    if not sys.prefix == VE_ROOT:
    if sys.platform == 'win32':
    python = path.join(VE_ROOT, 'Scripts', 'python.exe')
    def go_to_ve():
    # going into ve
    if not sys.prefix == VE_ROOT:
    if sys.platform == 'win32':
    python = path.join(VE_ROOT, 'Scripts', 'python.exe')
    else:
    python = path.join(VE_ROOT, 'bin', 'python')

    retcode = subprocess.call([python, __file__] + sys.argv[1:])
    sys.exit(retcode)

    if envtime < envspec or envreqs < envspec:
    if 'update_ve' in sys.argv:
    # install ve
    if envtime < envspec:
    if path.exists(VE_ROOT):
    shutil.rmtree(VE_ROOT)
    virtualenv.logger = virtualenv.Logger(consumers=[])
    virtualenv.create_environment(VE_ROOT, site_packages=True)

    go_to_ve()

    # check requirements
    if envreqs < envspec:
    import pip
    pip.main(initial_args=['install', '-r', REQUIREMENTS])
    file(VE_TIMESTAMP, 'w').close()
    sys.exit(0)
    else:
    python = path.join(VE_ROOT, 'bin', 'python')

    retcode = subprocess.call([python, __file__] + sys.argv[1:])
    sys.exit(retcode)

    # check requirements
    if envreqs < envspec:
    import pip
    pip.main(initial_args=['install', '-r', REQUIREMENTS])
    file(VE_TIMESTAMP, 'w').close()
    print "VirtualEnv need to be updated"
    print "Run ./manage.py update_ve"
    sys.exit(1)

    go_to_ve()

    # run django
    from django.core.management import execute_manager
  4. kmmbvnr created this gist Sep 2, 2010.
    50 changes: 50 additions & 0 deletions manage.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    #!/usr/bin/env python
    from os import path
    import shutil, sys, virtualenv, subprocess

    PROJECT_ROOT = path.abspath(path.dirname(__file__))
    REQUIREMENTS = path.join(PROJECT_ROOT, 'requirements.pip')

    VE_ROOT = path.join(PROJECT_ROOT, '.ve')
    VE_TIMESTAMP = path.join(VE_ROOT, 'timestamp')
    VE_ACTIVATE = path.join(VE_ROOT, 'bin', 'activate_this.py')

    envtime = path.exists(VE_ROOT) and path.getmtime(VE_ROOT) or 0
    envreqs = path.exists(VE_TIMESTAMP) and path.getmtime(VE_TIMESTAMP) or 0
    envspec = path.getmtime(REQUIREMENTS)

    # install ve
    if envtime < envspec:
    if path.exists(VE_ROOT):
    shutil.rmtree(VE_ROOT)
    virtualenv.logger = virtualenv.Logger(consumers=[])
    virtualenv.create_environment(VE_ROOT, site_packages=True)

    # going into ve
    if not sys.prefix == VE_ROOT:
    if sys.platform == 'win32':
    python = path.join(VE_ROOT, 'Scripts', 'python.exe')
    else:
    python = path.join(VE_ROOT, 'bin', 'python')

    retcode = subprocess.call([python, __file__] + sys.argv[1:])
    sys.exit(retcode)

    # check requirements
    if envreqs < envspec:
    import pip
    pip.main(initial_args=['install', '-r', REQUIREMENTS])
    file(VE_TIMESTAMP, 'w').close()


    # run django
    from django.core.management import execute_manager
    try:
    import settings # Assumed to be in the same directory.
    except ImportError:
    import sys
    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory")
    sys.exit(1)

    if __name__ == "__main__":
    execute_manager(settings)