我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用fabric.api.env.project_name()。
def set_env(config, version_tag=None): """ Fabric environmental variable setup """ # Bug: when setting this inside a function. Using host_string as workaround config_dict = get_config(config) env.hosts = [config_dict['HOST_NAME'], ] env.host_string = config_dict['HOST_NAME'] env.project_name = config_dict['PROJECT_NAME'] env.project_dir = posixpath.join('/srv/images/', env.project_name) env.use_ssh_config = True env.image_name = config_dict['IMAGE'].split(':')[0] env.base_image_name = env.image_name + '_base' env.version_tag = version_tag env.build_dir = '/srv/build' env.local_path = os.path.dirname(__file__)
def upload(): """Upload entire project to server""" # Bug: when setting this inside a function. Using host_string as workaround run('mkdir -p /srv/images/'+env.project_name+'/') rsync_project( env.project_dir, './', exclude=( '.git', '.gitignore', '__pycache__', '*.pyc', '.DS_Store', 'environment.yml', 'fabfile.py', 'Makefile', '.idea', 'bower_components', 'node_modules', '.env.example', 'README.md', 'var' ), delete=True) # Wrapper Functions:
def wheels(): """ Remotely build python binaries on image-factory server """ with lcd(env.local_path): put('./requirements.txt', '/srv/build/wheel_requirements.txt') put('./etc/base_image/image_requirements.txt', '/srv/build/requirements.txt') with cd('/srv/build/wheelhouse'): run('rm -rf *.whl') compose(cmd='-f service.yml -p %s run --rm wheel-factory' % env.project_name, path='/srv/build')
def heroku_bootstrap(): """Create an app for every environment on Heroku.""" require('project_name') require('environments') info('Initializing Heroku apps...') set_remotes() for environment in env.environments: env.environment = environment env.app_name = '{}-{}'.format(env.project_name, env.environment) heroku_initialize_app()
def heroku_configure_app(): """Configure an app with a basic configuration.""" require('environment') require('project_name') info('Configure app: {}'.format(env.app_name)) local('heroku addons:create heroku-postgresql --remote {}'.format(env.environment)) local('heroku pg:backups schedule DATABASE --at "04:00 UTC" --remote {}'.format(env.environment)) local('heroku pg:promote DATABASE_URL --remote {}'.format(env.environment)) local('heroku config:set SECRET_KEY="{}" --remote {}'.format(create_secret_key(), env.environment))
def init(vagrant=False): """Prepare a local machine for development.""" install_requirements() local('createdb %(project_name)s' % env) # create postgres database manage('migrate')
def setup(): run('mkdir -p {0.project_path}/{0.project_name}'.format(env)) run('ln -s {0.project_path}/{0.project_name} ~/{0.project_name}'.format(env)) with cd('~/{.project_name}'.format(env)): run('virtualenv -p python3 env')
def cleanup(): run('rm -r ~/{.project_name}'.format(env)) run('rm -r {0.project_path}/{0.project_name}'.format(env))
def deploy(filename=None): with cd('~/{.project_name}'.format(env)): if not filename: for source_filename in env.source_filenames: put('src/{}'.format(source_filename), '~/{.project_name}/'.format(env)) run('source env/bin/activate; pip install -r requirements.txt') else: put('src/{}'.format(filename), '~/{.project_name}/'.format(env))