def paste(self,item): '''First check if item is file then get its parent otherwise check if item is Dir''' if(item.isFile()): p = item.parent() else: p = item if(self.clipboard != []): for items in self.clipboard: if(items.isFile()): itemspath = items.getPath() '''Check if we are pasting files that alreadt exists using ospathjoin''' if not(ospathexists(ospathjoin(p.getPath(),items.name))): try: shutil.copyfile(itemspath,ospathjoin(p.getPath(),items.name)) newItem = File(p,items.name,ospathdirname(itemspath)) except: QMessageBox.about(self,"Error","File Cannot be Pasted"+ospathjoin(p.getPath(),items.name)) else: QMessageBox.about(self,"Error","File already Exists "+ospathjoin(p.getPath(),items.name)) return elif(items.isDir()): itemspath = items.getPath() '''Check if we are pasting files that alreadt exists using ospathjoin''' if not(ospathexists(ospathjoin(p.getPath(),items.name))): try: shutil.copyfile(itemspath,ospathjoin(p.getPath(),items.name)) newItem = File(p,items.name,ospathdirname(itemspath)) except: QMessageBox.about(self,"Error","File Cannot be Pasted"+ospathjoin(p.getPath(),items.name)) else: QMessageBox.about(self,"Error","File already Exists "+ospathjoin(p.getPath(),items.name)) return
def newFile(self,item): itempath = item.getPath() text,ok = QInputDialog.getText(self,"QInputDialog::getText()","Name:") if (ok and text != ''): fname = ospathjoin(ospathdirname(itempath),str(text)) try: nfile = open(fname,'w') nfile.close() f = File(item,ospathbasename(fname),ospathdirname(fname)) item.addChild(f) except: QMessageBox.about(self,"Error","Could Not Create The File")
def renameFile(self,item): text,ok = QInputDialog.getText(self,"QInputDialog::getText()","New Name:") itempath = item.getPath() if (ok and text != ''): newname = ospathjoin(ospathdirname(itempath),str(text)) try: #print newname osrename(itempath,newname) p = item.parent() p.removeChild(item) f = File(p,ospathbasename(newname),ospathdirname(newname)) #p.addChild(f) except: QMessageBox.about(self,"Error","Could Not Rename The File")
def download(self): self.emit(SIGNAL("progress")) url = 'https://raw.github.com/Pyros2097/Sabel/master/build/exe.win32-2.7/library.zip' file_name = url.split('/')[-1] try: u = urllib2.urlopen(url) f = open(file_name+"_2097", 'wb') meta = u.info() file_size = int(meta.getheaders('Content-Length')[0]) #print 'Downloading: %s Bytes: %s' % (file_name, file_size) file_size_dl = 0 block_sz = 8192 while self.running: buffer = u.read(block_sz) if not buffer: break file_size_dl += len(buffer) f.write(buffer) status = file_size_dl * 100.0 / file_size self.emit(SIGNAL("status"),status) ''' The file library.zip is never used the library is once loaded into the vm so no need to delete it ''' f.close() if(self.running): #to prevent it from executing this code if terminated if(ospathexists(file_name)): recycle(file_name) # deletes library.zip osrename(file_name+"_2097",ospathjoin(ospathdirname(file_name+"_2097"),"library.zip")) self.emit(SIGNAL("updated")) except urllib2.URLError as err: self.emit(SIGNAL("cant")) except: self.emit(SIGNAL("stop")) self.quit()
def newFolder(self,item): text,ok = QInputDialog.getText(self,"QInputDialog::getText()","Name:") if (ok and text != ''): fname = ospathdirname(item.getPath()) try: print fname+'/'+text #osmkdir(fname+'/'+text,0755) except: QMessageBox.about(self,"Error","Could Not Create The File")
def renameDir(self,item): itempath = item.getPath() text,ok = QInputDialog.getText(self,"QInputDialog::getText()","New Name:") if (ok and text != ''): newname = ospathjoin(ospathdirname(itempath),str(text)) try: print newname osrename(itempath,newname) p = item.parent() p.removeChild(item) #self.refreshAllProjects() except: QMessageBox.about(self,"Error","Could Not Rename The File")
def renameProject(self,item): itempath = item.getPath() text,ok = QInputDialog.getText(self,"QInputDialog::getText()","New Name:") if (ok and text != ''): newname = ospathjoin(ospathdirname(itempath)) try: print itempath print newname #osrename(itempath,newname) #self.takeTopLevelItem(self.indexOfTopLevelItem(item)) #self.addProject(newname) except: QMessageBox.about(self,"Error","Could Not Rename The File")