def __init__(self, parent): # DEFINE INSTANCE VARS #self.URI = 'URI:DIR2:muyiptb3avposlswpk7dwd6i6m:al2ypupmygotdo73undrq2az4dqjkh3bkcfelj5nmhtcffhoakvq' # GRABBING ROOT ALIAS AND URI #self.alias, self.URI = Get_Aliases()[0] super(FileBrowser, self).__init__() self.username = '' self.password = '' self.loginDialog = LoginDialog(self) results = self.loginDialog.exec_() print "RESULTS: " + str(results) print "USERNAME: "******"PASSWORD: "******"~") + "/.tahoe/private/aliases") as f: content = f.readline() while content == "\n": content = f.readline() self.alias, self.URI = content.rstrip().split(' ') self.localdir = os.path.expanduser("~") self.remotedir = '' self.remoteFileTree = Tree('', self.URI) self.initKey() self.initUI()
def updateFileTree(self): self.remoteFileTree = Tree('', self.URI) files = getSubTree(self.URI) self.URIMap = {} #for ent in files: for ent in files: self.remoteFileTree.insert(ent) self.URIMap[ent[0]] = ent[1]
class FileBrowser(QtGui.QWidget): def __init__(self, parent): # DEFINE INSTANCE VARS #self.URI = 'URI:DIR2:muyiptb3avposlswpk7dwd6i6m:al2ypupmygotdo73undrq2az4dqjkh3bkcfelj5nmhtcffhoakvq' # GRABBING ROOT ALIAS AND URI #self.alias, self.URI = Get_Aliases()[0] super(FileBrowser, self).__init__() self.username = '' self.password = '' self.loginDialog = LoginDialog(self) results = self.loginDialog.exec_() print "RESULTS: " + str(results) print "USERNAME: "******"PASSWORD: "******"~") + "/.tahoe/private/aliases") as f: content = f.readline() while content == "\n": content = f.readline() self.alias, self.URI = content.rstrip().split(' ') self.localdir = os.path.expanduser("~") self.remotedir = '' self.remoteFileTree = Tree('', self.URI) self.initKey() self.initUI() #print "ALIASES: " #for al in self.aliases: # print al def initKey(self): retVal = "" if (Get(self.URI + "/keyfile", "keyfile")): #if os.path.isfile("keyfile"): self.cryptHandle = CryptHandler("keyfile", self.username, self.password, True) else: print "Failed to download remote keyfile, creating new one" open("keyfile", "w").close() self.cryptHandle = CryptHandler("keyfile", self.username, self.password, False) #self.cryptHandle.encryptKeyFile() path = self.cryptHandle.encryptKeyFile() retVal = Upload(path, str(self.URI + "/keyfile")) if (retVal != ''): print "Upload sucessful, retVal=" + str(retVal) else: print "Upload failed, retVal=" + str(retVal) def initUI(self): hbox = QtGui.QVBoxLayout(self) self.localList = LocalList(self) self.remoteList = RemoteList(self) #QtGui.QListWidget(self) splitter = QtGui.QSplitter(QtCore.Qt.Horizontal) splitter.addWidget(self.localList) splitter.addWidget(self.remoteList) self.dlBtn = QtGui.QPushButton("Download", self) self.dlBtn.clicked.connect(self.download) self.dlBtn.setMaximumWidth(100) self.mkDirBtn = QtGui.QPushButton("Make Dir", self) self.mkDirBtn.clicked.connect(self.makeRemoteDir) self.mkDirBtn.setMaximumWidth(100) self.rmBtn = QtGui.QPushButton("Remove Dir/File", self) self.rmBtn.clicked.connect(self.removeRemDirFile) self.rmBtn.setMaximumWidth(130) self.ulBtn = QtGui.QPushButton("Upload", self) self.ulBtn.clicked.connect(self.upload) self.locMkDirBtn = QtGui.QPushButton("MakeDir", self) self.locMkDirBtn.clicked.connect(self.makeLocalDir) self.locRmBtn = QtGui.QPushButton("Remove Dir/File") self.locRmBtn.clicked.connect(self.removeLocDirFile) hspacer = QtGui.QHBoxLayout() hspacer.addWidget(self.ulBtn) hspacer.addWidget(self.locMkDirBtn) hspacer.addWidget(self.locRmBtn) hspacer.addStretch(1) hspacer.addWidget(self.dlBtn) hspacer.addWidget(self.mkDirBtn) hspacer.addWidget(self.rmBtn) hbox.addLayout(hspacer) hbox.addWidget(splitter) self.setLayout(hbox) QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks')) # SIGNALS/SLOTS self.localList.itemDoubleClicked.connect(self.changeLocalDir) self.remoteList.itemDoubleClicked.connect(self.changeRemoteDir) self.updateFileTree() self.repopulateList(self.localList) self.repopulateList(self.remoteList) def updateFileTree(self): self.remoteFileTree = Tree('', self.URI) files = getSubTree(self.URI) self.URIMap = {} #for ent in files: for ent in files: self.remoteFileTree.insert(ent) self.URIMap[ent[0]] = ent[1] def uploadDialog(self): fname = QtGui.QFileDialog.getOpenFileName(self, 'Upload file', '/home') if fname == "": return localPath = fname saveFileAs = fname.split("/")[-1] savePath = self.remotedir if self.remotedir: savePath = savePath + "/" savePath = savePath + saveFileAs print "YO WE'RE UPLOADING!!" print str(localPath), str(self.URI + "/" + savePath) #### #encrypt file pathEnc = self.cryptHandle.Encrypt(str(localPath), "AES") retVal = Upload(pathEnc, str(self.URI + "/" + savePath)) if retVal != '': print "Upload successful, retVal=" + str(retVal) kfPath = self.cryptHandle.UpdateAndEncryptKeyFile( retVal, str(localPath)) # reUpload the keyfile Upload(kfPath, self.URI + "/keyfile") self.updateFileTree() self.repopulateList(self.remoteList) else: print "Upload failed, retVal=" + str(retVal) #### #retVal = Upload(str(localPath), str(self.URI + "/" + savePath)) #if (retVal != ''): # print "Upload sucessful, retVal=" + str(retVal) # #self.remoteFileTree.insert(ent) # self.updateFileTree() # self.repopulateList(self.remoteList) #else: # print "Upload failed, retVal=" + str(retVal) def removeLocDirFile(self): if not self.localList.selectedItems(): print "NOTHING IS SELECTED" return name = str(self.localList.selectedItems()[0].text()) if name == "..": print "CANNOT REMOVE A DIRECTORY YOU ARE CURRENTLY IN!" return name = self.localdir + "/" + name if name[1] == "/": name = name[1:] if os.path.isfile(name): os.remove(name) print name elif os.path.isdir(name): shutil.rmtree(name) print name else: print "ERROR: Selected value is neither file nor directory?" return self.repopulateList(self.localList) def makeLocalDir(self): dirName, ok = QtGui.QInputDialog.getText(self, "New Local Directory", "Enter directory name") if ok: dirPath = str(self.localdir + "/" + dirName) if dirPath[1] == "/": dirPath = dirPath[1:] if not os.path.exists(dirPath): try: os.mkdir(dirPath) except OSError, e: print "FAILED TO MAKE DIRECTORY: " + dirPath print str(e) return self.repopulateList(self.localList) print "SUCCESS" else: print "Directory already exists" else:
class FileBrowser(QtGui.QWidget): def __init__(self, parent): # DEFINE INSTANCE VARS #self.URI = 'URI:DIR2:muyiptb3avposlswpk7dwd6i6m:al2ypupmygotdo73undrq2az4dqjkh3bkcfelj5nmhtcffhoakvq' # GRABBING ROOT ALIAS AND URI #self.alias, self.URI = Get_Aliases()[0] super(FileBrowser, self).__init__() self.username = '' self.password = '' self.loginDialog = LoginDialog(self) results = self.loginDialog.exec_() print "RESULTS: " + str(results) print "USERNAME: "******"PASSWORD: "******"~") + "/.tahoe/private/aliases") as f: content = f.readline() while content == "\n": content = f.readline() self.alias, self.URI = content.rstrip().split(' ') self.localdir = os.path.expanduser("~") self.remotedir = '' self.remoteFileTree = Tree('', self.URI) self.initKey() self.initUI() #print "ALIASES: " #for al in self.aliases: # print al def initKey(self): retVal = "" if (Get(self.URI + "/keyfile", "keyfile")): #if os.path.isfile("keyfile"): self.cryptHandle = CryptHandler("keyfile", self.username, self.password, True) else: print "Failed to download remote keyfile, creating new one" open("keyfile", "w").close() self.cryptHandle = CryptHandler("keyfile", self.username, self.password, False) #self.cryptHandle.encryptKeyFile() path = self.cryptHandle.encryptKeyFile() retVal = Upload(path, str(self.URI + "/keyfile")) if (retVal != ''): print "Upload sucessful, retVal=" + str(retVal) else: print "Upload failed, retVal=" + str(retVal) def initUI(self): hbox = QtGui.QVBoxLayout(self) self.localList = LocalList(self) self.remoteList = RemoteList(self)#QtGui.QListWidget(self) splitter = QtGui.QSplitter(QtCore.Qt.Horizontal) splitter.addWidget(self.localList) splitter.addWidget(self.remoteList) self.dlBtn = QtGui.QPushButton("Download", self) self.dlBtn.clicked.connect(self.download) self.dlBtn.setMaximumWidth(100) self.mkDirBtn = QtGui.QPushButton("Make Dir", self) self.mkDirBtn.clicked.connect(self.makeRemoteDir) self.mkDirBtn.setMaximumWidth(100) self.rmBtn = QtGui.QPushButton("Remove Dir/File", self) self.rmBtn.clicked.connect(self.removeRemDirFile) self.rmBtn.setMaximumWidth(130) self.ulBtn = QtGui.QPushButton("Upload", self) self.ulBtn.clicked.connect(self.upload) self.locMkDirBtn = QtGui.QPushButton("MakeDir", self) self.locMkDirBtn.clicked.connect(self.makeLocalDir) self.locRmBtn = QtGui.QPushButton("Remove Dir/File") self.locRmBtn.clicked.connect(self.removeLocDirFile) hspacer = QtGui.QHBoxLayout() hspacer.addWidget(self.ulBtn) hspacer.addWidget(self.locMkDirBtn) hspacer.addWidget(self.locRmBtn) hspacer.addStretch(1) hspacer.addWidget(self.dlBtn) hspacer.addWidget(self.mkDirBtn) hspacer.addWidget(self.rmBtn) hbox.addLayout(hspacer) hbox.addWidget(splitter) self.setLayout(hbox) QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks')) # SIGNALS/SLOTS self.localList.itemDoubleClicked.connect(self.changeLocalDir) self.remoteList.itemDoubleClicked.connect(self.changeRemoteDir) self.updateFileTree() self.repopulateList(self.localList) self.repopulateList(self.remoteList) def updateFileTree(self): self.remoteFileTree = Tree('', self.URI) files = getSubTree(self.URI) self.URIMap = {} #for ent in files: for ent in files: self.remoteFileTree.insert(ent) self.URIMap[ent[0]] = ent[1] def uploadDialog(self): fname = QtGui.QFileDialog.getOpenFileName(self, 'Upload file', '/home') if fname == "": return localPath = fname saveFileAs = fname.split("/")[-1] savePath = self.remotedir if self.remotedir: savePath = savePath + "/" savePath = savePath + saveFileAs print "YO WE'RE UPLOADING!!" print str(localPath), str(self.URI + "/" + savePath) #### #encrypt file pathEnc = self.cryptHandle.Encrypt(str(localPath), "AES") retVal = Upload(pathEnc, str(self.URI + "/" + savePath)) if retVal != '': print "Upload successful, retVal=" + str(retVal) kfPath = self.cryptHandle.UpdateAndEncryptKeyFile(retVal, str(localPath)) # reUpload the keyfile Upload(kfPath, self.URI + "/keyfile") self.updateFileTree() self.repopulateList(self.remoteList) else: print "Upload failed, retVal=" + str(retVal) #### #retVal = Upload(str(localPath), str(self.URI + "/" + savePath)) #if (retVal != ''): # print "Upload sucessful, retVal=" + str(retVal) # #self.remoteFileTree.insert(ent) # self.updateFileTree() # self.repopulateList(self.remoteList) #else: # print "Upload failed, retVal=" + str(retVal) def removeLocDirFile(self): if not self.localList.selectedItems(): print "NOTHING IS SELECTED" return name = str(self.localList.selectedItems()[0].text()) if name == "..": print "CANNOT REMOVE A DIRECTORY YOU ARE CURRENTLY IN!" return name = self.localdir + "/" + name if name[1] == "/": name = name[1:] if os.path.isfile(name): os.remove(name) print name elif os.path.isdir(name): shutil.rmtree(name) print name else: print "ERROR: Selected value is neither file nor directory?" return self.repopulateList(self.localList) def makeLocalDir(self): dirName, ok = QtGui.QInputDialog.getText(self, "New Local Directory", "Enter directory name") if ok: dirPath = str(self.localdir + "/" + dirName) if dirPath[1] == "/": dirPath = dirPath[1:] if not os.path.exists(dirPath): try: os.mkdir(dirPath) except OSError, e: print "FAILED TO MAKE DIRECTORY: " + dirPath print str(e) return self.repopulateList(self.localList) print "SUCCESS" else: print "Directory already exists" else: