def run(self): while 1: if not self.exec_(): return False try: if self.ui.starttime.dateTime() >= self.ui.endtime.dateTime(): QMessageBox.critical(self, self.tr('Range error'), self.tr('Start time is superior to end time'), QMessageBox.Ok) if self.parent != None: start = QDateTime.fromTime_t( \ self.ui.starttime.dateTime().toTime_t() - self.parent.interval.delta() \ ) end = QDateTime.fromTime_t( \ self.ui.endtime.dateTime().toTime_t() - self.parent.interval.delta() \ ) self.parent.interval = Interval('custom', start, end) self.parent.interval.setLastStartTime(self.ui.starttime.dateTime().toTime_t()) self.parent.interval.setLastEndClient(self.ui.endtime.dateTime().toTime_t()) return True except CheckError, e: QMessageBox.critical(self, self.tr("Invalid argument"), unicode(e), QMessageBox.Ok)
def set(self, tpl): self.idLabel.setText(str(tpl[0])) self.beginEdit.setDateTime(QDateTime.fromTime_t(tpl[1])) self.endEdit.setDateTime(QDateTime.fromTime_t(tpl[2])) self.timeDiff.setText( self.mkDiff( tpl[1], tpl[2] ) ) self.descriptionEdit.setText(str(tpl[3])) self.noteEdit.setText(str(tpl[4]))
def create_last_modified_item(last_modified): item = QStandardItem( QDateTime.fromTime_t(last_modified).toString( 'yyyy-MM-dd HH:mm:ss')) item.setData(last_modified, USER_ROLE_LAST_MODIFIED) return item
def updateHistory(self): lines = [] for line in self.lines: text = Qt.escape(line.text) target = Qt.escape(line.target) if line.type == Line.Chat or line.type == Line.Whisper: (r, g, b) = [int(c * 0.75) for c in line.playerColor] sender = Qt.escape(line.sender) dateTime = QDateTime.fromTime_t(int(line.timestamp)) time = dateTime.toString("hh:mm:ss AP") if line.type == Line.Whisper: lines.append("<p><strong style=\"color: rgb(%d, %d, %d)\">[%s] %s >> %s</strong>: %s</p>" % (r, g, b, time, sender, target, text)) else: lines.append("<p><strong style=\"color: rgb(%d, %d, %d)\">[%s] %s</strong>: %s</p>" % (r, g, b, time, sender, text)) else: if line.type == Line.Info: (r, g, b) = (0, 0, 170) text = line.text elif line.type == Line.PlayerJoined: (r, g, b) = (0, 170, 0) text = "%s has joined." % (target) elif line.type == Line.PlayerRejoined: (r, g, b) = (0, 170, 0) text = "%s has rejoined." % (target) elif line.type == Line.PlayerLeft: (r, g, b) = (170, 0, 0) text = "%s has left." % (target) lines.append("<p style=\"color: rgb(%d, %d, %d)\">** %s **</p>" % (r, g, b, text)) self.history.setHtml( "<html><body>%s</body></html>" % ("".join(lines)) ) self.history.verticalScrollBar().setValue(self.history.verticalScrollBar().maximum())
def dateFromTime_t(seconds): """ Module function to return the date. @param seconds time in seconds since epoch to be formatted (float or long) @return date (QDate) """ return QDateTime.fromTime_t(long(seconds)).toTimeSpec(Qt.LocalTime).date()
def dateTimeAt(self, point): """ Returns the date time at the inputed point. :param point | <QPoint> """ for dtime, data in self._dateTimeGrid.items(): if (data[1].contains(point)): return QDateTime.fromTime_t(dtime) return QDateTime()
def dateTimeAt( self, point ): """ Returns the date time at the inputed point. :param point | <QPoint> """ for dtime, data in self._dateTimeGrid.items(): if ( data[1].contains(point) ): return QDateTime.fromTime_t(dtime) return QDateTime()
def formatTime(seconds): """ Module function to return a formatted time string. @param seconds time in seconds since epoch to be formatted (float or long) @return formatted time string (QString) """ return QDateTime.fromTime_t(long(seconds))\ .toTimeSpec(Qt.LocalTime)\ .toString("yyyy-MM-dd hh:mm:ss")
def data(self, index, role): if not index.isValid(): return QVariant() ms = self.mapper.getMergeScanForId(index.internalId()) if ms is None: logger.critical( "data: wasn't able to get the FileSystemMerge for internal id {0}" .format(index.internalId())) return QVariant() if role == Qt.CheckStateRole and index.column( ) == MergeScanTreeModel.COL_CHECKED: return ms.checked if role == Qt.DecorationRole and index.column( ) == MergeScanTreeModel.COL_ICON: return self.IconProvider.icon( QFileIconProvider.Folder) if ms.is_dir else None if role == Qt.TextColorRole: if ms.flags == PersistentScanningState.ITEM_DELETED: return QColor(Qt.red) return QVariant() if role == Qt.FontRole: font = QFont() info = PathInfo(ms.abs_path, ms.path_info) if info.is_symlink or ms.flags == PersistentScanningState.ITEM_UNREADABLE: font.setItalic(True) return font if role == Qt.DisplayRole: data = None if index.column() == MergeScanTreeModel.COL_NAME: data = os.path.basename(ms.abs_path) if "Sample" in data: x = 0 elif index.column() == MergeScanTreeModel.COL_CHANGE_TYPE: if ms.flags == PersistentScanningState.ITEM_ADDED: data = "Added" elif ms.flags == PersistentScanningState.ITEM_DELETED: data = "Deleted" elif ms.flags == PersistentScanningState.ITEM_MODIFIED: data = "Modified" elif ms.flags == PersistentScanningState.ITEM_UNCHANGED: data = "" elif index.column() == MergeScanTreeModel.COL_SIZE: data = PathInfo( ms.abs_path, ms.path_info ).size_human_readable if not ms.is_dir else None elif index.column() == MergeScanTreeModel.COL_DATE_MODIFIED: value = QDateTime.fromTime_t( int(PathInfo(ms.abs_path, ms.path_info).modified_date)) data = value.toString() elif index.column() == MergeScanTreeModel.COL_PERMISSIONS: info = PathInfo(ms.abs_path, ms.path_info) data = "{0}:{1} {2}".format(info.uid, info.gid, info.posix_perms_human_readable) return data return QVariant()
def get_cookie(line): fields = map(str.strip, line.split("\t")) if len(fields) != 7: return domain, domain_flag, path, is_secure, expiration, name, value = fields cookie = QNetworkCookie(name, value) cookie.setDomain(domain) cookie.setPath(path) cookie.setSecure(str2bool(is_secure)) cookie.setExpirationDate(QDateTime.fromTime_t(int(expiration))) return cookie
def data(self, index, role): if not index.isValid(): return QVariant() ms = self.mapper.getMergeScanForId(index.internalId()) if ms is None: logger.critical("data: wasn't able to get the FileSystemMerge for internal id {0}".format(index.internalId())) return QVariant() if role == Qt.CheckStateRole and index.column() == MergeScanTreeModel.COL_CHECKED: return ms.checked if role == Qt.DecorationRole and index.column() == MergeScanTreeModel.COL_ICON: return self.IconProvider.icon(QFileIconProvider.Folder) if ms.is_dir else None if role == Qt.TextColorRole: if ms.flags == PersistentScanningState.ITEM_DELETED: return QColor(Qt.red) return QVariant() if role == Qt.FontRole: font = QFont() info = PathInfo(ms.abs_path, ms.path_info) if info.is_symlink or ms.flags == PersistentScanningState.ITEM_UNREADABLE: font.setItalic(True) return font if role == Qt.DisplayRole: data = None if index.column() == MergeScanTreeModel.COL_NAME: data = os.path.basename(ms.abs_path) if "Sample" in data: x = 0 elif index.column() == MergeScanTreeModel.COL_CHANGE_TYPE: if ms.flags == PersistentScanningState.ITEM_ADDED: data = "Added" elif ms.flags == PersistentScanningState.ITEM_DELETED: data = "Deleted" elif ms.flags == PersistentScanningState.ITEM_MODIFIED: data = "Modified" elif ms.flags == PersistentScanningState.ITEM_UNCHANGED: data = "" elif index.column() == MergeScanTreeModel.COL_SIZE: data = PathInfo(ms.abs_path, ms.path_info).size_human_readable if not ms.is_dir else None elif index.column() == MergeScanTreeModel.COL_DATE_MODIFIED: value = QDateTime.fromTime_t(int(PathInfo(ms.abs_path, ms.path_info).modified_date)) data = value.toString() elif index.column() == MergeScanTreeModel.COL_PERMISSIONS: info = PathInfo(ms.abs_path, ms.path_info) data = "{0}:{1} {2}".format(info.uid, info.gid, info.posix_perms_human_readable) return data return QVariant()
def load(self): try: ds = pickle.load(open(self.m_cookiesFile, 'rb')) except: ds = [] qs = [] t = int(time.time()) for d in ds: if d['expirationDate'] > t and not d['isSessionCookie']: c = QNetworkCookie(d['name'],d['value']) c.setDomain(d['domain']) c.setExpirationDate(QDateTime.fromTime_t(d['expirationDate'])) c.setHttpOnly(d['isHttpOnly']) c.setSecure(d['isSecure']) c.setPath(d['path']) qs.append(c) #for c in cs self.setAllCookies(qs)
def convert_QDateTime(t): return QDateTime.fromTime_t(int(t))
def cb_program_logs_list(result): okay, message = check_script_result(result, decode_stderr=True) if not okay: self.label_error.setText('<b>Error:</b> ' + Qt.escape(message)) self.label_error.setVisible(True) self.refresh_logs_done() return try: # FIXME: do decompress in an async_call program_logs_list = json.loads(zlib.decompress(buffer(result.stdout)).decode('utf-8')) except: program_logs_list = None if program_logs_list == None or not isinstance(program_logs_list, dict): self.label_error.setText('<b>Error:</b> Received invalid data') self.label_error.setVisible(True) self.refresh_logs_done() return self.label_error.setVisible(False) def create_file_size_item(size): item = QStandardItem(get_file_display_size(size)) item.setData(size, USER_ROLE_SIZE) return item def update_file_size_item(item, additional_size): current_size = item.data(USER_ROLE_SIZE) new_size = current_size + additional_size item.setText(get_file_display_size(new_size)) item.setData(new_size, USER_ROLE_SIZE) continuous_row = None date_rows = {} time_rows = {} for file_name, file_size in program_logs_list.iteritems(): QApplication.processEvents() file_name_parts = file_name.split('_') if file_name_parts[0] == "continuous": if len(file_name_parts) != 2: continue if continuous_row == None: continuous_item = QStandardItem("Continuous") continuous_item.setData(ITEM_TYPE_PARENT_CONT, USER_ROLE_ITEM_TYPE) continuous_row = [continuous_item, create_file_size_item(0)] self.tree_logs_model.appendRow(continuous_row) log_item = QStandardItem(file_name_parts[1]) log_item.setData(self.file_icon, Qt.DecorationRole) log_item.setData(file_name, USER_ROLE_FILE_NAME) log_item.setData(ITEM_TYPE_LOG_FILE_CONT, USER_ROLE_ITEM_TYPE) continuous_row[0].appendRow([log_item, create_file_size_item(file_size)]) update_file_size_item(continuous_row[1], file_size) else: if len(file_name_parts) != 3: continue try: timestamp = int(file_name_parts[1].split('+')[0]) / 1000000 except ValueError: continue date = QDateTime.fromTime_t(timestamp).toString('yyyy-MM-dd') time = QDateTime.fromTime_t(timestamp).toString('HH:mm:ss') date_time = date + 'T' + time if date in date_rows: date_row = date_rows[date] else: date_item = QStandardItem(date) date_item.setData(ITEM_TYPE_PARENT_DATE, USER_ROLE_ITEM_TYPE) date_row = [date_item, create_file_size_item(0)] date_rows[date] = date_row self.tree_logs_model.appendRow(date_row) if date_time in time_rows: time_row = time_rows[date_time] else: time_item = QStandardItem(time) time_item.setData(ITEM_TYPE_PARENT_TIME, USER_ROLE_ITEM_TYPE) time_row = [time_item, create_file_size_item(0)] time_rows[date_time] = time_row date_row[0].appendRow(time_row) log_item = QStandardItem(file_name_parts[2]) log_item.setData(self.file_icon, Qt.DecorationRole) log_item.setData(file_name, USER_ROLE_FILE_NAME) log_item.setData(ITEM_TYPE_LOG_FILE, USER_ROLE_ITEM_TYPE) time_row[0].appendRow([log_item, create_file_size_item(file_size)]) update_file_size_item(time_row[1], file_size) update_file_size_item(date_row[1], file_size) self.tree_logs.header().setSortIndicator(0, Qt.DescendingOrder) self.refresh_logs_done()
def create_last_modified_item(last_modified): item = QStandardItem(QDateTime.fromTime_t(last_modified).toString('yyyy-MM-dd HH:mm:ss')) item.setData(last_modified, USER_ROLE_LAST_MODIFIED) return item
def export_archive(self): timestamp = QDateTime.fromTime_t(int(time.time())).toString('yyyyMMdd-HHmmss') target_path = os.path.join(self.last_directory, 'red-brick-export-{0}.tfrba'.format(timestamp)) target_path = get_save_file_name(get_main_window(), 'Save Archive', target_path, '*.tfrba') if len(target_path) == 0: return self.last_directory = os.path.split(target_path)[0] script_instance_ref = [None] def progress_canceled(): script_instance = script_instance_ref[0] if script_instance != None: self.script_manager.abort_script(script_instance) chunked_downloader = self.chunked_downloader if chunked_downloader != None: chunked_downloader.canceled = True self.progress = ExpandingProgressDialog(self) self.progress.set_progress_text_visible(False) self.progress.setModal(True) self.progress.setWindowTitle('Export Archive') self.progress.setLabelText('Step 1 of 2: Archiving selected programs') self.progress.setRange(0, 0) self.progress.setAutoClose(False) self.progress.canceled.connect(progress_canceled) self.progress.show() selected_identifiers = [] for selected_item in self.tree_programs.selectedItems(): selected_identifiers.append(selected_item.text(1)) def cb_export(result): script_instance = script_instance_ref[0] if script_instance != None: aborted = script_instance.abort else: aborted = False script_instance_ref[0] = None if aborted: return if not report_script_result(result, 'Export Error', 'Could not archive selected programs', before_message_box=self.progress.close): return # step 2/2: download created archive source_path = posixpath.join(result.stdout.strip(), 'archive.tfrba') self.chunked_downloader = ChunkedDownloader(self) if not self.chunked_downloader.prepare(source_path): return self.progress.setLabelText('Step 2 of 2: Downloading archive') self.progress.set_progress_text_visible(True) self.chunked_downloader.start(target_path) # step 1/2: run export script to create archive script_instance_ref[0] = self.script_manager.execute_script('export', cb_export, selected_identifiers)
def cb_program_logs_list(result): okay, message = check_script_result(result, decode_stderr=True) if not okay: self.label_error.setText('<b>Error:</b> ' + Qt.escape(message)) self.label_error.setVisible(True) self.refresh_logs_done() return try: # FIXME: do decompress in an async_call program_logs_list = json.loads( zlib.decompress(buffer(result.stdout)).decode('utf-8')) except: program_logs_list = None if program_logs_list == None or not isinstance( program_logs_list, dict): self.label_error.setText('<b>Error:</b> Received invalid data') self.label_error.setVisible(True) self.refresh_logs_done() return self.label_error.setVisible(False) def create_file_size_item(size): item = QStandardItem(get_file_display_size(size)) item.setData(size, USER_ROLE_SIZE) return item def update_file_size_item(item, additional_size): current_size = item.data(USER_ROLE_SIZE) new_size = current_size + additional_size item.setText(get_file_display_size(new_size)) item.setData(new_size, USER_ROLE_SIZE) continuous_row = None date_rows = {} time_rows = {} for file_name, file_size in program_logs_list.iteritems(): QApplication.processEvents() file_name_parts = file_name.split('_') if file_name_parts[0] == "continuous": if len(file_name_parts) != 2: continue if continuous_row == None: continuous_item = QStandardItem("Continuous") continuous_item.setData(ITEM_TYPE_PARENT_CONT, USER_ROLE_ITEM_TYPE) continuous_row = [ continuous_item, create_file_size_item(0) ] self.tree_logs_model.appendRow(continuous_row) log_item = QStandardItem(file_name_parts[1]) log_item.setData(self.file_icon, Qt.DecorationRole) log_item.setData(file_name, USER_ROLE_FILE_NAME) log_item.setData(ITEM_TYPE_LOG_FILE_CONT, USER_ROLE_ITEM_TYPE) continuous_row[0].appendRow( [log_item, create_file_size_item(file_size)]) update_file_size_item(continuous_row[1], file_size) else: if len(file_name_parts) != 3: continue try: timestamp = int( file_name_parts[1].split('+')[0]) / 1000000 except ValueError: continue date = QDateTime.fromTime_t(timestamp).toString( 'yyyy-MM-dd') time = QDateTime.fromTime_t(timestamp).toString('HH:mm:ss') date_time = date + 'T' + time if date in date_rows: date_row = date_rows[date] else: date_item = QStandardItem(date) date_item.setData(ITEM_TYPE_PARENT_DATE, USER_ROLE_ITEM_TYPE) date_row = [date_item, create_file_size_item(0)] date_rows[date] = date_row self.tree_logs_model.appendRow(date_row) if date_time in time_rows: time_row = time_rows[date_time] else: time_item = QStandardItem(time) time_item.setData(ITEM_TYPE_PARENT_TIME, USER_ROLE_ITEM_TYPE) time_row = [time_item, create_file_size_item(0)] time_rows[date_time] = time_row date_row[0].appendRow(time_row) log_item = QStandardItem(file_name_parts[2]) log_item.setData(self.file_icon, Qt.DecorationRole) log_item.setData(file_name, USER_ROLE_FILE_NAME) log_item.setData(ITEM_TYPE_LOG_FILE, USER_ROLE_ITEM_TYPE) time_row[0].appendRow( [log_item, create_file_size_item(file_size)]) update_file_size_item(time_row[1], file_size) update_file_size_item(date_row[1], file_size) self.tree_logs.header().setSortIndicator(0, Qt.DescendingOrder) self.refresh_logs_done()
def export_archive(self): timestamp = QDateTime.fromTime_t(int( time.time())).toString('yyyyMMdd-HHmmss') target_path = os.path.join( self.last_directory, 'red-brick-export-{0}.tfrba'.format(timestamp)) target_path = get_save_file_name(get_main_window(), 'Save Archive', target_path, '*.tfrba') if len(target_path) == 0: return self.last_directory = os.path.split(target_path)[0] script_instance_ref = [None] def progress_canceled(): script_instance = script_instance_ref[0] if script_instance != None: self.script_manager.abort_script(script_instance) chunked_downloader = self.chunked_downloader if chunked_downloader != None: chunked_downloader.canceled = True self.progress = ExpandingProgressDialog(self) self.progress.set_progress_text_visible(False) self.progress.setModal(True) self.progress.setWindowTitle('Export Archive') self.progress.setLabelText('Step 1 of 2: Archiving selected programs') self.progress.setRange(0, 0) self.progress.setAutoClose(False) self.progress.canceled.connect(progress_canceled) self.progress.show() selected_identifiers = [] for selected_item in self.tree_programs.selectedItems(): selected_identifiers.append(selected_item.text(1)) def cb_export(result): script_instance = script_instance_ref[0] if script_instance != None: aborted = script_instance.abort else: aborted = False script_instance_ref[0] = None if aborted: return if not report_script_result( result, 'Export Error', 'Could not archive selected programs', before_message_box=self.progress.close): return # step 2/2: download created archive source_path = posixpath.join(result.stdout.strip(), 'archive.tfrba') self.chunked_downloader = ChunkedDownloader(self) if not self.chunked_downloader.prepare(source_path): return self.progress.setLabelText('Step 2 of 2: Downloading archive') self.progress.set_progress_text_visible(True) self.chunked_downloader.start(target_path) # step 1/2: run export script to create archive script_instance_ref[0] = self.script_manager.execute_script( 'export', cb_export, selected_identifiers)
def timestamp_to_date_at_time(timestamp): date = QDateTime.fromTime_t(timestamp).toString('yyyy-MM-dd') time = QDateTime.fromTime_t(timestamp).toString('HH:mm:ss') return date + ' at ' + time