def do_copy(self): ind=self.lb.current() src=self.all[ind][0] base=os.path.basename(src) if src.endswith(':') or not os.path.exists(src): return 1 path=os.path.dirname(src) if path.endswith('\\'): path=path[:-1] ui.note(u'select destination') running=1 while running: self.lb.set_list([(u'please wait...', self.wait_icon), ]) #e32.ao_yield() dst=useFman().AskUser(path, base, type='folder') if dst==None: return self.run(path, base) dst=dst+'\\'+base if dst.lower().startswith('z:'): ui.note(u'ACCESS DENIED', 'error') return self.run(path, base) try: if os.path.isfile(src): if os.path.exists(dst) and not os.stat(dst)[0]&128: if ui.query(u'replace Read-Only file?', 'query'): os.chmod(dst, ~0) sh.copyfile(src, dst) else: return self.run(path, base) sh.copyfile(src, dst) else: sh.copytree(src, dst) ui.note(u'successful', 'conf') except IOError: if os.path.isfile(dst): os.chmod(dst, ~0) os.remove(dst) ui.note(u'cant copy', 'error') except: if ui.query(u'Already exists! Sure to replace existing and Read-Only files?', 'query'): if self.__pwrcopy(src, dst): ui.note(u'successful', 'conf') else: ui.note(u'cant copy', 'error') return self.run(path, base) running=0
def __pwrcopy(src, dst): try: try: if os.path.isfile(src): os.chmod(dst, ~0) sh.copyfile(src, dst) return 1 else: sh.copytree(src, dst) return 1 except IOError: if os.path.isfile(dst): os.chmod(dst, ~0) os.remove(dst) return 0 except OSError: a=os.listdir(src) if len(a)==0 and os.path.exists(dst): #os.rmdir(src) return 1 else: for i in a: d=src+'\\'+i f=dst+'\\'+i if not os.path.exists(f): if os.path.isfile(d): sh.copyfile(d, f) else: sh.copytree(d, f) else: __pwrcopy(d, f) return 1 except: return 0 except IOError: if os.path.isfile(f): os.chmod(f, ~0) os.remove(f) return 0 except: return 0
def docopy(src, dst): def __pwrcopy(src, dst): try: try: if os.path.isfile(src): os.chmod(dst, ~0) sh.copyfile(src, dst) return 1 else: sh.copytree(src, dst) return 1 except IOError: if os.path.isfile(dst): os.chmod(dst, ~0) os.remove(dst) return 0 except OSError: a=os.listdir(src) if len(a)==0 and os.path.exists(dst): #os.rmdir(src) return 1 else: for i in a: d=src+'\\'+i f=dst+'\\'+i if not os.path.exists(f): if os.path.isfile(d): sh.copyfile(d, f) else: sh.copytree(d, f) else: __pwrcopy(d, f) return 1 except: return 0 except IOError: if os.path.isfile(f): os.chmod(f, ~0) os.remove(f) return 0 except: return 0 dst=dst+'\\'+os.path.basename(src) try: if os.path.isfile(src): sh.copyfile(src, dst) else: sh.copytree(src, dst) print 'successful' except IOError: if os.path.isfile(dst): os.chmod(dst, ~0) os.remove(dst) print 'cant copy' return except: print 'trying power copy' if __pwrcopy(src, dst): print 'success' else: print 'cant copy'