def call_7zip(filepath, outdir, fileext): """Call 7zip to extract an archive. This uses a tempfile and the 'os' methods instead of the built-in functions open, close, and remove. """ filepath = filepath.replace('\\', '/') prtfile = strip_directory_prefix(filepath) print("extract " + prtfile) exepath = libastyle.get_7zip_path() extract = [exepath, "x", "-ry", "-o" + outdir, filepath] if __extract_all_files: print("extracting ALL files", ) else: extract.extend(fileext) print("extracting " + str(fileext)) # open a tempfile and access it with the 'os' methods fd, filename = tempfile.mkstemp(prefix="extract.", suffix=".tmp", dir=libastyle.get_temp_directory(), text=True) # print(os.path.basename(filename)) try: subprocess.check_call(extract, stdout=fd) except subprocess.CalledProcessError as err: libastyle.system_exit("Bad 7zip return: " + str(err.returncode)) except OSError: libastyle.system_exit("Cannot find executable: " + exepath) os.close(fd) os.remove(filename)
def call_7zip(filepath, outdir, fileext): """Call 7zip to extract an archive. This uses a tempfile and the 'os' methods instead of the built-in functions open, close, and remove. """ filepath = filepath.replace('\\', '/') prtfile = strip_directory_prefix(filepath) print("extract " + prtfile) exepath = libastyle.get_7zip_path() extract = [exepath, "x", "-r", "-y", "-o" + outdir, filepath] if __extract_all_files: print("extracting ALL files", ) else: extract.extend(fileext) print("extracting " + str(fileext)) # open a tempfile and access it with the 'os' methods fd, filename = tempfile.mkstemp(prefix="extract.", suffix=".tmp", dir=libastyle.get_temp_directory(), text=True) # print(os.path.basename(filename)) try: subprocess.check_call(extract, stdout=fd) except subprocess.CalledProcessError as err: libastyle.system_exit("Bad 7zip return: " + str(err.returncode)) except OSError: libastyle.system_exit("Cannot find executable: " + exepath) os.close(fd) os.remove(filename)
def call_7zip(filepath, outdir, fileext): """Call 7zip to extract an archive. """ filepath = filepath.replace('\\', '/') prtfile = strip_directory_prefix(filepath) print "extract " + prtfile exepath = libastyle.get_7zip_path() extract = [exepath, "x", "-ry", "-o" + outdir, filepath] if extract_all_files: extract.extend(fileext) filename = libastyle.get_temp_directory() + "/extract.txt" outfile = open(filename, 'w') retval = subprocess.call(extract, stdout=outfile) if retval: libastyle.system_exit("Bad 7zip return: " + str(retval)) outfile.close() os.remove(filename)
def call_7zip(dist_base, compressed_file): """Call 7zip to create an archive. arg 1- the directory to compress. arg 2- name of the compressed file. """ exepath = libastyle.get_7zip_path() compress = [exepath, "a", compressed_file] # check file ending to see if it is a tarball if compressed_file.endswith((".gz", ".bz2")): compress.append("*.tar") # stdout file must have full path since 'cwd' is used in call filename = libastyle.get_file_py_directory(True) + "compress.txt" outfile = open(filename, 'w') retval = subprocess.call(compress, cwd=dist_base, stdout=outfile) if retval: libastyle.system_exit("Bad 7zip return: " + str(retval)) outfile.close() os.remove(filename) print(compressed_file + " created")
def call_7zip(distBase, compressedFile): """Call 7zip to create an archive. arg 1- the directory to compress. arg 2- name of the compressed file. """ exepath = libastyle.get_7zip_path() compress = [exepath, "a", compressedFile] # check file ending to see if it is a tarball if compressedFile.endswith((".gz", ".bz2")): compress.append("*.tar") # stdout file must have full path since 'cwd' is used in call filename = libastyle.get_file_py_directory(True) + "compress.txt" outfile = open(filename, 'w') retval = subprocess.call(compress, cwd=distBase, stdout=outfile) if retval: libastyle.system_exit("Bad 7zip return: " + str(retval)) outfile.close() os.remove(filename) print (compressedFile + " created")
def call_7zip(filepath, outdir, fileext): """Call 7zip to extract an archive. """ filepath = filepath.replace('\\', '/') prtfile = strip_directory_prefix(filepath) print ("extract " + prtfile) exepath = libastyle.get_7zip_path() extract = [exepath, "x", "-ry", "-o" + outdir, filepath] if extract_all_files: print ("extracting ALL files") else: extract.extend(fileext) print ("extracting " + str(fileext)) filename = libastyle.get_temp_directory() + "/extract.txt" outfile = open(filename, 'w') retval = subprocess.call(extract, stdout=outfile) if retval: libastyle.system_exit("Bad 7zip return: " + str(retval)) outfile.close() os.remove(filename)
def call_7zip(dist_base, compressed_file): """Call 7zip to create an archive. arg 1- the directory to compress. arg 2- name of the compressed file. """ exepath = libastyle.get_7zip_path() compress = [exepath, "a", compressed_file] # check file ending to see if it is a tarball if compressed_file.endswith((".gz", ".bz2")): compress.append("*.tar") # stdout file must have full path since 'cwd' is used in call filename = libastyle.get_file_py_directory(True) + "compress.txt" outfile = open(filename, 'w') try: subprocess.check_call(compress, cwd=dist_base, stdout=outfile) except subprocess.CalledProcessError as err: libastyle.system_exit("Bad 7zip return: " + str(err.returncode)) except OSError: libastyle.system_exit("Cannot find executable: " + compress[0]) outfile.close() os.remove(filename) print(compressed_file + " created")