Permalink
Browse files

updated skel

  • Loading branch information...
1 parent f855ad1 commit 340ff4d0b3fe459394f1457c77b0e783469575c4 @fiorix committed Dec 11, 2012
Showing with 1,211 additions and 0 deletions.
  1. +3 −0 default/.gitignore
  2. +115 −0 default/README.md
  3. BIN default/frontend/locale/es_ES/LC_MESSAGES/modname.mo
  4. +25 −0 default/frontend/locale/es_ES/LC_MESSAGES/modname.po
  5. BIN default/frontend/locale/pt_BR/LC_MESSAGES/modname.mo
  6. +25 −0 default/frontend/locale/pt_BR/LC_MESSAGES/modname.po
  7. BIN default/frontend/static/favicon.ico
  8. +26 −0 default/frontend/template/base.html
  9. +14 −0 default/frontend/template/index.html
  10. +7 −0 default/frontend/template/post.html
  11. +40 −0 default/modname.conf
  12. +6 −0 default/modname/__init__.py
  13. +83 −0 default/modname/config.py
  14. +31 −0 default/modname/utils.py
  15. +74 −0 default/modname/views.py
  16. +38 −0 default/modname/web.py
  17. +10 −0 default/scripts/cookie_secret.py
  18. +89 −0 default/scripts/debian-init.d
  19. +112 −0 default/scripts/debian-multicore-init.d
  20. +21 −0 default/scripts/localefix.py
  21. +6 −0 default/start.sh
  22. +1 −0 foreman/.env
  23. +3 −0 foreman/.gitignore
  24. +1 −0 foreman/Procfile
  25. +120 −0 foreman/README.md
  26. BIN foreman/frontend/locale/es_ES/LC_MESSAGES/modname.mo
  27. +25 −0 foreman/frontend/locale/es_ES/LC_MESSAGES/modname.po
  28. BIN foreman/frontend/locale/pt_BR/LC_MESSAGES/modname.mo
  29. +25 −0 foreman/frontend/locale/pt_BR/LC_MESSAGES/modname.po
  30. BIN foreman/frontend/static/favicon.ico
  31. +26 −0 foreman/frontend/template/base.html
  32. +14 −0 foreman/frontend/template/index.html
  33. +7 −0 foreman/frontend/template/post.html
  34. +31 −0 foreman/modname.conf
  35. +6 −0 foreman/modname/__init__.py
  36. +71 −0 foreman/modname/config.py
  37. +20 −0 foreman/modname/main.py
  38. +34 −0 foreman/modname/utils.py
  39. +41 −0 foreman/modname/views.py
  40. +28 −0 foreman/modname/web.py
  41. +2 −0 foreman/requirements.txt
  42. +10 −0 foreman/scripts/cookie_secret.py
  43. +21 −0 foreman/scripts/localefix.py
View
@@ -0,0 +1,3 @@
+*.swp
+*.pyc
+dropin.cache
View
@@ -0,0 +1,115 @@
+# cyclone-based project
+
+ This is the source code of $project_name
+ $name <$email>
+
+## About
+
+This file has been created automatically by cyclone-tool for $project_name.
+It contains the following files:
+
+- ``start.sh``: simple shell script to start the server
+- ``$modname.conf``: configuration file for the web server
+- ``$modname/__init__.py``: information such as author and version of this package
+- ``$modname/web.py``: map of url handlers and main class of the web server
+- ``$modname/config.py``: configuration parser for ``$modname.conf``
+- ``$modname/views.py``: code of url handlers for the web server
+- ``scripts/debian-init.d``: generic debian start/stop init script
+- ``scripts/debian-multicore-init.d``: run one instance per core on debian
+- ``scripts/localefix.py``: script to fix html text before running ``xgettext``
+- ``scripts/cookie_secret.py``: script for generating new secret key for the web server
+
+### Running
+
+For development and testing:
+
+ twistd -n cyclone --help
+ twistd -n cyclone -r $modname.web.Application [--help]
+
+For production:
+
+ twistd cyclone \
+ --logfile=/var/log/$project.log \
+ --pidfile=/var/run/$project.pid \
+ -r $modname.web.Application
+
+
+### Convert this document to HTML
+
+Well, since this is a web server, it might be a good idea to convert this document
+to HTML before getting into customization details.
+
+This can be done using [markdown](http://daringfireball.net/projects/markdown/).
+
+ brew install markdown
+ markdown README.md > frontend/static/readme.html
+
+And point your browser to <http://localhost:8888/static/readme.html> after this server
+is running.
+
+## Customization
+
+This section is dedicated to explaining how to customize your brand new package.
+
+### Databases
+
+cyclone provides built-in support for SQLite and Redis databases.
+It also supports any RDBM supported by the ``twisted.enterprise.adbapi`` module,
+like MySQL or PostgreSQL.
+
+The default configuration file ``$modname.conf`` ships with pre-configured
+settings for SQLite, Redis and MySQL.
+
+The code for loading all the database settings is in ``$modname/config.py``.
+Feel free to comment or even remove such code, and configuration entries. It
+shouldn't break the web server.
+
+Take a look at ``$modname/utils.py``, which is where persistent database
+connections are initialized.
+
+
+### Internationalization
+
+cyclone uses the standard ``gettext`` library for dealing with string
+translation.
+
+Make sure you have the ``gettext`` package installed. If you don't, you won't
+be able to translate your software.
+
+For installing the ``gettext`` package on Debian and Ubuntu systems, do this:
+
+ apt-get install gettext
+
+For Mac OS X, I'd suggest using [HomeBrew](http://mxcl.github.com/homebrew>).
+If you already use HomeBrew, run:
+
+ brew install gettext
+ brew link gettext
+
+For generating translatable files for HTML and Python code of your software,
+run this:
+
+ cat frontend/template/*.html $modname/*.py | python scripts/localefix.py | \
+ xgettext - --language=Python --from-code=utf-8 --keyword=_:1,2 -d $modname
+
+Then translate $modname.po, compile and copy to the appropriate locale
+directory:
+
+ (pt_BR is used as example here)
+ vi $modname.po
+ mkdir -p frontend/locale/pt_BR/LC_MESSAGES/
+ msgfmt $modname.po -o frontend/locale/pt_BR/LC_MESSAGES/$modname.mo
+
+There are sample translations for both Spanish and Portuguese in this package,
+already compiled.
+
+
+### Cookie Secret
+
+The current cookie secret key in ``$modname.conf`` was generated during the
+creation of this package. However, if you need a new one, you may run the
+``scripts/cookie_secret.py`` script to generate a random key.
+
+## Credits
+
+- [cyclone](http://github.com/fiorix/cyclone) web server.
Binary file not shown.
@@ -0,0 +1,25 @@
+# cyclone-tools sample translation.
+# Copyright (C) 2011 Alexandre Fiori
+# This file is distributed under the same license as the cyclone package.
+# Alexandre Fiori <fiorix@gmail.com>, 2011.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: 0.1\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2011-02-24 15:36-0300\n"
+"PO-Revision-Date: 2011-02-28 15:44+-0300\n"
+"Last-Translator: Alexandre Fiori <fiorix@gmail.com>\n"
+"Language-Team: Alexandre Fiori <fiorix@gmail.com>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: standard input:5
+msgid "cyclone web server"
+msgstr "servidor web cyclone"
+
+#: standard input:8
+msgid "It works!"
+msgstr "¡Funciona!"
Binary file not shown.
@@ -0,0 +1,25 @@
+# cyclone-tools sample translation.
+# Copyright (C) 2011 Alexandre Fiori
+# This file is distributed under the same license as the cyclone package.
+# Alexandre Fiori <fiorix@gmail.com>, 2011.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: 0.1\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2011-02-24 15:36-0300\n"
+"PO-Revision-Date: 2011-02-28 15:44+-0300\n"
+"Last-Translator: Alexandre Fiori <fiorix@gmail.com>\n"
+"Language-Team: Alexandre Fiori <fiorix@gmail.com>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: standard input:5
+msgid "cyclone web server"
+msgstr "servidor web cyclone"
+
+#: standard input:8
+msgid "It works!"
+msgstr "Funciona!"
Binary file not shown.
@@ -0,0 +1,26 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title>{{_("cyclone web server")}}</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+
+ <link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
+ <link href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet">
+ <link rel="shortcut icon" type="image/ico" href="{{ static_url('favicon.ico') }}">
+ <style>
+ body {padding-top: 60px;}
+ </style>
+
+ </head>
+
+ <body>
+ <div class="container">
+ <!--
+ you can create multiple block entries per template
+ ex: sidebar, menu, footer
+ -->
+ {% block page %}{% end %}
+ </div> <!-- /container -->
+ </body>
+</html>
@@ -0,0 +1,14 @@
+{% extends 'base.html' %}
+{% block page %}
+<h1>{{_("It works!")}}</h1>
+<p><small>
+ <a href="/lang/en_US">English</a>&nbsp;
+ <a href="/lang/es_ES">Español</a>&nbsp;
+ <a href="/lang/pt_BR">Português</a>
+</small></p>
+<p>hello = {{hello}}</p>
+<p>awesome = {{awesome}}</p>
+<form class="well" method="post">
+ <button type="submit" class="btn">Post example</button>
+</form>
+{% end %}
@@ -0,0 +1,7 @@
+{% extends 'base.html' %}
+{% block page %}
+<h1>POST example</h1>
+<p>This variable exists = {{fields.ip}}</p>
+<p>This variable does not exist = {{fields.something}}</p>
+<p>This one comes from .conf = {{fields.mysql_host}}</p>
+{% end %}
View
@@ -0,0 +1,40 @@
+[server]
+debug = true
+xheaders = false
+xsrf_cookies = false
+cookie_secret = $cookie_secret
+
+[frontend]
+locale_path = frontend/locale
+static_path = frontend/static
+template_path = frontend/template
+
+[sqlite]
+enabled = yes
+database = :memory:
+
+[redis]
+enabled = no
+# unixsocket = /tmp/redis.sock
+host = 127.0.0.1
+port = 6379
+dbid = 0
+poolsize = 10
+
+[mysql]
+enabled = no
+host = 127.0.0.1
+port = 3306
+username = foo
+password = bar
+database = dummy
+poolsize = 10
+debug = no
+
+[email]
+enabled = no
+host = smtp.gmail.com
+port = 587
+tls = yes
+username = foo
+password = bar
@@ -0,0 +1,6 @@
+# coding: utf-8
+#
+$license
+
+__author__ = "$name <$email>"
+__version__ = "$version"
@@ -0,0 +1,83 @@
+# coding: utf-8
+#
+$license
+
+import os
+import sys
+import ConfigParser
+
+from cyclone.util import ObjectDict
+
+
+def tryget(func, section, option, default=None):
+ try:
+ return func(section, option)
+ except ConfigParser.NoOptionError:
+ return default
+
+
+def my_parse_config(filename):
+ cp = ConfigParser.RawConfigParser()
+ cp.read([filename])
+
+ conf = dict(raw=cp, config_file=filename)
+
+ # server settings
+ conf["debug"] = tryget(cp.getboolean, "server", "debug", False)
+ conf["xheaders"] = tryget(cp.getboolean, "server", "xheaders", False)
+ conf["cookie_secret"] = cp.get("server", "cookie_secret")
+ conf["xsrf_cookies"] = tryget(cp.getboolean,
+ "server", "xsrf_cookies", False)
+
+ # make relative path absolute to this file's parent directory
+ root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
+ getpath = lambda k, v: os.path.join(root, tryget(cp.get, k, v))
+
+ # locale, template and static directories
+ conf["locale_path"] = getpath("frontend", "locale_path")
+ conf["static_path"] = getpath("frontend", "static_path")
+ conf["template_path"] = getpath("frontend", "template_path")
+
+ # sqlite support
+ if tryget(cp.getboolean, "sqlite", "enabled", False) is True:
+ conf["sqlite_settings"] = \
+ ObjectDict(database=cp.get("sqlite", "database"))
+
+ # redis support
+ if tryget(cp.getboolean, "redis", "enabled", False) is True:
+ conf["redis_settings"] = ObjectDict(
+ unixsocket=tryget(cp.get, "redis", "unixsocket", None),
+ host=tryget(cp.get, "redis", "host", "127.0.0.1"),
+ port=tryget(cp.getint, "redis", "port", 6379),
+ dbid=tryget(cp.getint, "redis", "dbid", 0),
+ poolsize=tryget(cp.getint, "redis", "poolsize", 10))
+
+ # mysql support
+ if tryget(cp.getboolean, "mysql", "enabled", False) is True:
+ conf["mysql_settings"] = ObjectDict(
+ host=cp.get("mysql", "host"),
+ port=cp.getint("mysql", "port"),
+ username=tryget(cp.get, "mysql", "username"),
+ password=tryget(cp.get, "mysql", "password"),
+ database=tryget(cp.get, "mysql", "database"),
+ poolsize=tryget(cp.getint, "mysql", "poolsize", 10),
+ debug=tryget(cp.getboolean, "mysql", "debug", False))
+
+ # email support
+ if tryget(cp.getboolean, "email", "enabled", False) is True:
+ conf["email_settings"] = ObjectDict(
+ host=cp.get("email", "host"),
+ port=tryget(cp.getint, "email", "port"),
+ tls=tryget(cp.getboolean, "email", "tls"),
+ username=tryget(cp.get, "email", "username"),
+ password=tryget(cp.get, "email", "password"))
+
+ return conf
+
+
+def parse_config(filename):
+ try:
+ return my_parse_config(filename)
+ except Exception, e:
+ print("Error parsing %s: %s" % (filename, e))
+ sys.exit(1)
@@ -0,0 +1,31 @@
+# coding: utf-8
+#
+$license
+
+import cyclone.escape
+import cyclone.web
+
+
+class TemplateFields(dict):
+ """Helper class to make sure our
+ template doesn't fail due to an invalid key"""
+ def __getattr__(self, name):
+ try:
+ return self[name]
+ except KeyError:
+ return None
+
+ def __setattr__(self, name, value):
+ self[name] = value
+
+
+class BaseHandler(cyclone.web.RequestHandler):
+ #def get_current_user(self):
+ # user_json = self.get_secure_cookie("user")
+ # if user_json:
+ # return cyclone.escape.json_decode(user_json)
+
+ def get_user_locale(self):
+ lang = self.get_secure_cookie("lang")
+ if lang:
+ return cyclone.locale.get(lang)
Oops, something went wrong.

0 comments on commit 340ff4d

Please sign in to comment.