{ "info": { "author": "Rob Madole", "author_email": "robmadole@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Framework :: Django", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent" ], "description": "django-sunset\n=============\n\nDjango Sunset makes working with Django settings in a team environment or a\nmulti-server deployment a bit easier.\n\nThe basic idea is that you separate your settings modules and based on the\n**hostname** of the machine you are running on, do the appropriate thing.\n\nInstallation\n------------\n\nUsing Pip:\n\n::\n\n pip install django-sunset\n\nOr ``easy_install`` if you don't have Pip:\n\n::\n\n easy_install django-sunset\n\nBasic Usage\n-----------\n\nWhen you create a new project in Django a Python module called ``settings`` (a\nfile called ``settings.py``) holds all the configuration for how your project\nwill operate.\n\nIf you are new to Django, `this tutorial\n`_ can get you started.\n\nStart with a new project (``django-admin.py startproject mysite``)::\n\n mysite/\n __init__.py\n manage.py\n settings.py\n urls.py\n\n\nRename the ``settings.py`` file to ``settingsbase.py`` ::\n\n mysite/\n __init__.py\n manage.py\n settingsbase.py\n urls.py\n\nLet's find out what your current hostname is ::\n\n $ python -c 'import os; print os.uname()[1]'\n rob-madoles-macbook-pro.local\n\nMine is ``rob-madoles-macbook-pro.local``. Throughout the examples I'll use\nthis, substitute your own where appropriate.\n\nNow create ``settings.py`` with the following contents ::\n\n from sunset import api\n\n import settingsbase\n api.collect(settingsbase)\n\n api.roles(\n api.dev('rob-madoles-macbook-pro'))\n\n from sunset.collection import *\n\nWe should have this ::\n\n mysite/\n __init__.py\n manage.py\n settings.py\n settingsbase.py\n urls.py\n\nKick Django off something like this ::\n\n $ ./manage.py shell\n Python 2.7 (r27:82500, Aug 16 2010, 15:13:20)\n [GCC 4.2.1 (Apple Inc. build 5664)] on darwin\n Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n (InteractiveConsole)\n >>>\n\nLook again and you should see a ``settingslocal.py``. It's empty but a comment\nat the top to indicate you place your local settings here. ::\n\n mysite/\n __init__.py\n manage.py\n settings.py\n settingsbase.py\n settingslocal.py\n urls.py\n\nSince these settings are local to only your machine, you probably don't want\nthem in the repository. Add it to ``.gitignore`` or ``.hgignore`` or whatever\nequivalent ignore file you have.\n\nGo ahead and make some changes in there, how about we change the database?\n\nEdit ``settingslocal.py`` ::\n\n DEBUG = True\n\n DATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': 'database.db',\n }\n }\n\nRun the Django shell again and inspect the value ::\n\n $ ./manage.py shell\n Python 2.7 (r27:82500, Aug 16 2010, 15:13:20)\n [GCC 4.2.1 (Apple Inc. build 5664)] on darwin\n Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n (InteractiveConsole)\n >>> from django.conf import settings\n >>> print settings.DATABASES['default']['ENGINE']\n django.db.backends.sqlite3\n >>> print settings.DATABASES['default']['NAME']\n database.db\n\nGreat, you have local settings now and you don't have to touch the main\n``settings.py`` file.\n\nBase your local settings on a template\n--------------------------------------\n\nLet's take what we have in the previous example and expand a bit on it. For our\nteam we have quite a few settings and a template would be nicer to start with\ninstead of an empty file.\n\nEdit ``settings.py`` with the following contents ::\n\n from sunset import api\n\n import settingsbase\n api.collect(settingsbase)\n\n import settingsdev\n api.dev_template(settingsdev)\n\n api.roles(\n api.dev('rob-madoles-macbook-pro'))\n\n from sunset.collection import *\n\nWe are adding this ::\n\n import settingsdev\n api.dev_template(settingsdev)\n\nCreate an empty file called ``settingsdev.py`` ::\n\n touch settingsdev.py\n\nMake the contents of ``settingsdev.py`` to this ::\n\n DEBUG = True\n\n DATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': 'database.db',\n }\n }\n\n FACEBOOK_APP_ID = ''\n FACEBOOK_APP_SECRET = ''\n FACEBOOK_API_KEY = ''\n\nThat works better, each developer will not have to repeat the same typing.\n\nRemove your ``settingslocal.py`` so Django Sunset can recreate it for you.\n::\n\n rm settingslocal.py\n\nAnd again load up the Django shell ::\n\n $ ./manage.py shell\n Python 2.7 (r27:82500, Aug 16 2010, 15:13:20)\n [GCC 4.2.1 (Apple Inc. build 5664)] on darwin\n Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n (InteractiveConsole)\n\nIf you look at ``settingslocal.py`` now you'll see the extra goodies.\n\nSettings for deployment or production\n-------------------------------------\n\nSettings for developers are one thing, they change often and are not usually\ntracked in a VCS.\n\nServers are a different story. You usually control these pretty closely and\nchange them seldom once they are running.\n\nSo for deployments the syntax is a bit different.\n\nCreate a directory called ``deployments`` and a file called ``web01.py`` ::\n\n mkdir deployments\n touch deployments/__init__.py\n touch deploymnets/web01.py\n\nEdit ``settings.py`` with the following contents ::\n\n from sunset import api\n\n import settingsbase\n api.collect(settingsbase)\n\n import settingsdev\n api.dev_template(settingsdev)\n\n from deployments import web01\n\n api.roles(\n api.dev('rob-madoles-macbook-pro')\n api.deployment('web01', web01)\n )\n\n from sunset.collection import *\n\nNotice that the ``api.deployment`` constructor takes 2 arguments. The first is\nthe partial hostname, the second is the module that will be added to the\ncollection of settings if the hostname matches.\n\nNow you can edit the ``web01.py`` file and change whatever settings you like.\n\nAs a bonus, it's easy to impersonate a deployed server locally. Simply set your\nhostname as a deployment.\n\n::\n\n api.roles(\n #api.dev('rob-madoles-macbook-pro')\n api.deployment('rob-madoles-macbook-pro', web01)\n api.deployment('web01', web01)\n )\n\n\nIn the case that you have a deployment to the cloud and do not know the hostname\nthat you code will be sitting in you can simply set the ignore_missing flag.\n\n::\n\n from sunset import api\n\n import settingsbase\n api.collect(settingsbase)\n\n import settingsdev\n api.dev_template(settingsdev)\n\n from deployments import web01\n from delpoyments import cloud\n\n api.collect(cloud)\n\n api.roles(\n api.dev('rob-madoles-macbook-pro'),\n api.deployment('web01', web01),\n ignore_missing=True)\n\n from sunset.collection import *\n\nUsing one module for a group of settings\n----------------------------------------\n\nWith Django Sunset you can separate your settings by hostname but there are\nstill situations where this isn't always the best method.\n\nFor example, let's say one developer is responsible for setting up the Facebook\nAPI keys for the team. She's gone into Facebook and spent the last half-hour\nmaking Applications and editing configurations.\n\nInstead of emailing everyone their keys, app id's and secrets she can create one\nmodule that houses them all.\n\nEdit ``settings.py`` with the following contents ::\n\n from sunset import api\n\n import settingsbase\n api.collect(settingsbase)\n\n import settingsdev\n api.collect(settingsdev)\n\n from deployments import web01\n\n from deployments import facebook\n api.collect(facebook)\n\n api.roles(\n api.dev('rob-madoles-macbook-pro')\n api.deployment('web01', web01)\n )\n\n from sunset.collection import *\n\nWhat we've added here is ::\n\n from deployments import facebook\n api.collect(facebook)\n\nNow let's create ``deployments/facebook.py`` with the following contents ::\n\n from sunset.api import hostname_like\n\n if hostname_like('rob-madoles-macbook-pro'):\n FACEBOOK_APP_ID = '13782914721428'\n FACEBOOK_APP_SECRET = 'asdfh8a7f8f2238a8s7d68f72'\n FACEBOOK_API_KEY = '8a7f79829f6a6ft0aygafkgsdaf86t4ugyagtf8'\n\n if hostname_like('ted-jones-macbook-pro'):\n FACEBOOK_APP_ID = '8723849237428'\n FACEBOOK_APP_SECRET = '8ffa23jk4fa9f34af3498afhf4'\n FACEBOOK_API_KEY = '123h129318hf91uwhd1937g8163g817317gd817'\n\n if hostname_like('web01', 'web02', 'web03'):\n FACEBOOK_APP_ID = '8723849237428'\n FACEBOOK_APP_SECRET = '8ffa23jk4fa9f34af3498afhf4'\n FACEBOOK_API_KEY = '123h129318hf91uwhd1937g8163g817317gd817'\n\nSo now this module performs the hostname matching internally instead of relying\non the roles. Also notice how ``hostname_like`` can take multiple arguments\nwhere if any of the hostnames match the settings will be applied.\n\nThe developer still has the opportunity to override the settings from the\n``facebook`` module in their own ``settingslocal``. The order in which API\ncalls happen within the ``settings`` module is preserved.\n\nQuestions and issues\n--------------------\n\nPlease enter issues in `GitHub `_ or you can email me directory robmadole@gmail.com.\n\n\nNews\n====\n\n0.3\n---\n\n*Release data: 31-Mar-2011*\n\n* Added ignore_missing keyword argument, will not complain about a hostname missing from the roles (thanks Travis Chase supercodepoet)\n\n0.2\n---\n\n*Release date: 24-Nov-2010*\n\n* Updated documentation errors regarding dev templates (thanks Guntis Strazds)\n* Updated roles module to support running Django from within the project (again thanks to Guntis)\n* Python 2.7, 2.6, and 2.5 support\n\n0.1\n---\n\n*Release date: 05-Nov-2010*\n\n* Initial release", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/robmadole/django-sunset", "keywords": "django settings", "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "django-sunset", "package_url": "https://pypi.org/project/django-sunset/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-sunset/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/robmadole/django-sunset" }, "release_url": "https://pypi.org/project/django-sunset/0.3/", "requires_dist": null, "requires_python": null, "summary": "Handle Django settings in a bit more organized fashion", "version": "0.3" }, "last_serial": 743780, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "e0377be69415ff767e8cdb26de8560db", "sha256": "036a46fb97e3e13b7e68986fcd348cc40f3fae11b6d4400adb4dcceee202adb6" }, "downloads": -1, "filename": "django-sunset-0.1.tar.gz", "has_sig": false, "md5_digest": "e0377be69415ff767e8cdb26de8560db", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9052, "upload_time": "2010-11-05T16:38:29", "url": "https://files.pythonhosted.org/packages/ee/4a/658334041dde0943266d290354eab2d8a232b257dc296923b3fb18ce826e/django-sunset-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "1add9f38ed479c44889d56543f65bc1b", "sha256": "ac3181d7f1bd52a7332e0f888c4fda03a7bded69d0e81d0ec4e5d7f043e53e0c" }, "downloads": -1, "filename": "django-sunset-0.2.tar.gz", "has_sig": false, "md5_digest": "1add9f38ed479c44889d56543f65bc1b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11919, "upload_time": "2010-11-24T21:21:26", "url": "https://files.pythonhosted.org/packages/f4/e6/1fedddbd62a3bb5c8498bc3acdd578065566f40f78241202d47d608712cc/django-sunset-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "1a35d8dc904d7a8f145c566a7933877f", "sha256": "eef6fae77888621ad3d541e3b2c24c28253adaff053759b1021f1f7f09b9a543" }, "downloads": -1, "filename": "django-sunset-0.3.tar.gz", "has_sig": false, "md5_digest": "1a35d8dc904d7a8f145c566a7933877f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9649, "upload_time": "2011-03-31T15:41:11", "url": "https://files.pythonhosted.org/packages/6a/d3/3d545d3dff7ad1dabe6d30291c461bf50f95081e9eab72b09b5811d0d845/django-sunset-0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1a35d8dc904d7a8f145c566a7933877f", "sha256": "eef6fae77888621ad3d541e3b2c24c28253adaff053759b1021f1f7f09b9a543" }, "downloads": -1, "filename": "django-sunset-0.3.tar.gz", "has_sig": false, "md5_digest": "1a35d8dc904d7a8f145c566a7933877f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9649, "upload_time": "2011-03-31T15:41:11", "url": "https://files.pythonhosted.org/packages/6a/d3/3d545d3dff7ad1dabe6d30291c461bf50f95081e9eab72b09b5811d0d845/django-sunset-0.3.tar.gz" } ] }