Ejemplo n.º 1
0
def bootstrap():
    make_virtualenv(path='venv', system_site_packages=False)
    with virtualenv('venv'):
        run('pip install --upgrade pip')
        run('pip install --upgrade distribute')
        run('rm -rf codalab_src')
        run("git clone %s codalab_src" % env.django_settings.SOURCE_GIT_URL)
    put(os.path.join(THIS_SETTINGS_DIR,'deploy.py'), 'codalab_src/codalab/codalab/settings')

    with virtualenv('venv'):
        run('cd codalab_src && bash ./requirements')
Ejemplo n.º 2
0
def site_config(path=None,
                archive_name='latest_codalab_config.tar',
                url=None,
                module=None):
    spath = 'src'
    if path and os.path.exists(path):
        path = os.path.abspath(path)
    elif module:
        mod = __import__(module)
        if os.path.isdir(mod.__path__[0]):
            path = mod.__path__[0]
        else:
            raise Exception("Must be a directory module")
    with settings(warn_ony=True), lcd(path):
        res = lrun('git diff --exit-code')
        if res.return_code != 0:
            raise Exception(
                "*** Module has local changes. You must commit them.")
        tmp = tempfile.mkdtemp()
        fname = archive_name
        tmpf = os.path.join(tmp, fname)
        path = path.rstrip('/')
        lrun('git archive --prefix=%s%s -o %s HEAD' %
             (os.path.basename(path), os.path.sep, tmpf))
    env.run('mkdir -p %s' % spath)
    put(tmpf)
    env.run('tar -C %s -xvf %s' % (spath, fname))

    with virtualenv(env.venvpath):
        env.run('pip install -U --force-reinstall ./%s' %
                pathjoin(spath, os.path.basename(path)))
    env.EXTERNAL_SITE_CONFIG = True
def deploy(debug='no'):
    """
    Deploys project to previously set stage.
    """
    require('stage', provided_by=(stable, development))
    require('settings', provided_by=(stable, development))
    # Set env.
    env.user = env.settings['user']
    env.host_string = env.settings['host']

    if debug == 'no':
        _hide = ('stderr', 'stdout', 'warnings', 'running')
    else:
        _hide = ()

    with hide(*_hide):
        with lcd(project_settings['local']['code_src_directory']):
            push_repository()
        with cd(env.settings['code_src_directory']):
            pull_repository()
        with virtualenv(env.settings['venv_directory']):
            with cd(env.settings['code_src_directory']):
                install_requirements()
                if project_settings.get('git_submodules', False):
                    pull_repository_submodules()
                migrate_models()
                if project_settings.get('scss', False):
                    compile_scss()
                collect_static()
        restart_application()
Ejemplo n.º 4
0
def hotdeploy():
    with cd(env.path):
        run("git pull %(push_remote)s %(push_branch)s" % env)
        compile_less()
        with virtualenv(env.virtualenv_path):
            run("./manage.py collectstatic --noinput")
    reload_webserver()
Ejemplo n.º 5
0
def update():
    with cd(env.path):
        run("git pull %(push_remote)s %(push_branch)s" % env)
        with virtualenv(env.virtualenv_path):
            run("pip install -r requirements.txt")
            run("./manage.py collectstatic --noinput")
            run("cd ecobasa && django-admin.py compilemessages")
Ejemplo n.º 6
0
def test_tarball(release='2'):
    """
    Test that the tarball can be unpacked and installed, and that sympy
    imports in the install.
    """
    if release not in {'2', '3'}:  # TODO: Add win32
        raise ValueError("release must be one of '2', '3', not %s" % release)

    venv = "/home/vagrant/repos/test-{release}-virtualenv".format(
        release=release)

    # We have to run this outside the virtualenv to make sure the version
    # check runs in Python 2
    tarball_formatter_dict = _tarball_formatter()
    with use_venv(release):
        make_virtualenv(venv)
        with virtualenv(venv):
            if release == '2':
                run("cp /vagrant/release/{py2} releasetar.tar".format(
                    **tarball_formatter_dict))
            if release == '3':
                run("cp /vagrant/release/{py33} releasetar.tar".format(
                    **tarball_formatter_dict))
            run("tar xvf releasetar.tar")
            with cd("/home/vagrant/{source-orig-notar}".format(
                    **tarball_formatter_dict)):
                run("python setup.py install")
                run('python -c "import sympy; print(sympy.__version__)"')
Ejemplo n.º 7
0
def update():
    with cd(env.path):
        run("git pull %(push_remote)s %(push_branch)s" % env)
        with virtualenv(env.virtualenv_path):
            run("pip install -r requirements.txt")
            run("./manage.py collectstatic --noinput")
            run("cd ecobasa && django-admin.py compilemessages")
Ejemplo n.º 8
0
def update():
    # Make sure the post-receive hook is up-to-date
    with cd('/var/repo/site.git'):
        sudo('chown qalelander:qalelander -R .')
        put('post-receive.hook', 'hooks/post-receive')
        run('chmod +x hooks/post-receive')

    # Push the server
    local('git push live master --force')
    run('git --work-tree=/var/www/site --git-dir=/var/repo/site.git checkout -f')

    # Update the nginx and upstart config
    with cd('/var/www/site'):
        sudo('cp capes.nginx /etc/nginx/sites-available/capes')
        sudo('cp capes.conf /etc/init/capes.conf')
        sudo('ln -s /etc/nginx/sites-available/capes /etc/nginx/sites-enabled', quiet=True)

        with virtualenv(env.virtualenv_dir):
            # Update pip dependencies
            run('pip-sync')

            # Migrate the database if necessary
            run('python manage.py collectstatic --noinput')

    # Restart the upstart and nginx services
    sudo('sudo service nginx reload')
    sudo('sudo service capes restart')
Ejemplo n.º 9
0
def restart_supervisor():
    with virtualenv(env.venvpath),cd(env.DEPLOY_PATH):
        if not exists('codalab/var/supervisord.pid', verbose=True):
            env.run('./supervisor')
        else:
            env.run('./supervisorctl update')
            env.run('./supervisorctl restart all')
Ejemplo n.º 10
0
def site_config(path=None,archive_name='latest_codalab_config.tar',url=None,module=None):
    spath = 'src'
    if path and os.path.exists(path):
        path = os.path.abspath(path)
    elif module:
        mod = __import__(module)
        if os.path.isdir(mod.__path__[0]):
            path = mod.__path__[0]
        else:
            raise Exception("Must be a directory module")
    with settings(warn_ony=True),lcd(path):
        res = lrun('git diff --exit-code')
        if res.return_code != 0:
            raise Exception("*** Module has local changes. You must commit them.")
        tmp = tempfile.mkdtemp()
        fname = archive_name
        tmpf =  os.path.join(tmp,fname)
        path = path.rstrip('/')
        lrun('git archive --prefix=%s%s -o %s HEAD' % (os.path.basename(path),os.path.sep,tmpf))
    env.run('mkdir -p %s' % spath)
    put(tmpf)
    env.run('tar -C %s -xvf %s' % (spath,fname))
    
    with virtualenv(env.venvpath):
        env.run('pip install -U --force-reinstall ./%s' % pathjoin(spath,os.path.basename(path)))
    env.EXTERNAL_SITE_CONFIG = True
Ejemplo n.º 11
0
def install():
    '''
    Installs project to previously set stage.
    '''
    require('stage', provided_by=(stable, development))
    require('settings', provided_by=(stable, development))
    # Set env.
    env.user = env.settings['user']
    env.host_string = env.settings['host']

    # upgrade_system()
    install_software()
    with hide('stderr', 'stdout', 'warnings', 'running'):
        clone_repository()
        create_virtualenv()
        with virtualenv(env.settings['venv_directory']):
            with cd(env.settings['code_src_directory']):
                install_requirements()
                create_key()
                create_database()
                deploy_gunicorn()
                make_migrations()
                migrate_models()
                collect_static()
            deploy_fail2ban()
            deploy_nginx()
            deploy_iptables()
        restart()
Ejemplo n.º 12
0
def restart_supervisor():
    with virtualenv(env.venvpath), cd(env.DEPLOY_PATH):
        if not exists('codalab/var/supervisord.pid', verbose=True):
            env.run('./supervisor')
        else:
            env.run('./supervisorctl update')
            env.run('./supervisorctl restart all')
Ejemplo n.º 13
0
def build_docs():
    """
    Build the html and pdf docs
    """
    with cd("/home/vagrant/repos/sympy"):
        run("mkdir -p dist")
        venv = "/home/vagrant/docs-virtualenv"
        make_virtualenv(venv,
                        dependencies=['sphinx==1.1.3', 'numpy', 'mpmath'])
        with virtualenv(venv):
            with cd("/home/vagrant/repos/sympy/doc"):
                run("make clean")
                run("make html-errors")
                run("make man")
                with cd("/home/vagrant/repos/sympy/doc/_build"):
                    run("mv html {html-nozip}".format(**tarball_formatter()))
                    run("zip -9lr {html} {html-nozip}".format(
                        **tarball_formatter()))
                    run("cp {html} ../../dist/".format(**tarball_formatter()))
                run("make clean")
                run("make latex")
                with cd("/home/vagrant/repos/sympy/doc/_build/latex"):
                    run("make")
                    run("cp {pdf-orig} ../../../dist/{pdf}".format(
                        **tarball_formatter()))
def deploy():
    update()
    with cd(env.path):
        with virtualenv(env.virtualenv_path):
            run("python manage.py syncdb")
            run("python manage.py migrate")
            run("python manage.py collectstatic --noinput")
            run("supervisorctl restart ecg")
Ejemplo n.º 15
0
def update_requirements():
    """ Update external dependencies on host """
    with virtualenv(VIRTUALENV_PATH):
        cmd = ['pip install']
        cmd += [
            '--requirement %s' % os.path.join(CODE_DIR, 'requirements.txt')
        ]
        run(' '.join(cmd))
Ejemplo n.º 16
0
def autopep8(path_to_file):
    """Run autopep8 on a file"""
    with virtualenv(VENV_ROOT):
        with hide('running'):
            with settings(warn_only=True):
                return run(
                    "autopep8 --experimental --aggressive --aggressive -i --max-line-length=119 {}"
                    .format(path_to_file), )
Ejemplo n.º 17
0
def update_release():
    welcome()
    with virtualenv(env.venv):
        with cd(env.directory):
            run('git pull')
            manage('compilemessages')
            manage('collectstatic --noinput')
            reload()
def requirements():
    sync()
    pull()
    with cd(project):
        with virtualenv(venv):
            run('pip install -r requirements')
        reset()
    serlog()
Ejemplo n.º 19
0
def update():
    ''' Only deploy and reload modules from git, do no installing or migrating'''
    with cd(env.path):
        run("git pull %(push_remote)s %(push_branch)s" % env)
        compile_less()
        with virtualenv(env.virtualenv_path):
            run("./manage.py collectstatic --noinput")

    reload_webserver()
Ejemplo n.º 20
0
def test():
    """Run tests on the code"""

    with cd(PROJECT_ROOT):
        with virtualenv(VENV_ROOT):

            run('pip uninstall -y pybitmessage')
            run('python setup.py install')

            run('pybitmessage -t')
            run('python setup.py test')
Ejemplo n.º 21
0
def deploy():
    with cd(env.path):
        run("git pull %(push_remote)s %(push_branch)s" % env)
        compile_less()
        with virtualenv(env.virtualenv_path):
            run("pip install -Ur requirements.txt")
            run("./manage.py collectstatic --noinput")

    migrate()
    reload_webserver()
    ping()
Ejemplo n.º 22
0
def test():
    """Run tests on the code"""

    with cd(PROJECT_ROOT):
        with virtualenv(VENV_ROOT):

            run('pip uninstall -y bmsxmlrpc')
            run('python setup.py install')

            run('bmsxmlrpc -t')
            run('python ./setup.py test')
Ejemplo n.º 23
0
def collectstatic():
    with cd(env.path):
        with virtualenv(env.virtualenv_path):
            if env.portal_instances:
                for portal in env.portal_instances:
                    # this will collect the staticfiles for each portal into a seperate folder
                    # nginx or whichever server will need to point each subdomain to their
                    # respective folder to serve static files
                    run("./manage.py collectstatic --noinput --cosinnus-portal %s"
                        % portal)
            else:
                run("./manage.py collectstatic --noinput")
Ejemplo n.º 24
0
def update(tag=None):
    with virtualenv(env.venvpath):
        with cd(env.DEPLOY_PATH):
            env.run('git pull')
            if tag:
               update_to_tag(tag=tag)
            requirements()          
            with cd('codalab'):
                config_gen(config=env.DJANGO_CONFIG,settings_module=env.SETTINGS_MODULE)
                env.run('./manage syncdb --noinput')
                # When South is enabled
                #env.run('./manage migrate')
                env.run('./manage collectstatic --noinput')
Ejemplo n.º 25
0
def pycodestyle(path_to_file):
    """Run pycodestyle on a file"""
    with virtualenv(VENV_ROOT):
        with hide('warnings', 'running', 'stdout', 'stderr'):
            with settings(warn_only=True):
                return run(
                    'pycodestyle --config={0} {1}'.format(
                        os.path.join(
                            PROJECT_ROOT,
                            'setup.cfg',
                        ),
                        path_to_file,
                    ), )
Ejemplo n.º 26
0
def flake8(path_to_file):
    """Run flake8 on a file"""
    with virtualenv(VENV_ROOT):
        with hide('warnings', 'running', 'stdout'):
            with settings(warn_only=True):
                return run(
                    'flake8 --config={0} {1}'.format(
                        os.path.join(
                            PROJECT_ROOT,
                            'setup.cfg',
                        ),
                        path_to_file,
                    ), )
Ejemplo n.º 27
0
def build_docs(dep_graph=False, apidoc=True):
    """
    Build the documentation locally.

    :param dep_graph: Build the dependency graphs
    :type dep_graph: Bool, default False
    :param apidoc: Build the automatically generated rst files from the source code
    :type apidoc: Bool, default True

    Default usage:

        $ fab -H localhost build_docs

    Implementation:

    First, a dependency graph is generated and converted into an image that is referenced in the development page.

    Next, the sphinx-apidoc command is (usually) run which searches the code. As part of this it loads the modules and
    if this has side-effects then they will be evident. Any documentation strings that make use of Python documentation
    conventions (like parameter specification) or the Restructured Text (RsT) syntax will be extracted.

    Next, the `make html` command is run to generate HTML output. Other formats (epub, pdf) are available.

    .. todo:: support other languages

    """

    apidoc = coerce_bool(apidoc)

    if coerce_bool(dep_graph):
        create_dependency_graphs()

    with virtualenv(VENV_ROOT):
        with hide('running'):

            apidoc_result = 0
            if apidoc:
                run('mkdir -p {}'.format(
                    os.path.join(PROJECT_ROOT, 'docs', 'autodoc')))
                with cd(os.path.join(PROJECT_ROOT, 'docs', 'autodoc')):
                    with settings(warn_only=True):
                        run('rm *.rst')
                with cd(os.path.join(PROJECT_ROOT, 'docs')):
                    apidoc_result = run(
                        'sphinx-apidoc -o autodoc ..').return_code

            with cd(os.path.join(PROJECT_ROOT, 'docs')):
                make_result = run('make html').return_code
                return_code = apidoc_result + make_result

    sys.exit(return_code)
Ejemplo n.º 28
0
def pylint(path_to_file):
    """Run pylint on a file"""
    with virtualenv(VENV_ROOT):
        with hide('warnings', 'running', 'stdout', 'stderr'):
            with settings(warn_only=True):
                with shell_env(PYTHONPATH=PYTHONPATH):
                    return run(
                        'pylint --rcfile={0} {1}'.format(
                            os.path.join(
                                PROJECT_ROOT,
                                'setup.cfg',
                            ),
                            path_to_file,
                        ), )
Ejemplo n.º 29
0
def update(tag=None):
    with virtualenv(env.venvpath):
        with cd(env.DEPLOY_PATH):
            env.run('git pull')
            if tag:
                update_to_tag(tag=tag)
            requirements()
            with cd('codalab'):
                config_gen(config=env.DJANGO_CONFIG,
                           settings_module=env.SETTINGS_MODULE)
                env.run('./manage syncdb --noinput')
                # When South is enabled
                #env.run('./manage migrate')
                env.run('./manage collectstatic --noinput')
Ejemplo n.º 30
0
def deploy():
    ' 定义一个部署任务 '
    # 远程服务器的临时文件:
    tag = datetime.now().strftime('%y.%m.%d_%H.%M.%S')
    print(env.host)
    hosttag = ''
    remote_work_dir = ''
    if env.host == '111.229.74.137':
        remote_work_dir = '/home/ubuntu/www/fuel/'
        hosttag = 'mx'
    else:
        exit(1)

    remote_tmp_tar = '/tmp/%s' % pack_name
    run('rm -f %s' % remote_tmp_tar)
    # 上传tar文件至远程服务器:
    put(pack_name, remote_tmp_tar)
    # 备份远程服务器工程
    # back_tar_name = '/home/ubuntu/www/backup/Lock%s.tar.gz' % tag
    # run('tar -czvf %s /home/ubuntu/www/Lock/*' % back_tar_name)
    # 删除原有工程
    # run('rm -rf /home/ubuntu/www/Lock/*')
    # 解压:
    run('tar -xzvf %s -C %s' % (remote_tmp_tar, remote_work_dir))
    run('mv %sother/settings_%s.py %sfuel/settings.py' %
        (remote_work_dir, hosttag, remote_work_dir))
    run('mv %sother/fuel_nginx_%s.conf %sfuel_nginx.conf' %
        (remote_work_dir, hosttag, remote_work_dir))
    run('mv %sother/fuel_uwsgi_%s.ini %sfuel_uwsgi.ini' %
        (remote_work_dir, hosttag, remote_work_dir))
    run('mv %sother/uwsgi_params_%s %suwsgi_params' %
        (remote_work_dir, hosttag, remote_work_dir))
    run('rm -rf %sother' % remote_work_dir)
    with cd(remote_work_dir):
        if env.host == '111.229.74.137':
            with virtualenv('/home/ubuntu/www/fuel/kkwork'):
                run('python manage.py makemigrations')
                run('python manage.py migrate')
                run('chmod a+x ./restart.sh')
                run('sh ./restart.sh', pty=False)
                run('sudo service nginx restart')
                run('sleep 5')
        else:
            run('python manage.py makemigrations')
            run('python manage.py migrate')
            run('chmod a+x ./restart.sh')
            run('sh ./restart.sh', pty=False)
            run('sudo service nginx restart')
            run('sleep 5')
Ejemplo n.º 31
0
def app_install():

	# Create directory structure
	sudo('mkdir -p %s' % env.app_dir)
	sudo('git clone %s %s' % (env.repo,env.app_code_dir))

	# Install virtual environement
	sudo('sudo apt-get install python-virtualenv')
	sudo('mkdir -p %s' % env.VIRTUALENV )
	sudo ('virtualenv %s' % env.VIRTUALENV)

	# Install python packages via vitualenv
	with cd(env.app_code_dir):
		with virtualenv(env.VIRTUALENV):
			run('pip install -r requirements.txt')
Ejemplo n.º 32
0
def bootstrap(tag=None):    
    with settings(warn_only=True):
       env.run('killall supervisord')
    if exists(env.DEPLOY_PATH):
       env.run('mv %s %s' %  (env.DEPLOY_PATH, env.DEPLOY_PATH + '_' + str(datetime.datetime.now().strftime('%Y%m%d%f%S'))))
    clone_repo(target=env.DEPLOY_PATH)
    with cd(env.DEPLOY_PATH):
       if tag:	     
          update_to_tag(tag=tag)
    makevenv(path=env.venvpath)
    #run('virtualenv --distribute %s' % env.venvpath)
    #with prefix('source %s' % os.path.join(env.venvpath, 'bin/activate')):
    with settings(warn_only=True):
       env.run('killall supervisord')
    with virtualenv(env.venvpath):
        env.run('pip install --upgrade pip')
        env.run('pip install --upgrade Distribute')
Ejemplo n.º 33
0
def bootstrap(tag=None):
    with settings(warn_only=True):
        env.run('killall supervisord')
    if exists(env.DEPLOY_PATH):
        env.run('mv %s %s' %
                (env.DEPLOY_PATH, env.DEPLOY_PATH + '_' +
                 str(datetime.datetime.now().strftime('%Y%m%d%f%S'))))
    clone_repo(target=env.DEPLOY_PATH)
    with cd(env.DEPLOY_PATH):
        if tag:
            update_to_tag(tag=tag)
    makevenv(path=env.venvpath)
    #run('virtualenv --distribute %s' % env.venvpath)
    #with prefix('source %s' % os.path.join(env.venvpath, 'bin/activate')):
    with settings(warn_only=True):
        env.run('killall supervisord')
    with virtualenv(env.venvpath):
        env.run('pip install --upgrade pip')
        env.run('pip install --upgrade Distribute')
Ejemplo n.º 34
0
def compile_translation_strings():
    path = env.target_path

    media_db_path = path + '/src/media-serv/'
    client_path = path + '/src/sma-client/'

    print(cyan("Compiling translation strings ..."))
    with virtualenv(media_db_path + '/env/'):
        print(cyan("virtualenv ..."))
        with cd(media_db_path):
            run("svn up")
            print(cyan("Pulling from transifex ..."))
            try:
                b = run("tx pull")
            except:
                print(red("Pulling from transifex failed."))
            run("pybabel compile -d translations")

    print(cyan("Compiled translation strings ..."))
Ejemplo n.º 35
0
def test_pypi(release='2'):
    """
    Test that the sympy can be pip installed, and that sympy imports in the
    install.
    """
    # This function is similar to test_tarball()

    version = get_sympy_version()

    if release not in {'2', '3'}: # TODO: Add win32
        raise ValueError("release must be one of '2', '3', not %s" % release)

    venv = "/home/vagrant/repos/test-{release}-pip-virtualenv".format(release=release)

    with use_venv(release):
        make_virtualenv(venv)
        with virtualenv(venv):
            run("pip install sympy")
            run('python -c "import sympy; assert sympy.__version__ == \'{version}\'"'.format(version=version))
Ejemplo n.º 36
0
def deploy():
    """ deploy the app to the server """

    require("repo_path", "venv_path")

    commit = git_head_rev()

    # Run the test suite first !
    test()

    # Update the new code
    git_seed(env.repo_path, commit=commit)

    # Activate the new code
    git_reset(env.repo_path, commit=commit)

    with cd(env.repo_path), virtualenv(env.venv_path):
        run("pip install -r requirements-prod.txt")
        restart()
Ejemplo n.º 37
0
def test_tarball(release='2'):
    """
    Test that the tarball can be unpacked and installed, and that sympy
    imports in the install.
    """
    if release not in {'2', '3'}: # TODO: Add win32
        raise ValueError("release must be one of '2', '3', not %s" % release)

    venv = "/home/vagrant/repos/test-{release}-virtualenv".format(release=release)
    tarball_formatter_dict = tarball_formatter()

    with use_venv(release):
        make_virtualenv(venv)
        with virtualenv(venv):
            run("cp /vagrant/release/{source} releasetar.tar".format(**tarball_formatter_dict))
            run("tar xvf releasetar.tar")
            with cd("/home/vagrant/{source-orig-notar}".format(**tarball_formatter_dict)):
                run("python setup.py install")
                run('python -c "import sympy; print(sympy.__version__)"')
Ejemplo n.º 38
0
def build_docs():
    """
    Build the html and pdf docs
    """
    with cd("/home/vagrant/repos/sympy"):
        run("mkdir -p dist")
        venv = "/home/vagrant/docs-virtualenv"
        make_virtualenv(venv, dependencies=['sphinx==1.1.3', 'numpy'])
        with virtualenv(venv):
            with cd("/home/vagrant/repos/sympy/doc"):
                run("make clean")
                run("make html-errors")
                with cd("/home/vagrant/repos/sympy/doc/_build"):
                    run("mv html {html-nozip}".format(**tarball_formatter()))
                    run("zip -9lr {html} {html-nozip}".format(**tarball_formatter()))
                    run("cp {html} ../../dist/".format(**tarball_formatter()))
                run("make clean")
                run("make latex")
                with cd("/home/vagrant/repos/sympy/doc/_build/latex"):
                    run("make")
                    run("cp {pdf-orig} ../../../dist/{pdf}".format(**tarball_formatter()))
Ejemplo n.º 39
0
def test_pypi(release='2'):
    """
    Test that the sympy can be pip installed, and that sympy imports in the
    install.
    """
    # This function is similar to test_tarball()

    version = get_sympy_version()

    release = str(release)

    if release not in {'2', '3'}: # TODO: Add win32
        raise ValueError("release must be one of '2', '3', not %s" % release)

    venv = "/home/vagrant/repos/test-{release}-pip-virtualenv".format(release=release)

    with use_venv(release):
        make_virtualenv(venv)
        with virtualenv(venv):
            run("pip install sympy")
            run('python -c "import sympy; assert sympy.__version__ == \'{version}\'"'.format(version=version))
Ejemplo n.º 40
0
def deploy():
    ' 定义一个部署任务 '
    tag = datetime.now()
    print(env.host)
    remote_work_dir = ''
    if env.host == '106.54.217.74':
        remote_work_dir = '/home/ubuntu/hydrology_mgmt/'
    else:
        exit(1)

    remote_tmp_tar = '/tmp/%s' % pack_name
    run('rm -f %s' % remote_tmp_tar)
    # 上传tar文件至远程服务器:
    put(pack_name, remote_tmp_tar)
    # 备份远程服务器工程
    # back_tar_name = '/home/ubuntu/www/backup/cmxsite_backup_%s.tar.gz' % tag
    # run('tar -czvf %s /home/ubuntu/www/cmxsite/*' % back_tar_name)
    # 删除原有工程
    # run('rm -rf /home/ubuntu/www/cmxsite/*')
    # 解压:
    run('tar -xzvf %s -C %s' % (remote_tmp_tar, remote_work_dir))
    run('mv %sother/settings.py %s/hydrology_mgmt/settings.py' %
        (remote_work_dir, remote_work_dir))
    run('mv %sother/ball_nginx.conf %s/hydrology_mgmt_nginx.conf' %
        (remote_work_dir, remote_work_dir))
    run('mv %sother/ball_uwsgi.ini %s/hydrology_mgmt_uwsgi.ini' %
        (remote_work_dir, remote_work_dir))
    run('mv %sother/uwsgi_params %s/uwsgi_params' %
        (remote_work_dir, remote_work_dir))
    run('rm -rf %sother' % remote_work_dir)
    with cd(remote_work_dir):
        with virtualenv('/home/ubuntu/hydrology_mgmt/kkwork'):
            run('python manage.py makemigrations')
            run('python manage.py migrate')
            run('chmod a+x ./restart.sh')
            run('sh ./restart.sh', pty=False)
            # run('sudo service nginx restart')
            run('sleep 5')
    print(datetime.now() - tag)
Ejemplo n.º 41
0
def generate_file_list(filename):
    """Return an unfiltered list of absolute paths to the files to act on"""

    with hide('warnings', 'running', 'stdout'):
        with virtualenv(VENV_ROOT):

            if filename:
                filename = os.path.abspath(filename)
                if not os.path.exists(filename):
                    print "Bad filename, specify a Python file"
                    sys.exit(1)
                else:
                    file_list = [filename]

            else:
                with cd(PROJECT_ROOT):
                    file_list = [
                        os.path.abspath(i.rstrip('\r'))
                        for i in run('find . -name "*.py"').split(os.linesep)
                    ]

    return file_list
Ejemplo n.º 42
0
def create_dependency_graphs():
    """
    To better understand the relationship between methods, dependency graphs can be drawn between functions and
    methods.

    Since the resulting images are large and could be out of date on the next commit, storing them in the repo is
    pointless. Instead, it makes sense to build a dependency graph for a particular, documented version of the code.

    .. todo:: Consider saving a hash of the intermediate dotty file so unnecessary image generation can be avoided.

    """
    with virtualenv(VENV_ROOT):
        with hide('running', 'stdout'):

            # .. todo:: consider a better place to put this, use a particular commit
            with cd(PROJECT_ROOT):
                with settings(warn_only=True):
                    if run('stat pyan').return_code:
                        run('git clone https://github.com/davidfraser/pyan.git'
                            )
            with cd(os.path.join(PROJECT_ROOT, 'pyan')):
                run('git checkout pre-python3')

            # .. todo:: Use better settings. This is MVP to make a diagram
            with cd(PROJECT_ROOT):
                file_list = run(
                    "find . -type f -name '*.py' ! -path './src/.eggs/*'"
                ).split('\r\n')
                for cmd in [
                        'neato -Goverlap=false -Tpng > deps-neato.png',
                        'sfdp -Goverlap=false -Tpng > deps-sfdp.png',
                        'dot -Goverlap=false -Tpng > deps-dot.png',
                ]:
                    pyan_cmd = './pyan/pyan.py {} --dot'.format(
                        ' '.join(file_list))
                    sed_cmd = r"sed s'/http\-old/http_old/'g"  # dot doesn't like dashes
                    run('|'.join([pyan_cmd, sed_cmd, cmd]))

                run('mv *.png docs/_build/html/_static/')
Ejemplo n.º 43
0
def _update_repo(force=False):
    version_path = join(APP_ROOT, version)
    if exists(version_path):
        if not force:
            if raw_input(
                    "Given version already exists, overwrite? (y/N) ").strip().lower() != 'y':
                print 'over and out'
                sys.exit(0)

    else:
        run('mkdir -p %s' % join(version_path, 'static'))

    put(join('./dist', _get_archive_name()), join(version_path, _get_archive_name(DEPLOY_UID)))

    with cd(APP_ROOT):
        run('rm _deploy; ln -sf %s ./_deploy' % version_path)

    with cd(version_path):
        if not exists('venv'):
            run('virtualenv venv')

    with virtualenv(join(version_path, 'venv')):
        run('pip uninstall -y %s' % PROJECT, quiet=True)
        run('pip install %s' % join(version_path, _get_archive_name(DEPLOY_UID)))

        if DJANGO:

            with shell_env(STATIC_ROOT='/var/www/%s/_deploy/static' % PROJECT):
                run('%s-manage collectstatic -l --noinput' % PROJECT)

            with shell_env(SERVER_SETTINGS_PATH='/var/www/%s/config/' % PROJECT):
                run('%s-manage migrate' % PROJECT)

    with cd(APP_ROOT):
        run('rm -f current; ln -sf %s ./current' % version_path)
        run('rm -f _deploy', quiet=True)
Ejemplo n.º 44
0
def shell_plus():
    env.output_prefix = False
    with cd(env.project):
        with virtualenv(env.venv):
            run("./manage.py shell_plus")
Ejemplo n.º 45
0
def production_settings():
    # I sent a pull request to allow user to specify some variables:
    # https://github.com/django-extensions/django-extensions/pull/488
    with cd(env.project):
        with virtualenv(env.venv):
            run("./manage.py print_settings --format=pprint")
Ejemplo n.º 46
0
def run_loaddbtemplates():
    with cd(env.project):
        with virtualenv(env.venv):
            run("./manage.py loaddata dbtemplates")
Ejemplo n.º 47
0
def run_loadflatpages():
    with cd(env.project):
        with virtualenv(env.venv):
            run("./manage.py loaddata flatpages")
Ejemplo n.º 48
0
def restart_uwsgi():
    """ Restart the uwsgi app as a background task. """
    with virtualenv(env.venv):
        run('uwsgi --emperor /etc/uwsgi/apps-enabled '
            '--daemonize /var/log/winkel.log')
Ejemplo n.º 49
0
def install_gunicorn():
  with virtualenv(VIRTUALENV_PATH):
    run("pip install gunicorn==0.16.1")
Ejemplo n.º 50
0
def run_collectstatic():
    with cd(env.project):
        with virtualenv(env.venv):
            run("./manage.py collectstatic --noinput")
Ejemplo n.º 51
0
def setup_venv():
    # TODO: Read paths from env.
    with cd('/vagrant/'):
        with virtualenv('/usr/local/venv'):
            yield
Ejemplo n.º 52
0
def jsons():
    with cd(project):
        with virtualenv(venv):
            run('./manager.py jsons')
Ejemplo n.º 53
0
def run_django_cmd(cmd):
    with cd(env.project):
        with virtualenv(env.venv):
            run("./manage.py %s" % cmd)
Ejemplo n.º 54
0
def pynt(cmd):
    """ Run a pynt command on the remote host. """
    with virtualenv(env.venv):
        with cd(env.directory):
            run('pynt %s' % cmd)
Ejemplo n.º 55
0
def run_migrations():
    with cd(env.project):
        with virtualenv(env.venv):
            run("./manage.py migrate")
Ejemplo n.º 56
0
def initialize_brats():
    with virtualenv(env.venvpath),cd(env.DEPLOY_PATH):
        env.run('codalab/scripts/init.sh')
Ejemplo n.º 57
0
def doc():
    with cd(project):
        with virtualenv(venv):
            run('./manager.py doc')
Ejemplo n.º 58
0
def env_command(cmd, env):
    with virtualenv(env):
        local(cmd)