Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

This first commit goes out to a very special lady.

  • Loading branch information...
commit c873988e2c4005aa7cc9357be9a0e96c6b8fac08 0 parents
@fish2000 authored
11 .gitignore
@@ -0,0 +1,11 @@
+.DS_Store
+Icon*
+
+viron.egg-info/
+dist/
+build/
+src/scripts/
+
+MANIFEST
+*.pyc
+*.pyo
3  MANIFEST.in
@@ -0,0 +1,3 @@
+include README.md
+include src/viron/*
+
64 README.md
@@ -0,0 +1,64 @@
+
+VIRON
+=====
+
+A dead-stupid templating utility script that simple-mindedly replaces
+$ENVIRONMENT_VARIABLE-ishy tokens with the contents of the environment
+variable of the same name. By "-ishy" I mean "the subset of environment
+variables whose names you can express with only capital letters, plus numerals
+and underscores after the first character".
+
+E.g.:
+
+ $YOU_CAN_USE_ME
+ $I2MOK
+ $_NO_DICE_IN_MY_CASE
+ $IWontFlyEither
+
+Viron handles curly-braces and backslash escapes for dollar signs work as you have
+no doubt come to expect, e.g.:
+
+ $I_BECOME_MY_CONTENT
+ \$WHEREAS_I_REMAIN_UNAFFECTED
+ ${I_LOVE_YOU}BUT_I_HAVE_BOUNDARIES
+
+Viron works hard to be this straightforardly stupid. For example, Viron is implemented
+on top of the python standard-lib [string.Template class](http://docs.python.org/release/2.5.2/lib/node40.html), which idiotically takes
+the liberty ofturning any occurances of doubled-up dollar signs (or '$$') into
+a single dollar sign (to wit, '$') that it encounters while templating... Viron
+specifically lacks this nonsensical 'feature'.
+
+Conversely, the stdlib templater's vexing ignorance of the backslash prefix to mean
+"this token is stripped of its power by my fiat, fuck the standard semiotic intent"
+by nearly all contemporary civilized programming languages. The idea is that Viron
+doesn't want to over-explain itself, so anything consistent with the "environment-variable
+template syntax" concept is in, like backslashes; notions requiring
+additional bullet points have been cut, with the most ruthless vetos going to
+questionable shit like "silently fucking with the number of dollar signs in your
+file in a way you might not immediately notice" and suchlike.
+
+And so yeah, this was a very deliberate "software architecture" decision, so you can
+relax right now and go about your business without worrying if I have heard of one
+of the other eleventy billion scripts, tools, frameworks, plug-ins, or thingees that
+accomplish this exact task except better or moreso or someshit. Viron isn't some
+kind of freakish zombified imperative markup like [HAML](http://haml-lang.com/), nor is it something wittily
+elegant that up and becomes a gosh-darned de-facto standard, such as for example
+[Mustache](http://mustache.github.com/). It's just dumb ol' environment variables in text files -- truth be told,
+I didn't even want to write it, but I keept needing it and none of the other solutions
+were stupid enough.
+
+And so! That said, I do love you and your contributions to open source, so please do
+feel free to fork it up and subsequently request pulls, I would be thrilled at any
+work you may have to contribute! I'm not even gonna say no if you take it the other
+way entirely and send me a patch titled "Viron is now turing-complete and implements
+semantically legible Oauth2 and free foot-rubs" I will probably totally accept it.
+Realistically, you're going to hack on stuff with more cachét, like e.g.
+
+ * demoing a realtime notification framework and protocol that uses at least three NoSQL stores simultaneously
+ * sharing clever Haskell type-inference schemes with other people who also write clever Haskell type-inference schemes
+ * not subclassing NSActionCell, staying in denial by writing convenience methods all day and only touching your app's mongoloid UI in the simulator
+ * punching Rasmus Lerdorf in the kidneys (q.v. backslash note ¶4 [supra])
+ * "writing" incoherent and Byzantine Oauth2 examples that do not clarify the issue or condescend to explain what all the bits are, why in fuck those bits are there, or why they are fucking different from some (but not all) of the bits on this other different Oauth2 example over here
+ * pair-programming behavior-driven domain-specific social-graph microframeworks pivoting on a responsive user-experience, in the cloud
+
+... So but if Viron can actually work for you, I am quite literally and unsarcastically thrilled on your behalf -- do let me know, and salud.
72 setup.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# VIRON -- Put environment variables in text file templates.
+#
+# Copyright © 2012 Alexander Bohn
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import os, os.path
+name = 'viron'
+version = '0.8.0'
+packages = []
+description = 'Put environment variables in text file templates.'
+keywords = 'python environment variable simple template text'
+
+classifiers = [
+ 'Development Status :: 5 - Production/Stable']
+
+try:
+ from setuptools import setup
+except ImportError:
+ from distutils.core import setup
+
+import shutil
+if not os.path.exists('src/scripts'):
+ os.makedirs('src/scripts')
+shutil.copyfile('src/viron/viron.py', 'src/scripts/viron')
+os.chmod('src/scripts/viron', 0755)
+
+setup(
+ name=name, version=version, description=description,
+ download_url = 'http://github.com/fish2000/%s/zipball/master' % name,
+
+ author=u"Alexander Bohn",
+ author_email='fish2000@gmail.com',
+ url='http://github.com/fish2000/%s/' % name,
+ license='GPLv2',
+
+ keywords=keywords,
+ platforms=['any'],
+ packages=['viron'],
+ package_dir={'viron': 'src/viron' },
+ package_data={},
+ scripts={
+ 'src/scripts/viron': 'viron' },
+
+ install_requires=[
+ 'argparse',
+ 'argh'],
+
+ classifiers=classifiers+[
+ 'License :: OSI Approved :: GNU General Public License (GPL)',
+ 'Operating System :: MacOS',
+ 'Operating System :: Microsoft :: Windows',
+ 'Operating System :: OS Independent',
+ 'Operating System :: POSIX',
+ 'Operating System :: Unix',
+ 'Programming Language :: Python :: 2.6'],
+)
0  src/viron/__init__.py
No changes.
128 src/viron/viron.py
@@ -0,0 +1,128 @@
+#!/usr/bin/env python
+# encoding: utf-8
+"""
+VIRON -- Put environment variables in text file templates.
+
+The VIRON License Agreement (MIT License)
+------------------------------------------
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Copyright © 2012 Alexander Bohn.
+This software is licensed under the terms of the GNU General Public
+License version 2 as published by the Free Software Foundation.
+
+"""
+import sys, os, re
+from string import Template
+from argh import ArghParser, command, arg
+
+@command
+def text(swaptext, swapdic=os.environ, dumpstride=3):
+
+ """ Simplistically replace any and all environment-variable-esque
+ $VAR_LABEL declarations in `swaptext` with content, as per the
+ `swapdic` mapping, *qua* said declared labels. """
+
+ matcher = r'(?<!\\)\${1}([A-Z][A-Z0-9_]+)'
+ bracedmatcher = r'(?<!\\)\${1}\{([A-Z][A-Z0-9_]+)\}'
+ swapmapper = lambda envname: envname and (envname, swapdic.get(envname, envname)) or ''
+
+ envs = dict(map(swapmapper,
+ re.compile(matcher).findall(swaptext)))
+ envs.update(dict(map(swapmapper,
+ re.compile(bracedmatcher).findall(swaptext))))
+
+ strays = set(envs.keys()).difference(swapdic.keys())
+
+ for stray in strays:
+ print >>sys.stderr, "Warning: unmapped template label %s" % stray
+
+ if len(strays) > 0:
+ valids = sorted(swapdic.keys(), key=lambda v: len(v))
+ strident = "%%-%ds" % len(list(reversed(valids))[0])
+ print >>sys.stderr, "Valid template labels are:\n"
+ for stride in [valids[i:dumpstride+i] for i in xrange(0, len(valids), dumpstride)]:
+ print >>sys.stderr, ": ".join([strident % step for step in stride])
+
+ return Template(
+ re.sub(r'(\$+?)(?![A-Z0-9\{]+?)', '\g<0>\g<1>', swaptext,
+ flags=re.MULTILINE)).safe_substitute(**envs)
+
+@arg('pth', help="File path from which to load text for viron agumentation")
+def filepath(args):
+ try:
+ with open(args.pth, 'r') as filepth:
+ return text(filepth.read())
+ except IOError, err:
+ print >>sys.stderr, "File path %s is totally invalid." % pth
+ print >>sys.stderr, unicode(err).encode('UTF-8')
+ sys.exit(1)
+
+p = ArghParser()
+p.add_commands([text, filepath])
+
+if __name__ == "__main__":
+ yodogg = """
+
+ DEBUG = True
+
+ TM_SELECTED_FILE = $TM_SELECTED_FILE
+ COMMAND_MODE = $COMMAND_MODE
+ TM_PROJECT_FILEPATH = $TM_PROJECT_FILEPATH
+ DJANGO_SETTINGS_MODULE = $DJANGO_SETTINGS_MODULE
+
+ $
+
+ import os
+ virtualpath = lambda *pths: os.path.join('$VIRTUAL_ENV', *pths)
+
+ HOME = \$HOME
+
+ SECURITYSESSIONID = ${SECURITYSESSIONID}
+ PYTHONPATH = ${PYTHONPATH}DOGG
+
+ $ $ $
+ $$ $$$ $$$$
+
+ ${
+
+
+ DATABASES = {
+ "default": {
+ # Ends with "postgresql_psycopg2", "mysql", "sqlite3" or "oracle".
+ "ENGINE": "django.db.backends.sqlite3",
+ # DB name or path to database file if using sqlite3.
+ "NAME": "dev-$INSTANCE_NAME.db",
+ # Not used with sqlite3.
+ "USER": "",
+ # Not used with sqlite3.
+ "PASSWORD": "",
+ # Set to empty string for localhost. Not used with sqlite3.
+ "HOST": "",
+ # Set to empty string for default. Not used with sqlite3.
+ "PORT": "",
+ }
+ }
+
+ """
+ p.dispatch(argv=['text', yodogg])
Please sign in to comment.
Something went wrong with that request. Please try again.