{ "info": { "author": "Dylan Jay", "author_email": "software@pretaweb.com", "bugtrack_url": null, "classifiers": [ "Framework :: Buildout", "Intended Audience :: Developers", "License :: OSI Approved :: Zope Public License", "Topic :: Software Development :: Build Tools" ], "description": "Mr.Scripty\n==========\n\n|travis| |pyversions|\n\n\n.. |travis| image:: https://travis-ci.org/ridha/mr.scripty.svg?branch=master\n :target: https://travis-ci.org/ridha/mr.scripty\n\n.. |pyversions| image:: https://img.shields.io/badge/python-2.6,_3.4,_3.5-blue.svg?style=flat\n :target: https://travis-ci.org/ridha/mr.scripty\n\n\nA quick way to build recipes by using python directly inside zc.buildout\n\n.. contents::\n\n\nSupported options\n=================\n\nThe recipe supports any number of options, which are Python functions. Since\nthe ini parser used with buildout doesn't preserve initial whitespace each\nline of your method should start with a `...` followed by the whitespace as\nper normal python. They will look like this::\n\n [myscripts]\n recipe = mr.scripty\n MAX = 10\n function1 =\n ... x = range(1,int(self.MAX))\n ... return ' '.join(x)\n\n [myrecipe]\n recipe = something.recipe\n argument = ${myscripts:function1}\n\n\nThe return value will be stored as a value in the buildout parts options which\nis available for replacement in other buildout parts. What is returned is\nalways converted to a string.\n\n\nFunctions vs Constants\n----------------------\n\nOptions all in upper case are treated as string constants and added to the\nRecipe instance as an attribute. All other options will be treated as python\nfunctions.\n\nAs each option is a Python function or variable, it needs to possess an acceptable\nfunction identifier (see\nhttp://docs.python.org/reference/lexical_analysis.html#grammar-token-identifier).\nFor instance, typical buildout options with hyphens (such as\n`environment-vars`) will be invalid.\n\nSince these functions are actually methods `self` is an available local variable\nwhich refers to the recipe instance. `self.options`, `self.buildout` and\n`self.name` are available.\n\nAny option beginning with `_` is not evaluated so can be used as a\nprivate function.\n\nInit, Install and Update\n------------------------\n\nThere are three special functions which are evaluated regardless if they\nare called from another recipe and whose value isn't stored.\n\n``init``: Init is called everytime the recipe is loaded. This function allows you\nto reduce the need for\nmultiple functions that may do similar jobs, remove the need for a dummy\noption in order to execute arbitrary code (and other uses), like so::\n\n [myscripts]\n recipe = mr.scripty\n init =\n ... import math\n ... self.options['pi'] = str(math.pi)\n ... self.options['e'] = str(math.e)\n ... self.options['sqrt_two'] = str(math.sqrt(2))\n\nAfter running buildout, the options ``pi``, ``e``, and ``sqrt_two`` will all\nbe available for use against the ``myscripts`` section like so:\n``${myscripts:sqrt_two}``. See the example regarding `Offsetting port\nnumbers`_ for more information.\n\n\n``install`` is called if the arguments (functions or constants) have changed\nsince the last run or if it's never run before.\n\n``update`` is called each time (but after init)\n\nThese can be\nused as quick in-place replacement for creating a real recipe and have the\nsame semantics as detailed in\nhttp://www.buildout.org/en/latest/docs/tutorial.html?highlight=update#writing-recipes.\n\n\nBugs and Repo\n=============\n\n- Code repository: https://github.com/collective/mr.scripty\n- Questions and comments to https://github.com/collective/mr.scripty\n- Report bugs at https://github.com/collective/mr.scripty\n\nExamples\n========\n\n\nTranforming Varnish backends for HAProxy\n----------------------------------------\n\nLet's say you want to transform a ``varnish:backends`` value to what can\nbe used inside haproxy::\n\n >>> write('buildout.cfg',\n ... \"\"\"\n ... [buildout]\n ... parts = scripty echobackends echorepeat\n ...\n ... [varnish]\n ... backends =\n ... \tmyhost.com:255.255.255.1\n ... myhost2.com:125.125.125.1\n ...\n ... [scripty]\n ... recipe = mr.scripty\n ... backends =\n ... ... res = \"\"\n ... ... for line in self.buildout['varnish']['backends'].splitlines():\n ... ... if ':' not in line:\n ... ... continue\n ... ... host, dest = line.strip().split(':')\n ... ... host = host.split('.')[0]\n ... ... res += \"acl {} url_sub VirtualHostRoot/{}\\\\n\".format(host, dest)\n ... ... return res\n ... repeat =\n ... ... opt_repeatx = int('10')\n ... ... fun_repeatx = self.repeatx()\n ... ... return '\\\\n'.join([\"this is line %s\"%i for i in range(1,opt_repeatx+1)])\n ... repeatx = return '10'\n ...\n ... [echobackends]\n ... recipe = mr.scripty\n ... install = print(self.buildout['scripty']['backends']); return []\n ...\n ... [echorepeat]\n ... recipe = mr.scripty\n ... install =\n ... ... script = self.buildout['scripty']\n ... ... print(script['repeat'])\n ... ... return []\n ... \"\"\")\n\nRunning the buildout gives us::\n\n >>> print(system(buildout))\n Installing scripty.\n Installing echobackends.\n acl myhost url_sub VirtualHostRoot/255.255.255.1\n acl myhost2 url_sub VirtualHostRoot/125.125.125.1\n Installing echorepeat.\n this is line 1\n this is line 2\n this is line 3\n this is line 4\n this is line 5\n this is line 6\n this is line 7\n this is line 8\n this is line 9\n this is line 10...\n\nFrom this example you'll notice several things. Options that are part of a\n`mr.scripty` part are turned into methods of the part instance and can call\neach other. In addition, each method can be called from other buildout recipes\nby accessing the option via ``${part:method}`` or in code via\n``self.buildout[part][method]``.\n\nOffsetting port numbers\n-----------------------\n\nThe following example will make all the values of ports_base available with an\noffset added to each one. This example demonstrates the special ``init``\noption, which enables you to run a special function where the result\nis not stored against the part within buildout::\n\n [ports_base]\n instance1=8101\n instance2=8102\n\n [ports]\n recipe = mr.scripty\n OFFSET = 1000\n init =\n ... for key,value in self.buildout['ports_base'].items():\n ... self.options[key] = str(int(value)+int(self.OFFSET))\n\nSo, the usage of ``init`` enables us to create options against the ``[ports]``\nsection using arbitrary code. In the example above, this will result in all\nof the options under ``[ports_base]`` being processed to add the ``OFFSET``\nvalue to the port. The end result is that other sections of buildout can now\nreference ``${ports:instance1}`` and ``${ports:instance2}``, which will have\nvalues of 9101 and 9102 respectively.\n\nDifferent download links for certain architectures\n--------------------------------------------------\n\nThis example usage shows how to alter download links for third-party libraries\nbased upon whether the host platform is 32 or 64-bit. Note that the example\nuses Python 2.6 or later::\n\n [buildout]\n parts =\n ...\n download\n\n [scripty]\n recipe = mr.scripty\n DOWNLOAD_URL_64 = http://site.com/64bit.tgz\n DOWNLOAD_URL_32 = http://site.com/32bit.tgz\n download_url =\n ... import platform\n ... is_64bit = any(['64' in x for x in platform.architecture()])\n ... return is_64bit and self.DOWNLOAD_URL_64 or self.DOWNLOAD_URL_32\n\n [download]\n recipe = hexagonit.recipe.download\n url = ${scripty:download_url}\n\nChecking existence of directories\n---------------------------------\n\nThis example tests the existence of a list of directories and selects\nthe first one that can be found on the system. In this particular example,\nwe look through a list of potential JDK directories, as the location will\ndiffer across Linux distributions, in order to install an egg that depends\non having a Java SDK install available::\n\n [buildout]\n parts =\n ...\n jpype\n\n [scripty]\n recipe = mr.scripty\n JAVA_PATHS =\n /usr/lib/jvm/java-6-openjdk\n /etc/alternatives/java_sdk\n ${buildout:directory}\n java =\n ... import os\n ... paths = self.JAVA_PATHS.split('\\n')\n ... exists = [os.path.exists(path) for path in paths]\n ... return paths[exists.index(True)]\n\n [java-env]\n JAVA_HOME = ${scripty:java}\n\n [jpype]\n recipe = zc.recipe.egg:custom\n egg = JPype\n find-links =\n http://aarnet.dl.sourceforge.net/project/jpype/JPype/0.5.4/JPype-0.5.4.1.zip\n environment = java-env\n\nContributors\n============\n\n\"software@dylanjay.com\", Dylan Jay\n\n\nChange history\n==============\n\n1.0 (2016-11-16)\n----------------\n\n- Add support for Python 3.4. This breaks with Python 2.6 and before. [Sylvain Viollon]\n- Integrate with travis, coveralls - [abdul.maliyakkal]\n- Improve readme [djay]\n\n\n1.0b3 (2011-12-14)\n------------------\n\n- Update documentation with additional examples. [davidjb] \n- fix indenting issues [djay]\n- init is handled as special function where result isn't stored [djay]\n\n\n1.0b2 (2011-03-23)\n------------------\n\n- Allow constants if option all uppercase [djay]\n- function return values converted to strings or empty string if None [djay]\n\n\n1.0b1 (2011-03-15)\n------------------\n\n- Initial version [\"Dylan Jay\", djay]", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/collective/mr.scripty", "keywords": "buildout", "license": "ZPL", "maintainer": null, "maintainer_email": null, "name": "mr.scripty", "package_url": "https://pypi.org/project/mr.scripty/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/mr.scripty/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/collective/mr.scripty" }, "release_url": "https://pypi.org/project/mr.scripty/1.0/", "requires_dist": null, "requires_python": null, "summary": "Use python to write configuration in zc.buildout", "version": "1.0" }, "last_serial": 4706109, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "a560ff4b20fb6e50ce31b278bb4a541a", "sha256": "50f7a694cdf21c13659e2617593eae318dbeb95fc2f6280aee91c9151908fbf3" }, "downloads": -1, "filename": "mr.scripty-1.0.tar.gz", "has_sig": false, "md5_digest": "a560ff4b20fb6e50ce31b278bb4a541a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11575, "upload_time": "2016-11-16T05:17:09", "url": "https://files.pythonhosted.org/packages/28/dd/4d7d951077aef2d6f8e188977ad8c1ffb2d02da20077319731ca01b9b7bf/mr.scripty-1.0.tar.gz" } ], "1.0b1": [ { "comment_text": "", "digests": { "md5": "851aa9623319188919dde2c1b1c0ade7", "sha256": "09896d49cb00f8a7fdf97ea1011de2b930b7cbf8d7800c4dedaacb9bb4dd7250" }, "downloads": -1, "filename": "mr.scripty-1.0b1.zip", "has_sig": false, "md5_digest": "851aa9623319188919dde2c1b1c0ade7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12553, "upload_time": "2011-03-15T08:26:23", "url": "https://files.pythonhosted.org/packages/c9/3a/b12a2b0d8c14e8660d2c597fe38852534af0d8c279c15eb747cc8e40d076/mr.scripty-1.0b1.zip" } ], "1.0b2": [ { "comment_text": "", "digests": { "md5": "2f16f7d1be05168b25e489ac46a132d1", "sha256": "388b337fda1198a6cd1ae56c213a8d4a8064c0a4205788621b3a7f4cb2aba5f1" }, "downloads": -1, "filename": "mr.scripty-1.0b2.zip", "has_sig": false, "md5_digest": "2f16f7d1be05168b25e489ac46a132d1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14175, "upload_time": "2011-03-23T07:35:58", "url": "https://files.pythonhosted.org/packages/e6/cf/716b5038167e6ea089d0b8ee93f364470e8946cc8eec4010025f456f118f/mr.scripty-1.0b2.zip" } ], "1.0b3": [ { "comment_text": "", "digests": { "md5": "86d08d7de0f01bb8142500e768ec70b3", "sha256": "eab3e9fab91cb1c96f380fbbce831b7afe326a0f83bb55589bf410f932544650" }, "downloads": -1, "filename": "mr.scripty-1.0b3.tar.gz", "has_sig": false, "md5_digest": "86d08d7de0f01bb8142500e768ec70b3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7461, "upload_time": "2011-12-14T17:38:20", "url": "https://files.pythonhosted.org/packages/20/d2/4fffd84897e9a39abf4c8cab37ae4b9688c20010ed869081c11fe5b04ee5/mr.scripty-1.0b3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a560ff4b20fb6e50ce31b278bb4a541a", "sha256": "50f7a694cdf21c13659e2617593eae318dbeb95fc2f6280aee91c9151908fbf3" }, "downloads": -1, "filename": "mr.scripty-1.0.tar.gz", "has_sig": false, "md5_digest": "a560ff4b20fb6e50ce31b278bb4a541a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11575, "upload_time": "2016-11-16T05:17:09", "url": "https://files.pythonhosted.org/packages/28/dd/4d7d951077aef2d6f8e188977ad8c1ffb2d02da20077319731ca01b9b7bf/mr.scripty-1.0.tar.gz" } ] }