How to use the scandir.scandir_generic function in scandir

To help you get started, we’ve selected a few scandir examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github benhoyt / scandir / test / test_scandir.py View on Github external
def setUp(self):
            self.scandir_func = scandir.scandir_generic
            self.has_file_attributes = False
            TestMixin.setUp(self)
github morpheus65535 / bazarr / libs / subliminal_patch / core.py View on Github external
def _search_external_subtitles(path, languages=None, only_one=False, scandir_generic=False, match_strictness="strict"):
    dirpath, filename = os.path.split(path)
    dirpath = dirpath or '.'
    fn_no_ext, fileext = os.path.splitext(filename)
    fn_no_ext_lower = fn_no_ext.lower()
    subtitles = {}
    _scandir = _scandir_generic if scandir_generic else scandir

    for entry in _scandir(dirpath):
        if (not entry.name or entry.name in ('\x0c', '$', ',', '\x7f')) and not scandir_generic:
            logger.debug('Could not determine the name of the file, retrying with scandir_generic')
            return _search_external_subtitles(path, languages, only_one, True)
        if not entry.is_file(follow_symlinks=False):
            continue

        p = entry.name

        # keep only valid subtitle filenames
        if not p.lower().endswith(SUBTITLE_EXTENSIONS):
            continue

        # not p.lower().startswith(fileroot.lower()) or not
github benhoyt / scandir / benchmark.py View on Github external
scandir.scandir = scandir.scandir_python
    elif options.scandir == 'os':
        if not hasattr(os, 'scandir'):
            print("ERROR: Python 3.5's os.scandir() not found!")
            sys.exit(1)
        scandir.scandir = os.scandir
    elif hasattr(os, 'scandir'):
        scandir.scandir = os.scandir

    if scandir.scandir == getattr(os, 'scandir', None):
        print("Using Python 3.5's builtin os.scandir()")
    elif scandir.scandir == scandir.scandir_c:
        print('Using fast C version of scandir')
    elif scandir.scandir == scandir.scandir_python:
        print('Using slower ctypes version of scandir')
    elif scandir.scandir == scandir.scandir_generic:
        print('Using very slow generic version of scandir')
    else:
        print('ERROR: Unsure which version of scandir we are using!')
        sys.exit(1)

    if hasattr(os, 'scandir'):
        os.walk = os_walk_pre_35
        print('Comparing against pre-Python 3.5 version of os.walk()')
    else:
        print('Comparing against builtin version of os.walk()')

    benchmark(tree_dir, get_size=options.size)
github benhoyt / scandir / benchmark.py View on Github external
help='get size of directory tree while walking')
    parser.add_option('-c', '--scandir', type='choice', choices=['best', 'generic', 'c', 'python', 'os'], default='best',
                      help='version of scandir() to use, default "%default"')
    options, args = parser.parse_args()

    if args:
        tree_dir = args[0]
    else:
        tree_dir = os.path.join(os.path.dirname(__file__), 'benchtree')
        if not os.path.exists(tree_dir):
            print('Creating tree at {0}: depth={1}, num_dirs={2}, num_files={3}'.format(
                tree_dir, DEPTH, NUM_DIRS, NUM_FILES))
            create_tree(tree_dir)

    if options.scandir == 'generic':
        scandir.scandir = scandir.scandir_generic
    elif options.scandir == 'c':
        if scandir.scandir_c is None:
            print("ERROR: Compiled C version of scandir not found!")
            sys.exit(1)
        scandir.scandir = scandir.scandir_c
    elif options.scandir == 'python':
        if scandir.scandir_python is None:
            print("ERROR: Python version of scandir not found!")
            sys.exit(1)
        scandir.scandir = scandir.scandir_python
    elif options.scandir == 'os':
        if not hasattr(os, 'scandir'):
            print("ERROR: Python 3.5's os.scandir() not found!")
            sys.exit(1)
        scandir.scandir = os.scandir
    elif hasattr(os, 'scandir'):
github n1nj4sec / pupy / pupy / packages / all / pupyutils / search.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from scandir import scandir
if scandir is None:
    from scandir import scandir_generic as scandir

import os
import re
import sys

try:
    import mmap
except ImportError:
    pass

import threading
import rpyc

import errno
import traceback
github morpheus65535 / bazarr / libs / subzero / subtitle_storage.py View on Github external
def get_all_files(self, scandir_generic=False):
        _scandir = _scandir_generic if scandir_generic else scandir
        for entry in _scandir(self.dataitems_path):
            if entry.is_file(follow_symlinks=False) and \
                    entry.name.startswith("subs_") and \
                    entry.name.endswith(self.extension):
                yield entry.name
github n1nj4sec / pupy / pupy / packages / all / pupyutils / basic_cmds.py View on Github external
import os
import glob
import shutil
import getpass
import stat
import sys
import datetime
import re
import codecs

from zipfile import ZipFile, is_zipfile
from tarfile import is_tarfile
from tarfile import open as open_tarfile

from scandir import scandir
if scandir is None:
    from scandir import scandir_generic as scandir

PREV_CWD = None

# -------------------------- For ls functions --------------------------

T_NAME      = 0
T_TYPE      = 1
T_SPEC      = 2
T_MODE      = 3
T_UID       = 4
T_GID       = 5
T_SIZE      = 6
T_TIMESTAMP = 7
T_PATH      = 8
T_FILES     = 9
github n1nj4sec / pupy / pupy / packages / all / transfer.py View on Github external
if Buffer in brine.simple_types:
    HAS_BUFFER_OPTIMIZATION = True
else:
    from io import BytesIO as Buffer

if sys.platform == 'win32':
    from junctions import islink, readlink, lstat
else:
    from os import readlink, lstat
    from os.path import islink

from zlib import compress

from scandir import scandir
if scandir is None:
    from scandir import scandir_generic as scandir

import rpyc
import sys

try:
    import umsgpack as msgpack
except ImportError:
    import msgpack

import re

from network.lib import getLogger
logger = getLogger('transfer')

FIELDS_MAP = {