From 913cfc4e198b31ba806e9d8c906a0c9bff05d098 Mon Sep 17 00:00:00 2001 From: Martin Abente Date: Wed, 09 Feb 2011 20:56:51 +0000 Subject: generator enhancements --- 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 = '\n\n\nMicroformat File\n\n\n\n' -FOOTER = '\n
\n\n' - -def activity_info(bundle_id, name, version, size, url): - info = '' - info += '\n\n\n' - info += '%s\n' % bundle_id - info += '%s\n' % name - info += '%s\n' % version - info += '%s\n' % size - info += 'download\n' % url - info += '\n' - return info +HEADER = ''' + + + +Micro-format File + + + + +''' + +CONTENT = ''' + + + +''' + +FOOTER = ''' +
+%s +%s +%s +%s +download +
+ + +''' 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() -- cgit v0.9.1