def save_operate(self, widget=None): '''do save operate''' screenshot = self.screenshot if screenshot.is_subprocess: screenshot.save_to_tmp_file() else: # auto save if screenshot.save_op_index == SAVE_OP_AUTO: folder = utils.get_pictures_dir() filename = "%s%s.%s" % (_(DEFAULT_FILENAME), utils.get_format_time(), "png") screenshot.save_snapshot("%s/%s" % (folder, filename)) # save as elif screenshot.save_op_index == SAVE_OP_AS: self.save_to_file() # copy to clip elif screenshot.save_op_index == SAVE_OP_CLIP: screenshot.save_snapshot() # auto save and copy to clip else: folder = utils.get_pictures_dir() filename = "%s%s.%s" % (_(DEFAULT_FILENAME), utils.get_format_time(), "png") screenshot.save_snapshot("%s/%s" % (folder, filename), clip_flag=True)
def task_extract(self, job_body): ''' 任务处理,包括任务执行状态的记录,并从任务中提取出引擎要处理的数据, 调用handle_task处理任务,默认为任务中的task_list字段, 添加新的任务类型时,当需要对除task_list之外的其它任务信息进行处理时, 需要增加 if job_body['cmd'] == 'XX' 时的处理方法,并在self.error_func中 增加出错时对应任务的信息处理方法 ''' job_body = copy.copy(job_body) if 'task_list' not in job_body or job_body['task_list'] == []: raise Exception("task_list not found or equal None") if job_body['cmd'] == 'ENGINE_TEST': job_body['running_engine'].append(self.engine_type) run_state = { self.config_name + '_engine_type': self.engine_type, self.config_name + '_engine_id': self.engine_id, self.config_name + '_start_time': get_format_time() } # 添加任务开始时间,默认情况下,引擎开始执行任务前,会发送任务开始状态到结果队列 job_body['run_state'].append(run_state) if self.engine_type in job_body['waiting_engine']: job_body['waiting_engine'].remove(self.engine_type) self.write_result(job_body) # 写回任务到结果队列,表明任务开始 job_body['task_list'] = self.handle_task(job_body['task_list']) job_body['run_win_engine'].append(self.engine_type) job_body['running_engine'].remove(self.engine_type) job_body['run_state'][-1][ self.config_name + '_over_time'] = get_format_time() # 添加任务完成时间 else: # 不更新任务状态信息,例如当'cmd'=='SINGLE_ENGINE_TEST'进行单独测试时 self.write_result(job_body) # 写回任务到结果队列,表明任务开始 job_body['task_list'] = self.handle_task(job_body['task_list']) return job_body
def __init__(self, mysql_config, table_name, engine_id, engine_type, queue_ip, queue_start_name, queue_result_name, update_interval=60): self.mysql_handle = MysqlHandleBase(mysql_config['host'], mysql_config['user'], mysql_config['password'], mysql_config['db']) self.table_name = table_name self.engine_type = engine_type self.update_interval = update_interval self.where_fields = {'engine_id': [engine_id, 's']} self.register_fields = { 'engine_id': [engine_id, 's'], 'ip': [getLocalIp(), 's'], 'engine_type': [engine_type, 's'], 'queue_ip': [queue_ip, 's'], 'queue_start_name': [queue_start_name, 's'], 'queue_result_name': [queue_result_name, 's'], 'status': [1, 's'], 'time': [get_format_time(), 's'] } self.update_fields = {}
def open_file_dialog(fullscreen=True, filetype='png'): ''' Save file to file. @param fullscreen: if get the fullscreen snapshot. @parser filetype: the filetype to save ''' pixbuf = get_screenshot_pixbuf(fullscreen) dialog = gtk.FileChooserDialog( "Save..", None, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT)) dialog.set_default_response(gtk.RESPONSE_ACCEPT) dialog.set_position(gtk.WIN_POS_CENTER) dialog.set_local_only(True) dialog.set_current_folder(get_pictures_dir()) dialog.set_current_name("%s%s.%s" % (_(DEFAULT_FILENAME), get_format_time(), "png")) response = dialog.run() if response == gtk.RESPONSE_ACCEPT: filename = dialog.get_filename() pixbuf.save(filename, save_filetype) print "Save snapshot to %s" % (filename) elif response == gtk.RESPONSE_REJECT: print 'Closed, no files selected' dialog.destroy()
def save_to_file(self): ''' save to file ''' self.win.hide_colorbar() self.win.hide_toolbar() #dialog = SaveFileDialog('', self.screenshot.window.window, #ok_callback=self._save_to_file_cb, cancel_callback=self._save_to_file_cancel) dialog = gtk.FileChooserDialog("Save..", self.win.window, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT)) dialog.set_action(gtk.FILE_CHOOSER_ACTION_SAVE) dialog.set_default_response(gtk.RESPONSE_ACCEPT) dialog.set_position(gtk.WIN_POS_MOUSE) dialog.set_local_only(True) last_folder = self.__config.get("save", "folder") if last_folder: dialog.set_current_folder(last_folder) else: dialog.set_current_folder(utils.get_pictures_dir()) dialog.set_current_name( "%s%s.%s" % (_(DEFAULT_FILENAME), utils.get_format_time(), "png")) response = dialog.run() filename = dialog.get_filename() if response == gtk.RESPONSE_ACCEPT: self.__config.set("save", folder=dialog.get_current_folder()) self._save_to_file_cb(filename) else: self._save_to_file_cancel(filename) dialog.destroy()
def open_file_dialog(fullscreen=True, filetype='png'): ''' Save file to file. @param fullscreen: if get the fullscreen snapshot. @parser filetype: the filetype to save ''' pixbuf = get_screenshot_pixbuf(fullscreen) dialog = gtk.FileChooserDialog("Save..", None, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT)) dialog.set_default_response(gtk.RESPONSE_ACCEPT) dialog.set_position(gtk.WIN_POS_CENTER) dialog.set_local_only(True) dialog.set_current_folder(get_pictures_dir()) dialog.set_current_name("%s%s.%s" % (_(DEFAULT_FILENAME), get_format_time(), "png")) response = dialog.run() if response == gtk.RESPONSE_ACCEPT: filename = dialog.get_filename() pixbuf.save(filename, save_filetype) print "Save snapshot to %s" % (filename) elif response == gtk.RESPONSE_REJECT: print 'Closed, no files selected' dialog.destroy()
def save_to_file(self): ''' save to file ''' self.win.hide_colorbar() self.win.hide_toolbar() #dialog = SaveFileDialog('', self.screenshot.window.window, #ok_callback=self._save_to_file_cb, cancel_callback=self._save_to_file_cancel) dialog = gtk.FileChooserDialog( "Save..", self.win.window, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT)) dialog.set_action(gtk.FILE_CHOOSER_ACTION_SAVE) dialog.set_default_response(gtk.RESPONSE_ACCEPT) dialog.set_position(gtk.WIN_POS_MOUSE) dialog.set_local_only(True) last_folder = self.__config.get("save", "folder") if last_folder: dialog.set_current_folder(last_folder) else: dialog.set_current_folder(utils.get_pictures_dir()) if config.OPTION_FILE: dialog.set_current_name(config.OPTION_FILE) else: dialog.set_current_name("%s%s.%s" % (_(DEFAULT_FILENAME), utils.get_format_time(), "png")) response = dialog.run() filename = dialog.get_filename() if response == gtk.RESPONSE_ACCEPT: self.__config.set("save", folder=dialog.get_current_folder()) self._save_to_file_cb(filename) else: self._save_to_file_cancel(filename) dialog.destroy()
def open_file_dialog(fullscreen=True, filetype='png'): ''' Save file to file. @param fullscreen: if get the fullscreen snapshot. @parser filetype: the filetype to save ''' from constant import SAVE_OP_AUTO, SAVE_OP_AUTO_AND_CLIP, SAVE_OP_AS from _share.config import OperateConfig config = OperateConfig() save_op = config.get("save", "save_op") if save_op: save_op_index = int(save_op) else: save_op_index = SAVE_OP_AS pixbuf = get_screenshot_pixbuf(fullscreen) if save_op_index == SAVE_OP_AUTO or save_op_index == SAVE_OP_AUTO_AND_CLIP: filename = "%s/%s%s.%s" % (get_pictures_dir(), _(DEFAULT_FILENAME), get_format_time(), "png") pixbuf.save(filename, save_filetype) msg = "%s '%s'" % (_("Picture has been saved to file"), filename) SCROT_BUS.emit_finish(1, filename) notify("Deepin Screenshot", 0, summary=_("DScreenshot"), body=msg) else: dialog = gtk.FileChooserDialog( "Save..", None, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT)) dialog.set_default_response(gtk.RESPONSE_ACCEPT) dialog.set_position(gtk.WIN_POS_CENTER) dialog.set_local_only(True) dialog.set_current_folder(get_pictures_dir()) dialog.set_current_name("%s%s.%s" % (_(DEFAULT_FILENAME), get_format_time(), "png")) response = dialog.run() if response == gtk.RESPONSE_ACCEPT: filename = dialog.get_filename() pixbuf.save(filename, save_filetype) msg = "%s '%s'" % (_("Picture has been saved to file"), filename) SCROT_BUS.emit_finish(1, filename) notify("Deepin Screenshot", 0, summary=_("DScreenshot"), body=msg) elif response == gtk.RESPONSE_REJECT: print 'Closed, no files selected' dialog.destroy()
def open_file_dialog(fullscreen=True, filetype='png'): ''' Save file to file. @param fullscreen: if get the fullscreen snapshot. @parser filetype: the filetype to save ''' from constant import SAVE_OP_AUTO, SAVE_OP_AUTO_AND_CLIP, SAVE_OP_AS from _share.config import OperateConfig config = OperateConfig() save_op = config.get("save", "save_op") if save_op: save_op_index = int(save_op) else: save_op_index = SAVE_OP_AS pixbuf = get_screenshot_pixbuf(fullscreen) if save_op_index == SAVE_OP_AUTO or save_op_index == SAVE_OP_AUTO_AND_CLIP: filename = "%s/%s%s.%s" % (get_pictures_dir(), _(DEFAULT_FILENAME), get_format_time(), "png") pixbuf.save(filename, save_filetype) msg = "%s '%s'" % (_("Picture has been saved to file"), filename) SCROT_BUS.emit_finish(1, filename) notify("Deepin Screenshot", 0, summary=_("DScreenshot"), body=msg) else: dialog = gtk.FileChooserDialog("Save..", None, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT)) dialog.set_default_response(gtk.RESPONSE_ACCEPT) dialog.set_position(gtk.WIN_POS_CENTER) dialog.set_local_only(True) dialog.set_current_folder(get_pictures_dir()) dialog.set_current_name( "%s%s.%s" % (_(DEFAULT_FILENAME), get_format_time(), "png")) response = dialog.run() if response == gtk.RESPONSE_ACCEPT: filename = dialog.get_filename() pixbuf.save(filename, save_filetype) msg = "%s '%s'" % (_("Picture has been saved to file"), filename) SCROT_BUS.emit_finish(1, filename) notify("Deepin Screenshot", 0, summary=_("DScreenshot"), body=msg) elif response == gtk.RESPONSE_REJECT: print 'Closed, no files selected' dialog.destroy()
def once_update_sever(self): ''' 执行线程工作,定时更新数据库,记录服务存活 ''' while True: self.update_fields = {} time.sleep(self.update_interval) self.reset_update_fields({'time': [get_format_time(), 's']}) self.mysql_handle.update(self.table_name, self.update_fields, self.where_fields)
def save_operate(self, widget=None): '''do save operate''' screenshot = self.screenshot #print "operate:", screenshot.save_op_index # auto save if screenshot.save_op_index == SAVE_OP_AUTO: folder = utils.get_pictures_dir() filename = "%s%s.%s" % (_(DEFAULT_FILENAME), utils.get_format_time(), "png") screenshot.save_snapshot("%s/%s" % (folder, filename)) # save as elif screenshot.save_op_index == SAVE_OP_AS: self.save_to_file() # copy to clip elif screenshot.save_op_index == SAVE_OP_CLIP: screenshot.save_snapshot() # auto save and copy to clip else: folder = utils.get_pictures_dir() filename = "%s%s.%s" % (_(DEFAULT_FILENAME), utils.get_format_time(), "png") screenshot.save_snapshot("%s/%s" % (folder, filename), clip_flag=True)
def create_url_list(mongo_handle_base, list_name='test', list_type='manual', usr_id=0, task_id=0): ''' 创建一个新的UrlList对象 输入:列表名称、类型、用户id、任务id 输出:UrlList对象,仅新创建记录,没有添加URL ''' url_list = UrlList(list_num=0) url_list.creat_time = get_format_time() url_list.update_time = get_format_time() url_list.list_name = list_name url_list.list_type = list_type url_list.usr_id = int(usr_id) url_list.task_id = int(task_id) url_list.use_count = 0 url_list.child_list = [] url_list.save() return url_list
def error_func(self, job_body): ''' 装饰器task_extract_deco中调用,当task_extract中出错时,执行的对应任务的 信息处理方法 ''' job_body = copy.copy(job_body) if job_body['cmd'] == 'ENGINE_TEST': job_body['run_error_engine'].append(self.engine_type) job_body['running_engine'].remove(self.engine_type) job_body['run_state'][-1][ self.config_name + '_over_time'] = get_format_time() # 添加任务完成时间 return job_body
def insert_task(mysql_handle_base, task_name='test', user_id=1, task_type=0, task_engine='', protected_id='', gray_id='', monitor_id='', counterfeit_id=''): ''' 创建任务 ''' fields = {'task_name': [task_name, 's'], 'user_id': [user_id, 'd'], 'task_type': [task_type, 'd'], 'task_engine': [task_engine, 's'], 'protected_id': [protected_id, 's'], 'gray_id': [gray_id, 's'], 'monitor_id': [monitor_id, 's'], 'counterfeit_id': [counterfeit_id, 's'], 'add_time': [get_format_time(), 's']} return mysql_handle_base.insert('task_info', fields, return_id=True)
def __deco(mysql_handle_base, urls, add_way='test'): @arg_exist(table_name) def hash_exist(mysql_handle_base, url): wheres = {'url_hash': [hash_md5(url), 's']} return wheres fields = [('url_hash', 's'), ('url', 's'), ('add_way', 's'), ('add_time', 's')] param = [] for url in urls: if hash_exist(mysql_handle_base, url) is not False: # 说明该URL已存在 continue param.append((hash_md5(url), url, add_way, get_format_time())) if param == []: return False param = tuple(param) return mysql_handle_base.batch_insert(table_name, fields, param)
def parse_articles(self, articles_list): all_articles = [] for articles in articles_list: article_timestamp = articles.get('comm_msg_info', {}).get('datetime') article_time = utils.get_format_time(article_timestamp) wechat_article = self.parse_article_common( articles.get('app_msg_ext_info')) if not wechat_article: self.log.warn('parse article error! %s' % wechat_article) continue wechat_article['publish_time'] = article_time all_articles.append(wechat_article) for art in articles.get('app_msg_ext_info', {}).get('multi_app_msg_item_list', []): wechat_article = self.parse_article_common(art) if not wechat_article: self.log.warn('parse article error! %s' % wechat_article) continue wechat_article['publish_time'] = article_time all_articles.append(wechat_article) return all_articles
def set_save_filetype(widget, filetype): global save_filetype widget.set_current_name("%s%s.%s" % (_(DEFAULT_FILENAME), get_format_time(), "png")) save_filetype =filetype
def set_save_filetype(widget, filetype): global save_filetype widget.set_current_name("%s%s.%s" % (_(DEFAULT_FILENAME), get_format_time(), "png")) save_filetype = filetype
def __deco(mysql_handle_base, url, timestamp_dir_path, file_list=[], update_sign=True): timestamp_abs_dir_clist = timestamp_dir_path.split('/') fields = { 'url_hash': [hash_md5(url), 's'], 'timestamp': [timestamp_abs_dir_clist[-1], 's'], 'url': [url, 's'], 'update_time': [get_format_time(), 's'], 'save_path': [ '/'.join(timestamp_abs_dir_clist[timestamp_abs_dir_clist. index('web_info') + 1:]), 's' ], 'url_file': [0, 'd'], 'main_html': [0, 'd'], 'normal_html_html': [0, 'd'], 'html': [0, 'd'], 'css': [0, 'd'], 'js': [0, 'd'], 'pic': [0, 'd'], 'text_json': [0, 'd'], 'block_json': [0, 'd'], 'border_json': [0, 'd'], 'block_html': [0, 'd'], 'cut_img': [0, 'd'], 'vips_imgs_txt': [0, 'd'], 'view_json': [0, 'd'], 'webpage_jpeg': [0, 'd'], 'blockpage_jpeg': [0, 'd'], 'other': ['', 's'] } for f in file_list: if f == 'images': # 第二版网页保存引擎中images目录下存储资源 resource_nums = count_resource_num(timestamp_dir_path) fields['js'][0] = resource_nums[0] fields['css'][0] = resource_nums[1] fields['pic'][0] = resource_nums[2] fields['html'][0] = resource_nums[3] elif f in fields: #对文件名和fields中一致的文件或目录进行添加, 第一版网页保存引擎中各资源存储在fields中对应名称的目录下 if os.path.isdir(pjoin(timestamp_dir_path, f)): f_num = len(os.listdir(pjoin(timestamp_dir_path, f))) fields[f][0] = f_num else: fields[f][0] = 1 elif f.replace('.', '_') in fields: # 对有后缀的文件进行添加 fields[f.replace('.', '_')][0] = 1 else: fields['other'][0] += (f + '/') wheres = { 'url_hash': fields['url_hash'], 'timestamp': fields['timestamp'] } if mysql_handle_base.select(table_name, ['*'], wheres): if update_sign: mysql_handle_base.update(table_name, fields, wheres) else: mysql_handle_base.insert(table_name, fields) return True