当前位置: 首页>>代码示例>>Python>>正文


Python files.exists方法代码示例

本文整理汇总了Python中fabric.contrib.files.exists方法的典型用法代码示例。如果您正苦于以下问题:Python files.exists方法的具体用法?Python files.exists怎么用?Python files.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fabric.contrib.files的用法示例。


在下文中一共展示了files.exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: deploy

# 需要导入模块: from fabric.contrib import files [as 别名]
# 或者: from fabric.contrib.files import exists [as 别名]
def deploy():
    """ Deploy application with packaging in mind """
    version = get_version()
    pip_path = os.path.join(
        REMOTE_PROJECT_LOCATION, version, 'bin', 'pip'
    )

    prepare_release()

    if not exists(REMOTE_PROJECT_LOCATION):
        # it may not exist for initial deployment on fresh host
        run("mkdir -p {}".format(REMOTE_PROJECT_LOCATION))

    with cd(REMOTE_PROJECT_LOCATION):
        # create new virtual environment using venv
        run('python3 -m venv {}'.format(version))

        run("{} install webxample=={} --index-url {}".format(
            pip_path, version, PYPI_URL
        ))

    switch_versions(version)
    # let's assume that Circus is our process supervision tool
    # of choice.
    run('circusctl restart webxample') 
开发者ID:PacktPublishing,项目名称:Expert-Python-Programming_Second-Edition,代码行数:27,代码来源:fabfile.py

示例2: update_spark_jars

# 需要导入模块: from fabric.contrib import files [as 别名]
# 或者: from fabric.contrib.files import exists [as 别名]
def update_spark_jars(jars_dir='/opt/jars'):
    try:
        configs = sudo('find /opt/ /etc/ /usr/lib/ -name spark-defaults.conf -type f').split('\r\n')
        if exists(jars_dir):
            for conf in filter(None, configs):
                des_path = ''
                all_jars = sudo('find {0} -name "*.jar"'.format(jars_dir)).split('\r\n')
                if ('-des-' in conf):
                    des_path = '/'.join(conf.split('/')[:3])
                    all_jars = find_des_jars(all_jars, des_path)
                sudo('''sed -i '/^# Generated\|^spark.jars/d' {0}'''.format(conf))
                sudo('echo "# Generated spark.jars by DLab from {0}\nspark.jars {1}" >> {2}'
                     .format(','.join(filter(None, [jars_dir, des_path])), ','.join(all_jars), conf))
                # sudo("sed -i 's/^[[:space:]]*//' {0}".format(conf))
        else:
            print("Can't find directory {0} with jar files".format(jars_dir))
    except Exception as err:
        append_result("Failed to update spark.jars parameter", str(err))
        print("Failed to update spark.jars parameter")
        sys.exit(1) 
开发者ID:apache,项目名称:incubator-dlab,代码行数:22,代码来源:fab.py

示例3: install_inactivity_checker

# 需要导入模块: from fabric.contrib import files [as 别名]
# 或者: from fabric.contrib.files import exists [as 别名]
def install_inactivity_checker(os_user, ip_address, rstudio=False):
    if not exists('/home/{}/.ensure_dir/inactivity_ensured'.format(os_user)):
        try:
            if not exists('/opt/inactivity'):
                sudo('mkdir /opt/inactivity')
            put('/root/templates/inactive.service', '/etc/systemd/system/inactive.service', use_sudo=True)
            put('/root/templates/inactive.timer', '/etc/systemd/system/inactive.timer', use_sudo=True)
            if rstudio:
                put('/root/templates/inactive_rs.sh', '/opt/inactivity/inactive.sh', use_sudo=True)
            else:
                put('/root/templates/inactive.sh', '/opt/inactivity/inactive.sh', use_sudo=True)
            sudo("sed -i 's|IP_ADRESS|{}|g' /opt/inactivity/inactive.sh".format(ip_address))
            sudo("chmod 755 /opt/inactivity/inactive.sh")
            sudo("chown root:root /etc/systemd/system/inactive.service")
            sudo("chown root:root /etc/systemd/system/inactive.timer")
            sudo("date +%s > /opt/inactivity/local_inactivity")
            sudo('systemctl daemon-reload')
            sudo('systemctl enable inactive.timer')
            sudo('systemctl start inactive.timer')
            sudo('touch /home/{}/.ensure_dir/inactive_ensured'.format(os_user))
        except Exception as err:
            print('Failed to setup inactivity check service!', str(err))
            sys.exit(1) 
开发者ID:apache,项目名称:incubator-dlab,代码行数:25,代码来源:fab.py

示例4: ensure_r_local_kernel

# 需要导入模块: from fabric.contrib import files [as 别名]
# 或者: from fabric.contrib.files import exists [as 别名]
def ensure_r_local_kernel(spark_version, os_user, templates_dir, kernels_dir):
    if not exists('/home/' + os_user + '/.ensure_dir/r_local_kernel_ensured'):
        try:
            sudo('R -e "IRkernel::installspec()"')
            r_version = sudo("R --version | awk '/version / {print $3}'")
            put(templates_dir + 'r_template.json', '/tmp/r_template.json')
            sudo('sed -i "s|R_VER|' + r_version + '|g" /tmp/r_template.json')
            sudo('sed -i "s|SP_VER|' + spark_version + '|g" /tmp/r_template.json')
            sudo('\cp -f /tmp/r_template.json {}/ir/kernel.json'.format(kernels_dir))
            sudo('ln -s /opt/spark/ /usr/local/spark')
            try:
                sudo('cd /usr/local/spark/R/lib/SparkR; R -e "install.packages(\'roxygen2\',repos=\'https://cloud.r-project.org\')" R -e "devtools::check(\'.\')"')
            except:
                pass
            sudo('cd /usr/local/spark/R/lib/SparkR; R -e "devtools::install(\'.\')"')
            sudo('chown -R ' + os_user + ':' + os_user + ' /home/' + os_user + '/.local')
            sudo('touch /home/' + os_user + '/.ensure_dir/r_local_kernel_ensured')
        except:
            sys.exit(1) 
开发者ID:apache,项目名称:incubator-dlab,代码行数:21,代码来源:notebook_lib.py

示例5: ensure_python3_libraries

# 需要导入模块: from fabric.contrib import files [as 别名]
# 或者: from fabric.contrib.files import exists [as 别名]
def ensure_python3_libraries(os_user):
    if not exists('/home/' + os_user + '/.ensure_dir/python3_libraries_ensured'):
        try:
            manage_pkg('-y install', 'remote', 'python3-setuptools')
            manage_pkg('-y install', 'remote', 'python3-pip')
            try:
                sudo('pip3 install tornado=={0} ipython==7.9.0 ipykernel=={1} --no-cache-dir' \
                     .format(os.environ['notebook_tornado_version'], os.environ['notebook_ipykernel_version']))
            except:
                sudo('pip3 install tornado=={0} ipython==5.0.0 ipykernel=={1} --no-cache-dir' \
                     .format(os.environ['notebook_tornado_version'], os.environ['notebook_ipykernel_version']))
            sudo('pip3 install -U pip=={} --no-cache-dir'.format(os.environ['conf_pip_version']))
            sudo('pip3 install boto3 --no-cache-dir')
            sudo('pip3 install fabvenv fabric-virtualenv future --no-cache-dir')
            sudo('touch /home/' + os_user + '/.ensure_dir/python3_libraries_ensured')
        except:
            sys.exit(1) 
开发者ID:apache,项目名称:incubator-dlab,代码行数:19,代码来源:notebook_lib.py

示例6: ensure_r_local_kernel

# 需要导入模块: from fabric.contrib import files [as 别名]
# 或者: from fabric.contrib.files import exists [as 别名]
def ensure_r_local_kernel(spark_version, os_user, templates_dir, kernels_dir):
    if not exists('/home/{}/.ensure_dir/r_kernel_ensured'.format(os_user)):
        try:
            sudo('chown -R ' + os_user + ':' + os_user + ' /home/' + os_user + '/.local')
            run('R -e "IRkernel::installspec()"')
            sudo('ln -s /opt/spark/ /usr/local/spark')
            try:
                sudo('cd /usr/local/spark/R/lib/SparkR; R -e "install.packages(\'roxygen2\',repos=\'https://cloud.r-project.org\')" R -e "devtools::check(\'.\')"')
            except:
                pass
            sudo('cd /usr/local/spark/R/lib/SparkR; R -e "devtools::install(\'.\')"')
            r_version = sudo("R --version | awk '/version / {print $3}'")
            put(templates_dir + 'r_template.json', '/tmp/r_template.json')
            sudo('sed -i "s|R_VER|' + r_version + '|g" /tmp/r_template.json')
            sudo('sed -i "s|SP_VER|' + spark_version + '|g" /tmp/r_template.json')
            sudo('\cp -f /tmp/r_template.json {}/ir/kernel.json'.format(kernels_dir))
            sudo('ln -s /usr/lib64/R/ /usr/lib/R')
            sudo('chown -R ' + os_user + ':' + os_user + ' /home/' + os_user + '/.local')
            sudo('touch /home/{}/.ensure_dir/r_kernel_ensured'.format(os_user))
        except:
            sys.exit(1) 
开发者ID:apache,项目名称:incubator-dlab,代码行数:23,代码来源:notebook_lib.py

示例7: ensure_r

# 需要导入模块: from fabric.contrib import files [as 别名]
# 或者: from fabric.contrib.files import exists [as 别名]
def ensure_r(os_user, r_libs, region, r_mirror):
    if not exists('/home/{}/.ensure_dir/r_ensured'.format(os_user)):
        try:
            if region == 'cn-north-1':
                r_repository = r_mirror
            else:
                r_repository = 'https://cloud.r-project.org'
            manage_pkg('-y install', 'remote', 'cmake')
            manage_pkg('-y install', 'remote', 'libcur*')
            sudo('echo -e "[base]\nname=CentOS-7-Base\nbaseurl=http://buildlogs.centos.org/centos/7/os/x86_64-20140704-1/\ngpgcheck=1\ngpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7\npriority=1\nexclude=php mysql" >> /etc/yum.repos.d/CentOS-base.repo')
            manage_pkg('-y install', 'remote', 'R R-core R-core-devel R-devel --nogpgcheck')
            sudo('R CMD javareconf')
            sudo('cd /root; git clone https://github.com/zeromq/zeromq4-x.git; cd zeromq4-x/; mkdir build; cd build; cmake ..; make install; ldconfig')
            for i in r_libs:
                sudo('R -e "install.packages(\'{}\',repos=\'{}\')"'.format(i, r_repository))
            sudo('R -e "library(\'devtools\');install.packages(repos=\'{}\',c(\'rzmq\',\'repr\',\'digest\',\'stringr\',\'RJSONIO\',\'functional\',\'plyr\'))"'.format(r_repository))
            sudo('R -e "library(\'devtools\');install_github(\'IRkernel/repr\');install_github(\'IRkernel/IRdisplay\');install_github(\'IRkernel/IRkernel\');"')
            sudo('R -e "library(\'devtools\');install_version(\'keras\', version = \'{}\', repos = \'{}\');"'.format(os.environ['notebook_keras_version'],r_repository))
            sudo('R -e "install.packages(\'RJDBC\',repos=\'{}\',dep=TRUE)"'.format(r_repository))
            sudo('touch /home/{}/.ensure_dir/r_ensured'.format(os_user))
        except:
            sys.exit(1) 
开发者ID:apache,项目名称:incubator-dlab,代码行数:24,代码来源:notebook_lib.py

示例8: ensure_python2_libraries

# 需要导入模块: from fabric.contrib import files [as 别名]
# 或者: from fabric.contrib.files import exists [as 别名]
def ensure_python2_libraries(os_user):
    if not exists('/home/' + os_user + '/.ensure_dir/python2_libraries_ensured'):
        try:
            sudo('pip2 install pyparsing==2.0.3')
            manage_pkg('-y install', 'remote', 'python-setuptools python-wheel')
            manage_pkg('-y install', 'remote', 'python-virtualenv openssl-devel python-devel openssl-libs libxslt-devel --nogpgcheck')
            try:
                sudo('python2 -m pip install backports.shutil_get_terminal_size tornado=={0} ipython ipykernel=={1} --no-cache-dir' \
                     .format(os.environ['notebook_tornado_version'], os.environ['notebook_ipykernel_version']))
            except:
                sudo('python2 -m pip install backports.shutil_get_terminal_size tornado=={0} ipython==5.0.0 ipykernel=={1} --no-cache-dir' \
                     .format(os.environ['notebook_tornado_version'], os.environ['notebook_ipykernel_version']))
            sudo('echo y | python2 -m pip uninstall backports.shutil_get_terminal_size')
            sudo('python2 -m pip install backports.shutil_get_terminal_size --no-cache-dir')
            sudo('pip2 install -UI pip=={} setuptools --no-cache-dir'.format(os.environ['conf_pip_version']))
            sudo('pip2 install boto3 backoff --no-cache-dir')
            sudo('pip2 install fabvenv fabric-virtualenv future --no-cache-dir')
            downgrade_python_version()
            sudo('touch /home/' + os_user + '/.ensure_dir/python2_libraries_ensured')
        except:
            sys.exit(1) 
开发者ID:apache,项目名称:incubator-dlab,代码行数:23,代码来源:notebook_lib.py

示例9: ensure_python3_libraries

# 需要导入模块: from fabric.contrib import files [as 别名]
# 或者: from fabric.contrib.files import exists [as 别名]
def ensure_python3_libraries(os_user):
    if not exists('/home/' + os_user + '/.ensure_dir/python3_libraries_ensured'):
        try:
            manage_pkg('-y install', 'remote', 'https://centos7.iuscommunity.org/ius-release.rpm')
            manage_pkg('-y install', 'remote', 'python35u python35u-pip python35u-devel')
            sudo('python3.5 -m pip install -U pip=={} setuptools --no-cache-dir'.format(os.environ['conf_pip_version']))
            sudo('python3.5 -m pip install boto3 --no-cache-dir')
            sudo('python3.5 -m pip install fabvenv fabric-virtualenv future --no-cache-dir')
            try:
                sudo('python3.5 -m pip install tornado=={0} ipython==7.9.0 ipykernel=={1} --no-cache-dir' \
                     .format(os.environ['notebook_tornado_version'], os.environ['notebook_ipykernel_version']))
            except:
                sudo('python3.5 -m pip install tornado=={0} ipython==5.0.0 ipykernel=={1} --no-cache-dir' \
                     .format(os.environ['notebook_tornado_version'], os.environ['notebook_ipykernel_version']))
            sudo('touch /home/' + os_user + '/.ensure_dir/python3_libraries_ensured')
        except:
            sys.exit(1) 
开发者ID:apache,项目名称:incubator-dlab,代码行数:19,代码来源:notebook_lib.py

示例10: install_caffe2

# 需要导入模块: from fabric.contrib import files [as 别名]
# 或者: from fabric.contrib.files import exists [as 别名]
def install_caffe2(os_user, caffe2_version, cmake_version):
    if not exists('/home/{}/.ensure_dir/caffe2_ensured'.format(os_user)):
        env.shell = "/bin/bash -l -c -i"
        manage_pkg('update-minimal --security -y', 'remote', '')
        manage_pkg('-y install --nogpgcheck', 'remote', 'automake cmake3 gcc gcc-c++ kernel-devel leveldb-devel lmdb-devel libtool protobuf-devel graphviz')
        sudo('pip2 install flask graphviz hypothesis jupyter matplotlib==2.0.2 numpy=={} protobuf pydot python-nvd3 pyyaml '
             'requests scikit-image scipy setuptools tornado future --no-cache-dir'.format(os.environ['notebook_numpy_version']))
        sudo('pip3.5 install flask graphviz hypothesis jupyter matplotlib==2.0.2 numpy=={} protobuf pydot python-nvd3 pyyaml '
             'requests scikit-image scipy setuptools tornado future --no-cache-dir'.format(os.environ['notebook_numpy_version']))
        sudo('cp /opt/cudnn/include/* /opt/cuda-8.0/include/')
        sudo('cp /opt/cudnn/lib64/* /opt/cuda-8.0/lib64/')
        sudo('wget https://cmake.org/files/v{2}/cmake-{1}.tar.gz -O /home/{0}/cmake-{1}.tar.gz'.format(
            os_user, cmake_version, cmake_version.split('.')[0] + "." + cmake_version.split('.')[1]))
        sudo('tar -zxvf cmake-{}.tar.gz'.format(cmake_version))
        with cd('/home/{}/cmake-{}/'.format(os_user, cmake_version)):
            sudo('./bootstrap --prefix=/usr/local && make && make install')
        sudo('ln -s /usr/local/bin/cmake /bin/cmake{}'.format(cmake_version))
        sudo('git clone https://github.com/pytorch/pytorch.git')
        with cd('/home/{}/pytorch/'.format(os_user)):
            sudo('git submodule update --init')
            with settings(warn_only=True):
                sudo('git checkout v{}'.format(caffe2_version))
                sudo('git submodule update --recursive')
            sudo('mkdir build && cd build && cmake{} .. && make "-j$(nproc)" install'.format(cmake_version))
        sudo('touch /home/' + os_user + '/.ensure_dir/caffe2_ensured') 
开发者ID:apache,项目名称:incubator-dlab,代码行数:27,代码来源:notebook_lib.py

示例11: retrieve

# 需要导入模块: from fabric.contrib import files [as 别名]
# 或者: from fabric.contrib.files import exists [as 别名]
def retrieve(agent_packages):
    ctx.logger.info('Downloading Cloudify Agents...')

    for agent, source in agent_packages.items():
        # if source is not a downloadable link, it will not be downloaded
        if not source.startswith(('http', 'https', 'ftp')):
            continue

        dest_path = ctx.instance.runtime_properties['agent_packages_path']
        agent_name = agent.replace('_', '-')

        # This is a workaround for mapping Centos release names to versions
        # to provide a better UX when providing agent inputs.
        if agent_name == 'centos-7x-agent':
            agent_name = 'centos-core-agent'
        elif agent_name == 'centos-6x-agent':
            agent_name = 'centos-final-agent'
        elif agent_name == 'redhat-7x-agent':
            agent_name = 'redhat-maipo-agent'
        elif agent_name == 'redhat-6x-agent':
            agent_name = 'redhat-santiago-agent'

        if agent_name == 'cloudify-windows-agent':
            filename = '{0}.exe'.format(agent_name)
        else:
            filename = '{0}.tar.gz'.format(agent_name)
        dest_file = '{0}/{1}'.format(dest_path, filename)

        ctx.logger.info('Downloading Agent Package {0} to {1} if it does not '
                        'already exist...'.format(source, dest_file))
        if remote_exists(dest_file):
            ctx.logger.info('agent package file will be '
                            'overridden: {0}'.format(dest_file))
        dl_cmd = 'curl --retry 10 -f -s -S -L {0} --create-dirs -o {1}'
        fabric.api.sudo(dl_cmd.format(source, dest_file)) 
开发者ID:cloudify-cosmo,项目名称:cloudify-manager-blueprints,代码行数:37,代码来源:retrieve_agents.py

示例12: _update_virtualenv

# 需要导入模块: from fabric.contrib import files [as 别名]
# 或者: from fabric.contrib.files import exists [as 别名]
def _update_virtualenv():
    if not exists('{v}/bin/pip'.format(v=VENV_PATH)):  
        run('python3 -m venv {v}'.format(v=VENV_PATH))
    run('{v}/bin/pip install -r requirements/local.txt'.format(v=VENV_PATH))
    run('~/.rbenv/shims/gem install bundler')
    run('~/.rbenv/shims/bundle install') 
开发者ID:ecds,项目名称:readux,代码行数:8,代码来源:fabfile.py

示例13: _update_symlink

# 需要导入模块: from fabric.contrib import files [as 别名]
# 或者: from fabric.contrib.files import exists [as 别名]
def _update_symlink():
    with cd('../'):
        if exists('{rp}/current'.format(rp=ROOT_PATH)):
            run('rm {rp}/current'.format(rp=ROOT_PATH))
        run('ln -s {rp}/{v} current'.format(rp=ROOT_PATH, v=VERSION)) 
开发者ID:ecds,项目名称:readux,代码行数:7,代码来源:fabfile.py

示例14: ensure_pip

# 需要导入模块: from fabric.contrib import files [as 别名]
# 或者: from fabric.contrib.files import exists [as 别名]
def ensure_pip(requisites):
    try:
        if not exists('/home/{}/.ensure_dir/pip_path_added'.format(os.environ['conf_os_user'])):
            sudo('echo PATH=$PATH:/usr/local/bin/:/opt/spark/bin/ >> /etc/profile')
            sudo('echo export PATH >> /etc/profile')
            sudo('pip install -UI pip=={} --no-cache-dir'.format(os.environ['conf_pip_version']))
            sudo('pip install --upgrade setuptools')
            sudo('pip install -U {} --no-cache-dir'.format(requisites))
            sudo('touch /home/{}/.ensure_dir/pip_path_added'.format(os.environ['conf_os_user']))
    except:
        sys.exit(1) 
开发者ID:apache,项目名称:incubator-dlab,代码行数:13,代码来源:fab.py

示例15: install_pip_pkg

# 需要导入模块: from fabric.contrib import files [as 别名]
# 或者: from fabric.contrib.files import exists [as 别名]
def install_pip_pkg(requisites, pip_version, lib_group):
    status = list()
    error_parser = "Could not|No matching|ImportError:|failed|EnvironmentError:"
    try:
        if pip_version == 'pip3' and not exists('/bin/pip3'):
            sudo('ln -s /bin/pip3.5 /bin/pip3')
        sudo('{} install -U pip=={} setuptools'.format(pip_version, os.environ['conf_pip_version']))
        sudo('{} install -U pip=={} --no-cache-dir'.format(pip_version, os.environ['conf_pip_version']))
        sudo('{} install --upgrade pip=={}'.format(pip_version, os.environ['conf_pip_version']))
        for pip_pkg in requisites:
            sudo('{0} install {1} --no-cache-dir 2>&1 | if ! grep -w -i -E  "({2})" >  /tmp/{0}install_{1}.log; then  echo "" > /tmp/{0}install_{1}.log;fi'.format(pip_version, pip_pkg, error_parser))
            err = sudo('cat /tmp/{0}install_{1}.log'.format(pip_version, pip_pkg)).replace('"', "'")
            sudo('{0} freeze | if ! grep -w -i {1} > /tmp/{0}install_{1}.list; then  echo "" > /tmp/{0}install_{1}.list;fi'.format(pip_version, pip_pkg))
            res = sudo('cat /tmp/{0}install_{1}.list'.format(pip_version, pip_pkg))
            changed_pip_pkg = False
            if res == '':
                changed_pip_pkg = pip_pkg.replace("_", "-").split('-')
                changed_pip_pkg = changed_pip_pkg[0]
                sudo(
                    '{0} freeze | if ! grep -w -i {1} > /tmp/{0}install_{1}.list; then  echo "" > /tmp/{0}install_{1}.list;fi'.format(
                        pip_version, changed_pip_pkg))
                res = sudo(
                    'cat /tmp/{0}install_{1}.list'.format(pip_version, changed_pip_pkg))
            if res:
                res = res.lower()
                ansi_escape = re.compile(r'\x1b[^m]*m')
                ver = ansi_escape.sub('', res).split("\r\n")
                if changed_pip_pkg:
                    version = [i for i in ver if changed_pip_pkg.lower() in i][0].split('==')[1]
                else:
                    version = \
                    [i for i in ver if pip_pkg.lower() in i][0].split(
                        '==')[1]
                status.append({"group": "{}".format(lib_group), "name": pip_pkg, "version": version, "status": "installed"})
            else:
                status.append({"group": "{}".format(lib_group), "name": pip_pkg, "status": "failed", "error_message": err})
        return status
    except Exception as err:
        append_result("Failed to install {} packages".format(pip_version), str(err))
        print("Failed to install {} packages".format(pip_version))
        sys.exit(1) 
开发者ID:apache,项目名称:incubator-dlab,代码行数:43,代码来源:fab.py


注:本文中的fabric.contrib.files.exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。