def commit(self): ''' :description stroe pulish information to database ''' source = os.path.join(self.directory, self.type, self.tag) db = database.Connect(table=self.type) if self.isExists(): result = self.removeOriginData(self.tag) if not result: return False, 'Not able to remove <%s>' % self.tag result, message = db.overwrite(tag=self.tag, manifest=source) else: result, message = db.insert(tag=self.tag, manifest=source) return result, message
def load_data(self, combobox, treewidget, *args): treewidget.clear() table = str(combobox.itemText(args[0])) if not table or table == 'None': return db = database.Connect(table=table) columns = db.get_columns() if not columns: return treewidget.clear() for index, each in enumerate(columns): treewidget.headerItem().setText(index, each) treewidget.header().resizeSection(index, 250) treewidget.header().resizeSection(0, 100) treewidget.header().resizeSection(1, 200) treewidget.header().resizeSection(2, 200) treewidget.header().resizeSection(3, 300) contents = db.select() for content in contents: item = QtGui.QTreeWidgetItem(treewidget) for index, each in enumerate(content): item.setText(index, str(each))
def remove(self): replay = QtGui.QMessageBox.question( self, 'Question', 'Are you sure\nWant to reomve?...', QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) if replay == QtGui.QMessageBox.No: logging.warning('abort!...') return table = str(self.combobox_input.currentText()) if not table or table == 'None': QtGui.QMessageBox.warning( self, 'Warning', 'Select the any one in the table and try!...', QtGui.QMessageBox.Ok) return if not self.treewidget.selectedItems(): QtGui.QMessageBox.warning( self, 'Warning', 'Select the any one in the items and try!...', QtGui.QMessageBox.Ok) return select_items = self.treewidget.selectedItems() result = True for item in select_items: id = str(item.text(0)) tag = str(item.text(1)) db = database.Connect(table=table) try: db.delete(id, tag) result = True except Exception as error: QtGui.QMessageBox.warning(self, 'Warning', str(error), QtGui.QMessageBox.Ok) result = False if result: logging.info('Remove success!...') else: logging.warning('Remove failed!...') self.reload()
def getDatas(self): db = database.Connect(table=self.type) data = db.select() return data
def getTables(self): db = database.Connect(table=self.type) tags = db.get_columns() return tags
def getTypes(self): db = database.Connect() tables = db.get_tables() return tables
def modify_ui(self): db = database.Connect() tables = db.get_tables() tables = ['None'] + tables self.combobox_input.addItems(tables)