osx - .app is no longer openable on OS X after copy with python -
i have python application supposed copy .app on os x new place, run it. sha1 checksum on file before , after copy ensure copy without error, , checksum checks out. can think of reason why be? did ensure file permissions open chmod 777 on copied .app, doesn't fix it.
this core of copy function in python. pulled somewhere else edited:
def copy_directory_recursive(self, srcpath, dstpath): dirandfilelist = os.listdir(srcpath) dirlist = [] filelist = [] in dirandfilelist: if os.path.isdir(os.path.join(srcpath, i)): dirlist.append(i) elif os.path.isfile(os.path.join(srcpath, i)): filelist.append(i) dirlist.sort() filelist.sort() directory in dirlist: # if qitem.hascancelled(): #if user has cancelled copy, quit # break os.mkdir(os.path.join(dstpath, directory)) newsrc = os.path.join(srcpath, directory) newdst = os.path.join(dstpath, directory) # call move newly created subfolder , # repeat... self.copy_directory_recursive(newsrc, newdst) file in filelist: # if qitem.hascancelled(): #if user has cancelled copy, quit # break # copy file shutil.copyfile( os.path.join(srcpath, file), os.path.join(dstpath, file)) self.filescopied += 1 # feedback progress bar of queue item self.update()
you can use copytree
call shutils
, still update progress. example:
def update(self): proportiondone = self.filescopied/float(self.totalfiles) # whatever other work necessary here show progress bar print "i'm %.2f percent done!" % (proportiondone * 100) def progress(self, path, names): self.filescopied += len(names) self.update() return [] def copy_directory_recursive(self, srcpath, dstpath): self.filescopied = 0 self.totalfiles = 0 root, dirs, files in os.walk(srcpath): self.totalfiles += len(files) + len(dirs) shutil.copytree(srcpath, dstpath, ignore=self.progress)
Comments
Post a Comment