本文整理汇总了Python中rarfile.is_rarfile函数的典型用法代码示例。如果您正苦于以下问题:Python is_rarfile函数的具体用法?Python is_rarfile怎么用?Python is_rarfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_rarfile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_image_format
def get_image_format(filename, arguments):
"""gets the image format"""
image = None
bad_image = 1
image_format = NONE_FORMAT
sequenced = False
try:
image = Image.open(filename)
bad_image = image.verify()
image_format = image.format
sequenced = is_image_sequenced(image)
except (OSError, IOError):
pass
if sequenced:
image_format = SEQUENCED_TEMPLATE % image_format
elif image is None or bad_image or image_format == NONE_FORMAT:
image_format = ERROR_FORMAT
filename_ext = os.path.splitext(filename)[-1].lower()
if filename_ext in COMIC_EXTS:
if zipfile.is_zipfile(filename):
image_format = CBZ_FORMAT
elif rarfile.is_rarfile(filename):
image_format = CBR_FORMAT
if (arguments.verbose > 1) and image_format == ERROR_FORMAT and (not arguments.list_only):
print(filename, "doesn't look like an image or comic archive.")
return image_format
开发者ID:kinkerl,项目名称:picopt,代码行数:27,代码来源:picopt.py
示例2: findVideo
def findVideo(self):
fullpath = self.config['file']['path'] + self.config['file']['name']
files = False
if os.path.isdir(fullpath):
os.chdir(fullpath)
files = {"path": os.getcwd(), "files": []}
archive = False
for file in os.listdir(files['path']):
if zipfile.is_zipfile(file):
print "Unzip..."
zip = zipfile.ZipFile(file)
zip.extractall()
archive = True
elif rarfile.is_rarfile(file):
try:
print "Unrar..."
rar = rarfile.RarFile(file)
rar.extractall()
archive = True
except rarfile.NeedFirstVolume:
pass
self.config['file']['name'] = file
if self.isVideo():
files['files'].append(file)
if archive:
allFiles = os.listdir(files['path'])
for file in allFiles:
self.config['file']['name'] = file
if not file in files['files'] and self.isVideo():
files['files'].append(file)
return files
开发者ID:olyckne,项目名称:tvshow_parser,代码行数:32,代码来源:file.py
示例3: main
def main():
parser = optparse.OptionParser("Usage: pyUnCompress.py " +
"-f <zipfile | rarfile> -d <dictionary>")
parser.add_option('-f', dest='zname', type='string',
help='specify zip | rar file')
parser.add_option('-d', dest='dname', type='string',
help='specify dictionary file')
(options, args) = parser.parse_args()
if (options.zname == None) | (options.dname == None):
print parser.usage
exit(0)
else:
zname = options.zname
dname = options.dname
flag = 0 # filetype -- rar = 1 | zip = 2
if (rarfile.is_rarfile(zname)):
compressFile = rarfile.RarFile(zname)
elif (zipfile.is_zipfile(zname)):
compressFile = zipfile.ZipFile(zname)
else:
print 'Unrecognized file'
exit(0)
passFile = open(dname)
for line in passFile.readlines():
if (ALIVE == False):
exit(0)
password = line.strip('\n')
t = Thread(target=extractFile, args=(compressFile, password))
t.start()
开发者ID:0verl0ad,项目名称:pyJuanker,代码行数:34,代码来源:pyUnCompress.py
示例4: download_subtitle
def download_subtitle(self, subtitle):
r = self.session.get(subtitle.download_link, timeout=10)
r.raise_for_status()
# open the archive
archive_stream = io.BytesIO(r.content)
if is_rarfile(archive_stream):
logger.debug('Archive identified as rar')
archive = RarFile(archive_stream)
elif is_zipfile(archive_stream):
logger.debug('Archive identified as zip')
archive = ZipFile(archive_stream)
else:
subtitle.content = r.content
if subtitle.is_valid():
return
subtitle.content = None
raise ProviderError('Unidentified archive type')
subs_in_archive = archive.namelist()
# if Serbian lat and cyr versions are packed together, try to find right version
if len(subs_in_archive) > 1 and (subtitle.language == 'sr' or subtitle.language == 'sr-Cyrl'):
self.get_subtitle_from_bundled_archive(subtitle, subs_in_archive, archive)
else:
# use default method for everything else
subtitle.content = self.get_subtitle_from_archive(subtitle, archive)
开发者ID:plexinc-agents,项目名称:Sub-Zero.bundle,代码行数:28,代码来源:titlovi.py
示例5: testPath
def testPath(path):
print("testing path: %s" % path)
#is it file or folder ?
if os.path.isfile(path):
print("manga: path is a file")
desc = getFileDescription(path)
print("file type: %s" % desc)
mime = getFilePathMime(path)
print("file mime: %s" % mime)
mimeSplit = mime.split('/')
m1 = mimeSplit[0]
m2 = mimeSplit[1]
if m1 == 'image':
print("image file selected,\ncontaining folder could be loaded as a manga")
(folderPath, tail) = os.path.split(path)
return "folder", folderPath, desc, mime
elif mime == 'application/zip' or mime == 'application/x-zip' or zipfile.is_zipfile(path):
print("file is probably a zip file")
return "zip", path, desc, mime
elif mime == 'application/rar' or mime == 'application/x-rar' or rarfile.is_rarfile(path):
print("file is probably a rar file")
return 'rar', path, desc, mime
else:
print("the path: %s is an unsupported file")
print("it has this mime: %s" % mime)
print("and this description: %s" % desc)
return False
elif os.path.isdir(path):
print("manga: path is a directory")
return "folder", path, None, "a folder"
else:
print("manga: loading failed, path is neither file nor directory")
return False
开发者ID:TiTNooS,项目名称:mieru,代码行数:34,代码来源:container.py
示例6: main
def main():
target_dir = sys.argv[1]
newsdomains = set([])
with open(sys.argv[2], 'r') as newssites:
for line in newssites:
newsdomains.add(line.strip())
if len(sys.argv) < 3:
print 'Usage: ' + sys.argv[0] + ' + <traversal dir> + <news domains text file>'
sys.exit(1)
for item in os.listdir(target_dir):
item_path = os.path.join(target_dir, item)
if item.startswith('web-') and rarfile.is_rarfile(item_path):
rf = rarfile.RarFile(item_path)
try:
tmp_dir = tempfile.mkdtemp()
rf.extractall(path=tmp_dir)
filename = rf.namelist()[0]
flatsnap = process_file(os.path.join(tmp_dir, filename), filename, newsdomains)
archive_name = os.path.splitext(filename)[0] + '_news.gz'
with gzip.open(archive_name, 'wb') as archive:
for item in flatsnap:
archive.write('%s\n' % item)
finally:
try:
shutil.rmtree(tmp_dir)
except OSError, e:
if e.errno != 2: # code 2 - no such file or directory
raise
开发者ID:rjweiss,项目名称:SNAP-tools,代码行数:34,代码来源:snaprar.py
示例7: is_rar
def is_rar(path, file):
try:
if rarfile.is_rarfile(os.path.join(path, file)):
return True
except OSError, e:
logging.error("Error in is_rar for '%s': %s" % (file, e))
raise OSError
开发者ID:bl4ckh0l3z,项目名称:droidtrail,代码行数:7,代码来源:utils.py
示例8: is_archive
def is_archive(filename):
"""
test if file is a valid archive (zip, tar or rar)
"""
return tarfile.is_tarfile(filename) or \
zipfile.is_zipfile(filename) or \
(ARCHIVE_RAR_AVAILABLE and rarfile.is_rarfile(filename))
开发者ID:golaizola,项目名称:freevo1,代码行数:7,代码来源:archive.py
示例9: save_file
def save_file(url, filename):
filename = "out/" + filename
# Check if we already have it
if os.path.isfile(filename + ".zip") or os.path.isfile(filename + ".rar") or os.path.isfile(filename + ".zip"):
print "We already have " + filename + ", skipping"
return
print("Downloading... " + filename)
try:
f = open(filename, 'wb')
f.write(urllib2.urlopen(url).read())
f.close()
if zipfile.is_zipfile(filename):
print(filename + " is a zip file")
shutil.move(filename, filename + ".zip")
elif rarfile.is_rarfile(filename):
print(filename + " is a rar file")
shutil.move(filename, filename + ".rar")
else:
print(filename + " is an nds file")
shutil.move(filename, filename + ".nds")
except urllib2.URLError:
print "Failed to download: " + filename
开发者ID:josh-perry,项目名称:NDSHomebrewDownloader,代码行数:26,代码来源:main.py
示例10: openFile
def openFile(self):
'''
Open a file stream to either a rar/cbr or zip/cbz file
'''
inFile, _ = QtGui.QFileDialog.getOpenFileName(self, 'Open file',
QtCore.QDir.currentPath())
self.currentPage = 0
if zipfile.is_zipfile(inFile) == True: #Check if its a zip file (.zip, .cbz)
self.z = zipfile.ZipFile(inFile, "r")
elif rarfile.is_rarfile(inFile) == True: #Check if its a rar file (.rar, .cbr)
self.z = rarfile.RarFile(inFile)
else:
msgBox = QtGui.QMessageBox()
msgBox.setText("This is not a valid CBZ or CBR file!")
msgBox.setStandardButtons(QtGui.QMessageBox.Ok)
msgBox.setDefaultButton(QtGui.QMessageBox.Ok)
ret = msgBox.exec_()
#if statement is probably unecessary
if ret == QtGui.QMessageBox.Ok:
self.openFile()
self.showImage(self.currentPage)
#Make the label clickable to go forward pages
Utility.clickable(self.lbl).connect(self.changePage)
self.scaleFactor = 1.0
self.scaleImage(self.scaleFactor)
self.updateActions()
开发者ID:Ringil,项目名称:Comic-Viewer,代码行数:32,代码来源:ComicViewer.py
示例11: __init__
def __init__(self, origFileName):
self.origFileName = origFileName
if zipfile.is_zipfile(origFileName):
self.compressor = 'zip'
elif rarfile.is_rarfile(origFileName):
self.compressor = 'rar'
else:
self.compressor = None
开发者ID:devernay,项目名称:kcc,代码行数:8,代码来源:cbxarchive.py
示例12: __init__
def __init__(self, path):
Container.__init__(self, path)
self.rf = None
if rarfile.is_rarfile(path):
try:
self.rf = rarfile.RarFile(path,'r')
except Exception, e:
"error, loading rar file failed: %s" % e
开发者ID:TiTNooS,项目名称:mieru,代码行数:8,代码来源:container.py
示例13: extract
def extract(archive_file, path=".", delete_on_success=False,
enable_rar=False):
"""
Automatically detect archive type and extract all files to specified path.
.. code:: python
import os
os.listdir(".")
# ['test_structure.zip']
reusables.extract("test_structure.zip")
os.listdir(".")
# [ 'test_structure', 'test_structure.zip']
:param archive_file: path to file to extract
:param path: location to extract to
:param delete_on_success: Will delete the original archive if set to True
:param enable_rar: include the rarfile import and extract
:return: path to extracted files
"""
if not os.path.exists(archive_file) or not os.path.getsize(archive_file):
logger.error("File {0} unextractable".format(archive_file))
raise OSError("File does not exist or has zero size")
arch = None
if zipfile.is_zipfile(archive_file):
logger.debug("File {0} detected as a zip file".format(archive_file))
arch = zipfile.ZipFile(archive_file)
elif tarfile.is_tarfile(archive_file):
logger.debug("File {0} detected as a tar file".format(archive_file))
arch = tarfile.open(archive_file)
elif enable_rar:
import rarfile
if rarfile.is_rarfile(archive_file):
logger.debug("File {0} detected as "
"a rar file".format(archive_file))
arch = rarfile.RarFile(archive_file)
if not arch:
raise TypeError("File is not a known archive")
logger.debug("Extracting files to {0}".format(path))
try:
arch.extractall(path=path)
finally:
arch.close()
if delete_on_success:
logger.debug("Archive {0} will now be deleted".format(archive_file))
os.unlink(archive_file)
return os.path.abspath(path)
开发者ID:cdgriffith,项目名称:Reusables,代码行数:58,代码来源:file_operations.py
示例14: getrarlist
def getrarlist(rarname):
rarfile.NEED_COMMENTS = 0
filelist = []
if not rarfile.is_rarfile(rarname):
return filelist
rararc = rarfile.RarFile(rarname)
for rarentry in rararc.infolist():
filelist.append(rarentry.filename)
return filelist
开发者ID:mdmdmdmdmd,项目名称:pystream,代码行数:9,代码来源:stream.py
示例15: __init__
def __init__(self, origFileName):
self.origFileName = origFileName
if zipfile.is_zipfile(origFileName):
self.compressor = 'zip'
elif rarfile.is_rarfile(origFileName):
self.compressor = 'rar'
elif origFileName.endswith('.7z') or origFileName.endswith('.cb7'):
self.compressor = '7z'
else:
self.compressor = None
开发者ID:welmoki,项目名称:kcc,代码行数:10,代码来源:cbxarchive.py
示例16: is_rarfile
def is_rarfile(filename):
"""Verify if file is rar file
Args:
filename: name of file
Returns: True if file is a rar file otherwise, False
"""
return rarfile.is_rarfile(filename)
开发者ID:pynocchio,项目名称:pynocchio,代码行数:10,代码来源:comic_file_loader_rar.py
示例17: test_real
def test_real(fn, psw):
"""Actual archive processing.
"""
xprint("Archive: %s", fn)
cb = None
if cf_verbose > 1:
cb = show_item
rfarg = fn
if cf_test_memory:
rfarg = io.BytesIO(open(fn, 'rb').read())
# check if rar
if not rf.is_rarfile(rfarg):
xprint(" --- %s is not a RAR file ---", fn)
return
# open
r = rf.RarFile(rfarg, charset=cf_charset, info_callback=cb)
# set password
if r.needs_password():
if psw:
r.setpassword(psw)
else:
xprint(" --- %s requires password ---", fn)
return
# show comment
if cf_show_comment and r.comment:
for ln in r.comment.split('\n'):
xprint(" %s", ln)
elif cf_verbose > 0 and r.comment:
cm = repr(r.comment)
if cm[0] == 'u':
cm = cm[1:]
xprint(" comment=%s", cm)
# process
for n in r.namelist():
inf = r.getinfo(n)
if inf.isdir():
continue
if cf_verbose == 1:
show_item(inf)
if cf_test_read:
test_read(r, inf)
if cf_extract:
r.extractall()
for inf in r.infolist():
r.extract(inf)
if cf_test_unrar:
r.testrar()
开发者ID:ArthurGarnier,项目名称:SickRage,代码行数:55,代码来源:dumprar.py
示例18: extract_archive
def extract_archive(self, movie, video):
dest_dir = os.path.join(old_movie.directory, movie)
os.chdir(new_movie.directory)
for item in os.listdir():
if item.startswith(movie + "." + video):
os.chdir(item)
for archive in os.listdir():
if "part1" in archive and rarfile.is_rarfile(archive):
rf = rarfile.RarFile(archive)
rf.extractall(path=dest_dir, pwd="Ares275")
os.rename(dest_dir +"/"+ rf.infolist()[0].filename, os.path.join(dest_dir, video) + ".mkv")
开发者ID:Highlike,项目名称:moviesort,代码行数:11,代码来源:oo_moviesort.py
示例19: __init__
def __init__(self):
self.destdir = ''
self.tmpdir = '/tmp/cdbs'
self.cdbsdirs = ['IMAGE', 'SMALL_N', 'THMB_N', 'SMALL_R', 'THMB_R', 'NAME']
self.cbdsname = ''
self.totalpags = 0
for comic in argv[1:]:
for d in self.cdbsdirs:
if not path.exists(self.tmpdir+'/'+d):
makedirs(self.tmpdir+'/'+d)
self.destdir = path.dirname(comic)
if path.isdir(comic):
self.cbdsname = path.basename(comic)
print 'Convirtiendo:', self.cbdsname
self.fromDir(comic)
elif path.isfile(comic):
tempdir = self.tmpdir+'/temp'
if not path.exists(tempdir):
print 'Creando directoriotemporal'
makedirs(tempdir)
self.cbdsname = path.splitext(path.split(comic)[1])[0]
print 'Convirtiendo:', self.cbdsname
try:
zip = zipfile.ZipFile(comic)
zip.extractall(tempdir)
self.fromDir(tempdir)
except zipfile.BadZipfile:
if rarfile.is_rarfile(comic):
rar = rarfile.RarFile(comic)
if rar.needs_password():
try:
passwd = raw_input('Contraseña del RAR: ')
rar.setpassword(passwd)
rar.extractall(tempdir)
self.fromDir(self.tmpdir)
except rarfile.RarCRCError:
print 'Contraseña del rar invalida o archivo dañado'
else:
rar.extractall(tempdir)
self.fromDir(self.tmpdir)
elif comic.endswith('.pdf'):
pipe = 'pdfimages -j %s %s/' % (comic, tempdir)
cmd = Popen(pipe.split())
cmd.wait()
self.fromDir(self.tmpdir)
else:
print 'Archivo no valido o dañado'
开发者ID:son-link,项目名称:cbdsconv,代码行数:54,代码来源:cdbsconv.py
示例20: unrar
def unrar(rarFileName, path, filename=''):
if (rarfile.is_rarfile(rarFileName)):
rarFile = rarfile.RarFile(rarFileName)
for f in rarFile.infolist():
if not filename:
filename = f.filename
targetFile = open(path + filename, 'wb')
targetFile.write(rarFile.read(f))
targetFile.close()
else:
raise ValueError("File %s is not RAR file" % rarFileName)
开发者ID:fat-and-angry,项目名称:eset_update,代码行数:11,代码来源:functions.py
注:本文中的rarfile.is_rarfile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论