Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit bfdc0ed37ca73e4d09bba4a223d8cd9adea46e3b @evilsocket committed Mar 13, 2011
Showing with 3,620 additions and 0 deletions.
  1. +226 −0 LICENSE
  2. +83 −0 README
  3. 0 core/__init__.py
  4. BIN core/__init__.pyc
  5. +41 −0 core/authormanager.py
  6. BIN core/authormanager.pyc
  7. +45 −0 core/authorparser.py
  8. BIN core/authorparser.pyc
  9. +104 −0 core/categorymanager.py
  10. BIN core/categorymanager.pyc
  11. +106 −0 core/config.py
  12. BIN core/config.pyc
  13. +97 −0 core/itemparser.py
  14. BIN core/itemparser.pyc
  15. +69 −0 core/pageparser.py
  16. BIN core/pageparser.pyc
  17. +48 −0 core/tagmanager.py
  18. BIN core/tagmanager.pyc
  19. +48 −0 core/templatemanager.py
  20. BIN core/templatemanager.pyc
  21. 0 entities/__init__.py
  22. BIN entities/__init__.pyc
  23. +45 −0 entities/author.py
  24. BIN entities/author.pyc
  25. +41 −0 entities/category.py
  26. BIN entities/category.pyc
  27. +52 −0 entities/item.py
  28. BIN entities/item.pyc
  29. +60 −0 entities/page.py
  30. BIN entities/page.pyc
  31. +40 −0 entities/tag.py
  32. BIN entities/tag.pyc
  33. +12 −0 example-site.com/.htaccess
  34. +64 −0 example-site.com/css/reset.css
  35. +1,781 −0 example-site.com/css/style.css
  36. +6 −0 example-site.com/db/categories.txt
  37. +6 −0 example-site.com/db/example-author.txt
  38. +11 −0 example-site.com/db/pages/12.txt
  39. +11 −0 example-site.com/db/pages/14.txt
  40. +11 −0 example-site.com/db/pages/3.txt
  41. +11 −0 example-site.com/db/pages/7.txt
  42. +11 −0 example-site.com/db/pages/9.txt
  43. +33 −0 example-site.com/example-site.com.cfg
  44. BIN example-site.com/images/45pc_black.png
  45. BIN example-site.com/images/60pc_black.png
  46. BIN example-site.com/images/Screenshot-2-204x300.png
  47. BIN example-site.com/images/Screenshot.png
  48. BIN example-site.com/images/Screenshot1.png
  49. BIN example-site.com/images/Screenshot2.png
  50. BIN example-site.com/images/a-300x187.png
  51. BIN example-site.com/images/a1-300x187.png
  52. BIN example-site.com/images/activity_arrow.gif
  53. BIN example-site.com/images/admin-menu-arrow.gif
  54. BIN example-site.com/images/ajax-loader.gif
  55. BIN example-site.com/images/anjuta.png
  56. BIN example-site.com/images/arch-linux-logo-150x150.png
  57. BIN example-site.com/images/background.gif
  58. BIN example-site.com/images/bollino.png
  59. BIN example-site.com/images/chrome-vs-firefox.JPG
  60. BIN example-site.com/images/closed.png
  61. BIN example-site.com/images/default_header.jpg
  62. 0 example-site.com/images/facebook.png
  63. BIN example-site.com/images/fang.jpg
  64. BIN example-site.com/images/feedburner-logo-279x300.png
  65. BIN example-site.com/images/finger.png
  66. BIN example-site.com/images/git-logo.png
  67. BIN example-site.com/images/github.png
  68. BIN example-site.com/images/google_hack1-300x224.jpg
  69. BIN example-site.com/images/googlereader.png
  70. BIN example-site.com/images/headermesh.png
  71. BIN example-site.com/images/identica.png
  72. BIN example-site.com/images/img_0098.jpg
  73. 0 example-site.com/images/index.html
  74. BIN example-site.com/images/iphone_worm-300x300.jpg
  75. BIN example-site.com/images/item_back.gif
  76. BIN example-site.com/images/kind-geschenk-300x186.jpg
  77. BIN example-site.com/images/lastfm.png
  78. BIN example-site.com/images/libtest.png
  79. BIN example-site.com/images/linkedin.png
  80. BIN example-site.com/images/lock.png
  81. BIN example-site.com/images/logo_grey.jpg
  82. BIN example-site.com/images/me.jpg
  83. BIN example-site.com/images/mesh-back.jpg
  84. BIN example-site.com/images/more-196x300.png
  85. BIN example-site.com/images/mutt.png
  86. BIN example-site.com/images/mysql_logo-300x155.png
  87. BIN example-site.com/images/pdf-su-cellulari-android.jpg
  88. BIN example-site.com/images/python.png
  89. BIN example-site.com/images/replyto_arrow.gif
  90. BIN example-site.com/images/rss.png
  91. BIN example-site.com/images/sidebar_back.gif
  92. BIN example-site.com/images/spumante-300x288.jpg
  93. BIN example-site.com/images/steam_logo.jpg
  94. BIN example-site.com/images/ted_screenshot-300x240.png
  95. BIN example-site.com/images/twitter.png
  96. BIN example-site.com/images/white-grad.png
  97. BIN example-site.com/images/wikileaks-banner.jpg
  98. BIN example-site.com/images/wpshot.png
  99. +20 −0 example-site.com/templates/404.tpl
  100. +45 −0 example-site.com/templates/author.tpl
  101. +47 −0 example-site.com/templates/category.tpl
  102. +36 −0 example-site.com/templates/feed.tpl
  103. +9 −0 example-site.com/templates/footer.tpl
  104. +60 −0 example-site.com/templates/header.tpl
  105. +54 −0 example-site.com/templates/index.tpl
  106. +48 −0 example-site.com/templates/page.tpl
  107. +37 −0 example-site.com/templates/sidebar.tpl
  108. +47 −0 example-site.com/templates/sitemap.tpl
  109. +47 −0 example-site.com/templates/tag.tpl
  110. +108 −0 swg.py
226 LICENSE

Large diffs are not rendered by default.

Oops, something went wrong.
83 README
@@ -0,0 +1,83 @@
+### SWG - Static Website Generator
+Copyleft by Simone 'evilsocket' Margaritelli <evilsocket@gmail.com>
+
+### What is SWG ?
+
+SWG is a new generation static website generator, featured by the Mako (http://www.makotemplates.org/) template system, born from the need to
+have both performances and "WEB 2.0" contents and capabilities.
+
+Given a set of files, one for each page/article, one for each author and one for the categories hyerarchy, SWG will read the configuration file
+you specify from command line and generate a complete static website, with tags and categories indexing.
+
+### An example configuration file
+
+ # Path of the db, templates and so on
+ datapath = example-site.com
+ # Path of the db
+ dbpath = example-site.com/db
+ # DB files extension
+ dbitem_ext = txt
+ # Category hierarchy file
+ hierarchy = example-site.com/db/categories.txt
+ # Templates path
+ tplpath = example-site.com/templates
+ # Template cache path
+ tplcache = example-site.com/cache
+ # URL of the site you are going to generate
+ siteurl = http://www.example-site.com
+ # Site name / description
+ sitename = An example site generated by SWG
+ # Site charset
+ charset = utf-8
+ # Site language
+ language = it
+ # Comma separated site keywords
+ keywords = some, html, keywords, here
+ # Site destination basepath
+ basepath =
+ # Site page files output extension
+ page_ext = html
+ # Generated site output path
+ outputpath = out
+ # Items (dirs or files) to copy from datapath to outputpath (eg. static files, css, etc)
+ copypaths = css, images, .htaccess
+
+Pretty self explanatory isn't it ? :)
+
+### Example project
+
+You will find an example site in the example-site.com directory, with templates, db and everything else you need to start.
+
+To start a test generation run:
+
+ python swg.py example-site.com/example-site.com.cfg
+
+You will have an output like:
+
+ - SWG 1.0.0 by Simone 'evilsocket' Margaritelli <evilsocket@gmail.com> -
+
+ @ Parsing pages ...
+ @ Sorting pages by date ...
+ @ Creating 'out' path ...
+ @ Importing 'example-site.com/images' to 'out/images' ...
+ @ Importing 'example-site.com/.htaccess' to 'out/.htaccess' ...
+ @ Importing 'example-site.com/css' to 'out/css' ...
+ @ Creating index file ...
+ @ Creating 404 file ...
+ @ Creating sitemap.xml file ...
+ @ Creating feed.xml file ...
+ @ Rendering 5 pages ...
+ @ DONE
+
+Then upload the contents of 'out' directory to your web server to see the example site.
+If you want to test it locally on your machine, you will have to change the line :
+
+ siteurl = http://www.example-site.com
+
+In the configuration file to something like:
+
+ siteurl = file:///your/project/path/out
+
+And then simply open 'out/index.html' with your preferred web browser.
+
+Enjoy ^^
No changes.
Binary file not shown.
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+# This file is part of SWG (Static Website Generator).
+#
+# Copyright(c) 2010-2011 Simone Margaritelli
+# evilsocket@gmail.com
+# http://www.evilsocket.net
+# http://www.backbox.org
+#
+# This file may be licensed under the terms of of the
+# GNU General Public License Version 2 (the ``GPL'').
+#
+# Software distributed under the License is distributed
+# on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
+# express or implied. See the GPL for the specific language
+# governing rights and limitations.
+#
+# You should have received a copy of the GPL along with this
+# program. If not, go to http://www.gnu.org/licenses/gpl.html
+# or write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+from core.authorparser import AuthorParser
+from core.config import Config
+
+class AuthorManager:
+ __instance = None
+
+ def __init__(self):
+ self.authors = {}
+
+ def get( self, username ):
+ id = username.lower()
+ if not self.authors.has_key(id):
+ self.authors[id] = AuthorParser().parse( Config.getInstance().dbpath + ("/%s.%s" % (username,Config.getInstance().dbitem_ext)) )
+
+ return self.authors[id]
+
+ @classmethod
+ def getInstance(cls):
+ if cls.__instance is None:
+ cls.__instance = AuthorManager()
+ return cls.__instance
Binary file not shown.
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+# This file is part of SWG (Static Website Generator).
+#
+# Copyright(c) 2010-2011 Simone Margaritelli
+# evilsocket@gmail.com
+# http://www.evilsocket.net
+# http://www.backbox.org
+#
+# This file may be licensed under the terms of of the
+# GNU General Public License Version 2 (the ``GPL'').
+#
+# Software distributed under the License is distributed
+# on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
+# express or implied. See the GPL for the specific language
+# governing rights and limitations.
+#
+# You should have received a copy of the GPL along with this
+# program. If not, go to http://www.gnu.org/licenses/gpl.html
+# or write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+from itemparser import ItemParser
+from entities.author import Author
+
+class AuthorParser(ItemParser):
+ MANDATORY_FIELDS = {
+ 'username' : 'string',
+ 'avatar' : 'string',
+ 'email' : 'string',
+ 'website' : 'string'
+ }
+
+ def __init__(self):
+ ItemParser.__init__(self)
+
+ def parse( self, filename ):
+ ItemParser.parse( self, AuthorParser.MANDATORY_FIELDS, filename )
+
+ object = Author( self.info['username'] )
+ object.avatar = self.info['avatar']
+ object.email = self.info['email']
+ object.website = self.info['website']
+ object.content = self.body
+ object.abstract = self.abstract
+
+ return object
Binary file not shown.
@@ -0,0 +1,104 @@
+# -*- coding: utf-8 -*-
+# This file is part of SWG (Static Website Generator).
+#
+# Copyright(c) 2010-2011 Simone Margaritelli
+# evilsocket@gmail.com
+# http://www.evilsocket.net
+# http://www.backbox.org
+#
+# This file may be licensed under the terms of of the
+# GNU General Public License Version 2 (the ``GPL'').
+#
+# Software distributed under the License is distributed
+# on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
+# express or implied. See the GPL for the specific language
+# governing rights and limitations.
+#
+# You should have received a copy of the GPL along with this
+# program. If not, go to http://www.gnu.org/licenses/gpl.html
+# or write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+from entities.category import Category
+from core.config import Config
+import codecs
+
+class CategoryManager:
+ __instance = None
+
+ def __init__(self):
+ self.categories = {}
+ self.hierarchy = []
+
+ def get( self, title = None ):
+ if title != None:
+ id = title.lower()
+ if not self.categories.has_key(id):
+ self.categories[id] = Category(title)
+
+ return self.categories[id]
+ else:
+ if self.hierarchy == []:
+ self.__build_hierarchy()
+
+ return self.hierarchy
+
+ def __find_category( self, title ):
+ for category in self.categories.values():
+ if category.title == title:
+ return category
+ return None
+
+ def __find_in_hyerarchy( self, title, node ):
+ if node.title == title:
+ return node
+
+ for child in node.children:
+ if child.title == title:
+ return child
+ else:
+ found = self.__find_in_hyerarchy( title, child )
+ if found != None:
+ return found
+
+ return None
+
+ def __build_hierarchy(self):
+ fd = codecs.open( Config.getInstance().hierarchy, "r", "utf-8" )
+
+ for line in iter(fd):
+ line = line.strip()
+ if line != '':
+ if ':' in line:
+ ( root, children ) = line.split( ':', 1 )
+ root = root.strip()
+ children = children.strip().split(',')
+ children = map( lambda s: s.strip(), children )
+ else:
+ root = line
+ children = []
+
+ h_root = None
+
+ for category in self.hierarchy:
+ h_root = self.__find_in_hyerarchy( root, category )
+ if h_root != None:
+ break
+
+ if h_root == None:
+ h_root = self.__find_category(root)
+ if h_root != None:
+ self.hierarchy.append(h_root)
+
+ for child in children:
+ h_child = self.__find_category(child)
+ if h_root is not None and h_child is not None:
+ h_root.children.append(h_child)
+
+
+ fd.close()
+
+ @classmethod
+ def getInstance(cls):
+ if cls.__instance is None:
+ cls.__instance = CategoryManager()
+ return cls.__instance
Binary file not shown.
@@ -0,0 +1,106 @@
+# -*- coding: utf-8 -*-
+# This file is part of SWG (Static Website Generator).
+#
+# Copyright(c) 2010-2011 Simone Margaritelli
+# evilsocket@gmail.com
+# http://www.evilsocket.net
+# http://www.backbox.org
+#
+# This file may be licensed under the terms of of the
+# GNU General Public License Version 2 (the ``GPL'').
+#
+# Software distributed under the License is distributed
+# on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
+# express or implied. See the GPL for the specific language
+# governing rights and limitations.
+#
+# You should have received a copy of the GPL along with this
+# program. If not, go to http://www.gnu.org/licenses/gpl.html
+# or write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+import datetime
+import codecs
+
+class Config:
+ __instance = None;
+
+ def __init__(self):
+ self.version = "1.0.0"
+
+ self.now = datetime.datetime.now()
+
+ self.datapath = "data"
+
+ self.dbpath = self.datapath + "/db"
+ self.dbitem_ext = "txt"
+ self.hierarchy = self.dbpath + "/categories." + self.dbitem_ext
+
+ self.tplpath = self.datapath + "/templates"
+ self.tplcache = self.datapath + "/cache"
+
+ self.siteurl = ""
+ self.sitename = "Generated with SWG " + self.version
+ self.charset = "utf-8"
+ self.language = "en"
+ self.keywords = []
+
+ self.basepath = ""
+ self.page_ext = "html"
+
+ self.outputpath = "output"
+
+ self.copypaths = {}
+
+ def load( self, filename ):
+ fd = codecs.open( filename, "r", "utf-8" )
+
+ for line in iter(fd):
+ line = line.strip()
+ if line != '' and line[0] != '#':
+ (key,value) = line.split( '=', 1 )
+ key = key.strip()
+ value = value.strip()
+ if key == 'datapath':
+ self.datapath = value
+ elif key == 'dbpath':
+ self.dbpath = value
+ elif key == 'dbitem_ext':
+ self.dbitem_ext = value
+ elif key == 'hierarchy':
+ self.hierarchy = value
+ elif key == 'tplpath':
+ self.tplpath = value
+ elif key == 'tplcache':
+ self.tplcache = value
+ elif key == 'siteurl':
+ self.siteurl = value
+ elif key == 'sitename':
+ self.sitename = value
+ elif key == 'charset':
+ self.charset = value
+ elif key == 'language':
+ self.language = value
+ elif key == 'basepath':
+ self.basepath = value
+ elif key == 'page_ext':
+ self.page_ext = value
+ elif key == 'outputpath':
+ self.outputpath = value
+ elif key == 'copypaths':
+ items = value.split(',')
+ items = map( lambda s: s.strip(), items )
+ for item in items:
+ self.copypaths[ self.datapath + '/' + item ] = self.outputpath + '/' + item
+ elif key == 'keywords':
+ items = value.split(',')
+ self.keywords = map( lambda s: s.strip(), items )
+ else:
+ raise Exception( "Unknown configuration key '%s'" % key )
+
+ fd.close()
+
+ @classmethod
+ def getInstance(cls):
+ if cls.__instance is None:
+ cls.__instance = Config()
+ return cls.__instance
Binary file not shown.
Oops, something went wrong.

0 comments on commit bfdc0ed

Please sign in to comment.