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


Python Path.isdir方法代码示例

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


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

示例1: main

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isdir [as 别名]
def main():
    """
    Controller.
    """
    args = sys.argv[1:]
    if len(args) == 0:
        print_usage()
        sys.exit(0)

    args = check_args(args)

    prg = args[0]  # script in venv
    args = args[1:]  # arguments of the script in venv

    p = Path(prg).absolute()
    venv_file = find_venv_file(p.parent)

    venv_dir = Path(venv_file.read_file().strip())
    # .venv can also contain a relative path
    if not venv_dir.isabsolute():
        venv_dir = Path(venv_file.parent, venv_dir).norm()

    if not venv_dir.isdir():
        print("Error: {vd} is not a directory.".format(vd=venv_dir), file=sys.stderr)
        sys.exit(1)
    #
    python_path = Path(venv_dir, "bin/python")
    if not python_path.isfile():
        print("Error: {pp} is missing.".format(pp=python_path), file=sys.stderr)
        sys.exit(1)

    if DEBUG:
        print("# venv dir:  {d}".format(d=venv_dir), file=sys.stderr)

    my_call(python_path, prg, args)
开发者ID:killerswan,项目名称:wpython,代码行数:37,代码来源:wpython.py

示例2: get_closest_uid

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isdir [as 别名]
def get_closest_uid(path):
	path = Path(path)
	while not path.isdir():
		path = path.ancestor(1)
		if path == '/':
			return False
	return path.stat().st_uid
开发者ID:ball6847,项目名称:docker-django-gitlab-deploy,代码行数:9,代码来源:utils.py

示例3: Manager

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isdir [as 别名]
class Manager(object):
  __metaclass__ = ABCMeta

  def __init__(self, admin_repository):
    self.path = Path(admin_repository)
    self.git = Git(admin_repository)

    if not self.path.isdir():
      raise ValueError('Admin repository path should point to directory')

  def get_or_create(self, lookup_entity, *args, **kwargs):
    return self.get(lookup_entity) or self.create(lookup_entity, *args,
                                                  **kwargs)

  @abstractmethod
  def get(self, entity):
    raise NotImplementedError("Each manager needs a get method")

  @abstractmethod
  def create(self, entity):
    raise NotImplementedError("Each manager needs a create method")

  @abstractmethod
  def delete(self, entity_name):
    raise NotImplementedError("Each manager needs a delete method")
开发者ID:bcersows,项目名称:pyolite,代码行数:27,代码来源:manager.py

示例4: get

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isdir [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

示例5: __check_directory

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isdir [as 别名]
 def __check_directory(self):
     """
     Check if the entered directory exists
     :return: (unipath.Path or False) the path to the existing directory
     """
     directory = Path(self.arguments['<directory>'])
     if not directory.exists() or not directory.isdir():
         msg = '{} is not a valid directory'.format(directory.absolute())
         self.__output(msg, error=True)
         return False
     return directory
开发者ID:cuducos,项目名称:sortimages,代码行数:13,代码来源:sortimages.py

示例6: dump_path

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isdir [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

示例7: process

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isdir [as 别名]
def process(appname):
    appdir = Path(appname)
    if not appdir.isdir():
        print("Error: there is no app called {0}.".format(appdir))
        sys.exit(1)
    # else
    static = Path(appname, 'static', appname)
    static.mkdir(True)
    templates = Path(appname, 'templates', appname)
    templates.mkdir(True)
    urls = Path(appname, 'urls.py')
    if not urls.isfile():
        urls.write_file(urls_py)
开发者ID:jabbalaci,项目名称:django-hello_project,代码行数:15,代码来源:init_app.py

示例8: clean

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isdir [as 别名]
def clean(options):
    '''
    Clean the last build

    '''
    cfg = options.cfg.default
    clean_dirs = [_dir % cfg for _dir in cfg.clean_dirs]
    clean_dirs = [Path(_dir).absolute() for _dir in clean_dirs if _dir and Path.isdir(_dir)]
    for _dir in clean_dirs:
        if _dir.components() < 4:
            print 'Directory %s is too close to the root.  Skipping.' % _dir
            continue
        cmd = 'rd /s /q %(_dir)s' % locals()
        sub.check_call(cmd, shell=True)
开发者ID:binaryphile,项目名称:www.minimak.org,代码行数:16,代码来源:pavement.py

示例9: __init__

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isdir [as 别名]
    def __init__(self, input_file, output_file=None, binary=None):

        self.width = None
        self.height = None
        self.quality = None
        self.group = None

        if binary:
            self.binary = binary

        self.input_file = Path(input_file)

        input_name = self.input_file.name.rsplit(".", 1)[0]

        if output_file:
            output_file = Path(output_file)
            if output_file.isdir():
                self.output_file = output_file.child(input_name)
            else:
                self.output_file = output_file
        else:
            self.output_file = self.input_file.parent.child(self.input_file.stem)
开发者ID:pombredanne,项目名称:html5video,代码行数:24,代码来源:base.py

示例10: content

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isdir [as 别名]
def content(request=None):
    base = Path(current_app.config.get('INUPYPI_REPO',
                Path('.', 'packages')))

    if request:
        repo = Path(base, request)
    else:
        repo = base

    try:
        repo = repo.absolute()
        base = base.absolute()

        if not repo.exists():
            if base == repo:
                raise InuPyPIMissingRepoPath

            # sets the request to lowercase and compares it with
            # the existing items in the repository in lowercase
            repo = search_path(repo, base)

            if not repo:
                raise InuPyPI404Exception

        if repo.isdir():
            return Dirs(repo)
        if repo.isfile():
            return repo

    except InuPyPIMissingRepoPath:
        abort(500, 'Missing repository or package path!')
    except InuPyPI404Exception:
        abort(404, 'Path or File could not be found!')
    except:
        abort(500, 'Internal Server Error!')
    return repo
开发者ID:hallaj,项目名称:inupypi,代码行数:38,代码来源:__init__.py

示例11: ReleaseSorter

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isdir [as 别名]
class ReleaseSorter(object):
    def __init__(self, sort_dir):
        self.sort_dir = Path(sort_dir)

        # Make sure the sort dir is a dir and cd into it
        if not self.sort_dir.isdir():
            raise ReleaseSorterError('Invalid sort-dir {}'.format(sort_dir))
        os.chdir(sort_dir)

        self.files_to_sort = {}

    def relative_path(self, path, root_path):
        relative_path = path.replace(root_path, '')
        if relative_path[0:1] == '/':
            return relative_path[1:]
        else:
            return relative_path

    def check_extension(self, extension):
        if extension in ('.mkv', '.avi'):
            return True
        else:
            return False

    def check_modified_time(self, time_since_modified):
        if time_since_modified < timedelta(minutes=20):
            return False
        else:
            return True

    def create_series_folders(self, sorter_file):
        if sorter_file.series_dir and not sorter_file.series_dir.exists():
            log.info('Creating series dir {}'.format(
                sorter_file.relative_path(sorter_file.series_dir)))
            sorter_file.series_dir.mkdir()

        if sorter_file.season_dir and not sorter_file.season_dir.exists():
            log.info('Creating season dir {}'.format(
                sorter_file.relative_path(sorter_file.season_dir)))
            sorter_file.season_dir.mkdir()

    def move_subtitle_files(self, sorter_file):
        """Check for existing subtitle files matching media file and move
        them to sort folder too.
        """

        for ext in ('.srt', '.sub', '.idx'):
            subtitle_path = Path(sorter_file.path.parent, '{}{}'.format(
                sorter_file.path.stem, ext))

            if subtitle_path.exists():
                log.info('Moving subtitle file {} to {}'.format(
                    self.relative_path(subtitle_path, self.sort_dir),
                    sorter_file.season_dir))
                subtitle_path.move(Path(self.sort_dir,
                                   sorter_file.season_dir))

    def move_sorter_file(self, sorter_file):
        log.info('Moving {} to {}'.format(sorter_file.relative_path(),
                                          sorter_file.season_dir))
        sorter_file.path.move(Path(self.sort_dir, sorter_file.season_dir))

    def get_sorter_files(self):
        """List sort dir and find all files to sort"""

        log.debug('Sorting dir {}'.format(self.sort_dir))

        file_list = self.sort_dir.listdir(filter=FILES)

        for file in file_list:
            sorter_file = SorterFile(file, self.sort_dir)

            # File extension
            if not self.check_extension(sorter_file.extension):
                log.debug('Skipping {}, wrong file extension'.format(
                    sorter_file.relative_path()))
                continue

            # Modifed time, only process files who hasen't been modified the
            # in the last 20 min
            time_since_modified = datetime.now() - sorter_file.mtime
            if not self.check_modified_time(time_since_modified):
                log.debug('Skipping {}, has been modified in the last 20 min '
                          '({})'.format(sorter_file.relative_path(),
                                        human(time_since_modified)))
                continue

            # Skip if file is not a TV release
            if not sorter_file.release.tv_release:
                log.debug('Skipping {}, not a TV release'.format(
                    sorter_file.relative_path()))
                continue

            # Add file to sorter list
            series_name = sorter_file.release.tv_series_data['series_name']
            series_episodes = self.files_to_sort.get(series_name)
            if not series_episodes:
                series_episodes = {}
            series_episodes[unicode(sorter_file)] = sorter_file
            self.files_to_sort[series_name] = series_episodes
#.........这里部分代码省略.........
开发者ID:dnxxx,项目名称:releasesorter,代码行数:103,代码来源:releasesorter.py

示例12: SubtitleDownloader

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isdir [as 别名]
class SubtitleDownloader(object):
    def __init__(self, search_dir, search_all=False):
        self.search_dir = Path(search_dir)
        self.search_all = search_all

        # Make sure the sort dir is a dir and cd into it
        if not self.search_dir.isdir():
            raise SubtitleDownloaderError('Invalid search-dir {}'.format(
                search_dir))

    @staticmethod
    def relative_path(path, root_path):
        """Return the relative path of path in root_path"""

        relative_path = path.replace(root_path, '')
        if relative_path[0:1] == '/':
            return relative_path[1:]
        else:
            return relative_path

    def scan_for_search_files(self):
        """Scan search dir and return all files to search subtiles for"""

        log.debug('Searching for files in dir {}'.format(self.search_dir))

        search_files = []
        for file_path in self.search_dir.walk(filter=FILES, top_down=False):
            if not file_path.ext in ('.mkv', '.avi'):
                continue

            subtitle_download = SubtitleDownload(file_path)

            # Search for subtitle if self.search_all is True or if the file
            # modified time is in the last week
            search_subtitle = self.search_all or \
                subtitle_download.time_since_modified < timedelta(weeks=1)

            # Don't search subtitle for this file
            if not search_subtitle:
                continue

            # Check if subtitle already exists
            if subtitle_download.subtitle_exist():
                log.debug('Subtitle for {} already exists'.format(
                    self.relative_path(file_path, self.search_dir)))
                continue

            search_files.append(subtitle_download)

        return search_files

    def scan_search(self):
        """Scan for files to download subtitles for and try to download
        subtitle.
        """

        search_files = self.scan_for_search_files()
        num_searches = len(search_files)
        for i, subtitle_download in enumerate(search_files):
            log.info('Subtitle search for {}'.format(subtitle_download.name))

            subtitle_download.search_download_subtitle()

            # Sleep between searches if it's not the last search file
            if i + 1 != num_searches:
                log.info('Sleeping for {} seconds'.format(SLEEP_TIME))
                sleep(SLEEP_TIME)

    def cleanup(self):
        """Remove subtitle files left over where the media file is removed"""

        log.debug('Running subtitle cleanup on dir {}'.format(self.search_dir))

        subtitle_extensions = ('.srt', '.sub', '.idx')

        for file_path in self.search_dir.walk(filter=FILES, top_down=False):
            if not file_path.ext in subtitle_extensions:
                continue

            # Remove the subtitle file if no media file exists in the same dir
            media_file_path_mkv = Path(file_path.parent, '{}.mkv'.format(
                file_path.stem))
            media_file_path_avi = Path(file_path.parent, '{}.avi'.format(
                file_path.stem))
            if (not media_file_path_mkv.exists() and
                    not media_file_path_avi.exists()):
                log.info('Removing leftover subtitle file {}'.format(
                    self.relative_path(file_path, self.search_dir)))

                file_path.remove()
开发者ID:dnxxx,项目名称:subtitledownloader,代码行数:92,代码来源:subtitledownloader.py

示例13: test_get_path_with_local_storage

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isdir [as 别名]
 def test_get_path_with_local_storage(self):
     with app.app_context():
         backup = Backup()
         path = Path(backup.path)
         self.assertTrue(path.exists())
         self.assertTrue(path.isdir())
开发者ID:nonidentity2,项目名称:alchemydumps,代码行数:8,代码来源:test_helpers_backup.py

示例14: _clear_figs_for_report

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isdir [as 别名]
def _clear_figs_for_report(report):
    report_dir = Path(report).parent
    figs_dir = Path(report_dir, 'figs')
    if figs_dir.isdir():
        print 'removing figs dir:\n\t{}'.format(figs_dir)
        figs_dir.rmtree()
开发者ID:lupyanlab,项目名称:words-in-transition,代码行数:8,代码来源:reports.py

示例15: test_mkdir_and_rmdir_with_parents

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import isdir [as 别名]
 def test_mkdir_and_rmdir_with_parents(self):
     abc = Path(self.d, "a", "b", "c")
     abc.mkdir(parents=True)
     assert abc.isdir()
     abc.rmdir(parents=True)
     assert not Path(self.d, "a").exists()
开发者ID:Mondego,项目名称:pyreco,代码行数:8,代码来源:allPythonContent.py


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