Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Abente <martin.abente.lahaye@gmail.com>2011-02-09 20:56:51 (GMT)
committer Martin Abente <martin.abente.lahaye@gmail.com>2011-02-09 20:56:51 (GMT)
commit913cfc4e198b31ba806e9d8c906a0c9bff05d098 (patch)
treed4c9660e286efef2d50c67761433251a3e2d815e
parentd4eafa14a3ad12d029c6c620e0901ed7bce1b592 (diff)
generator enhancements
-rwxr-xr-xgenerator.py55
1 files changed, 39 insertions, 16 deletions
diff --git a/generator.py b/generator.py
index 3b20645..44ea7c2 100755
--- a/generator.py
+++ b/generator.py
@@ -17,6 +17,7 @@
import os
import io
+import sys
from urlparse import urljoin
from zipfile import ZipFile, is_zipfile
from ConfigParser import ConfigParser, NoOptionError
@@ -24,25 +25,43 @@ from ConfigParser import ConfigParser, NoOptionError
config = ConfigParser()
script_path = os.path.dirname(os.path.abspath(__file__))
config_path = os.path.join(script_path, 'config.ini')
-config.read(config_path)
+
+if len(config.read(config_path)) == 0:
+ print 'Can\'t load configuration file.'
+ sys.exit(-1)
ACTIVITIES_BASE_URL = config.get('server', 'base_url')
REL_ACTIVITIES_PATH = 'activities'
ABS_ACTIVITIES_PATH = os.path.join(script_path, REL_ACTIVITIES_PATH)
-HEADER = '<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html lang=\"en\">\n<head>\n<title>Microformat File</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n</head>\n<body>\n<table>'
-FOOTER = '\n</table>\n</body>\n</html>'
-
-def activity_info(bundle_id, name, version, size, url):
- info = ''
- info += '\n<tr>\n<td class="olpc-activity-info">\n'
- info += '<span class=\"olpc-activity-id\">%s</span>\n' % bundle_id
- info += '<span class=\"olpc-activity-name\">%s</span>\n' % name
- info += '<span class=\"olpc-activity-version\">%s</span>\n' % version
- info += '<span class=\"olpc-activity-size\">%s</span>\n' % size
- info += '<span class=\"olpc-activity-url\"><a href=\"%s\">download</a></span>\n' % url
- info += '</td>\n</tr>'
- return info
+HEADER = '''
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+<head>
+<title>Micro-format File</title>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+</head>
+<body>
+<table>
+'''
+
+CONTENT = '''
+<tr>
+<td class="olpc-activity-info">
+<span class="olpc-activity-id">%s</span>
+<span class="olpc-activity-name">%s</span>
+<span class="olpc-activity-version">%s</span>
+<span class="olpc-activity-size">%s</span>
+<span class="olpc-activity-url"><a href="%s">download</a></span>
+</td>
+</tr>
+'''
+
+FOOTER = '''
+</table>
+</body>
+</html>
+'''
def get_value(config, section, option, alt_option=''):
try:
@@ -75,13 +94,13 @@ def activities_info():
bundle_id = get_value(activity_config, 'Activity', 'bundle_id', 'service_name')
name = get_value(activity_config, 'Activity', 'name')
- version = get_value(activity_config, 'Activity', 'version')
+ version = get_value(activity_config, 'Activity', 'activity_version')
size = os.path.getsize(xo_bundle_abs_path)
xo_bundle_rel_path = os.path.join(REL_ACTIVITIES_PATH, activity_file)
url = urljoin(ACTIVITIES_BASE_URL, xo_bundle_rel_path)
- info += activity_info(bundle_id, name, version, size, url)
+ info += CONTENT % (bundle_id, name, version, size, url)
break
return info
@@ -89,10 +108,14 @@ def activities_info():
def main():
index_path = os.path.join(script_path, 'index.html')
index_file = open(index_path, 'w')
+
index_file.write(HEADER)
index_file.write(activities_info())
index_file.write(FOOTER)
+ index_file.close()
+
print 'index.html successfully updated.'
+ sys.exit(0)
if __name__ == "__main__":
main()