1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#!/usr/bin/env python
#
# Lazygal, a lazy static web gallery generator: v0.7 conf migration tool.
# Copyright (C) 2011-2012 Alexandre Rossi <alexandre.rossi@gmail.com>
#
# 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
import configparser
TRANSLATION_TABLE_07 = {
'quiet' : ('runtime', 'quiet'),
'output-directory' : ('global' , 'output-directory'),
'puburl' : ('global' , 'puburl'),
'theme' : ('global' , 'theme'),
'default-style' : ('webgal' , 'default-style'),
'clean-destination' : ('global' , 'clean-destination'),
'check-all-dirs' : ('runtime', 'check-all-dirs'),
'dir-flattening-depth': ('global' , 'dir-flattening-depth'),
'original' : ('webgal' , 'original'),
'orig-base' : ('webgal' , 'original-baseurl'),
'orig-symlink' : ('webgal' , 'original-symlink'),
'image-size' : ('webgal' , 'image-size'),
'thumbnail-size' : ('webgal' , 'thumbnail-size'),
'make-dir-zip' : ('webgal' , 'dirzip'),
'thumbs-per-page' : ('webgal' , 'thumbs-per-page'),
'pic-sort-by' : ('webgal' , 'sort-medias'),
'subgal-sort-by' : ('webgal' , 'sort-subgals'),
'quality' : ('webgal' , 'jpeg-quality'),
'optimize' : ('webgal' , 'jpeg-optimize'),
'progressive' : ('webgal' , 'jpeg-progressive'),
'webalbumpic-bg' : ('webgal' , 'webalbumpic-bg'),
}
def config_to_0_7(file_path):
oldconfig = configparser.RawConfigParser()
config_fp = open(file_path)
oldconfig.readfp(config_fp)
config_fp.close()
newconfig = configparser.RawConfigParser()
for oldkey, (new_section, new_key) in TRANSLATION_TABLE_07.items():
if oldconfig.has_option('lazygal', oldkey):
if not newconfig.has_section(new_section):
newconfig.add_section(new_section)
newconfig.set(new_section, new_key,
oldconfig.get('lazygal', oldkey))
if oldconfig.has_section('template-vars'):
newconfig.add_section('template-vars')
for tplvar in oldconfig.options('template-vars'):
newconfig.set('template-vars', tplvar,
oldconfig.get('template-vars', tplvar))
return newconfig
if __name__ == '__main__':
import sys
config_to_0_7(sys.argv[1]).write(sys.stdout)
# vim: ts=4 sw=4 expandtab
|