def archive_test(self, filename): """Test archive testing.""" archive = os.path.join(datadir, filename) for verbosity in (-1, 0, 1, 2): patoolib.test_archive(archive, program=self.program, verbosity=verbosity)
def recursive_unpack(path, udir='/tmp', recursive=True, top_level=True): """ Recursively unpack archive and all archives in content Deletes symlinks """ if top_level == False: if all(not path.endswith(suffix) for suffix in unpack_suffixes): # print("skip {}".format(path)) return None try: patoolib.test_archive(path, verbosity=-1) except patoolib.util.PatoolError: return None nudir = mkdtemp(prefix='hashget-uniunpack-', dir=udir) patoolib.extract_archive(path, outdir=nudir, verbosity=-1) for f in dircontent(nudir): if os.path.islink(f): os.unlink(f) if recursive: for f in dircontent(nudir): if os.path.isfile(f) and not os.path.islink(f): recursive_unpack(f, nudir, top_level=False) return nudir
def check_archive(data, write_sample=False): """Check if data is an archive. Args: data (string): raw data write_sample (boolean): if True it writes sample on disk Returns: boolean: only True is archive (False otherwise) if write_sample is False tuple (boolean, string): True is archive (False otherwise) and sample path """ is_archive = True temp = tempfile.mkstemp()[-1] try: with open(temp, 'wb') as f: f.write(data) except UnicodeEncodeError: with open(temp, 'wb') as f: f.write(data.encode("utf-8")) try: patoolib.test_archive(temp, verbosity=-1) except Exception: is_archive = False finally: if not write_sample: os.remove(temp) temp = None return is_archive, temp
def is_archive(data, write_sample=False): """If write_sample=False this function return only a boolean: True if data is a archive, else False. Else write_sample=True this function return a tuple: (is_archive, path_sample) """ is_archive = True try: temp = tempfile.mkstemp()[1] with open(temp, 'wb') as f: f.write(data) except: raise TempIOError("Failed opening '{}' file".format(temp)) try: patoolib.test_archive(temp, verbosity=-1) except: is_archive = False finally: if write_sample: return is_archive, temp else: os.remove(temp) return is_archive
def is_archive(data, write_sample=False): """Check if data is an archive. Args: data (string): raw data write_sample (boolean): if True it writes sample on disk Returns: boolean: only True is archive (False otherwise) if write_sample is False tuple (boolean, string): True is archive (False otherwise) and sample path """ is_archive = True try: temp = tempfile.mkstemp()[1] with open(temp, 'wb') as f: f.write(data) except: raise TempIOError("Failed opening '{}' file".format(temp)) try: patoolib.test_archive(temp, verbosity=-1) except: is_archive = False finally: if write_sample: return is_archive, temp else: os.remove(temp) return is_archive
def getArchiveMembers(fileName): import patoolib try: patoolib.test_archive(fileName, verbosity=-1) print "<ArchiveMembers>" patoolib.list_archive(fileName) print "</ArchiveMembers>" except: pass
def run_test(args): """Test files in archive(s).""" res = 0 for archive in args.archive: try: patoolib.test_archive(archive, verbosity=args.verbosity, interactive=args.interactive, password=args.password) except PatoolError as msg: log_error("error testing %s: %s" % (archive, msg)) res += 1 return res
def is_supported(path): """Return whether the file at path is supported by patoolib. path (string): the path to test. return (bool): whether path is supported. """ try: patoolib.test_archive(path, interactive=False) return True except PatoolError: return False
def is_archive(params): """ Détermine si le fichier passé en paramètre est une archive. :param params: les paramètres :return: True si c'est une archive, False sinon """ # noinspection PyBroadException try: test_archive(params['path'], verbosity=-1, interactive=False) except Exception: return False return True
def check_archive(self, archive_path): """Check that a given archive is actually ok for reading. Args: archive_path (str): Archive to check Returns: True if archive is successfully read, False otherwise. """ try: patoolib.test_archive(archive_path, verbosity=-1) except Exception as e: print('Exception Thrown: ' + str(e)) self.logfile.log_error("Corrupt archive: " + self.SUBMITTED_FILE) return False else: return True
import patoolib import os import glob import os.path from os import path basepath = "C:\Respaldo\Mar21/" myfiles = [f for f in glob.glob(basepath + "*.bak")] listfinal = [] for f in myfiles: x = f.find("Mar_") if x > 0: f = f.upper() fx = f.replace(".BAK", ".RAR") if path.exists(fx) == False: listfinal.append(f) for t in listfinal: t = t.upper() fx = t.replace(".BAK", ".RAR") print(t) patoolib.create_archive(fx, (t, )) patoolib.test_archive(fx, verbosity=1)
def _test_patool(file_path): archive_format = patoolib.get_archive_format(file_path) rv = patoolib.test_archive(file_path) contents = patoolib.list_archive(file_path) return contents
def test_archive(self): try: Pat.test_archive(self.files, verbosity=-1) return True except: return False
def archive_test (self, filename): """Test archive testing.""" archive = os.path.join(datadir, filename) for verbosity in (-1, 0, 1, 2): patoolib.test_archive(archive, program=self.program, verbosity=verbosity)
def is_compressed(file_path) : try : res = test_archive("fichiers shape.zip", verbosity=-1, interactive=False) except PatoolError : return False,"the file is not an archive or not correctly defined" return True,"the file is an archive"
def is_compressed(file_path) : try : res = test_archive(file_path, verbosity=-1, interactive=False) except PatoolError : return False #ptet un RAISE EXCEPTION return True