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


Python Env.getPermission方法代码示例

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


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

示例1: _createType

# 需要导入模块: from whatpotato.environment import Env [as 别名]
# 或者: from whatpotato.environment.Env import getPermission [as 别名]
    def _createType(self, meta_name, root, movie_info, group, file_type, i):  # Get file path
        camelcase_method = underscoreToCamel(file_type.capitalize())
        name = getattr(self, "get" + camelcase_method + "Name")(meta_name, root, i)

        if name and (self.conf("meta_" + file_type) or self.conf("meta_" + file_type) is None):

            # Get file content
            content = getattr(self, "get" + camelcase_method)(movie_info=movie_info, data=group, i=i)
            if content:
                log.debug("Creating %s file: %s", (file_type, name))
                if os.path.isfile(content):
                    content = sp(content)
                    name = sp(name)

                    if not os.path.exists(os.path.dirname(name)):
                        os.makedirs(os.path.dirname(name))

                    shutil.copy2(content, name)
                    shutil.copyfile(content, name)

                    # Try and copy stats seperately
                    try:
                        shutil.copystat(content, name)
                    except:
                        pass
                else:
                    self.createFile(name, content)
                    group["renamed_files"].append(name)

                try:
                    os.chmod(sp(name), Env.getPermission("file"))
                except:
                    log.debug("Failed setting permissions for %s: %s", (name, traceback.format_exc()))
开发者ID:michaelsexton,项目名称:WhatPotato,代码行数:35,代码来源:base.py

示例2: makeDir

# 需要导入模块: from whatpotato.environment import Env [as 别名]
# 或者: from whatpotato.environment.Env import getPermission [as 别名]
    def makeDir(self, path):
        path = sp(path)
        try:
            if not os.path.isdir(path):
                os.makedirs(path, Env.getPermission('folder'))
            return True
        except Exception as e:
            log.error('Unable to create folder "%s": %s', (path, e))

        return False
开发者ID:michaelsexton,项目名称:WhatPotato,代码行数:12,代码来源:base.py

示例3: createFile

# 需要导入模块: from whatpotato.environment import Env [as 别名]
# 或者: from whatpotato.environment.Env import getPermission [as 别名]
    def createFile(self, path, content, binary = False):
        path = sp(path)

        self.makeDir(os.path.dirname(path))

        if os.path.exists(path):
            log.debug('%s already exists, overwriting file with new version', path)

        write_type = 'w+' if not binary else 'w+b'

        # Stream file using response object
        if isinstance(content, requests.models.Response):

            # Write file to temp
            with open('%s.tmp' % path, write_type) as f:
                for chunk in content.iter_content(chunk_size = 1048576):
                    if chunk:  # filter out keep-alive new chunks
                        f.write(chunk)
                        f.flush()

            # Rename to destination
            os.rename('%s.tmp' % path, path)

        else:
            try:
                f = open(path, write_type)
                f.write(content)
                f.close()

                try:
                    os.chmod(path, Env.getPermission('file'))
                except:
                    log.error('Failed writing permission to file "%s": %s', (path, traceback.format_exc()))

            except:
                log.error('Unable to write file "%s": %s', (path, traceback.format_exc()))
                if os.path.isfile(path):
                    os.remove(path)
开发者ID:michaelsexton,项目名称:WhatPotato,代码行数:40,代码来源:base.py

示例4: download

# 需要导入模块: from whatpotato.environment import Env [as 别名]
# 或者: from whatpotato.environment.Env import getPermission [as 别名]
    def download(self, data=None, media=None, filedata=None):
        """ Send a torrent/nzb file to the downloader

        :param data: dict returned from provider
            Contains the release information
        :param media: media dict with information
            Used for creating the filename when possible
        :param filedata: downloaded torrent/nzb filedata
            The file gets downloaded in the searcher and send to this function
            This is done to have failed checking before using the downloader, so the downloader
            doesn't need to worry about that
        :return: boolean
            One faile returns false, but the downloaded should log his own errors
        """

        if not media:
            media = {}
        if not data:
            data = {}

        directory = self.conf("directory")

        # The folder needs to exist
        if not directory or not os.path.isdir(directory):
            log.error("No directory set for blackhole %s download.", data.get("protocol"))
        else:
            try:
                # Filedata can be empty, which probably means it a magnet link
                if not filedata or len(filedata) < 50:
                    try:
                        if data.get("protocol") == "torrent_magnet":
                            filedata = self.magnetToTorrent(data.get("url"))
                            data["protocol"] = "torrent"
                    except:
                        log.error("Failed download torrent via magnet url: %s", traceback.format_exc())

                    # If it's still empty, don't know what to do!
                    if not filedata or len(filedata) < 50:
                        log.error("No nzb/torrent available: %s", data.get("url"))
                        return False

                # Create filename with imdb id and other nice stuff
                file_name = self.createFileName(data, filedata, media)
                full_path = os.path.join(directory, file_name)

                # People want thinks nice and tidy, create a subdir
                if self.conf("create_subdir"):
                    try:
                        new_path = os.path.splitext(full_path)[0]
                        if not os.path.exists(new_path):
                            os.makedirs(new_path)
                            full_path = os.path.join(new_path, file_name)
                    except:
                        log.error("Couldnt create sub dir, reverting to old one: %s", full_path)

                try:

                    # Make sure the file doesn't exist yet, no need in overwriting it
                    if not os.path.isfile(full_path):
                        log.info("Downloading %s to %s.", (data.get("protocol"), full_path))
                        with open(full_path, "wb") as f:
                            f.write(filedata)
                        os.chmod(full_path, Env.getPermission("file"))
                        return self.downloadReturnId("")
                    else:
                        log.info("File %s already exists.", full_path)
                        return self.downloadReturnId("")

                except:
                    log.error("Failed to download to blackhole %s", traceback.format_exc())
                    pass

            except:
                log.info("Failed to download file %s: %s", (data.get("name"), traceback.format_exc()))
                return False

        return False
开发者ID:michaelsexton,项目名称:WhatPotato,代码行数:79,代码来源:blackhole.py


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