當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。