python类copy_tree()的实例源码

test_dir_util.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def test_copy_tree_exception_in_listdir(self):
        """
        An exception in listdir should raise a DistutilsFileError
        """
        with patch("os.listdir", side_effect=OSError()), \
             self.assertRaises(errors.DistutilsFileError):
            src = self.tempdirs[-1]
            dir_util.copy_tree(src, None)
copy_files_home.py 文件源码 项目:azurequickstarts 作者: sysgain 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def do_step(context):
    settings = context.meta['settings']
    index_file = context.meta['index-file']

    username = settings["username"]
    home_dir = os.path.join("/home", username)

    # Copy all the files in ./bosh into the home directory
    dir_util.copy_tree("./bosh/", home_dir)
    copy("./manifests/{0}".format(index_file), "{0}/manifests/".format(home_dir))

    call("chown -R {0} {1}".format(username, home_dir), shell=True)
    call("chmod 400 {0}/bosh".format(home_dir), shell=True)

    return context
utils.py 文件源码 项目:webfp-crawler-phantomjs 作者: pankajb64 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def clone_dir_with_timestap(orig_dir_path):
    """Copy a folder into the same directory and append a timestamp."""
    new_dir = create_dir(append_timestamp(orig_dir_path))
    try:
        du.copy_tree(orig_dir_path, new_dir)
    except Exception, e:
        wl_log.error("Error while cloning the dir with timestamp" + str(e))
    finally:
        return new_dir
sstable_generation_loading_test.py 文件源码 项目:cassandra-dtest 作者: apache 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def copy_sstables(self, cluster, node):
        for x in xrange(0, cluster.data_dir_count):
            data_dir = os.path.join(node.get_path(), 'data{0}'.format(x))
            copy_root = os.path.join(node.get_path(), 'data{0}_copy'.format(x))
            for ddir in os.listdir(data_dir):
                keyspace_dir = os.path.join(data_dir, ddir)
                if os.path.isdir(keyspace_dir) and ddir != 'system':
                    copy_dir = os.path.join(copy_root, ddir)
                    dir_util.copy_tree(keyspace_dir, copy_dir)
__init__.py 文件源码 项目:dockeroo 作者: dockeroo 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def copy_layout(self, src, dst):
        self.logger.info("Copying layout \"%s\" on \"%s\"", src, dst)
        return copy_tree(src, dst)
build.py 文件源码 项目:ambari-tomcat-service 作者: yaroslav-nikolaiko 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def copyDependencies():
    copy_tree(target("dependencies"), tomcatLib)

#copy_tree(project("server"), target())
openshift.py 文件源码 项目:touch-pay-client 作者: HackPucBemobi 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def deploy():
    apps = sorted(file for file in os.listdir(apath(r=request)))
    form = SQLFORM.factory(
        Field(
            'osrepo', default='/tmp', label=T('Path to local openshift repo root.'),
            requires=EXISTS(error_message=T('directory not found'))),
        Field('osname', default='web2py', label=T('WSGI reference name')),
        Field('applications', 'list:string',
              requires=IS_IN_SET(apps, multiple=True),
              label=T('web2py apps to deploy')))

    cmd = output = errors = ""
    if form.accepts(request, session):
        try:
            kill()
        except:
            pass

        ignore_apps = [
            item for item in apps if not item in form.vars.applications]
        regex = re.compile('\(applications/\(.*')
        w2p_origin = os.getcwd()
        osrepo = form.vars.osrepo
        osname = form.vars.osname
        #Git code starts here
        repo = Repo(form.vars.osrepo)
        index = repo.index
        assert repo.bare == False

        for i in form.vars.applications:
            appsrc = os.path.join(apath(r=request), i)
            appdest = os.path.join(osrepo, 'wsgi', osname, 'applications', i)
            dir_util.copy_tree(appsrc, appdest)
            #shutil.copytree(appsrc,appdest)
            index.add(['wsgi/' + osname + '/applications/' + i])
            new_commit = index.commit("Deploy from Web2py IDE")

        origin = repo.remotes.origin
        origin.push
        origin.push()
        #Git code ends here
    return dict(form=form, command=cmd)
openshift.py 文件源码 项目:true_review_web2py 作者: lucadealfaro 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def deploy():
    apps = sorted(file for file in os.listdir(apath(r=request)))
    form = SQLFORM.factory(
        Field(
            'osrepo', default='/tmp', label=T('Path to local openshift repo root.'),
            requires=EXISTS(error_message=T('directory not found'))),
        Field('osname', default='web2py', label=T('WSGI reference name')),
        Field('applications', 'list:string',
              requires=IS_IN_SET(apps, multiple=True),
              label=T('web2py apps to deploy')))

    cmd = output = errors = ""
    if form.accepts(request, session):
        try:
            kill()
        except:
            pass

        ignore_apps = [
            item for item in apps if not item in form.vars.applications]
        regex = re.compile('\(applications/\(.*')
        w2p_origin = os.getcwd()
        osrepo = form.vars.osrepo
        osname = form.vars.osname
        #Git code starts here
        repo = Repo(form.vars.osrepo)
        index = repo.index
        assert repo.bare == False

        for i in form.vars.applications:
            appsrc = os.path.join(apath(r=request), i)
            appdest = os.path.join(osrepo, 'wsgi', osname, 'applications', i)
            dir_util.copy_tree(appsrc, appdest)
            #shutil.copytree(appsrc,appdest)
            index.add(['wsgi/' + osname + '/applications/' + i])
            new_commit = index.commit("Deploy from Web2py IDE")

        origin = repo.remotes.origin
        origin.push
        origin.push()
        #Git code ends here
    return dict(form=form, command=cmd)
collect_late.py 文件源码 项目:csci_tool 作者: vmagro 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def run(self, args):
        assignment = args.assignment
        logger.info('Collecting late submissions for %s', assignment)

        config = Config.load_config()
        github = config.github

        failures = []

        for line in args.submissions:
            email, late_days, sha = line.strip().split(',')
            logger.info('Collecting %s from %s for %s, %s late day(s)',
                        sha, email, assignment, late_days)
            try:
                student = Student(email, None)

                # clone the repo into the subdirectory at args.destination
                dest_dir = path.join(args.destination, student.unix_name)
                # just add a submodule rather than downloading the whole repo
                with tempfile.TemporaryDirectory() as tmpdir:
                    # clone the repo into a temp directory and copy the assignment dir to the submissions dir
                    repo = git.Repo.clone_from(student.repo_url, tmpdir)

                    # make sure we got the right sha
                    repo.git.checkout(sha)

                    dir_util.copy_tree(path.join(tmpdir, assignment), dest_dir)

                # comment on the commit that we collected
                repo_fqn = config.github_org + '/' + student.repo_name
                # must use fully qualified repo name with org
                repo = github.get_repo(repo_fqn)
                commit = repo.get_commits(sha=sha)[0]

                comment = 'This commit was collected as part of "{}". \n \
This was a late submission using {} late day(s). If you think this is \
incorrect, please post on Piazza.'.format(assignment, late_days)
                logger.debug('Commenting on GitHub')
                commit.create_comment(comment)
            except Exception as e:
                logger.error('Failed for %s, %s', email, e)
                failures.append((email, late_days, sha))

        if failures:
            logger.error('Failed on %d students, please try them again', len(failures))
            logger.error('Failures have been written out to ./failures.txt')
            with open('failures.txt', 'w') as f:
                for s in failures:
                    f.write('{},{},{}\n'.format(email, late_days, sha))
collect.py 文件源码 项目:csci_tool 作者: vmagro 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def run(self, args):
        assignment = args.assignment
        students = self.load_students(args.students)
        logger.info('Collecting %s from %d students', assignment, len(students))

        os.makedirs(args.destination, exist_ok=True)

        meta_repo = Repo.meta_repo()
        config = Config.load_config()
        github = config.github

        failures = []
        for student in students:
            try:
                # clone the repo into the subdirectory at args.destination
                dest_dir = path.join(args.destination, student.unix_name)
                # just add a submodule rather than downloading the whole repo
                with tempfile.TemporaryDirectory() as tmpdir:
                    # clone the repo into a temp directory and copy the assignment dir to the submissions dir
                    repo = git.Repo.clone_from(student.repo_url, tmpdir)

                    # if we have a deadline check out the commit from master at that time
                    if args.deadline is not None:
                        rev_list = getattr(repo.git, 'rev-list')
                        sha = rev_list('master', n=1, before=args.deadline)
                    else:
                        sha = repo.head.commit.hexsha
                    dir_util.copy_tree(path.join(tmpdir, assignment), dest_dir)

                logger.info('Collected %s at %s into %s', student.unix_name,
                            sha, dest_dir)

                # comment on the commit that we collected
                repo_fqn = config.github_org + '/' + student.repo_name
                # must use fully qualified repo name with org
                repo = github.get_repo(repo_fqn)
                commit = repo.get_commits(sha=sha)[0]
                comment = 'This commit was collected as part of "{}". \n \
If you think this was a mistake or you want to submit this assignment late, \
please fill out the late form.'.format(assignment)
                commit.create_comment(comment)
            except Exception as e:
                logger.error('Failed to collect %s', student.unix_name)
                logger.error(e)
                failures.append(student)

        if failures:
            logger.error('Failed on %d students, please try them again', len(failures))
            logger.error('Failures have been written out to ./failures.txt')
            with open('failures.txt', 'w') as f:
                for s in failures:
                    f.write(s.email + ' ' + s.github + '\n')

        # commit all the submissions at once

        meta_repo.index.commit('Collected {} from {} students'
                               .format(assignment, len(students)))
        meta_repo.remote().push()
openshift.py 文件源码 项目:Problematica-public 作者: TechMaz 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def deploy():
    apps = sorted(file for file in os.listdir(apath(r=request)))
    form = SQLFORM.factory(
        Field(
            'osrepo', default='/tmp', label=T('Path to local openshift repo root.'),
            requires=EXISTS(error_message=T('directory not found'))),
        Field('osname', default='web2py', label=T('WSGI reference name')),
        Field('applications', 'list:string',
              requires=IS_IN_SET(apps, multiple=True),
              label=T('web2py apps to deploy')))

    cmd = output = errors = ""
    if form.accepts(request, session):
        try:
            kill()
        except:
            pass

        ignore_apps = [
            item for item in apps if not item in form.vars.applications]
        regex = re.compile('\(applications/\(.*')
        w2p_origin = os.getcwd()
        osrepo = form.vars.osrepo
        osname = form.vars.osname
        #Git code starts here
        repo = Repo(form.vars.osrepo)
        index = repo.index
        assert repo.bare == False

        for i in form.vars.applications:
            appsrc = os.path.join(apath(r=request), i)
            appdest = os.path.join(osrepo, 'wsgi', osname, 'applications', i)
            dir_util.copy_tree(appsrc, appdest)
            #shutil.copytree(appsrc,appdest)
            index.add(['wsgi/' + osname + '/applications/' + i])
            new_commit = index.commit("Deploy from Web2py IDE")

        origin = repo.remotes.origin
        origin.push
        origin.push()
        #Git code ends here
    return dict(form=form, command=cmd)
openshift.py 文件源码 项目:web3py 作者: web2py 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def deploy():
    apps = sorted(file for file in os.listdir(apath(r=request)))
    form = SQLFORM.factory(
        Field(
            'osrepo', default='/tmp', label=T('Path to local openshift repo root.'),
            requires=EXISTS(error_message=T('directory not found'))),
        Field('osname', default='web2py', label=T('WSGI reference name')),
        Field('applications', 'list:string',
              requires=IS_IN_SET(apps, multiple=True),
              label=T('web2py apps to deploy')))

    cmd = output = errors = ""
    if form.accepts(request, session):
        try:
            kill()
        except:
            pass

        ignore_apps = [
            item for item in apps if not item in form.vars.applications]
        regex = re.compile('\(applications/\(.*')
        w2p_origin = os.getcwd()
        osrepo = form.vars.osrepo
        osname = form.vars.osname
        #Git code starts here
        repo = Repo(form.vars.osrepo)
        index = repo.index
        assert repo.bare == False

        for i in form.vars.applications:
            appsrc = os.path.join(apath(r=request), i)
            appdest = os.path.join(osrepo, 'wsgi', osname, 'applications', i)
            dir_util.copy_tree(appsrc, appdest)
            #shutil.copytree(appsrc,appdest)
            index.add(['wsgi/' + osname + '/applications/' + i])
            new_commit = index.commit("Deploy from Web2py IDE")

        origin = repo.remotes.origin
        origin.push
        origin.push()
        #Git code ends here
    return dict(form=form, command=cmd)
openshift.py 文件源码 项目:slugiot-client 作者: slugiot 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def deploy():
    apps = sorted(file for file in os.listdir(apath(r=request)))
    form = SQLFORM.factory(
        Field(
            'osrepo', default='/tmp', label=T('Path to local openshift repo root.'),
            requires=EXISTS(error_message=T('directory not found'))),
        Field('osname', default='web2py', label=T('WSGI reference name')),
        Field('applications', 'list:string',
              requires=IS_IN_SET(apps, multiple=True),
              label=T('web2py apps to deploy')))

    cmd = output = errors = ""
    if form.accepts(request, session):
        try:
            kill()
        except:
            pass

        ignore_apps = [
            item for item in apps if not item in form.vars.applications]
        regex = re.compile('\(applications/\(.*')
        w2p_origin = os.getcwd()
        osrepo = form.vars.osrepo
        osname = form.vars.osname
        #Git code starts here
        repo = Repo(form.vars.osrepo)
        index = repo.index
        assert repo.bare == False

        for i in form.vars.applications:
            appsrc = os.path.join(apath(r=request), i)
            appdest = os.path.join(osrepo, 'wsgi', osname, 'applications', i)
            dir_util.copy_tree(appsrc, appdest)
            #shutil.copytree(appsrc,appdest)
            index.add(['wsgi/' + osname + '/applications/' + i])
            new_commit = index.commit("Deploy from Web2py IDE")

        origin = repo.remotes.origin
        origin.push
        origin.push()
        #Git code ends here
    return dict(form=form, command=cmd)
www_proc.py 文件源码 项目:cotcha 作者: hevnsnt 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def before_buildfs(source, target, env):
    print "before_buildfs"

# SPIFFS Stats With Different Combinations of Processing
# Updated: 12.28.2016
# No Processing
#   20 Files, 1.46 MB of 2.81 MB Used
# custom_option = "gz"
#   19 Files, 898.84 KB of 2.81 MB Used
# custom_option =   "gz|css"
#   17 Files, 896.88 KB of 2.81 MB Used
# custom_option = "gz|css|js"
#   13 Files, 893.94 KB of 2.81 MB Used
# custom_option = "gz|css|js|media"
#   8 Files, 898.60 KB of 2.81 MB Used

    # clone 'www' folder to 'data' folder
    files = dir_util.copy_tree(www, data, )

    # embed Javascript, CSS & media into html files
    if re.search(r'css|js|media', options):
        for file in files:
            if re.search(r'\.htm', file):
                print file
                content = read_file(file)
                if re.search(r'css', options):
                    content = embed_css( content )
                if re.search(r'js', options):
                    content = combine_js( content )
                if re.search(r'media', options):
                    content = embed_media( content )

                # Save New HTML File
                with open(file, 'w') as new_file:
                    new_file.write( content )
                new_file.close()

    # gzip appropriate files
    if re.search(r'gz', options):
        pattern = re.compile(ur'\.htm|\.css|\.js|\.map|\.svg|\.ico')
        for file in files:
            if re.search(pattern, file):
                if os.path.exists(file):
                    print file
                    gzFile( file )


# remove 'data' folder after upload
openshift.py 文件源码 项目:StuffShare 作者: StuffShare 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def deploy():
    apps = sorted(file for file in os.listdir(apath(r=request)))
    form = SQLFORM.factory(
        Field(
            'osrepo', default='/tmp', label=T('Path to local openshift repo root.'),
            requires=EXISTS(error_message=T('directory not found'))),
        Field('osname', default='web2py', label=T('WSGI reference name')),
        Field('applications', 'list:string',
              requires=IS_IN_SET(apps, multiple=True),
              label=T('web2py apps to deploy')))

    cmd = output = errors = ""
    if form.accepts(request, session):
        try:
            kill()
        except:
            pass

        ignore_apps = [
            item for item in apps if not item in form.vars.applications]
        regex = re.compile('\(applications/\(.*')
        w2p_origin = os.getcwd()
        osrepo = form.vars.osrepo
        osname = form.vars.osname
        #Git code starts here
        repo = Repo(form.vars.osrepo)
        index = repo.index
        assert repo.bare == False

        for i in form.vars.applications:
            appsrc = os.path.join(apath(r=request), i)
            appdest = os.path.join(osrepo, 'wsgi', osname, 'applications', i)
            dir_util.copy_tree(appsrc, appdest)
            #shutil.copytree(appsrc,appdest)
            index.add(['wsgi/' + osname + '/applications/' + i])
            new_commit = index.commit("Deploy from Web2py IDE")

        origin = repo.remotes.origin
        origin.push
        origin.push()
        #Git code ends here
    return dict(form=form, command=cmd)
master.py 文件源码 项目:ambari-tomcat-service 作者: yaroslav-nikolaiko 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def install(self, env):
        print 'Install the Tomcat Master.'

        # Load the all configuration files
        config = Script.get_config()

        tomcat_user = config['configurations']['common-env']['user']
        tomcat_group = config['configurations']['common-env']['group']
        tomcat_home = config['configurations']['common-env']['catalina_home']
        tomcat_package = os.path.join(os.path.dirname(__file__), '..', 'tomcat')

        # Create  user and group (if they don't exist)
        try: grp.getgrnam(tomcat_group)
        except KeyError: Execute(format('groupadd {tomcat_group}'))

        try: pwd.getpwnam(tomcat_user)
        except KeyError: Execute(format('adduser {tomcat_user} -g {tomcat_group}'))

        Execute(format('mkdir -p {tomcat_home}'),
                user=tomcat_user,
                group=tomcat_group)

        Execute(format('rm -r {tomcat_home}'))

        #copy_tree(tomcat_package, tomcat_home)

        #os.chown(tomcat_home, tomcat_user, tomcat_group)


        os.system(format('cp -a {tomcat_package} {tomcat_home}'))
        os.system(format('mkdir {tomcat_home}/logs'))
        os.system(format('mkdir {tomcat_home}/work'))

        os.system(format('chown {tomcat_user}:{tomcat_group} -R {tomcat_home}'))
        os.system(format('chmod ug+x {tomcat_home}/bin/*.sh'))

        uid = pwd.getpwnam(tomcat_user).pw_uid
        gid = grp.getgrnam(tomcat_group).gr_gid
        #copytree(tomcat_package, tomcat_home)
        #os.chown(tomcat_package, uid, gid)

        #Execute(format('cp -a {tomcat_package} {tomcat_home}'))


        # Install packages
        self.install_packages(env)

        #Directory([tomcat_home],
        #          recursive=True)
        #Execute('cp -r %s/* %s' % (tomcat_package, tomcat_home))


        # Create a new user and group
        #Execute( format("groupadd -f {tomcat_user}") )
        #Execute( format("id -u {tomcat_user} &>/dev/null || useradd -s /bin/bash {tomcat_user} -g {tomcat_user}") )

        ### Continue installing and configuring your service

        print 'Installation complete.'


问题


面经


文章

微信
公众号

扫码关注公众号