def listMetaTags(self, context): site_props = getToolByName(context, 'portal_properties').site_properties exposeDCMetaTags = site_props.exposeDCMetaTags metaTags = SortedDict() metaTags.update(old_lmt(self, context)) metadataList = [ ('qSEO_Description', 'description'), ('qSEO_Keywords', 'keywords'), ('qSEO_Robots', 'robots'), ('qSEO_Distribution','distribution')] if exposeDCMetaTags: metadataList.append(('qSEO_Distribution', 'DC.distribution')) for accessor, key in metadataList: method = getattr(context, accessor, None) if not callable(method): # ups continue # Catch AttributeErrors raised by some AT applications try: value = method() except AttributeError: value = None if not value: # no data continue if ( type(value) == tuple ) or ( type(value) == list ): # convert a list to a string value = ', '.join(value) metaTags[key] = value return metaTags
def __init__(self, destDir=None): self.helper = self.asnHelperClass() self.destDir = destDir or self.destDir self.toc = TopicToc(helper=self.helper) SortedDict.__init__(self) self.read() print "%d standards documents read" % len(self.data)
def load_plugins_info(self): import plugins from util import SortedDict self.plugins = SortedDict() self.enabled_plugins = SortedDict() for plugin in plugins.plugin_list: self.plugins[plugin.name] = plugin if plugin.enabled: self.enabled_plugins[plugin.name] = plugin
def listMetaTags(self, context): portal_props = getToolByName(context, 'portal_properties') seo_props = getToolByName(portal_props, 'seo_properties', None) if seo_props is None: return old_lmt(self, context) site_props = getToolByName(portal_props, 'site_properties') exposeDCMetaTags = site_props.exposeDCMetaTags metaTags = SortedDict() metaTags.update(old_lmt(self, context)) metadataList = [ ('qSEO_Description', 'description'), ('qSEO_Keywords', 'keywords'), ('qSEO_Robots', 'robots'), ('qSEO_Distribution','distribution')] if exposeDCMetaTags: metadataList.append(('qSEO_Distribution', 'DC.distribution')) for accessor, key in metadataList: method = getattr(context, accessor, None) if not callable(method): # ups continue # Catch AttributeErrors raised by some AT applications try: value = method() except AttributeError: value = None if not value: continue if isinstance(value, (tuple, list)): value = ', '.join(value) metaTags[key] = value # add custom meta tags (added from qseo tab by user) for given context property_prefix = 'qSEO_custom_' for property, value in context.propertyItems(): idx = property.find(property_prefix) if idx == 0 and len(property) > len(property_prefix): metaTags[property[len(property_prefix):]] = value # Set the additional matching keywords, if any if zope_interface_available: adapter = IKeywords(context, None) if adapter is not None: keywords = adapter.listKeywords() if keywords: metaTags['keywords'] = keywords return metaTags
class TopicToc(Toc): title = "ASN Standards Documents" topics = SortedDict() def addEntry(self, docInfo): Toc.addEntry(self, docInfo) topic = docInfo.topic if not topic in self.topics.keys(): self.topics[topic] = [] self.topics[topic].append(makeKey(docInfo)) self.writeXml() def getTocHtml(self): html = DIV() for topic in self.topics.keys(): html.append( DIV(B(self.helper.getTopic(topic)), klass="topic-header")) toc = UL() print "topic items" topic_keys = self.topics[topic] topic_keys.sort() for key in topic_keys: # url = key + ".html" # inktext = "%s (%s)" % (self.helper.getAuthor(docInfo.author), docInfo.created) # href = Href (url, inktext, # title=docInfo.title, # target="content") print "\tkey: ", key link = self.getLink(key) toc.append(LI(link, klass="toc-link", id=key)) html.append(toc) return html
def __init__(self, modules, nets, name=''): super().__init__(name) self._modules = set() self._nets = set() mods = SortedDict() for mod_name,args in modules.items(): mod = Module(mod_name, args['type'], args['conf']) self.modules.add(mod) mods[mod_name] = mod for src_name, src_port, dst_name, dst_port, width in nets: src = mods[src_name] dst = mods[dst_name] self.nets.add(Net(src, src_port, dst, dst_port, width))
def load_core(file, *libs): context = coreir.Context() for lib in libs: context.load_library(lib) top_module = context.load_from_file(file) top_def = top_module.definition modules = SortedDict() for inst in top_def.instances: inst_name = inst.selectpath[0] inst_type = inst.module_name modules[inst_name] = dict() if inst_type[:2] == 'PE': modules[inst_name]['type'] = 'PE' modules[inst_name]['conf'] = inst.get_config_value('op') elif inst_type[:5] == 'Const': modules[inst_name]['type'] = 'Const' modules[inst_name]['conf'] = inst.get_config_value('value') elif inst_type[:2] == 'IO': modules[inst_name]['type'] = 'IO' modules[inst_name]['conf'] = inst.get_config_value('mode') elif inst_type[:3] == 'Reg': modules[inst_name]['type'] = 'Reg' modules[inst_name]['conf'] = None elif inst_type[:3] == 'Mem': modules[inst_name]['type'] = 'Mem' modules[inst_name]['conf'] = inst.get_config_value('mode') else: raise ValueError( "Unknown module_name '{}' expected <'PE', 'Const', 'IO', 'Reg', 'Mem'>" .format(inst_type)) nets = set() for con in top_def.connections: v1 = con.first.selectpath v2 = con.second.selectpath if 'out' in v1: src = v1 dst = v2 else: src = v2 dst = v1 src_name = src[0] dst_name = dst[0] src_port = PORT_TRANSLATION[modules[src_name]['type']][','.join( src[1:])] dst_port = PORT_TRANSLATION[modules[dst_name]['type']][','.join( dst[1:])] width = 16 net = (src_name, src_port, dst_name, dst_port, width) nets.add(net) return modules, nets
def __init__(self, docInfos=[], helper=None): self.helper = helper SortedDict.__init__(self) for docInfo in docInfos: self.addEntry(docInfo)
class Wizard(object): def __init__(self): import config self.cfg = config.get_config('sshproxy') self.menu = self.make_menu() while True: try: self.menu() break except KeyboardInterrupt: print try: ans = raw_input("Do you want to abort without" " saving ? [y/n]") except KeyboardInterrupt: print 'Aborted.' sys.exit(0) if ans and ans.lower()[0] == 'y': print 'Aborted.' sys.exit(0) self.cfg.write() print 'Configuration saved.' def get_current_backends(self): return (self.cfg['acl_db'], self.cfg['client_db'], self.cfg['site_db']) def set_listen_on(self, value): self.cfg['listen_on'] = value def set_port(self, value): try: value = int(value) except ValueError: print "Port must be numeric" return False if not (0 < value < 65536): print "Port must be a number comprised between 1 and 65535" return False self.cfg['port'] = value def set_auto_add_key(self, value): value = value.lower() if value not in ('yes', 'no'): try: if int(value) < 0: raise ValueError except ValueError: print "Unknown value %s" % value return False self.cfg['auto_add_key'] = value def set_pkey_id(self, value): self.cfg['pkey_id'] = value def set_cipher(self, value): import cipher if value not in cipher.list_engines(): return False self.cfg['cipher_type'] = value def set_blowfish_secret(self, value): import cipher import config if value: if len(value) < 10: print "You must enter at least 10 characters." return False config.get_config['blowfish']['secret'] = value else: raw_input("Secret passphrase untouched.\nPress enter") def set_backend(self, value, backend): if self.cfg[backend] == value: return old = self.cfg[backend] self.cfg[backend] = value # add the new backend to the plugin list self.enable_plugin(value, True) if old not in self.get_current_backends(): # remove the old unused backend from the plugin list self.enable_plugin(old, False) def enable_plugin(self, value, state): enp = self.cfg['plugin_list'].split() if state: enp.append(value) else: enp.remove(value) # make unique enp = dict(map(lambda x: (x, x), enp)).keys() enp.sort() self.cfg['plugin_list'] = ' '.join(enp) self.plugins[value].enabled = state return True def load_plugins_info(self): import plugins from util import SortedDict self.plugins = SortedDict() self.enabled_plugins = SortedDict() for plugin in plugins.plugin_list: self.plugins[plugin.name] = plugin if plugin.enabled: self.enabled_plugins[plugin.name] = plugin def make_plugins_menu(self): plugin_list = [] for name, plugin in self.plugins.items(): if plugin.backend: continue plugin_list.append( MenuSwitch(plugin.plugin_name, plugin.name, plugin.enabled, cb=self.enable_plugin)) select_plugins = Menu('Select plugins', 'Add or remove plugins from the list', *plugin_list) plugmenu = MenuDyn(self.make_plugin_list, "Plugins settings") return [MenuSep('Plugin options'), select_plugins, MenuSep(), plugmenu] def make_plugin_list(self): plugins = [] for name, plugin in self.plugins.items(): if not plugin.enabled or plugin.backend: continue plugins.append( Menu(plugin.plugin_name, plugin.description, *(plugin.setup() or []))) return plugins def make_backends_menu(self): backends = self.get_current_backends() backend_items = [] backend_plugins = [] for name, plugin in self.plugins.items(): if not plugin.backend: continue backend_items.append((plugin.plugin_name, name)) if name in backends: backend_plugins.append( Menu(plugin.plugin_name, plugin.description, *(plugin.setup() or []))) acl_menu = MenuChoice('ACL database backend type', "Choose a backend", self.cfg['acl_db'], self.set_backend, backend='acl_db', *backend_items) client_menu = MenuChoice('Client database backend type', "Choose a backend", self.cfg['client_db'], self.set_backend, backend='client_db', *backend_items) site_menu = MenuChoice('Site backend type', "Choose a backend", self.cfg['site_db'], self.set_backend, backend='site_db', *backend_items) backend_menu = MenuSub("Backends", "", *backend_plugins) return [ MenuSep('Choose backends'), acl_menu, client_menu, site_menu, MenuSep(), MenuSep('Configure backends'), backend_menu ] def make_cipher_menu(self): import config cipher = self.cipher_module cipher_list = [(o.capitalize(), o) for o in cipher.list_engines()] menu = [] menu.append( MenuChoice('Cipher engine', ("Please choose a cipher engine to crypt passwords " "in the database."), self.cfg['cipher_type'], self.set_cipher, *cipher_list)) if self.cfg['cipher_type'] == 'blowfish': menu.append( MenuPassword('Blowfish secret passphrase', "Enter at least 10 characters.", config.get_config['blowfish']['secret'], self.set_blowfish_secret)) return menu def make_menu(self): import cipher self.cipher_module = cipher self.load_plugins_info() menu = Menu( 'Configure sshproxy', None, MenuSep('Global options'), MenuInput('IP address or interface', ("Enter the IP address or the interface name on wich " "the server will listen for incoming connections."), self.cfg['listen_on'] or 'any', self.set_listen_on), MenuInput('Port', ("Enter the port on which the server will listen for " "incoming connections."), self.cfg['port'], self.set_port), MenuInput('Auto-add public key', ("If you want the auto-add-key feature, enter here the " "number of keys auto-added in the client keyring, or " "'yes' for no limit. Saying 'no' disable this feature." "\nAttention: this feature, if enabled, can be " "dangerous."), self.cfg['auto_add_key'], self.set_auto_add_key), MenuInput('Public key id string', ("Enter the public key id string used to identify the " "proxy public key that can be put in a remote " ".ssh/authorized_keys file. This is typically in the " "form of an email address."), self.cfg['pkey_id'], self.set_pkey_id), ) menu.add(MenuDyn(self.make_cipher_menu, "Cipher")) menu.add(MenuSep()) menu.add(MenuDyn(self.make_backends_menu, "Backends")) menu.add(MenuSep()) menu.add(self.make_plugins_menu()) menu.add(MenuSep()) menu.back_text = "Quit" return menu
class Wizard(object): def __init__(self): import config self.cfg = config.get_config("sshproxy") self.menu = self.make_menu() while True: try: self.menu() break except KeyboardInterrupt: print try: ans = raw_input("Do you want to abort without" " saving ? [y/n]") except KeyboardInterrupt: print "Aborted." sys.exit(0) if ans and ans.lower()[0] == "y": print "Aborted." sys.exit(0) self.cfg.write() print "Configuration saved." def get_current_backends(self): return (self.cfg["acl_db"], self.cfg["client_db"], self.cfg["site_db"]) def set_listen_on(self, value): self.cfg["listen_on"] = value def set_port(self, value): try: value = int(value) except ValueError: print "Port must be numeric" return False if not (0 < value < 65536): print "Port must be a number comprised between 1 and 65535" return False self.cfg["port"] = value def set_auto_add_key(self, value): value = value.lower() if value not in ("yes", "no"): try: if int(value) < 0: raise ValueError except ValueError: print "Unknown value %s" % value return False self.cfg["auto_add_key"] = value def set_pkey_id(self, value): self.cfg["pkey_id"] = value def set_cipher(self, value): import cipher if value not in cipher.list_engines(): return False self.cfg["cipher_type"] = value def set_blowfish_secret(self, value): import cipher import config if value: if len(value) < 10: print "You must enter at least 10 characters." return False config.get_config["blowfish"]["secret"] = value else: raw_input("Secret passphrase untouched.\nPress enter") def set_backend(self, value, backend): if self.cfg[backend] == value: return old = self.cfg[backend] self.cfg[backend] = value # add the new backend to the plugin list self.enable_plugin(value, True) if old not in self.get_current_backends(): # remove the old unused backend from the plugin list self.enable_plugin(old, False) def enable_plugin(self, value, state): enp = self.cfg["plugin_list"].split() if state: enp.append(value) else: enp.remove(value) # make unique enp = dict(map(lambda x: (x, x), enp)).keys() enp.sort() self.cfg["plugin_list"] = " ".join(enp) self.plugins[value].enabled = state return True def load_plugins_info(self): import plugins from util import SortedDict self.plugins = SortedDict() self.enabled_plugins = SortedDict() for plugin in plugins.plugin_list: self.plugins[plugin.name] = plugin if plugin.enabled: self.enabled_plugins[plugin.name] = plugin def make_plugins_menu(self): plugin_list = [] for name, plugin in self.plugins.items(): if plugin.backend: continue plugin_list.append(MenuSwitch(plugin.plugin_name, plugin.name, plugin.enabled, cb=self.enable_plugin)) select_plugins = Menu("Select plugins", "Add or remove plugins from the list", *plugin_list) plugmenu = MenuDyn(self.make_plugin_list, "Plugins settings") return [MenuSep("Plugin options"), select_plugins, MenuSep(), plugmenu] def make_plugin_list(self): plugins = [] for name, plugin in self.plugins.items(): if not plugin.enabled or plugin.backend: continue plugins.append(Menu(plugin.plugin_name, plugin.description, *(plugin.setup() or []))) return plugins def make_backends_menu(self): backends = self.get_current_backends() backend_items = [] backend_plugins = [] for name, plugin in self.plugins.items(): if not plugin.backend: continue backend_items.append((plugin.plugin_name, name)) if name in backends: backend_plugins.append(Menu(plugin.plugin_name, plugin.description, *(plugin.setup() or []))) acl_menu = MenuChoice( "ACL database backend type", "Choose a backend", self.cfg["acl_db"], self.set_backend, backend="acl_db", *backend_items ) client_menu = MenuChoice( "Client database backend type", "Choose a backend", self.cfg["client_db"], self.set_backend, backend="client_db", *backend_items ) site_menu = MenuChoice( "Site backend type", "Choose a backend", self.cfg["site_db"], self.set_backend, backend="site_db", *backend_items ) backend_menu = MenuSub("Backends", "", *backend_plugins) return [ MenuSep("Choose backends"), acl_menu, client_menu, site_menu, MenuSep(), MenuSep("Configure backends"), backend_menu, ] def make_cipher_menu(self): import config cipher = self.cipher_module cipher_list = [(o.capitalize(), o) for o in cipher.list_engines()] menu = [] menu.append( MenuChoice( "Cipher engine", ("Please choose a cipher engine to crypt passwords " "in the database."), self.cfg["cipher_type"], self.set_cipher, *cipher_list ) ) if self.cfg["cipher_type"] == "blowfish": menu.append( MenuPassword( "Blowfish secret passphrase", "Enter at least 10 characters.", config.get_config["blowfish"]["secret"], self.set_blowfish_secret, ) ) return menu def make_menu(self): import cipher self.cipher_module = cipher self.load_plugins_info() menu = Menu( "Configure sshproxy", None, MenuSep("Global options"), MenuInput( "IP address or interface", ( "Enter the IP address or the interface name on wich " "the server will listen for incoming connections." ), self.cfg["listen_on"] or "any", self.set_listen_on, ), MenuInput( "Port", ("Enter the port on which the server will listen for " "incoming connections."), self.cfg["port"], self.set_port, ), MenuInput( "Auto-add public key", ( "If you want the auto-add-key feature, enter here the " "number of keys auto-added in the client keyring, or " "'yes' for no limit. Saying 'no' disable this feature." "\nAttention: this feature, if enabled, can be " "dangerous." ), self.cfg["auto_add_key"], self.set_auto_add_key, ), MenuInput( "Public key id string", ( "Enter the public key id string used to identify the " "proxy public key that can be put in a remote " ".ssh/authorized_keys file. This is typically in the " "form of an email address." ), self.cfg["pkey_id"], self.set_pkey_id, ), ) menu.add(MenuDyn(self.make_cipher_menu, "Cipher")) menu.add(MenuSep()) menu.add(MenuDyn(self.make_backends_menu, "Backends")) menu.add(MenuSep()) menu.add(self.make_plugins_menu()) menu.add(MenuSep()) menu.back_text = "Quit" return menu