Fabric 在Linux上自动创建文件目录

自动创建系列目录,并且给予权限。

import paramiko, os, time
from fabric.api import env, roles, run, execute, cd

# !/usr/bin/env python

# Please modify server_info with your Linux Server

env.hosts=['[email protected]:22',]
env.password='test2017'


basepath = r'/data/share/public/teamshare/04build/客户环境/'

folders = {
    'version': basepath,
    'java':os.path.join(basepath,'java'),
    'chameleon-callback':os.path.join(basepath,'java/chameleon-callback/'),
    'chameleon-compute':os.path.join(basepath,'java/chameleon-compute/'),
    'chameleon-cvg':os.path.join(basepath,'java/chameleon-cvg/'),
    'chameleon-gateway':os.path.join(basepath,'java/chameleon-gateway/'),
    'chameleon-message':os.path.join(basepath,'java/chameleon-message/'),
    'chameleon-network':os.path.join(basepath,'java/chameleon-network/'),
    'chameleon-product':os.path.join(basepath,'java/chameleon-product/'),
    'chameleon-stats':os.path.join(basepath,'java/chameleon-stats/'),
    'chameleon-user':os.path.join(basepath,'java/chameleon-user/'),
    'chameleon-volume':os.path.join(basepath,'java/chameleon-volume/'),
    'fc-gateway':os.path.join(basepath,'java/fc-gateway/'),
    'chameleon-cloudedit':os.path.join(basepath,'java/chameleon-cloudedit/'),
    'vm-gateway':os.path.join(basepath,'java/vm-gateway/'),
    'sql':os.path.join(basepath,'java/sql/'),
    'php': os.path.join(basepath, 'php'),
    'approval':os.path.join(basepath,'php/approval/'),
    'cvg-approval':os.path.join(basepath,'php/cvg-approval/'),
    'platform':os.path.join(basepath,'php/platform/'),
    'xs-gateway':os.path.join(basepath,'php/xs-gateway/'),
    'sql2':os.path.join(basepath,'php/sql/'),
    'web': os.path.join(basepath, 'web'),
}

print('###start create folders###',file=open("create_folders_in_122.txt", 'w'))

def create_cmp_folders():
    for i in folders.keys():
        try:
            run('mkdir %s'%folders[i])
            run('chmod 777 %s'%folders[i])
            print('create %s complete' % (folders[i]), file=open("create_folders_in_122.txt", 'a+'))
        except:
            print('create %s is not succeed'%folders[i])

print('###complete create folders###',file=open("create_folders_in_122.txt", 'a+'))

if __name__ == '__main__':
    create_cmp_folders()

猜你喜欢

转载自blog.csdn.net/warm77/article/details/80276721
今日推荐