{"action":"created","issue":{"url":"https://api.github.com/repos/plone/Products.CMFPlone/issues/1070","labels_url":"https://api.github.com/repos/plone/Products.CMFPlone/issues/1070/labels{/name}","comments_url":"https://api.github.com/repos/plone/Products.CMFPlone/issues/1070/comments","events_url":"https://api.github.com/repos/plone/Products.CMFPlone/issues/1070/events","html_url":"https://github.com/plone/Products.CMFPlone/issues/1070","id":107987667,"number":1070,"title":"Is it possible to remove the \"txt\" file hack inside profile folder?","user":{"login":"idgserpro","id":8203476,"avatar_url":"https://avatars.githubusercontent.com/u/8203476?v=3","gravatar_id":"","url":"https://api.github.com/users/idgserpro","html_url":"https://github.com/idgserpro","followers_url":"https://api.github.com/users/idgserpro/followers","following_url":"https://api.github.com/users/idgserpro/following{/other_user}","gists_url":"https://api.github.com/users/idgserpro/gists{/gist_id}","starred_url":"https://api.github.com/users/idgserpro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/idgserpro/subscriptions","organizations_url":"https://api.github.com/users/idgserpro/orgs","repos_url":"https://api.github.com/users/idgserpro/repos","events_url":"https://api.github.com/users/idgserpro/events{/privacy}","received_events_url":"https://api.github.com/users/idgserpro/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/plone/Products.CMFPlone/labels/Enhancement","name":"Enhancement","color":"d4c5f9"},{"url":"https://api.github.com/repos/plone/Products.CMFPlone/labels/question","name":"question","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-09-23T19:17:14Z","updated_at":"2015-09-24T14:18:31Z","closed_at":null,"body":"One of the most intriguing example of Plone \"moving parts\" to me is the need of a txt file in profile folder, \"to be sure this is the correct profile to be applied\". This seems to me as a really ugly hack that beginners to Plone will just copy over and over without really knowing why it's there in the first place, and the day they remove an (supposed) useless txt things will go hairy.\r\n\r\nWe even have this hack in new [bobtemplates.plone](https://github.com/plone/bobtemplates.plone/blob/4a4174ee26deb16c1c93e02b646628f6018ed0d1/bobtemplates/plone_addon/src/%2Bpackage.namespace%2B/%2Bpackage.name%2B/setuphandlers.py.bob#L20), and new users of Plone 5 will need to use this workaround as well.\r\n\r\nMy question is: *is it possible* to fix this or are we stuck to GenericSetup implementation (and the only thing we could do is add an [entry to docs](http://docs.plone.org/develop/addons/components/genericsetup.html?highlight=readdatafile#custom-installer-code-setuphandlers-py))?\r\n\r\nIf not possible, @pbauer, I think we should at least add an explanation (or a link mentioning the [plone docs](http://docs.plone.org/develop/addons/components/genericsetup.html?highlight=readdatafile#custom-installer-code-setuphandlers-py), whatever) to the [txt template in bobtemplates.plone](https://github.com/plone/bobtemplates.plone/blob/7047805779115fa726e3ad70091e845f2d22e00e/bobtemplates/plone_addon/src/%2Bpackage.namespace%2B/%2Bpackage.name%2B/profiles/default/%2Bpackage.longname%2B_default.txt) and setuphandlers as well.\r\n\r\n@mauritsvanrees and @hannosch, I'm mentioning you both since I think you can answer this tricky subject from your experience in the field. Thanks in advance!"},"comment":{"url":"https://api.github.com/repos/plone/Products.CMFPlone/issues/comments/142943599","html_url":"https://github.com/plone/Products.CMFPlone/issues/1070#issuecomment-142943599","issue_url":"https://api.github.com/repos/plone/Products.CMFPlone/issues/1070","id":142943599,"user":{"login":"mauritsvanrees","id":210587,"avatar_url":"https://avatars.githubusercontent.com/u/210587?v=3","gravatar_id":"","url":"https://api.github.com/users/mauritsvanrees","html_url":"https://github.com/mauritsvanrees","followers_url":"https://api.github.com/users/mauritsvanrees/followers","following_url":"https://api.github.com/users/mauritsvanrees/following{/other_user}","gists_url":"https://api.github.com/users/mauritsvanrees/gists{/gist_id}","starred_url":"https://api.github.com/users/mauritsvanrees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mauritsvanrees/subscriptions","organizations_url":"https://api.github.com/users/mauritsvanrees/orgs","repos_url":"https://api.github.com/users/mauritsvanrees/repos","events_url":"https://api.github.com/users/mauritsvanrees/events{/privacy}","received_events_url":"https://api.github.com/users/mauritsvanrees/received_events","type":"User","site_admin":false},"created_at":"2015-09-24T14:18:31Z","updated_at":"2015-09-24T14:18:31Z","body":"In a zcml file we register the import step. GenericSetup has no way of knowing if this import step is only meant for this single profile, or if this is meant for multiple profiles, say an import step in plone.app.registry that reads registry.xml for any profile that gets imported.\r\n\r\nI cannot think of anything that would let us get rid of the txt file without requiring something extra in zcml.\r\nWell, possibly by requiring an explicit name, for example the import step must be in `setuphandlers.py` and the method must be named `import_various`. Or probably better: the name of the import step in zcml must be `package.dottedname-only`. But I don't like that.\r\n\r\nThe way with the txt file will always be supported. It seems technically impossible to somehow disallow this. So we do not need to worry about needing to remove stuff.\r\n\r\nBut I would not mind adding an extra way that is easier to understand and also better, like this:\r\n\r\n```\r\n  <genericsetup:registerProfile\r\n      name=\"default\"\r\n      ...\r\n      post_handler=\".setuphandler.post_install\"\r\n```\r\n\r\nBest about this is that this is then guaranteed to be run after all other import steps have been run. We could add a pre_handler too.\r\n\r\nBut apart from changes like this, it is not possible to get rid of the txt file. So then we may need to explain this better in the docs and in bobtemplates.plone.\r\n\r\nWell, one idea. This is from a pdb within an import step of a client project:\r\n\r\n```\r\n(Pdb) __file__\r\n'/Users/mauritsvanrees/clients/mpi.intranet.buildout/src/intrampi.policy/intrampi/policy/setuphandlers.py'\r\n(Pdb) os.path.dirname(__file__)\r\n'/Users/mauritsvanrees/clients/mpi.intranet.buildout/src/intrampi.policy/intrampi/policy'\r\n(Pdb) context\r\n<Products.GenericSetup.context.DirectoryImportContext object at 0x10ec32c50>\r\n(Pdb) context._profile_path\r\nu'/Users/mauritsvanrees/clients/mpi.intranet.buildout/src/intrampi.policy/intrampi/policy/profiles/default'\r\n(Pdb) context._profile_path.startswith(os.path.dirname(__file__))\r\nTrue\r\n(Pdb) context._profile_path == os.path.join(os.path.dirname(__file__), 'profiles', 'default')\r\nTrue\r\n```\r\n\r\nThat last check could come instead of the current check. So instead of this:\r\n\r\n```\r\ndef setup_various(context):\r\n    if context.readDataFile('intrampi.policy_various.txt') is None:\r\n        return\r\n```\r\n\r\nyou would have this:\r\n\r\n```\r\ndef setup_various(context):\r\n    if context._profile_path != os.path.join(os.path.dirname(__file__), 'profiles', 'default'):\r\n        return\r\n```\r\n\r\nNote that this would not work when your `setuphandlers.py` is in a sub directory, but you could compensate for that in the condition.\r\n\r\nThis could be nice."}}