def _update_parent_types_fti_xml(configurator): parent_ct_name = configurator.variables.get( 'dexterity_parent_container_type_name') # NOQA: E501 if not parent_ct_name: return parent_dexterity_type_fti_file_name = get_normalized_ftiname( parent_ct_name) # NOQA: E501 file_name = u'{0}.xml'.format(parent_dexterity_type_fti_file_name, ) file_path = '{0}/profiles/default/types/{1}'.format( configurator.variables['package_folder'], file_name, ) with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) type_name = configurator.variables['dexterity_type_name'] if len(tree.xpath(".//element[@value='{name}']".format( name=type_name))): # NOQA: E501 print( '{name} already in {filename}, skip adding!'.format( name=type_name, filename=file_name, ), ) return match_str = """<property name="allowed_content_types">""" insert_str = """ <element value="{0}" /> """.format(configurator.variables['dexterity_type_name'], ) update_file(configurator, file_path, match_str, insert_str)
def _update_permissions_zcml(configurator): file_name = u'permissions.zcml' file_path = configurator.variables['package_folder'] + '/' + file_name nsprefix = '{http://namespaces.zope.org/zope}' with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() permid = '{0}.Add{1}'.format( configurator.variables['package.dottedname'], configurator.variables['dexterity_type_name_klass'], ) xpath_selector = ".//{0}permission[@id='{1}']".format(nsprefix, permid) if len(tree_root.findall(xpath_selector)): print('{permission} already in permissions.zcml, skip adding!'. format(permission=permid)) # NOQA: E501 return match_str = '-*- extra stuff goes here -*-' insert_str = """ <permission id="{0}.Add{1}" title="{0}: Add {1}" /> """.format( configurator.variables['package.dottedname'], configurator.variables['dexterity_type_name_klass'], ) update_file(configurator, file_path, match_str, insert_str)
def _update_setup_py(configurator): file_name = u"setup.py" file_path = configurator.variables["package.root_folder"] + "/" + file_name match_str = "-*- Extra requirements: -*-" insert_strings = [ "collective.transmogrifier", "plone.app.transmogrifier", "transmogrify.dexterity", "ftw.blueprints", "collective.jsonmigrator", ] for insert_str in insert_strings: insert_str = " '{0}',\n".format(insert_str) if is_string_in_file(configurator, file_path, insert_str): continue update_file(configurator, file_path, match_str, insert_str) match_str = "target = plone" insert_strings = [ "run_migration = {0}.migration.scripts:run_migration".format( configurator.variables["package.dottedname"]), "list_migrations = {0}.migration.scripts:list_migrations".format( configurator.variables["package.dottedname"]), "[zopectl.command]", ] for insert_str in insert_strings: insert_str = " {0}\n".format(insert_str) if is_string_in_file(configurator, file_path, insert_str): continue update_file(configurator, file_path, match_str, insert_str)
def _update_configure_zcml(configurator): file_name = u'configure.zcml' file_path = configurator.variables['package_folder'] + '/' + file_name with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() theme_name = configurator.variables['theme.normalized_name'] theme_xpath = "./plone:static[@name='{0}']".format(theme_name) if len(tree_root.xpath(theme_xpath, namespaces=ZCML_NAMESPACES)): print( '{name} already in configure.zcml, skip adding!'.format( name=theme_name, ), ) return match_str = '-*- extra stuff goes here -*-' insert_str = """ <plone:static directory="theme" type="theme" name="{0}" /> """.format(configurator.variables['theme.normalized_name']) update_file(configurator, file_path, match_str, insert_str)
def _update_configure_zcml(configurator): file_name = u"configure.zcml" file_path = configurator.variables["package_folder"] + "/" + file_name namespaces = {"plone": "http://namespaces.plone.org/plone"} with open(file_path, "r") as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() theme_name = configurator.variables["theme.normalized_name"] theme_xpath = "./plone:static[@name='{0}']".format(theme_name) if len(tree_root.xpath(theme_xpath, namespaces=namespaces)): print( "{name} already in configure.zcml, skip adding!".format(name=theme_name) ) return match_str = "-*- extra stuff goes here -*-" insert_str = """ <plone:static directory="theme" type="theme" name="{0}" /> """.format( configurator.variables["theme.normalized_name"] ) update_file(configurator, file_path, match_str, insert_str)
def _update_parent_types_fti_xml(configurator): parent_ct_name = configurator.variables.get('dexterity_parent_container_type_name') # NOQA: E501 if not parent_ct_name: return parent_dexterity_type_fti_file_name = get_normalized_ftiname(parent_ct_name) # NOQA: E501 file_name = u'{0}.xml'.format( parent_dexterity_type_fti_file_name, ) file_path = '{0}/profiles/default/types/{1}'.format( configurator.variables['package_folder'], file_name, ) with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) type_name = configurator.variables['dexterity_type_name'] if len(tree.xpath(".//element[@value='{name}']".format(name=type_name))): # NOQA: E501 print( '{name} already in {filename}, skip adding!'.format( name=type_name, filename=file_name, ), ) return match_str = """<property name="allowed_content_types">""" insert_str = """ <element value="{0}" /> """.format( configurator.variables['dexterity_type_name'], ) update_file(configurator, file_path, match_str, insert_str)
def _update_rolemap_xml(configurator): file_name = u'rolemap.xml' file_path = '{0}/profiles/default/{1}'.format( configurator.variables['package_folder'], file_name, ) with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() permname = '{0}: Add {1}'.format( configurator.variables['package.dottedname'], configurator.variables['dexterity_type_name_klass'], ) xpath_selector = ".//permission[@name='{0}']".format(permname) if len(tree_root.findall(xpath_selector)): print('{name} already in rolemap.xml, skip adding!'.format(name=permname)) # NOQA: E501 return match_str = '-*- extra stuff goes here -*-' insert_str = """ <permission name="{0}: Add {1}" acquire="True"> <role name="Manager"/> <role name="Site Administrator"/> <role name="Owner"/> <role name="Contributor"/> </permission> """.format( configurator.variables['package.dottedname'], configurator.variables['dexterity_type_name_klass'], ) update_file(configurator, file_path, match_str, insert_str)
def _update_permissions_zcml(configurator): file_name = u'permissions.zcml' file_path = configurator.variables['package_folder'] + '/' + file_name nsprefix = '{http://namespaces.zope.org/zope}' with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() permid = '{0}.Add{1}'.format( configurator.variables['package.dottedname'], configurator.variables['dexterity_type_name_klass'], ) xpath_selector = ".//{0}permission[@id='{1}']".format(nsprefix, permid) if len(tree_root.findall(xpath_selector)): print('{permission} already in permissions.zcml, skip adding!'.format(permission=permid)) # NOQA: E501 return match_str = '-*- extra stuff goes here -*-' insert_str = """ <permission id="{0}.Add{1}" title="{0}: Add {1}" /> """.format( configurator.variables['package.dottedname'], configurator.variables['dexterity_type_name_klass'], ) update_file(configurator, file_path, match_str, insert_str)
def _update_rolemap_xml(configurator): file_name = u'rolemap.xml' file_path = '{0}/profiles/default/{1}'.format( configurator.variables['package_folder'], file_name, ) with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() permname = '{0}: Add {1}'.format( configurator.variables['package.dottedname'], configurator.variables['dexterity_type_name_klass'], ) xpath_selector = ".//permission[@name='{0}']".format(permname) if len(tree_root.findall(xpath_selector)): print('{name} already in rolemap.xml, skip adding!'.format( name=permname)) # NOQA: E501 return match_str = '-*- extra stuff goes here -*-' insert_str = """ <permission name="{0}: Add {1}" acquire="True"> <role name="Manager"/> <role name="Site Administrator"/> <role name="Owner"/> <role name="Contributor"/> </permission> """.format( configurator.variables['package.dottedname'], configurator.variables['dexterity_type_name_klass'], ) update_file(configurator, file_path, match_str, insert_str)
def _update_configure_zcml(configurator): file_name = u"configure.zcml" file_path = configurator.variables["package_folder"] + "/" + file_name match_str = "-*- extra stuff goes here -*-" insert_str = """ <include package=".migration" /> """ update_file(configurator, file_path, match_str, insert_str)
def _update_portlets_xml(configurator): file_name = u'portlets.xml' directory_path = configurator.variables[ 'package_folder'] + '/profiles/default/' # NOQA: E501 file_path = directory_path + file_name configure_example_file_path = configurator.variables[ 'package_folder'] + '/profiles/default/portlets.xml.example' # NOQA: E501 file_list = os.listdir(os.path.dirname(directory_path)) if file_name not in file_list: os.rename(configure_example_file_path, file_path) namespaces = '{http://namespaces.zope.org/zope}' with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() view_xpath = u"{0}portlet[@addview='{1}']".format( namespaces, configurator.variables['portlet_configuration_name'], ) if len(tree_root.findall(view_xpath)): print( u'{0} already in portlets.xml, skip adding!'.format( configurator.variables['portlet_name'], ), ) return match_str = u'<!-- Extra portlets here -->' insert_str = u""" <portlet addview="{0}" title="{1}" description="A portlet which can render weather of the given place." i18n:attributes="title title_{2}; description description_{3}"> <!-- This will enable the portlet for right column, left column and the footer too. --> <for interface="plone.app.portlets.interfaces.IColumn" /> <!-- This will enable the portlet in the dashboard. --> <!--<for interface="plone.app.portlets.interfaces.IDashboard" />--> </portlet> """.format( configurator.variables['portlet_configuration_name'], configurator.variables['portlet_name'], configurator.variables['portlet_name_normalized'], configurator.variables['portlet_name_normalized'], ) update_file(configurator, file_path, match_str, insert_str)
def test_update_file(tmpdir): match_str = "-*- extra stuff goes here -*-" path = tmpdir.strpath + "/configure.zcml" template = """Some text {0} """.format(match_str) with open(os.path.join(path), "w") as f: f.write(template) base.update_file(None, path, match_str, "INSERTED") assert base.is_string_in_file(None, path, "INSERTED") is True
def _update_setup_py(configurator): file_name = u'setup.py' file_path = configurator.variables['package.root_folder'] + '/' + file_name match_str = '-*- Extra requirements: -*-' insert_strings = [ 'plone.app.dexterity', ] for insert_str in insert_strings: insert_str = " '{0}',\n".format(insert_str) if is_string_in_file(configurator, file_path, insert_str): continue update_file(configurator, file_path, match_str, insert_str)
def _update_portlets_xml(configurator): file_name = u'portlets.xml' directory_path = configurator.variables['package_folder'] + '/profiles/default/' # NOQA: E501 file_path = directory_path + file_name configure_example_file_path = configurator.variables['package_folder'] + '/profiles/default/portlets.xml.example' # NOQA: E501 file_list = os.listdir(os.path.dirname(directory_path)) if file_name not in file_list: os.rename(configure_example_file_path, file_path) with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() xpath_selector = "./portlet[@addview='{0}']".format( configurator.variables['portlet_configuration_name'], ) if len(tree_root.xpath(xpath_selector, namespaces=ZCML_NAMESPACES)): print(( u'{0} already in portlets.xml, skip adding!'.format( configurator.variables['portlet_configuration_name'], ), )) return match_str = u'<!-- Extra portlets here -->' insert_str = u""" <portlet addview="{0}" title="{1}" description="A portlet which can render weather of the given place." i18n:attributes="title title_{2}; description description_{3}"> <!-- This will enable the portlet for right column, left column and the footer too. --> <for interface="plone.app.portlets.interfaces.IColumn" /> <!-- This will enable the portlet in the dashboard. --> <!--<for interface="plone.app.portlets.interfaces.IDashboard" />--> </portlet> """.format( configurator.variables['portlet_configuration_name'], configurator.variables['portlet_name'], configurator.variables['portlet_name_normalized'], configurator.variables['portlet_name_normalized'], ) update_file(configurator, file_path, match_str, insert_str)
def test_update_file(tmpdir): match_str = '-*- extra stuff goes here -*-' path = tmpdir.strpath + '/configure.zcml' template = """Some text {0} """.format(match_str, ) with open(os.path.join(path), 'w') as f: f.write(template) base.update_file(None, path, match_str, 'INSERTED') assert base.is_string_in_file(None, path, 'INSERTED') is True
def _update_setup_py(configurator): file_name = u"setup.py" file_path = configurator.variables["package.root_folder"] + "/" + file_name match_str = "-*- Extra requirements: -*-" insert_strings = [ # "collective.themesitesetup", # disable while not ready for Plone 5.2 "collective.themefragments", "plone.app.themingplugins", ] for insert_str in insert_strings: insert_str = " '{0}',\n".format(insert_str) if is_string_in_file(configurator, file_path, insert_str): continue update_file(configurator, file_path, match_str, insert_str)
def _update_setup_py(configurator): if configurator.variables['plone.is_plone5']: return file_name = u'setup.py' file_path = configurator.variables['package.root_folder'] + '/' + file_name match_str = '-*- Extra requirements: -*-' insert_strings = [ 'plone.app.dexterity', ] for insert_str in insert_strings: insert_str = " '{0}',\n".format(insert_str) if is_string_in_file(configurator, file_path, insert_str): continue update_file(configurator, file_path, match_str, insert_str)
def _update_setup_py(configurator): file_name = u'setup.py' file_path = configurator.variables['package.root_folder'] + '/' + file_name match_str = '-*- Extra requirements: -*-' insert_strings = [ 'collective.themesitesetup', 'collective.themefragments', 'plone.app.themingplugins', ] for insert_str in insert_strings: insert_str = " '{0}',\n".format(insert_str) if is_string_in_file(configurator, file_path, insert_str): continue update_file(configurator, file_path, match_str, insert_str)
def _update_setup_py(configurator): file_name = u'setup.py' file_path = configurator.variables['package.root_folder'] + '/' + file_name match_str = '-*- Extra requirements: -*-' insert_strings = [ # 'collective.themesitesetup', # disable while not ready for Plone 5.2 'collective.themefragments', 'plone.app.themingplugins', ] for insert_str in insert_strings: insert_str = " '{0}',\n".format(insert_str) if is_string_in_file(configurator, file_path, insert_str): continue update_file(configurator, file_path, match_str, insert_str)
def _update_behaviors_configure_zcml(configurator): file_name = u'configure.zcml' file_path = configurator.variables[ 'package_folder'] + '/behaviors/' + file_name example_file_path = file_path + '.example' file_list = os.listdir(os.path.dirname(file_path)) if file_name not in file_list: os.rename(example_file_path, file_path) namespaces = {'plone': 'http://namespaces.plone.org/plone'} with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() behavior_name = '{0}.{1}'.format( configurator.variables['behavior_name_normalized'], configurator.variables['behavior_name_klass'], ) xpath_str = "./plone:behavior[@factory='{0}']".format(behavior_name) if len(tree_root.xpath(xpath_str, namespaces=namespaces)): print( '{name} already in configure.zcml, skip adding!'.format( name=behavior_name, ), ) return match_str = '-*- extra stuff goes here -*-' insert_str = """ <plone:behavior name="{package_dottedname}.{normalized_name}" title="{title}" description="{description}" provides=".{normalized_name}.I{klass_name}" factory=".{normalized_name}.{klass_name}" marker=".{normalized_name}.I{klass_name}Marker" /> """.format( title=configurator.variables['behavior_name_klass'], description=configurator.variables['behavior_description'], normalized_name=configurator.variables['behavior_name_normalized'], klass_name=configurator.variables['behavior_name_klass'], package_dottedname=configurator.variables['package.dottedname'], ) update_file(configurator, file_path, match_str, insert_str)
def _update_portlets_configure_zcml(configurator): file_name = u'configure.zcml' directory_path = configurator.variables['package_folder'] + '/portlets/' file_path = directory_path + file_name configure_example_file_path = configurator.variables[ 'package_folder'] + '/portlets/configure.zcml.example' # NOQA: E501 file_list = os.listdir(os.path.dirname(directory_path)) if file_name not in file_list: os.rename(configure_example_file_path, file_path) namespaces = '{http://namespaces.zope.org/zope}' with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() view_xpath = u"{0}plone:portlet[@name='{1}']".format( namespaces, configurator.variables['portlet_configuration_name'], ) if len(tree_root.findall(view_xpath)): print( u'{0} already in configure.zcml, skip adding!'.format( configurator.variables['portlet_name'], ), ) return match_str = '-*- extra stuff goes here -*-' insert_str = u""" <plone:portlet name="{0}" interface=".{1}.{2}" assignment=".{3}.Assignment" renderer=".{4}.Renderer" addview=".{5}.AddForm" editview=".{6}.EditForm" /> """.format( configurator.variables['portlet_configuration_name'], configurator.variables['portlet_name_normalized'], configurator.variables['data_provider_class_name'], configurator.variables['portlet_name_normalized'], configurator.variables['portlet_name_normalized'], configurator.variables['portlet_name_normalized'], configurator.variables['portlet_name_normalized'], ) update_file(configurator, file_path, match_str, insert_str)
def _update_behaviors_configure_zcml(configurator): file_name = u'configure.zcml' file_path = configurator.variables[ 'package_folder'] + '/behaviors/' + file_name example_file_path = file_path + '.example' file_list = os.listdir(os.path.dirname(file_path)) if file_name not in file_list: os.rename(example_file_path, file_path) namespaces = {'plone': 'http://namespaces.plone.org/plone'} with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() behavior_name = '{0}.{1}'.format( configurator.variables['behavior_name_normalized'], configurator.variables['behavior_name_klass'], ) xpath_str = "./plone:behavior[@factory='{0}']".format(behavior_name) if len(tree_root.xpath(xpath_str, namespaces=namespaces)): print( '{name} already in configure.zcml, skip adding!'.format( name=behavior_name, ), ) return match_str = '-*- extra stuff goes here -*-' insert_str = """ <plone:behavior name="{normalized_name}" title="{title}" description="{description}" provides=".{normalized_name}.I{klass_name}" factory=".{normalized_name}.{klass_name}" marker=".{normalized_name}.I{klass_name}" /> """.format( title=configurator.variables['behavior_name_klass'], description=configurator.variables['behavior_description'], normalized_name=configurator.variables['behavior_name_normalized'], klass_name=configurator.variables['behavior_name_klass'], ) update_file(configurator, file_path, match_str, insert_str)
def _update_portlets_configure_zcml(configurator): file_name = u'configure.zcml' directory_path = configurator.variables['package_folder'] + '/portlets/' file_path = directory_path + file_name configure_example_file_path = configurator.variables['package_folder'] + '/portlets/configure.zcml.example' # NOQA: E501 file_list = os.listdir(os.path.dirname(directory_path)) if file_name not in file_list: os.rename(configure_example_file_path, file_path) with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() portlet_xpath = u"./plone:portlet[@name='{0}']".format( configurator.variables['portlet_name'], ) if len(tree_root.xpath(portlet_xpath, namespaces=ZCML_NAMESPACES)): print(( u'{0} already in configure.zcml, skip adding!'.format( configurator.variables['portlet_name'], ), )) return match_str = '-*- extra stuff goes here -*-' insert_str = u""" <plone:portlet name="{0}" interface=".{1}.{2}" assignment=".{3}.Assignment" renderer=".{4}.Renderer" addview=".{5}.AddForm" editview=".{6}.EditForm" /> """.format( configurator.variables['portlet_configuration_name'], configurator.variables['portlet_name_normalized'], configurator.variables['data_provider_class_name'], configurator.variables['portlet_name_normalized'], configurator.variables['portlet_name_normalized'], configurator.variables['portlet_name_normalized'], configurator.variables['portlet_name_normalized'], ) update_file(configurator, file_path, match_str, insert_str)
def _update_configure_zcml(configurator): file_name = u'configure.zcml' file_path = configurator.variables['package_folder'] + '/' + file_name with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() xpath_selector = "./include[@package='{0}']".format( '.portlets') # NOQA: E501 if len(tree_root.xpath(xpath_selector, namespaces=ZCML_NAMESPACES)): print((u'.views already in configure.zcml, skip adding!', )) return match_str = '-*- extra stuff goes here -*-' insert_str = u""" <include package=".portlets" /> """ update_file(configurator, file_path, match_str, insert_str)
def _update_configure_zcml(configurator): file_name = u'configure.zcml' file_path = configurator.variables['package_folder'] + '/' + file_name namespaces = '{http://namespaces.zope.org/zope}' with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() view_xpath = "{0}include[@package='.viewlets']".format(namespaces) if len(tree_root.findall(view_xpath)): print('.viewlets already in configure.zcml, skip adding!', ) return match_str = '-*- extra stuff goes here -*-' insert_str = """ <include package=".viewlets" /> """ update_file(configurator, file_path, match_str, insert_str)
def _update_configure_zcml(configurator): file_name = u'configure.zcml' file_path = configurator.variables['package_folder'] + '/' + file_name with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() xpath_selector = "./include[@package='{0}']".format('.portlets') # NOQA: E501 if len(tree_root.xpath(xpath_selector, namespaces=ZCML_NAMESPACES)): print(( u'.views already in configure.zcml, skip adding!', )) return match_str = u'<!--<includeDependencies package="." />-->' insert_str = u""" <include package=".portlets" /> """ update_file(configurator, file_path, match_str, insert_str)
def _update_vocabularies_configure_zcml(configurator): file_name = u'configure.zcml' file_path = configurator.variables[ 'package_folder'] + '/vocabularies/' + file_name example_file_path = file_path + '.example' file_list = os.listdir(os.path.dirname(file_path)) if file_name not in file_list: os.rename(example_file_path, file_path) nsprefix = '{http://namespaces.zope.org/zope}' with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() vocab_name = '{0}.{1}'.format( configurator.variables['package.dottedname'], configurator.variables['vocabulary_name_klass'], ) xpath_selector = ".//{0}utility[@name='{1}']".format( nsprefix, vocab_name, ) if len(tree_root.findall(xpath_selector)): print('{0} already in configure.zcml, skip adding!'.format( vocab_name)) # NOQA: E501 return match_str = '-*- extra stuff goes here -*-' insert_str = """ <utility component=".{0}.{1}Factory" name="{2}.{1}" /> """.format( configurator.variables['vocabulary_name_normalized'], configurator.variables['vocabulary_name_klass'], configurator.variables['package.dottedname'], ) update_file(configurator, file_path, match_str, insert_str)
def _update_package_configure_zcml(configurator): file_name = u'configure.zcml' file_path = configurator.variables['package_folder'] + '/' + file_name nsprefix = '{http://namespaces.zope.org/zope}' with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() permid = '.vocabularies' xpath_selector = ".//{0}include[@package='{1}']".format( nsprefix, permid) # NOQA: E501 if len(tree_root.findall(xpath_selector)): print('{0} already in configure.zcml, skip adding!'.format(permid)) return match_str = '-*- extra stuff goes here -*-' insert_str = """ <include package=".vocabularies" /> """ update_file(configurator, file_path, match_str, insert_str)
def _update_package_configure_zcml(configurator): file_name = u'configure.zcml' file_path = configurator.variables['package_folder'] + '/' + file_name nsprefix = '{http://namespaces.zope.org/zope}' with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() permid = '.behaviors' xpath_selector = ".//{0}include[@package='{1}']".format( nsprefix, permid, ) # NOQA: S100 if len(tree_root.findall(xpath_selector)): print('{0} already in configure.zcml, skip adding!'.format(permid)) return match_str = '-*- extra stuff goes here -*-' insert_str = """ <include package=".behaviors" /> """ update_file(configurator, file_path, match_str, insert_str)
def _update_views_configure_zcml(configurator): file_name = u'configure.zcml' directory_path = configurator.variables['package_folder'] + '/views/' file_path = directory_path + file_name configure_example_file_path = configurator.variables[ 'package_folder'] + '/views/configure.zcml.example' # NOQA: E501 file_list = os.listdir(os.path.dirname(directory_path)) if file_name not in file_list: os.rename(configure_example_file_path, file_path) match_str = '-*- extra stuff goes here -*-' if configurator.variables['view_template'] and configurator.variables[ 'view_python_class']: # NOQA: E501 insert_str = """ <browser:page name="{0}" for="Products.CMFCore.interfaces.IFolderish" class=".{1}.{2}" template="{3}.pt" permission="zope2.View" /> """.format( configurator.variables['view_name'], configurator.variables['view_python_file_name'], configurator.variables['view_python_class_name'], configurator.variables['view_template_name'], ) if configurator.variables['view_template'] and not configurator.variables[ 'view_python_class']: # NOQA: E501 insert_str = """ <browser:page name="{0}" for="Products.CMFCore.interfaces.IFolderish" template="{1}.pt" permission="zope2.View" /> """.format( configurator.variables['view_name'], configurator.variables['view_template_name'], ) if not configurator.variables['view_template'] and configurator.variables[ 'view_python_class']: # NOQA: E501 insert_str = """ <browser:page name="{0}" for="Products.CMFCore.interfaces.IFolderish" class=".{1}.{2}" permission="zope2.View" /> """.format( configurator.variables['view_name'], configurator.variables['view_python_file_name'], configurator.variables['view_python_class_name'], ) with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() view_xpath = "./browser:page[@name='{0}']".format( configurator.variables['view_name'], ) if len(tree_root.xpath(view_xpath, namespaces=ZCML_NAMESPACES)): echo( u'{0} already in configure.zcml, do you really want to add this config?' u'\n\n{1}\n [y/N]: '.format( configurator.variables['view_name'], insert_str, ), 'info', ) if configurator.bobconfig.get('non_interactive'): return choice = six.moves.input().lower() if choice != 'y': return update_file(configurator, file_path, match_str, insert_str)
def _update_views_configure_zcml(configurator): file_name = u'configure.zcml' directory_path = configurator.variables['package_folder'] + '/views/' file_path = directory_path + file_name configure_example_file_path = configurator.variables[ 'package_folder'] + '/views/configure.zcml.example' # NOQA: E501 file_list = os.listdir(os.path.dirname(directory_path)) if file_name not in file_list: os.rename(configure_example_file_path, file_path) namespaces = '{http://namespaces.zope.org/zope}' with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() view_xpath = "{0}browser:page[@name='{1}']".format( namespaces, configurator.variables['view_name'], ) if len(tree_root.findall(view_xpath)): print( '{0} already in configure.zcml, skip adding!'.format( configurator.variables['view_name'], ), ) return match_str = '-*- extra stuff goes here -*-' if configurator.variables['view_template'] and configurator.variables[ 'view_python_class']: # NOQA: E501 insert_str = """ <browser:page name="{0}" for="Products.CMFCore.interfaces.IFolderish" class=".{1}.{2}" template="{3}.pt" permission="zope2.View" /> """.format( configurator.variables['view_name'], configurator.variables['view_python_file_name'], configurator.variables['view_python_class_name'], configurator.variables['view_template_name'], ) if configurator.variables['view_template'] and not configurator.variables[ 'view_python_class']: # NOQA: E501 insert_str = """ <browser:page name="{0}" for="Products.CMFCore.interfaces.IFolderish" template="{1}.pt" permission="zope2.View" /> """.format( configurator.variables['view_name'], configurator.variables['view_template_name'], ) if not configurator.variables['view_template'] and configurator.variables[ 'view_python_class']: # NOQA: E501 insert_str = """ <browser:page name="{0}" for="Products.CMFCore.interfaces.IFolderish" class=".{1}.{2}" permission="zope2.View" /> """.format( configurator.variables['view_name'], configurator.variables['view_python_file_name'], configurator.variables['view_python_class_name'], ) update_file(configurator, file_path, match_str, insert_str)
def _update_viewlets_configure_zcml(configurator): file_name = u'configure.zcml' directory_path = configurator.variables['package_folder'] + '/viewlets/' file_path = directory_path + file_name configure_example_file_path = configurator.variables[ 'package_folder'] + '/viewlets/configure.zcml.example' # NOQA: E501 file_list = os.listdir(os.path.dirname(directory_path)) if file_name not in file_list: os.rename(configure_example_file_path, file_path) with open(file_path, 'r') as xml_file: parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(xml_file, parser) tree_root = tree.getroot() view_xpath = "./browser:viewlet[@name='{0}']".format( configurator.variables['viewlet_name'], ) if len(tree_root.xpath(view_xpath, namespaces=ZCML_NAMESPACES)): print( '{0} already in configure.zcml, skip adding!!!'.format( configurator.variables['viewlet_name'], ), ) return match_str = '-*- extra stuff goes here -*-' if configurator.variables['plone.is_plone5']: iface_name = 'plone.app.contenttypes.interfaces.IDocument' else: # BBB Plone 4 fallback: iface_name = 'Products.ATContentTypes.interfaces.document.IATDocument' if configurator.variables['viewlet_template']: insert_str = """ <browser:viewlet name="{0}" for="{1}" manager="plone.app.layout.viewlets.interfaces.IAboveContentTitle" layer="{2}.interfaces.{3}" class=".{4}.{5}" template="{6}.pt" permission="zope2.View" /> """.format( configurator.variables['viewlet_name'], iface_name, configurator.variables['package.dottedname'], configurator.variables['browser_layer'], configurator.variables['viewlet_python_file_name'], configurator.variables['viewlet_python_class_name'], configurator.variables['viewlet_template_name'], ) else: insert_str = """ <browser:viewlet name="{0}" for="{1}" manager="plone.app.layout.viewlets.interfaces.IAboveContentTitle" layer="{2}.interfaces.{3}" class=".{4}.{5}" permission="zope2.View" /> """.format( configurator.variables['viewlet_name'], iface_name, configurator.variables['package.dottedname'], configurator.variables['browser_layer'], configurator.variables['viewlet_python_file_name'], configurator.variables['viewlet_python_class_name'], ) update_file(configurator, file_path, match_str, insert_str)