當前位置: 首頁>>代碼示例>>Python>>正文


Python rarfile.UNRAR_TOOL屬性代碼示例

本文整理匯總了Python中rarfile.UNRAR_TOOL屬性的典型用法代碼示例。如果您正苦於以下問題:Python rarfile.UNRAR_TOOL屬性的具體用法?Python rarfile.UNRAR_TOOL怎麽用?Python rarfile.UNRAR_TOOL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在rarfile的用法示例。


在下文中一共展示了rarfile.UNRAR_TOOL屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _open_unrar

# 需要導入模塊: import rarfile [as 別名]
# 或者: from rarfile import UNRAR_TOOL [as 別名]
def _open_unrar(self, rarfile, inf, psw=None, tmpfile=None, force_file=False):
        cmd = [UNRAR_TOOL] + list(OPEN_ARGS)
        add_password_arg(cmd, psw)
        cmd.append("--")
        cmd.append(rarfile)

        # not giving filename avoids encoding related problems
        if not tmpfile or force_file:
            fn = inf.filename
            if PATH_SEP != os.sep:
                fn = fn.replace(PATH_SEP, os.sep)
            cmd.append(fn)

        # read from unrar pipe
        return PipeReader(self, inf, cmd, tmpfile)

#
# RAR3 format
# 
開發者ID:BasioMeusPuga,項目名稱:Lector,代碼行數:21,代碼來源:rarfile.py

示例2: custom_popen

# 需要導入模塊: import rarfile [as 別名]
# 或者: from rarfile import UNRAR_TOOL [as 別名]
def custom_popen(cmd):
    """Disconnect cmd from parent fds, read only from stdout.
    """
    # needed for py2exe
    creationflags = 0
    if sys.platform == 'win32':
        creationflags = 0x08000000   # CREATE_NO_WINDOW

    # run command
    try:
        p = Popen(cmd, bufsize=0, stdout=PIPE, stdin=PIPE, stderr=STDOUT,
                  creationflags=creationflags)
    except OSError as ex:
        if ex.errno == errno.ENOENT:
            raise RarCannotExec("Unrar not installed? (rarfile.UNRAR_TOOL=%r)" % UNRAR_TOOL)
        if ex.errno == errno.EACCES or ex.errno == errno.EPERM:
            raise RarCannotExec("Cannot execute unrar (rarfile.UNRAR_TOOL=%r)" % UNRAR_TOOL)
        raise
    return p 
開發者ID:BasioMeusPuga,項目名稱:Lector,代碼行數:21,代碼來源:rarfile.py

示例3: _check_unrar_tool

# 需要導入模塊: import rarfile [as 別名]
# 或者: from rarfile import UNRAR_TOOL [as 別名]
def _check_unrar_tool():
    global UNRAR_TOOL, OPEN_ARGS, EXTRACT_ARGS, TEST_ARGS
    try:
        # does UNRAR_TOOL work?
        custom_check([ORIG_UNRAR_TOOL], True)

        UNRAR_TOOL = ORIG_UNRAR_TOOL
        OPEN_ARGS = ORIG_OPEN_ARGS
        EXTRACT_ARGS = ORIG_EXTRACT_ARGS
        TEST_ARGS = ORIG_TEST_ARGS
    except RarCannotExec:
        try:
            # does ALT_TOOL work?
            custom_check([ALT_TOOL] + list(ALT_CHECK_ARGS), True)
            # replace config
            UNRAR_TOOL = ALT_TOOL
            OPEN_ARGS = ALT_OPEN_ARGS
            EXTRACT_ARGS = ALT_EXTRACT_ARGS
            TEST_ARGS = ALT_TEST_ARGS
        except RarCannotExec:
            # no usable tool, only uncompressed archives work
            return False
    return True 
開發者ID:BasioMeusPuga,項目名稱:Lector,代碼行數:25,代碼來源:rarfile.py

示例4: custom_popen

# 需要導入模塊: import rarfile [as 別名]
# 或者: from rarfile import UNRAR_TOOL [as 別名]
def custom_popen(cmd):
    """Disconnect cmd from parent fds, read only from stdout.
    """
    # needed for py2exe
    creationflags = 0
    if sys.platform == 'win32':
        creationflags = 0x08000000   # CREATE_NO_WINDOW

    # run command
    try:
        p = Popen(cmd, bufsize=0, stdout=PIPE, stdin=PIPE, stderr=STDOUT,
                  creationflags=creationflags)
    except OSError as ex:
        if ex.errno == errno.ENOENT:
            raise RarCannotExec("Unrar not installed? (rarfile.UNRAR_TOOL=%r)" % UNRAR_TOOL)
        raise
    return p 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:19,代碼來源:rarfile.py

示例5: _check_unrar_tool

# 需要導入模塊: import rarfile [as 別名]
# 或者: from rarfile import UNRAR_TOOL [as 別名]
def _check_unrar_tool():
    global UNRAR_TOOL, OPEN_ARGS, EXTRACT_ARGS, TEST_ARGS
    try:
        # does UNRAR_TOOL work?
        custom_check([ORIG_UNRAR_TOOL], True)

        UNRAR_TOOL = ORIG_UNRAR_TOOL
        OPEN_ARGS = ORIG_OPEN_ARGS
        EXTRACT_ARGS = ORIG_EXTRACT_ARGS
        TEST_ARGS = ORIG_TEST_ARGS
    except RarCannotExec:
        try:
            # does ALT_TOOL work?
            custom_check([ALT_TOOL] + list(ALT_CHECK_ARGS), True)
            # replace config
            UNRAR_TOOL = ALT_TOOL
            OPEN_ARGS = ALT_OPEN_ARGS
            EXTRACT_ARGS = ALT_EXTRACT_ARGS
            TEST_ARGS = ALT_TEST_ARGS
        except RarCannotExec:
            # no usable tool, only uncompressed archives work
            pass 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:24,代碼來源:rarfile.py

示例6: read

# 需要導入模塊: import rarfile [as 別名]
# 或者: from rarfile import UNRAR_TOOL [as 別名]
def read(self, fname, psw=None):
        """
        read specific content of rarfile without parsing
        :param fname:
        :param psw:
        :return:
        """
        cmd = [rarfile.UNRAR_TOOL] + list(rarfile.ORIG_OPEN_ARGS)

        with rarfile.XTempFile(self._rarfile) as rf:
            log.debug(u"RAR CMD: %s", cmd + [rf, fname])
            p = rarfile.custom_popen(cmd + [rf, fname])
            output = p.communicate()[0]
            rarfile.check_returncode(p, output)

            return output 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:18,代碼來源:rar.py

示例7: init_binaries

# 需要導入模塊: import rarfile [as 別名]
# 或者: from rarfile import UNRAR_TOOL [as 別名]
def init_binaries():
    from utils import get_binary
    exe = get_binary("unrar")
    
    rarfile.UNRAR_TOOL = exe
    rarfile.ORIG_UNRAR_TOOL = exe
    try:
        rarfile.custom_check([rarfile.UNRAR_TOOL], True)
    except:
        logging.debug("custom check failed for: %s", exe)
    
    rarfile.OPEN_ARGS = rarfile.ORIG_OPEN_ARGS
    rarfile.EXTRACT_ARGS = rarfile.ORIG_EXTRACT_ARGS
    rarfile.TEST_ARGS = rarfile.ORIG_TEST_ARGS
    logging.debug("Using UnRAR from: %s", exe)
    unrar = exe
    
    return unrar 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:20,代碼來源:init.py

示例8: testrar

# 需要導入模塊: import rarfile [as 別名]
# 或者: from rarfile import UNRAR_TOOL [as 別名]
def testrar(self):
        """Let 'unrar' test the archive.
        """
        cmd = [UNRAR_TOOL] + list(TEST_ARGS)
        add_password_arg(cmd, self._password)
        cmd.append('--')

        if is_filelike(self.rarfile):
            tmpname = membuf_tempfile(self.rarfile)
            cmd.append(tmpname)
        else:
            tmpname = None
            cmd.append(self.rarfile)

        try:
            p = custom_popen(cmd)
            output = p.communicate()[0]
            check_returncode(p, output)
        finally:
            if tmpname:
                os.unlink(tmpname) 
開發者ID:entynetproject,項目名稱:arissploit,代碼行數:23,代碼來源:rarfile.py

示例9: _open_unrar

# 需要導入模塊: import rarfile [as 別名]
# 或者: from rarfile import UNRAR_TOOL [as 別名]
def _open_unrar(self, rarfile, inf, psw = None, tmpfile = None):
        if is_filelike(rarfile):
            raise ValueError("Cannot use unrar directly on memory buffer")
        cmd = [UNRAR_TOOL] + list(OPEN_ARGS)
        add_password_arg(cmd, psw)
        cmd.append("--")
        cmd.append(rarfile)

        # not giving filename avoids encoding related problems
        if not tmpfile:
            fn = inf.filename
            if PATH_SEP != os.sep:
                fn = fn.replace(PATH_SEP, os.sep)
            cmd.append(fn)

        # read from unrar pipe
        return PipeReader(self, inf, cmd, tmpfile) 
開發者ID:entynetproject,項目名稱:arissploit,代碼行數:19,代碼來源:rarfile.py

示例10: custom_popen

# 需要導入模塊: import rarfile [as 別名]
# 或者: from rarfile import UNRAR_TOOL [as 別名]
def custom_popen(cmd):
    """Disconnect cmd from parent fds, read only from stdout."""

    # needed for py2exe
    creationflags = 0
    if sys.platform == 'win32':
        creationflags = 0x08000000 # CREATE_NO_WINDOW

    # run command
    try:
        p = Popen(cmd, bufsize = 0,
                  stdout = PIPE, stdin = PIPE, stderr = STDOUT,
                  creationflags = creationflags)
    except OSError as ex:
        if ex.errno == errno.ENOENT:
            raise RarCannotExec("Unrar not installed? (rarfile.UNRAR_TOOL=%r)" % UNRAR_TOOL)
        raise
    return p 
開發者ID:entynetproject,項目名稱:arissploit,代碼行數:20,代碼來源:rarfile.py

示例11: testrar

# 需要導入模塊: import rarfile [as 別名]
# 或者: from rarfile import UNRAR_TOOL [as 別名]
def testrar(self):
        """Let 'unrar' test the archive.
        """
        cmd = [UNRAR_TOOL] + list(TEST_ARGS)
        add_password_arg(cmd, self._password)
        cmd.append('--')
        with XTempFile(self._rarfile) as rarfile:
            cmd.append(rarfile)
            p = custom_popen(cmd)
            output = p.communicate()[0]
            check_returncode(p, output) 
開發者ID:BasioMeusPuga,項目名稱:Lector,代碼行數:13,代碼來源:rarfile.py

示例12: _extract

# 需要導入模塊: import rarfile [as 別名]
# 或者: from rarfile import UNRAR_TOOL [as 別名]
def _extract(self, fnlist, path=None, psw=None):
        cmd = [UNRAR_TOOL] + list(EXTRACT_ARGS)

        # pasoword
        psw = psw or self._password
        add_password_arg(cmd, psw)
        cmd.append('--')

        # rar file
        with XTempFile(self._rarfile) as rarfn:
            cmd.append(rarfn)

            # file list
            for fn in fnlist:
                if os.sep != PATH_SEP:
                    fn = fn.replace(PATH_SEP, os.sep)
                cmd.append(fn)

            # destination path
            if path is not None:
                cmd.append(path + os.sep)

            # call
            p = custom_popen(cmd)
            output = p.communicate()[0]
            check_returncode(p, output)

#
# File format parsing
# 
開發者ID:BasioMeusPuga,項目名稱:Lector,代碼行數:32,代碼來源:rarfile.py

示例13: check_returncode

# 需要導入模塊: import rarfile [as 別名]
# 或者: from rarfile import UNRAR_TOOL [as 別名]
def check_returncode(p, out):
    """Raise exception according to unrar exit code.
    """
    code = p.returncode
    if code == 0:
        return

    # map return code to exception class, codes from rar.txt
    errmap = [None,
              RarWarning, RarFatalError, RarCRCError, RarLockedArchiveError,    # 1..4
              RarWriteError, RarOpenError, RarUserError, RarMemoryError,        # 5..8
              RarCreateError, RarNoFilesError, RarWrongPassword]                # 9..11
    if UNRAR_TOOL == ALT_TOOL:
        errmap = [None]
    if code > 0 and code < len(errmap):
        exc = errmap[code]
    elif code == 255:
        exc = RarUserBreak
    elif code < 0:
        exc = RarSignalExit
    else:
        exc = RarUnknownError

    # format message
    if out:
        msg = "%s [%d]: %s" % (exc.__doc__, p.returncode, out)
    else:
        msg = "%s [%d]" % (exc.__doc__, p.returncode)

    raise exc(msg) 
開發者ID:BasioMeusPuga,項目名稱:Lector,代碼行數:32,代碼來源:rarfile.py

示例14: __init__

# 需要導入模塊: import rarfile [as 別名]
# 或者: from rarfile import UNRAR_TOOL [as 別名]
def __init__(self):
		# Set the unrar tool based on filesystem
		if os.getenv('TENMA_UNRAR_PATH'):
			rarfile.UNRAR_TOOL = os.getenv('TENMA_UNRAR_PATH')
		elif sys.platform == 'win32':		# Windows
			rarfile.UNRAR_TOOL = os.path.dirname(comics.__file__) + "/utils/unrar/unrar.exe"
		elif sys.platform == 'darwin':	# Mac
			rarfile.UNRAR_TOOL = os.path.dirname(comics.__file__) + "/utils/unrar/unrar_mac"
		elif sys.platform == 'linux':	# Linux
			rarfile.UNRAR_TOOL = os.path.dirname(comics.__file__) + "/utils/unrar/unrar-nonfree_ubuntu"

	#================================================================================================== 
開發者ID:Tenma-Server,項目名稱:Tenma,代碼行數:14,代碼來源:comicfilehandler.py

示例15: _extract

# 需要導入模塊: import rarfile [as 別名]
# 或者: from rarfile import UNRAR_TOOL [as 別名]
def _extract(self, fnlist, path=None, psw=None):
        cmd = [UNRAR_TOOL] + list(EXTRACT_ARGS)

        # pasoword
        psw = psw or self._password
        add_password_arg(cmd, psw)
        cmd.append('--')

        # rar file
        with XTempFile(self._rarfile) as rarfn:
            cmd.append(rarfn)

            # file list
            for fn in fnlist:
                if os.sep != PATH_SEP:
                    fn = fn.replace(PATH_SEP, os.sep)
                cmd.append(fn)

            # destination path
            if path is not None:
                if _have_pathlib and isinstance(path, Path):
                    path = str(path)
                #cmd.append(path + os.sep)
                cmd.append(path)

            # call
            p = custom_popen(cmd)
            output = p.communicate()[0]
            check_returncode(p, output)

#
# File format parsing
# 
開發者ID:alfa-addon,項目名稱:addon,代碼行數:35,代碼來源:rarfile.py


注:本文中的rarfile.UNRAR_TOOL屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。