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


Python Path.listdir方法代码示例

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


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

示例1: create

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import listdir [as 别名]
def create(dataset, work_dir):
    # Find all the pages in the dataset
    img_dir = Path(Path.cwd().ancestor(1), 'data/hwr_data/pages', dataset)
    ann_dir = Path(Path.cwd().ancestor(1), 'data/charannotations')
    images = img_dir.listdir('*.jpg')
    annotations = ann_dir.listdir(dataset + '*.words')
    files = merge(images, annotations)

    # Create character segmentations
    stats = {}
    for f in files:
        # Preprocess
        logging.info("Preprocessing %s", str(f[0]))
        pagesPathFolder = Path(work_dir, 'pages')
        pagesPathFolder.mkdir()
        pagePath = Path(pagesPathFolder, f[0].stem + '.ppm')
        img = cv2.imread(f[0], cv2.IMREAD_GRAYSCALE)
        img = preprocess(img)
        cv2.imwrite(pagePath, img)

        # Segment
        segmentPathFolder = Path(work_dir, 'segments')
        segmentPathFolder.mkdir()
        e = ET.parse(f[1]).getroot()
        logging.info("Segmenting %s", str(f[0]))
        segment(img, e, segmentPathFolder, stats)

    print_statistics(stats, dataset)
开发者ID:XeryusTC,项目名称:handwritingrecog,代码行数:30,代码来源:create_segments.py

示例2: get

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import listdir [as 别名]
def get(project=None):
    """Get the data from different experiments.

    Warning! Experiment directories are expected in a particular location
    outside of this (words-in-transition) directory.

    Options are:

        telephone-app
        acoustic-similarity
        learning-sound-names

    """
    if project is None or project == 'telephone-app':
        app_dir = Path('../telephone-app')
        snapshot_dir = Path(app_dir, 'words-in-transition')
        if src_dir.exists():
            src_dir.rmtree()
        copytree(snapshot_dir, src_dir)

    if project is None or project == 'acoustic-similarity':
        # src
        proj_dir = Path('../acoustic-similarity/data')
        judgments = Path(proj_dir, 'judgments')

        # dst
        acoustic_similarity_dir = Path(data_raw, 'acoustic-similarity')
        if not acoustic_similarity_dir.isdir():
            acoustic_similarity_dir.mkdir()

        # copy the csvs in the root proj data dir
        for csv in proj_dir.listdir('*.csv'):
            csv.copy(Path(acoustic_similarity_dir, csv.name))

        # concat and save judgments files
        judgments_csv = Path(acoustic_similarity_dir, 'judgments.csv')
        judgments = [pd.read_csv(x) for x in judgments.listdir('*.csv')]
        if judgments:
            (pd.concat(judgments, ignore_index=True)
               .to_csv(judgments_csv, index=False))

    if project is None or project == 'learning-sound-names':
        src = Path('../learning-sound-names/data')
        dst = Path(data_raw, 'learning_sound_names.csv')
        data = pd.concat([pd.read_csv(x) for x in src.listdir('LSN*.csv')])
        data['is_correct'] = data.is_correct.astype(int)
        data.to_csv(dst, index=False)

        # also get subject info and questionnaire data
        to_get = ['questionnaire_v1', 'subject_info']
        for x in to_get:
            src_file = Path(src, '{}.csv'.format(x))
            dst_file = Path(data_raw, 'learning_sound_names_{}.csv'.format(x))
            run('cp {} {}'.format(src_file, dst_file))
开发者ID:lupyanlab,项目名称:words-in-transition,代码行数:56,代码来源:data.py

示例3: JarBuilder

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import listdir [as 别名]
class JarBuilder(object):
    """Holds the information needed for building a Java Archive (`.jar`)
file.

    """

    def __init__(self, jarfile, sourcedir, tsa):
        self.libjars = []
        self.tsa = tsa
        self.jarfile = Path(jarfile)
        self.sourcedir = Path(sourcedir)
        self.sources = list(self.sourcedir.listdir('*.java'))

        self.jarcontent = [Path('Manifest.txt')]
        self.jarcontent += [
            Path(x) for x in self.sourcedir.listdir('*.class')]

    def add_lib(self, pth):
        self.libjars.append(Path(pth))

    def build_jar(self, ctx, outdir, alias):
        flags = '-storepass "`cat ~/.secret/.keystore_password`"'
        if self.tsa:
            flags += ' -tsa {0}'.format(self.tsa)

        def run_signer(jarfile):
            ctx.run("jarsigner %s %s %s" % (flags, jarfile, alias), pty=True)
            ctx.run("jarsigner -verify %s" % jarfile, pty=True)

        outdir = Path(outdir)
        jarfile = outdir.child(self.jarfile)
        if jarfile.needs_update(self.jarcontent):
            jarcontent = [x.replace("$", r"\$") for x in self.jarcontent]
            ctx.run("jar cvfm %s %s" % (jarfile, ' '.join(jarcontent)), pty=True)
        run_signer(jarfile)
        for libfile in self.libjars:
            jarfile = outdir.child(libfile.name)
            if not jarfile.exists() or libfile.needs_update([jarfile]):
                libfile.copy(jarfile)
            run_signer(jarfile)

    def build_classes(self, ctx):
        flags = "-Xlint:unchecked"
        if len(self.libjars):
            cp = ':'.join(self.libjars)
            flags += " -classpath %s" % cp
        for src in self.sources:
            ctx.run("javac %s %s" % (flags, src), pty=True)
开发者ID:khchine5,项目名称:atelier,代码行数:50,代码来源:jarbuilder.py

示例4: __init__

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import listdir [as 别名]
    def __init__(self, path):
        try:
            path = Path(path)

            self.__parents__ = path
            self.__contents__ = [d.name for d in path.listdir()]
        except:
            pass
开发者ID:hallaj,项目名称:inupypi,代码行数:10,代码来源:info.py

示例5: install_skeletton

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import listdir [as 别名]
    def install_skeletton(self):
        logger.info('Installing %s' % self.flavor)

        source = Path(self.repo_dir, self.flavor)

        #move all items in the directory into the install_path
        for item in source.listdir():
            item.move(self.install_path)
        self.delete_tmp_dir()
        logger.info('...done')
开发者ID:Libermentix,项目名称:project_installer,代码行数:12,代码来源:project_installer.py

示例6: find_labels

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import listdir [as 别名]
def find_labels():
    files = {}
    work_dir = Path("tmp/segments")
    if not work_dir.exists():
        raise Exception("You must first create the labels")

    files = {}
    labels = work_dir.listdir(filter=DIRS_NO_LINKS)
    for label in labels:
        files[str(label.name)] = label.listdir(pattern='*.ppm')
    return files
开发者ID:XeryusTC,项目名称:handwritingrecog,代码行数:13,代码来源:discover_data.py

示例7: dump_path

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import listdir [as 别名]
def dump_path(path, prefix="", tab="    ", file=None):
    if file is None:
        file = sys.stdout
    p = Path(path)
    if   p.islink():
        print >>file, "%s%s -> %s" % (prefix, p.name, p.read_link())
    elif p.isdir():
        print >>file, "%s%s:" % (prefix, p.name)
        for p2 in p.listdir():
            dump_path(p2, prefix+tab, tab, file)
    else:
        print >>file, "%s%s  (%d)" % (prefix, p.name, p.size())
开发者ID:Alwnikrotikz,项目名称:promogest,代码行数:14,代码来源:tools.py

示例8: JarBuilder

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import listdir [as 别名]
class JarBuilder(object):
    """
    Used by my Java projects :ref:`davlink` and :ref:`eidreader`.
    """
    def __init__(self, jarfile, sourcedir):
        self.jarfile = Path(jarfile)
        self.sourcedir = Path(sourcedir)
        self.sources = list(self.sourcedir.listdir('*.java'))

        self.jarcontent = [Path('Manifest.txt')]
        self.jarcontent += list(self.sourcedir.listdir('*.class'))
        self.jarcontent = [
            Path(x.replace("$", "\\$")) for x in self.jarcontent]
        self.libjars = []

    def add_lib(self, pth):
        self.libjars.append(Path(pth))

    def build_jar(self, outdir, alias):
        flags = '-storepass "`cat ~/.secret/.keystore_password`"'
        flags += ' -tsa http://timestamp.globalsign.com/scripts/timestamp.dll'
        outdir = Path(outdir)
        jarfile = outdir.child(self.jarfile)
        if jarfile.needs_update(self.jarcontent):
            local("jar cvfm %s %s" % (jarfile, ' '.join(self.jarcontent)))
        local("jarsigner %s %s %s" % (flags, jarfile, alias))
        for libfile in self.libjars:
            jarfile = outdir.child(libfile.name)
            if libfile.needs_update([jarfile]):
                libfile.copy(jarfile)
            local("jarsigner %s %s %s" % (flags, jarfile, alias))

    def build_classes(self):
        flags = "-Xlint:unchecked"
        if len(self.libjars):
            cp = ':'.join(self.libjars)
            flags += " -classpath %s" % cp
        for src in self.sources:
            local("javac %s %s" % (flags, src))
开发者ID:ManuelWeidmann,项目名称:atelier,代码行数:41,代码来源:fablib.py

示例9: parse

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import listdir [as 别名]
def parse(path='./flat_files/'):
    path = Path(path)
    print "parsing records at {}".format(path.absolute())

    records = []
    for p in path.listdir():
        try:
            gbr = GenBank.read(open(p))
            records.append(gbr)
        except:
            print 'error with file', p
    print "parsed %s records.." % len(records)

    return records
开发者ID:HakimGeorge,项目名称:chromo9,代码行数:16,代码来源:init_database.py

示例10: __init__

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import listdir [as 别名]
    def __init__(self, path):
        self.__parents__ = None
        self.__contents__ = None

        try:
            path = Path(path)

            self.__parents__ = path
            self.__contents__ = sorted([dir_.absolute() for dir_ in
                                        path.listdir()
                                        if dir_.isdir() or dir_.isfile()],
                                       key=lambda v: parse_version(v))
        except:
            pass
开发者ID:hallaj,项目名称:inupypi,代码行数:16,代码来源:__init__.py

示例11: recursive_listdir

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import listdir [as 别名]
def recursive_listdir(path):
    """
    Lists recursively all files inside a given directory and its subdirectories
    :param path: (unipath.Path or string) path to the directory
    :return: (list of unipath.Path) list containing the path to all the files
        inside the given directory
    """
    folder = Path(path)
    files = list()
    for f in folder.listdir():
        if f.isdir():
            files.extend(recursive_listdir(f))
        else:
            files.append(f.absolute())
    return files
开发者ID:cuducos,项目名称:whiskyton,代码行数:17,代码来源:sitemap.py

示例12: parse_auth_log

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import listdir [as 别名]
def parse_auth_log(log_folder='/var/log/'):
    directory = Path(log_folder)
    for auth_file in directory.listdir('auth*.*', FILES):
        if auth_file.ext == '.gz':
            auth = gzip.open(auth_file, 'rb')
        else:
            auth = open(auth_file, 'rU')

        prev_id = ''
        attempt = None
        for line in auth.readlines():
            line = line.strip()

            # Skip sudo entries
            if line.find('sudo') >= 0:
                continue
            # Grab the date/time of the attempt and remove that from line
            attempted, line = get_date_from_line(line)

            # Grab the attempt ID
            attempt_id = get_id_from_line(line)

            # Is this a dup?
            if SshHackAttempt.objects.filter(ssh_id=attempt_id).count() > 0:
                continue

            # Is this a new attempt?
            new_attempt = prev_id != attempt_id

            if new_attempt:
                if getattr(attempt, 'has_all_keys', None):
                    # Store the previous attempt and start a new one
                    attempt.save()
                attempt = AuthAttempt()
                attempt.ssh_id = attempt_id
                attempt.attempted = attempted

            # Grab the IP address
            attempt.set_ip_from_line(line)

            # Is the username in this line?
            attempt.set_username_from_line(line)

            # Does the ID need updated?
            if prev_id != attempt_id:
                prev_id = attempt_id

        auth.close()
开发者ID:hellsgate1001,项目名称:graphs,代码行数:50,代码来源:cron.py

示例13: get_package_files

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import listdir [as 别名]
def get_package_files(eggbasket, package):
    package_path = get_package_path(eggbasket)
    package = package_path.listdir()[[x.name.lower() for x in package_path.listdir()].index(package.lower())]

    package_dir = Path(package_path, package)
    files = []

    for package_file in package_dir.listdir():
        p = Package()
        p.filepath = package_file
        p.eggbasket = eggbasket
        try:
            p.name = SDist(package_file).name
            p.author = SDist(package_file).metadata['PKG-INFO']['Author']
        except Exception:
            pass
        files.append(p)
    return sorted(files, reverse=True)
开发者ID:Zhaf,项目名称:inupypi,代码行数:20,代码来源:__init__.py

示例14: create_own_lexicon

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import listdir [as 别名]
def create_own_lexicon():

    lexicon = {}

    for dataset in ['KNMP', 'Stanford']:
        # Find all the annotated pages in the dataset
        ann_dir = Path(Path.cwd().ancestor(1), 'data/hwr_data/words/' + dataset)
        annotations = ann_dir.listdir( '*.words')

        for f in annotations:
            # Segment
            annotation = ET.parse(f).getroot()
            for word in annotation.iter('Word'):
                text = word.get('text')

                # Add word to lexicon
                if lexicon.has_key(text):
                    lexicon[text] += 1
                else :
                    lexicon[text] = 1
    return lexicon
开发者ID:XeryusTC,项目名称:handwritingrecog,代码行数:23,代码来源:create_lexicon.py

示例15: check_circular_imports

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import listdir [as 别名]
def check_circular_imports(path, prefix):
    path = Path(path)
    python_files_paths = path.listdir(filter=FILES, pattern='*.py')
    relative_import_modules = {}
    pattern = re.compile(
        r'(from {0} import )?(\w+),?[\s+]?(as\s\w+)?'.format(prefix),
        re.IGNORECASE)
    for pyf in python_files_paths:
        with open(pyf, 'r') as f:
            for line in f.read().splitlines():
                matchs = pattern.findall(line)
                if not matchs:
                    continue
                modules_names = [m[1] for m in matchs]
                relative_import_modules[pyf.stem] = modules_names

    for module, next_module in combinations(relative_import_modules.keys(), 2):
        module_modules = relative_import_modules[module]
        next_module_modules = relative_import_modules[next_module]
        if module.name in next_module_modules and next_module.name in module_modules:
            print "Circular imports in modules {0} and {1}".format(
                module, next_module)
开发者ID:tejinderss,项目名称:find-circular-imports,代码行数:24,代码来源:find_cicular_imports.py


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