📄 umitconf.py
字号:
#!/usr/bin/env python# -*- coding: utf-8 -*-# Copyright (C) 2005 Insecure.Com LLC.## Author: Adriano Monteiro Marques <py.adriano@gmail.com>## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USAimport refrom types import StringTypesfrom ConfigParser import NoSectionError, NoOptionErrorfrom zenmapCore.Paths import Pathfrom zenmapCore.ScanProfileConf import scan_profile_filefrom zenmapCore.UmitLogging import logfrom zenmapCore.UmitConfigParser import UmitConfigParserfrom zenmapCore.I18N import _# Check if running on MaemoMAEMO = Falsetry: import hildon MAEMO = Trueexcept ImportError: passdef is_maemo(): return MAEMOclass UmitConf(object): def __init__(self): self.parser = Path.config_parser def save_changes(self): self.parser.save_changes() def get_colored_diff(self): try: cd = self.parser.get('diff', 'colored_diff') if cd == "False" or \ cd == "false" or \ cd == "0" or \ cd == "" or \ cd == False: return False return True except: return True def set_colored_diff(self, enable): if not self.parser.has_section('diff'): self.parser.add_section('diff') self.parser.set('diff', 'colored_diff', str(enable)) def get_diff_mode(self): try: return self.parser.get('diff', 'diff_mode') except: return "compare" def set_diff_mode(self, diff_mode): if not self.parser.has_section('diff'): self.parser.add_section('diff') self.parser.set('diff', 'diff_mode', diff_mode) colored_diff = property(get_colored_diff, set_colored_diff) diff_mode = property(get_diff_mode, set_diff_mode)class SearchConfig(UmitConfigParser, object): def __init__(self): self.parser = Path.config_parser self.section_name = "search" if not self.parser.has_section(self.section_name): self.create_section() def save_changes(self): self.parser.save_changes() def create_section(self): self.parser.add_section(self.section_name) self.directory = "" self.file_extension = "usr" self.save_time = "60;days" self.store_results = True self.search_db = True def _get_it(self, p_name, default): return self.parser.get(self.section_name, p_name, default) def _set_it(self, p_name, value): self.parser.set(self.section_name, p_name, value) def boolean_sanity(self, attr): if attr == True or \ attr == "True" or \ attr == "true" or \ attr == "1": return 1 return 0 def get_directory(self): return self._get_it("directory", "") def set_directory(self, directory): self._set_it("directory", directory) def get_file_extension(self): return self._get_it("file_extension", "usr").split(";") def set_file_extension(self, file_extension): if type(file_extension) == type([]): self._set_it("file_extension", ";".join(file_extension)) elif type(file_extension) in StringTypes: self._set_it("file_extension", file_extension) def get_save_time(self): return self._get_it("save_time", "60;days").split(";") def set_save_time(self, save_time): if type(save_time) == type([]): self._set_it("save_time", ";".join(save_time)) elif type(save_time) in StringTypes: self._set_it("save_time", save_time) def get_store_results(self): return self.boolean_sanity(self._get_it("store_results", True)) def set_store_results(self, store_results): self._set_it("store_results", self.boolean_sanity(store_results)) def get_search_db(self): return self.boolean_sanity(self._get_it("search_db", True)) def set_search_db(self, search_db): self._set_it("search_db", self.boolean_sanity(search_db)) def get_converted_save_time(self): try: return int(self.save_time[0]) * self.time_list[self.save_time[1]] except: # If something goes wrong, return a save time of 60 days return 60 * 60 * 24 * 60 def get_time_list(self): # Time as key, seconds a value return {_("Hours"): 60 * 60, _("Days"): 60 * 60 * 24, _("Weeks"): 60 * 60 * 24 * 7, _("Months"): 60 * 60 * 24 * 7 * 30, _("Years"): 60 * 60 * 24 * 7 * 30 * 12, _("Minutes"): 60, _("Seconds"): 1} directory = property(get_directory, set_directory) file_extension = property(get_file_extension, set_file_extension) save_time = property(get_save_time, set_save_time) store_results = property(get_store_results, set_store_results) search_db = property(get_search_db, set_search_db) converted_save_time = property(get_converted_save_time) time_list = property(get_time_list)class Profile(UmitConfigParser, object): def __init__(self, user_profile=None, *args): UmitConfigParser.__init__(self, *args) if not user_profile: user_profile = scan_profile_file fconf = open(user_profile, 'r') self.readfp(fconf, user_profile) fconf.close() del(fconf) self.attributes = {} def _get_it(self, profile, attribute): if self._verify_profile(profile): return self.get(profile, attribute) return "" def _set_it(self, profile, attribute, value=''): if self._verify_profile(profile): return self.set(profile, attribute, value) def add_profile(self, profile_name, **attributes): log.debug(">>> Add Profile '%s': %s" % (profile_name, attributes)) try: self.add_section(profile_name) except: return None [self._set_it(profile_name, attr, attributes[attr]) for attr in attributes if attr != "options"] options = attributes["options"] if type(options) in StringTypes: self._set_it(profile_name, "options", options) elif type(options) == type({}): self._set_it(profile_name, "options", ",".join(options.keys())) for opt in options: if options[opt]: self._set_it(profile_name, opt, options[opt]) self.save_changes() def remove_profile(self, profile_name): try: self.remove_section(profile_name) except: pass self.save_changes() def _verify_profile(self, profile_name): if profile_name not in self.sections(): return False return Trueclass CommandProfile (Profile, object): def __init__(self, user_profile=''): if not user_profile: user_profile = scan_profile_file Profile.__init__(self, user_profile) def get_command(self, profile): return self._get_it(profile, 'command') def get_hint(self, profile): return self._get_it(profile, 'hint') def get_description(self, profile): return self._get_it(profile, 'description') def get_annotation(self, profile): return self._get_it(profile, 'annotation') def get_options(self, profile): dic = {} for opt in self._get_it(profile, 'options').split(','): try: dic[unicode(opt.strip())] = self._get_it(profile, opt) except NoOptionError: dic[unicode(opt.strip())] = None return dic def set_command(self, profile, command=''): self._set_it(profile, 'command', command) def set_hint(self, profile, hint=''): self._set_it(profile, 'hint', hint) def set_description(self, profile, description=''): self._set_it(profile, 'description', description) def set_annotation (self, profile, annotation=''): self._set_it(profile, 'annotation', annotation) def set_options(self, profile, options={}): for opt in options: if options[opt]:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -