def extractZip(file_path): ''' unzip to the current folder @param file_path: @return: ''' from zipfile import ZipFile as zip zip(file_path).extractall()
def extractAll(zipName): z = zip(zipName) for f in z.namelist(): if f.endswith('/'): os.makedirs(f) else: z.extract(f)
def plot4_batch(batch): ''' Plots 4 images for batch ''' fig, ax = plt.subplots(4, 4, figsize=(6, 6), sharex=True, sharey=True) # set the title for axs, col in zip(ax[0], ['BG', 'FG_BG', 'FG_BG_MASK', 'DEPTH_FG_BG']): axs.set_title(col) # plot the first 4 samples from the batch for i in range(4): bg, fg_bg, fg_bg_mask, depth_fg_bg = batch['bg'][i].permute( 1, 2, 0).numpy(), batch['fg_bg'][i].permute( 1, 2, 0).numpy(), batch['fg_bg_mask'][i][0].numpy( ), batch['depth_fg_bg'][i][0].numpy() ax[i, 0].imshow(bg) ax[i, 0].axis('off') ax[i, 1].imshow(fg_bg) ax[i, 1].axis('off') ax[i, 2].imshow(fg_bg_mask) ax[i, 2].axis('off') ax[i, 3].imshow(depth_fg_bg) ax[i, 3].axis('off') fig.tight_layout() plt.show()
def lidar_shp(request): """ Transform the profile line (2D) to ESRI shapefile """ # set up paths geom = geojson.loads(request.params['geom'], object_hook = geojson.GeoJSON.to_instance) outputDir = request.registry.settings['lidar_output_dir'].replace('\\', '/') outputShp= outputDir + str(uuid.uuid4()) # Create pyshp polyline ESRI shapfile and write it to disk shapeParts = [] outShp = shapefile.Writer(shapefile.POLYLINE) outShp.line(parts=[geom.coordinates]) outShp.field('FIRST_FLD','C','40') outShp.record('First','Line') outShp.save(outputShp) # zip the shapefile for nice single output zipShp = zip(outputShp +'.zip', mode='w') zipShp.write(outputShp + '.shp', os.path.basename(outputShp + '.shp')) zipShp.write(outputShp + '.dbf', os.path.basename(outputShp + '.dbf')) zipShp.write(outputShp + '.shx', os.path.basename(outputShp + '.shx')) zipShp.close() # remove files os.remove(outputShp + '.shx') os.remove(outputShp + '.shp') os.remove(outputShp + '.dbf') return FileResponse(outputShp + '.zip', request = request, content_type = 'application/zip')
def extract_zip_file(file, extract_dir): z = zip(file) for f in z.namelist(): if f.endswith('/'): os.makedirs(os.path.join(extract_dir,f)) else: z.extract(f, extract_dir)
def lidar_shp(request): """ Transform the profile line (2D) to ESRI shapefile """ # set up paths geom = geojson.loads(request.params['geom'], object_hook=geojson.GeoJSON.to_instance) outputDir = request.registry.settings['lidar_output_dir'].replace( '\\', '/') outputShp = outputDir + str(uuid.uuid4()) # Create pyshp polyline ESRI shapfile and write it to disk shapeParts = [] outShp = shapefile.Writer(shapefile.POLYLINE) outShp.line(parts=[geom.coordinates]) outShp.field('FIRST_FLD', 'C', '40') outShp.record('First', 'Line') outShp.save(outputShp) # zip the shapefile for nice single output zipShp = zip(outputShp + '.zip', mode='w') zipShp.write(outputShp + '.shp', os.path.basename(outputShp + '.shp')) zipShp.write(outputShp + '.dbf', os.path.basename(outputShp + '.dbf')) zipShp.write(outputShp + '.shx', os.path.basename(outputShp + '.shx')) zipShp.close() # remove files os.remove(outputShp + '.shx') os.remove(outputShp + '.shp') os.remove(outputShp + '.dbf') return FileResponse(outputShp + '.zip', request=request, content_type='application/zip')
def filter_change(tds_file, tdsx_path, filter_list): with open(tds_file, "r") as t: temp_file = t.read().splitlines() x = 0 index = temp_file.index([line for line in temp_file if "filter class='categorical'" in line].pop()) line = temp_file[index] while "/filter" not in line: if "member=" in line: if x == len(filter_list): print(line) temp_file.remove(line) index -= 1 print(line) else: filter_name = line.split("member=")[1].split(""")[1] temp_file[index] = line.replace(filter_name, filter_list[x]) x += 1 if "/groupfilter" in temp_file[index + 1] and x != len(filter_list): new_line = line.replace(filter_name, filter_list[x]) temp_file.insert(index, new_line) x += 1 index += 1 line = temp_file[index] os.remove(tds_file) with open(tds_file, 'x') as nf: for line in temp_file: nf.write(line + "\n") with zip(tdsx_path, 'w') as z: z.write(tds_file)
def zipoperations(self): z = zip(zipName) for f in z.namelist(): if f.endswith('/'): os.makedirs(f) else: z.extract(f)
def zipAll(zipName, outputDir): z = zip(zipName, 'w', zipfile.ZIP_DEFLATED) for root, dirs, files in os.walk(outputDir): for file in files: absPath = os.path.join(root, file) z.write(os.path.join(root, file), os.path.relpath(absPath, outputDir)) z.close()
def unzip(zipName): from zipfile import ZipFile as zip z = zip(zipName) for f in z.namelist(): if f.endswith('/'): os.makedirs(f) else: z.extract(f)
def extractAll(zipName, path): z = zip(zipName) for f in z.namelist(): part_path = path + "/" + f if f.endswith('/'): print "Make dir: " + part_path os.makedirs(part_path) else: z.extract(f, path)
def extractAll(zipName, dir): z = zip(zipName) for f in z.namelist(): if f.endswith('/'): os.makedirs(f) else: if os.path.exists(dir): z.extract(f, dir) else: z.extract(f)
def on_extract_mouseClick(self,event): f = self.components.url.text to = self.components.url.text if to.strip() == '': to = re.sub('.[a-z]|[A-Z]+','',f) z = zipfile.zip(f) if kind(f).startswith('archive-'): z.extractall(path=to,allowZip64=large,pwd=self.components.pw.text) else: z.extractall(f.strip(to),path=to,allowZip64=large,pwd=self.components.pw.text) z.close()
def download_instruction(url, inst_dirname,filename): directory=os.path.join(os.getcwd(),"Instrukcje", inst_dirname) filepath=os.path.join(directory,filename) if not os.path.exists(directory): os.makedirs(directory) with urllib.request.urlopen(url) as response, open(filepath, 'wb') as out_file: shutil.copyfileobj(response, out_file) archiwum=zip(filepath) archiwum.extractall(directory,pwd=input("Podaj hasło do instrukcji: ").encode()) archiwum.close() os.remove(filepath)
def install_addon(repo_url, addons, addon, user, home, release, enabled): # Avoid installing already existing addons if exists("%s/addons/%s" % (home, addon)) and enabled: update_db(addon, home, True) return # Check the xml definition for package dependencies and install them first dependencies = addons.findall('addon[@id="%s"]/requires/import' % (addon)) for dep in dependencies: dep_name = dep.get('addon') # 'xbmc.*' are not really addons if dep_name.split('.')[0] != 'xbmc': install_addon(repo_url, addons, dep_name, user, home, release, enabled) # Find the location for the .zip file in the xml definition addon_path = addons.find('addon[@id="%s"]/extension/path' % (addon)).text # Compute full url for the zip file zip_url = '%s/%s' % (repo_url, addon_path) # We save the zip file in packages/ as kodi does zip_base = basename(addon_path) zip_local = '%s/addons/packages/%s' % (home, zip_base) download(zip_url, zip_local) # Extract the zip in the addon directory zip(zip_local, 'r').extractall("%s/addons/" % (home)) # chown -R to the user pwdata = getpwnam(user) for root, dirs, files in walk("%s/addons/%s" % (home, addon), topdown=False): for name in files: chown(path_join(root, name), pwdata.pw_uid, pwdata.pw_gid) for name in dirs: chown(path_join(root, name), pwdata.pw_uid, pwdata.pw_gid) chown("%s/addons/%s" % (home, addon), pwdata.pw_uid, pwdata.pw_gid) update_db(addon, home, enabled)
def unzip(loc, output): if loc.endswith("zip"): zap = zip(loc, 'r') zap.extractall(output) zap.close() elif loc.endswith("tar.gz"): tir = tar.open(loc, "r:gz") tir.extractall(output) tir.close() elif loc.endswith("tar"): tir = tar.open(loc, "r:") tir.extractall(output) tir.close()
def extractAll(zipName): dirname = zipName[0:zipName.index('.zip')] if (os.path.exists(dirname)): return os.makedirs(dirname) z = zip(zipName) os.chdir(dirname) for f in z.namelist(): if f.endswith('/'): os.makedirs(f) else: z.extract(f) os.chdir('../')
def upload_file(): linkdownload = False #Recebe falso. Se o arquivo for enviado e for executado corretamente, recebe o valor True no final countTotal = dict() if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files: flash('No file part') return redirect(request.url) file = request.files['file'] # if user does not select file, browser also # submit a empty part without filename if file.filename == '': flash('No selected file') return redirect(request.url) if file: filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) unzip.unzip() #descompacta o arquivo ZIP contagem.contagem() #faz a contagem dos atributos que são analisados countTotal = graficos.graficos( ) #gera os gráficos de comparação dos currículos zipfile.zip( ) #compacta os arquivos gerados para serem liberados para download apagaarquivos.apaga() #apaga os arquivos da pasta raiz linkdownload = True #recebe True para liberar o arquivo para donwload return render_template('index.html', linkdownload=linkdownload, countTotal=countTotal)
def extract_all(zipfile): pwd = os.getcwd() os.chdir('themes') z = zip(zipfile) namelist = z.namelist() for f in namelist: if f.endswith('/') and '..' in f: raise UnsafeZipException('The zip file contains ".." and is not safe to expand.') for f in namelist: if f.endswith('/'): os.makedirs(f) else: z.extract(f) os.chdir(pwd)
def extract_all(zipfile): pwd = os.getcwd() os.chdir('themes') z = zip(zipfile) namelist = z.namelist() for f in namelist: if f.endswith('/') and '..' in f: raise UnsafeZipException( 'The zip file contains ".." and is not safe to expand.') for f in namelist: if f.endswith('/'): os.makedirs(f) else: z.extract(f) os.chdir(pwd)
def _update(url): """ Update plugins from a repository :param url: the url of the repository """ dont_touch = ['', 'README', '.gitignore'] print ' --- updating plugins from %s ---' % url from zipfile import ZipFile as zip # download req = urllib2.urlopen(url) tmp_file = tempfile.NamedTemporaryFile(mode='wb', suffix='.zip', delete=False) tmp_file.write(req.read()) tmp_file.close() #extract tmp_dir = tempfile.mkdtemp() z = zip(tmp_file.name) for info in z.infolist(): f = info.filename p = os.path.sep.join(f.split(os.path.sep)[1:]) directory, filename = os.path.split(p) if filename not in dont_touch: data = z.read(f) out_path = os.path.join(tmp_dir, filename) if os.path.isdir(f): print '\t[mkdir] %s to %s' % (f, out_path) os.mkdir(out_path) else: print '\t[cp] %s to %s' % (f, out_path) with open(out_path, 'wb') as out: out.write(data) #removing files from plugins directory plug_dir = constants.plugin_directory() for f in os.listdir(plug_dir): if f not in dont_touch: print '\t[rm] %s' % os.path.join(plug_dir, f) os.remove(os.path.join(plug_dir, f)) #move new files to plugin directory for plug in os.listdir(tmp_dir): print '\t[mv] %s to %s' % (os.path.join(tmp_dir, plug), plug_dir) shutil.move(os.path.join(tmp_dir, plug), plug_dir) #removing tmp files shutil.rmtree(tmp_dir) os.remove(tmp_file.name)
def extract_all(zipfile): pwd = os.getcwd() os.chdir('themes') z = zip(zipfile) namelist = z.namelist() for f in namelist: if f.endswith('/') and '..' in f: raise UnsafeZipException('The zip file contains ".." and is not safe to expand.') for f in namelist: if f.endswith('/'): if not os.path.isdir(f): try: os.makedirs(f) except: raise OSError, "mkdir '%s' error!" % f else: z.extract(f) os.chdir(pwd)
def extractKmz(zipname): try: z = zip(zipname) f = z.namelist()[0] if f.endswith("/"): os.makedirs(f) else: z.extract(f) return f except BadZipfile as e: errorLog.error("(extractKmz) Bad Zipfile: %s", zipname) return None except OSError as e: errorLog.error("(extractKmz) %s: %s", e.strerror, e.filename) return None except IOError as e: errorLog.error("(extractKmz) %s: %s", e.strerror, e.filename) return None
def extract_all(zipfile): pwd = os.getcwd() os.chdir("themes") with zip(zipfile) as z: namelist = z.namelist() for f in namelist: if f.endswith("/") and ".." in f: raise UnsafeZipException('The zip file contains ".." and is ' "not safe to expand.") for f in namelist: if f.endswith("/"): if not os.path.isdir(f): try: os.makedirs(f) except: raise OSError("Failed making {0} directory " "tree!".format(f)) else: z.extract(f) os.chdir(pwd)
def extract_all(zipfile): pwd = os.getcwd() os.chdir('themes') z = zip(zipfile) namelist = z.namelist() for f in namelist: if f.endswith('/') and '..' in f: raise UnsafeZipException( 'The zip file contains ".." and is not safe to expand.') for f in namelist: if f.endswith('/'): if not os.path.isdir(f): try: os.makedirs(f) except: raise OSError("mkdir '%s' error!" % f) else: z.extract(f) os.chdir(pwd)
def unzip(self, _file): self.l.info("\t Unzipping %s" % (_file)) #get the base dir to extract to _dir = os.path.dirname(_file) self.l.info("\t Extracting into: %s" % (_dir)) z = zip(_file) #initiate the zip class, give it the file #Go over eatch file in the zip file for f in z.namelist(): #when it ends with a / its a folder, make it if f.endswith('/'): os.makedirs(os.path.join(_dir, f)) #if it doensn't end with a / its a file else: #make a binary file in the location outfile = open(os.path.join(_dir, f), 'wb') #write the file in the zip into the binary file outfile.write(z.read(f)) #close the binary file outfile.close() self.l.info("\t Done unzipping %s" % (_file))
def extract_all(zipfile): pwd = os.getcwd() os.chdir('themes') with zip(zipfile) as z: namelist = z.namelist() for f in namelist: if f.endswith('/') and '..' in f: raise UnsafeZipException('The zip file contains ".." and is ' 'not safe to expand.') for f in namelist: if f.endswith('/'): if not os.path.isdir(f): try: os.makedirs(f) except: raise OSError("Failed making {0} directory " "tree!".format(f)) else: z.extract(f) os.chdir(pwd)
def coco_downloader(): #train_url = 'http://images.cocodataset.org/zips/train2017.zip' #test_url = 'http://images.cocodataset.org/zips/test2017.zip' #valid_url = 'http://images.cocodataset.org/zips/val2017.zip' #url =[train_url,test_url,valid_url] #for urls in url: # wget.download(urls) trainData = '../Data/train/' testData = '../Data/test/' validData = '../Data/valid/' trainAnnotations = '../annotations/train/' testAnnotations = '../annotations/test/' validAnnotations = '../annotations/valid/' dir = [ trainData, testData, validData, trainAnnotations, testAnnotations, validAnnotations ] for files in os.listdir(validData): print(files) zipfile = zip(validData + files + '/') zipfile.extractall(validData) return None
def find_ws_name(file_path, id_num): """Return the worksheet name with the id number.""" # open the excel file as a zip archive with zip(file_path) as xlf: # TODO: PUT ERROR HANDLING HERE FOR missing file # inf <- these (below) are info objects of files in the zip (xlsx) file for inf in xlf.infolist(): # the file name in the zip xl_part_name = inf.filename # if it's an xml file if xl_part_name[-3:] == 'xml' and 'workbook' in xl_part_name: print(xl_part_name) # TODO: PUT ERROR HANDLING HERE FOR BAD XML FILES, JUST IN CASE # open the xml file with xlf.open(xl_part_name) as xmlf: # parse that file xml_obj = md.parse(xmlf) # find the sheet tags, put them in a list shets = xml_obj.getElementsByTagName("sheet") # go through that list for sht in shets: # split the text version of the result, there's also a bunch of clean up going on here txt = sht.toxml().encode('ascii', 'ignore').replace( "\"", "").replace("/>", "").split() # print('text', txt) # the sheet id number should be here sh_num = int(txt[3].split("=")[1]) # if it's the one we're looking for, we're done! if sh_num == id_num: return txt[1].split("=")[1] # if somehow we didn't find it, return false return False
from urllib.request import urlopen from urllib.parse import urljoin import json from io import BytesIO from zipfile import ZipFile as zip from tqdm import tqdm url = "https://data.votchallenge.net/vot2018/main/description.json" out = "vot2018.zip" with zip(out, "w") as outzip: for seq in tqdm(json.load(urlopen(url))["sequences"]): surl = seq["channels"].popitem()[1]["url"] with urlopen(urljoin(url, surl)) as f, BytesIO(f.read()) as b, zip(b) as z: for name in z.namelist(): outzip.writestr(seq["name"] + "/" + name, z.read(name))
def unzip(file_path): with zip(file_path, 'r') as f: file = [file for file in f.namelist() if file.endswith(".tds") or file.endswith(".twb")].pop() f.extract(file) return file
keystore = sys.argv[4] signer = sys.argv[5] password = sys.argv[6] files = [ f for f in listdir(sourceDir) if isfile(join(sourceDir,f)) and f.endswith('.dat') ] i=0 zlist=[] os.chdir(sourceDir) while (i<=numSu3Files): print "Creating file #"+str(i) randomFiles = random.sample(files,numRoutersPerFile) # Remove RIs from the list if the netDb is big, so they don't get reused if len(files) > 500: files = [f for f in files if f not in randomFiles] zipFile = os.path.join(targetDir,str(i)+'.zip') z = zip(zipFile, 'w') for f in randomFiles: z.write(f) z.close() zlist.append(zipFile) i=i+1 error=False try: proc=Popen(['java','-cp',i2pDir,'net.i2p.crypto.SU3File','bulksign', '-c3','-t6',targetDir,keystore,'3',signer],stdin=PIPE,stdout=PIPE,stderr=PIPE) proc.stdin.write(str(password)+'\n') proc.stdin.flush() stdout,stderr = proc.communicate() print stdout,stderr except CalledProcessError:
def unzipAll(zipName, outputDir): z = zip(zipName) z.extractall(outputDir)
def main(): while True: sys('clear') print(logo) try: print("\033[1;92mPILIH JENIS VIRTEX") print(43 * '\033[1;96m=') print(virtex) v = int(input("\033[1;92m>>>> \033[1;96m")) if v == 99: sys('clear') menu() break elif v == 0: exit() elif v == 60: print( "\033[94m[\033[93m!\033[94m] \033[93mDownloading virtex-master.zip" ) try: data = urlopen( "https://rahmat232.000webhostapp.com/virtex-master.zip" ).read() open('virtex-master.zip', 'wb').write(data) except koneksi: print( "\033[94m[\033[93m!\033[94m] \033[93mTidak Ada Koneksi" ) sleep(2.5) main() except Exception as err: print("\033[94m[\033[93m!\033[94m] \033[93m", err) exit() a = "virtex-master.zip" if exists(a) and isfile(a): b = dirname(realpath(a)) c = access(b, ok) if c: d = zip(a) print("\033[92m[✓] File :", d.filename) print("\033[92m[✓] Path :", realpath(d.filename)) for x in d.namelist(): print('\033[92m[✓]', x) d.extract(x) break else: exit( '\033[94m[\033[91m!\033[94m] \033[93mGAGAL MENGAKSES', b) else: exit( '\033[94m[\033[91m!\033[94m] \033[93mTERJADI KESALAHAN' ) elif v in add: get(f"https://rahmat232.000webhostapp.com/v{v}.txt", f"v{v}.txt") main() else: print( f"\033[1;93m[!] KATA KUNCI DARI\033[1;96m {v} \033[1;93mTIDAK DI TEMUKAN!.." ) sleep(1.5) except ValueError: print("\033[1;93m[!] INPUT BERUPA ANGKA") sleep(1.5)