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


Python utils.find函数代码示例

本文整理汇总了Python中utils.find函数的典型用法代码示例。如果您正苦于以下问题:Python find函数的具体用法?Python find怎么用?Python find使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: brickfind_crawl

def brickfind_crawl(brick, args):
    if brick.endswith("/"):
        brick = brick[0:len(brick)-1]

    working_dir = os.path.dirname(args.outfile)
    mkdirp(working_dir, exit_on_err=True, logger=logger)
    create_file(args.outfile, exit_on_err=True, logger=logger)

    with open(args.outfile, "a+") as fout:
        brick_path_len = len(brick)

        def output_callback(path, filter_result, is_dir):
            path = path.strip()
            path = path[brick_path_len+1:]

            if args.type == "both":
                output_write(fout, path, args.output_prefix,
                             encode=(not args.no_encode), tag=args.tag,
                             field_separator=args.field_separator)
            else:
                if (is_dir and args.type == "d") or (
                    (not is_dir) and args.type == "f"):
                    output_write(fout, path, args.output_prefix,
                    encode=(not args.no_encode), tag=args.tag,
                    field_separator=args.field_separator)

        ignore_dirs = [os.path.join(brick, dirname)
                       for dirname in
                       conf.get_opt("brick_ignore_dirs").split(",")]

        find(brick, callback_func=output_callback,
             ignore_dirs=ignore_dirs)

        fout.flush()
        os.fsync(fout.fileno())
开发者ID:gluster,项目名称:glusterfs,代码行数:35,代码来源:brickfind.py

示例2: filter

    def filter(self, pts2D):
        """ Filter image points based on loaded mask. 
        
        Usage: Mask = BaseMask('mask.png')
               FilteredPts = Mask.filter(pts)
        
        Input:
            pts - 2-by-N numpy array of 2D points

        Output:
            FilteredPts - 2-by-N numpy array of 2D points. Those that agree 
            with the mask (i.e., those points [x, y] s.t. mask[x,y] = True)
            remain the same, while invalid points are zeroed.
        """
        
        # Find points that are not zero in image space
        idxPts = utils.find( np.logical_and(pts2D[0, :] > 0, pts2D[1,:] > 0) )

        # Get rounded and flattened (1D) pixel indexes for our 2D points
        idxPtsFlat = utils.ravel_index(pts2D[::-1, idxPts].astype(int), \
                                       self.data.shape)

        # Find invalid 2D points by comparing them to the mask
        idxInvalidPts = utils.find( self.data.flat[idxPtsFlat] == 0 )

        # Set invalid points to zero
        pts2D[:, idxPts[idxInvalidPts]] = 0

        return pts2D
开发者ID:apoorvcn47,项目名称:moped,代码行数:29,代码来源:MaskReader.py

示例3: test_find

def test_find():
    looking_for = {'a': 1, 'match': True}
    foo = [looking_for, {'b': 1}, {'a': 2}]
    match = find(foo, {'a': 1})
    assert match == looking_for
    match = find(foo, {'c': 1})
    assert not match
开发者ID:cameronmaske,项目名称:skipper-prototype,代码行数:7,代码来源:tests.py

示例4: gfid_to_path_using_batchfind

def gfid_to_path_using_batchfind(brick, changelog_data):
    # If all the GFIDs converted using gfid_to_path_using_pgfid
    if not changelog_data.inodegfid_exists({"converted": 0}):
        return

    def inode_filter(path):
        # Looks in inodegfid table, if exists returns
        # inode number else None
        try:
            st = os.lstat(path)
        except (OSError, IOError):
            st = None

        if st and changelog_data.inodegfid_exists({"inode": st.st_ino}):
            return st.st_ino

        return None

    # Length of brick path, to remove from output path
    brick_path_len = len(brick)

    def output_callback(path, inode):
        # For each path found, encodes it and updates path1
        # Also updates converted flag in inodegfid table as 1
        path = path.strip()
        path = path[brick_path_len + 1 :]
        path = output_path_prepare(path, args.output_prefix)

        changelog_data.append_path1(path, inode)

    ignore_dirs = [os.path.join(brick, dirname) for dirname in conf.get_opt("brick_ignore_dirs").split(",")]

    # Full Namespace Crawl
    find(brick, callback_func=output_callback, filter_func=inode_filter, ignore_dirs=ignore_dirs)
开发者ID:kotreshhr,项目名称:glusterfs,代码行数:34,代码来源:changelog.py

示例5: gfid_to_path_using_batchfind

def gfid_to_path_using_batchfind(brick, gfids_file, output_file):
    """
    find -samefile gets the inode number and crawls entire namespace
    to get the list of files/dirs having same inode number.
    Do find without any option, except the ignore directory option,
    print the output in <INODE_NUM> <PATH> format, use this output
    to look into in-memory dictionary of inode numbers got from the
    list of GFIDs
    """
    with open(output_file, "a+") as fout:
        inode_dict = {}
        with open(gfids_file) as f:
            for gfid in f:
                gfid = gfid.strip()
                backend_path = os.path.join(brick, ".glusterfs",
                                            gfid[0:2], gfid[2:4], gfid)

                try:
                    inode_dict[str(os.stat(backend_path).st_ino)] = 1
                except (IOError, OSError) as e:
                    if e.errno == ENOENT:
                        continue
                    else:
                        fail("%s Failed to convert to path from "
                             "GFID %s: %s" % (brick, gfid, e), logger=logger)

        if not inode_dict:
            return

        def inode_filter(path):
            try:
                st = os.lstat(path)
            except (OSError, IOError) as e:
                if e.errno == ENOENT:
                    st = None
                else:
                    raise

            if st and inode_dict.get(str(st.st_ino), None):
                return True

            return False

        brick_path_len = len(brick)

        def output_callback(path):
            path = path.strip()
            path = path[brick_path_len+1:]
            output_write(fout, path, args.output_prefix)

        ignore_dirs = [os.path.join(brick, dirname)
                       for dirname in
                       conf.get_opt("brick_ignore_dirs").split(",")]
        # Length of brick path, to remove from output path
        find(brick, callback_func=output_callback,
             filter_func=inode_filter,
             ignore_dirs=ignore_dirs)

        fout.flush()
        os.fsync(fout.fileno())
开发者ID:SourabhShenoy,项目名称:glusterfs,代码行数:60,代码来源:changelog.py

示例6: brickfind_crawl

def brickfind_crawl(brick, args):
    if brick.endswith("/"):
        brick = brick[0:len(brick)-1]

    working_dir = os.path.dirname(args.outfile)
    mkdirp(working_dir, exit_on_err=True, logger=logger)
    create_file(args.outfile, exit_on_err=True, logger=logger)

    with open(args.outfile, "a+") as fout:
        brick_path_len = len(brick)

        def output_callback(path, filter_result):
            path = path.strip()
            path = path[brick_path_len+1:]
            output_write(fout, path, args.output_prefix, encode=True)

        ignore_dirs = [os.path.join(brick, dirname)
                       for dirname in
                       conf.get_opt("brick_ignore_dirs").split(",")]

        find(brick, callback_func=output_callback,
             ignore_dirs=ignore_dirs)

        fout.flush()
        os.fsync(fout.fileno())
开发者ID:Jingle-Wang,项目名称:glusterfs,代码行数:25,代码来源:brickfind.py

示例7: gfid_to_path_using_pgfid

def gfid_to_path_using_pgfid(brick, changelog_data, args):
    """
    For all the pgfids collected, Converts to Path and
    does readdir on those directories and looks up inodegfid
    table for matching inode number.
    """
    populate_pgfid_and_inodegfid(brick, changelog_data)

    # If no GFIDs needs conversion to Path
    if not changelog_data.inodegfid_exists({"converted": 0}):
        return

    def inode_filter(path):
        # Looks in inodegfid table, if exists returns
        # inode number else None
        try:
            st = os.lstat(path)
        except (OSError, IOError):
            st = None

        if st and changelog_data.inodegfid_exists({"inode": st.st_ino}):
            return st.st_ino

        return None

    # Length of brick path, to remove from output path
    brick_path_len = len(brick)

    def output_callback(path, inode):
        # For each path found, encodes it and updates path1
        # Also updates converted flag in inodegfid table as 1
        path = path.strip()
        path = path[brick_path_len+1:]

        path = output_path_prepare(path, args)

        changelog_data.append_path1(path, inode)
        changelog_data.inodegfid_update({"converted": 1}, {"inode": inode})

    ignore_dirs = [os.path.join(brick, dirname)
                   for dirname in
                   conf.get_opt("brick_ignore_dirs").split(",")]

    for row in changelog_data.pgfid_get():
        try:
            path = symlink_gfid_to_path(brick, row[0])
            find(os.path.join(brick, path),
                 callback_func=output_callback,
                 filter_func=inode_filter,
                 ignore_dirs=ignore_dirs,
                 subdirs_crawl=False)
        except (IOError, OSError) as e:
            logger.warn("Error converting to path: %s" % e)
            continue
开发者ID:gluster,项目名称:glusterfs,代码行数:54,代码来源:changelog.py

示例8: main

def main():
  aunts = parse(sys.stdin.readlines())
  
  similar = lambda ref, x: all(x.get(k, v) == v for k, v in ref.items())
  best_aunt = find(partial(similar, REF_AUNT), aunts)
  print('part 1:', best_aunt['id'])

  key2cmp = {'cats': ge, 'trees': ge, 'pomeranians': le, 'goldfish': le}
  compare = lambda key, fst, snd: key2cmp.get(key, eq)(fst, snd)
  similar = lambda ref, x: all(compare(k, x.get(k, v), v) for k, v in ref.items())
  best_aunt = find(partial(similar, REF_AUNT), aunts)
  print('part 2:', best_aunt['id'])
开发者ID:yonax,项目名称:advent-of-code,代码行数:12,代码来源:day16.py

示例9: get_or_create_test_host

def get_or_create_test_host(c):
    instances = all_hosts(c)
    test_host = find(instances, {'tags': {'name': 'test_host', 'type': 'skipper'}})
    if not test_host:
        test_host = create_host(c)
        test_host.add_tag('name', 'test_host')
    return test_host
开发者ID:cameronmaske,项目名称:skipper-prototype,代码行数:7,代码来源:skipper.py

示例10: get_arch_srcs

        def get_arch_srcs(prebuilt, arch):
            """Returns build rule for arch specific srcs.

            e.g.,
                arch: {
                    arm: {
                        srcs: ["..."]
                    },
                    arm64: {
                        srcs: ["..."]
                    },
                }

            Args:
              prebuilt: string, name of prebuilt object
              arch: string, VNDK snapshot arch (e.g. 'arm64')
            """
            arch_srcs = '{ind}arch: {{\n'.format(ind=self.INDENT)
            src_paths = utils.find(src_root, [prebuilt])
            # filter out paths under 'binder32' subdirectory
            src_paths = filter(lambda src: not src.startswith(utils.BINDER32),
                               src_paths)

            for src in sorted(src_paths):
                arch_srcs += ('{ind}{ind}{arch}: {{\n'
                              '{ind}{ind}{ind}srcs: ["{src}"],\n'
                              '{ind}{ind}}},\n'.format(
                                  ind=self.INDENT,
                                  arch=utils.prebuilt_arch_from_path(
                                      os.path.join(arch, src)),
                                  src=src))
            arch_srcs += '{ind}}},\n'.format(ind=self.INDENT)
            return arch_srcs
开发者ID:android,项目名称:platform_development,代码行数:33,代码来源:gen_buildfiles.py

示例11: dl_fna

def dl_fna(species_name):
    """Dl fna if necessary, return filename"""
    accession = dl_gbk(species_name)
    print "accession:",accession
    fna_name = accession + ".fna"
    print "fna_name:",fna_name
    target_path = os.path.join("data",species_name,fna_name)
    if os.path.isfile(target_path):
        print "found fna:",target_path
        return target_path
    print "didn't find fna for:",species_name,"downloading"
    host.chdir('/genomes/Bacteria/')
    dir_list = host.listdir(host.curdir)
    sorted_dir_list = sorted(dir_list,key=lambda fname:levenshtein(species_name,fname))
    for dir_name in sorted_dir_list:
        print "trying:",dir_name
        try:
            host.chdir('/genomes/Bacteria/' + dir_name + '/')
            sub_dir_list = host.listdir(host.curdir)
            if find(lambda name:name.startswith(accession),sub_dir_list):
                host.download(fna_name,target_path)
                return target_path
        except:
            continue
    print "Couldn't find fna for:",species_name
    return None
开发者ID:ErillLab,项目名称:TFBS_data,代码行数:26,代码来源:common.py

示例12: get_arch_srcs

        def get_arch_srcs(prebuilt, variant):
            """Returns build rule for arch specific srcs.

            e.g.,
                arch: {
                    arm: {
                        srcs: ["..."]
                    },
                    arm64: {
                        srcs: ["..."]
                    },
                }

            Args:
              prebuilt: string, name of prebuilt object
              variant: string, VNDK snapshot variant (e.g. 'arm64')
            """
            arch_srcs = '{ind}arch: {{\n'.format(ind=self.INDENT)
            variant_path = os.path.join(self._install_dir, variant)
            src_paths = utils.find(variant_path, [prebuilt])
            for src in sorted(src_paths):
                arch_srcs += (
                    '{ind}{ind}{arch}: {{\n'
                    '{ind}{ind}{ind}srcs: ["{src}"],\n'
                    '{ind}{ind}}},\n'.format(
                        ind=self.INDENT,
                        arch=utils.arch_from_path(os.path.join(variant, src)),
                        src=src))
            arch_srcs += '{ind}}},\n'.format(ind=self.INDENT)
            return arch_srcs
开发者ID:endian11,项目名称:platform_development,代码行数:30,代码来源:gen_buildfiles.py

示例13: get

    def get(self, event_code, talk_code):
        logging.info('Event Code: %s Talk Code: %s ' % (event_code, talk_code))
        talk_code = talk_code.upper()
        event_code = event_code.lower()

        event = utils.find(lambda e: event_code == e.code, Events().get_all())
        talk = Talks().get_talk_for_event(event_code, talk_code)

        if((talk is None) or (event is None)):
            self.response.write('Resource Not Found')
            self.response.set_status(404)
            return

        talk = talk[0]

        logging.info('Talk Details: ' + talk.code)

        feedbacks = get_talk_feedbacks(talk_code)

        template_values = {}
        template_values['feedbacks'] = feedbacks
        template_values['talk'] = talk
        template_values['header'] = event.header
        template_values['feedbacksCount'] = len(feedbacks)
        template_values['averageRating'] = 0 if len(feedbacks) == 0 else  sum(
            [int(ast.literal_eval(feedback.content)['ratingC']) for feedback in feedbacks]) / len(feedbacks)

        template = jinja_environment.get_template(html_path + 'view.html')
        self.response.out.write(template.render(template_values))
开发者ID:akshaysn,项目名称:Feedback-App,代码行数:29,代码来源:controller.py

示例14: rate_matrix

def rate_matrix(q,koffs,verbose=False):
    """Generate the stochastic rate matrix for the givens system."""
    # Chromosome states can be represented by binary numerals; order the
    # states this way.
    G = len(koffs)
    states = enumerate_states(G,q)
    num_states = len(states)
    assert len(states) == sum(choose(G,i) for i in range(q+1))
    R = np.zeros((num_states,num_states))
    for i,state_i in enumerate(states):
        for j,state_j in enumerate(states):
            if verbose:
                print "considering:",i,state_i,"->",j,state_j
            dist = hamming(state_i,state_j)
            if dist != 1:
                # deal with diagonal elements later...
                if verbose:
                    print "distance is:",dist,"continuing..."
                continue
            if sum(state_j) == sum(state_i) + 1:
                R[i][j] = q - sum(state_i)
                if verbose:
                    print i,state_i,"->",j,state_j, "is an on-reaction, rate:",R[i][j]
            elif sum(state_j) == sum(state_i) - 1:
                diff_idx,diff_site = find(lambda (idx,(si,sj)):si != sj,enumerate(zip(state_i,state_j)))
                R[i][j] = koffs[diff_idx]
                if verbose:
                    print i,state_i,"->",j,state_j, "is an off-reaction (at site",diff_idx,")  rate:",R[i][j]
    # deal with diagonal elements
    for i in range(num_states):
        R[i][i] = -sum(R[i])
    print "finished rate matrix"
    return R
开发者ID:poneill,项目名称:amic,代码行数:33,代码来源:cme.py

示例15: get_or_create_security_group

def get_or_create_security_group(c):
    groups = c.get_all_security_groups()
    group = find(groups, {'name': 'skipper'})
    if not group:
        print("Creating new security group.")
        group = c.create_security_group("skipper", "Skipper security group")
    else:
        print("Found existing security group.")
    return group
开发者ID:cameronmaske,项目名称:skipper-prototype,代码行数:9,代码来源:skipper.py


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