Commit | Line | Data |
---|---|---|
111a9752 CAW |
1 | # GNU MediaGoblin -- federated, autonomous media hosting |
2 | # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. | |
3 | # | |
4 | # This program is free software: you can redistribute it and/or modify | |
5 | # it under the terms of the GNU Affero General Public License as published by | |
6 | # the Free Software Foundation, either version 3 of the License, or | |
7 | # (at your option) any later version. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU Affero General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | ||
17 | import os | |
18 | ||
19 | from mediagoblin.init import setup_global_and_app_config | |
20 | from mediagoblin.tools.theme import register_themes | |
21 | ||
22 | ||
23 | def theme_parser_setup(subparser): | |
24 | theme_subparsers = subparser.add_subparsers( | |
25 | dest=u"subcommand", | |
26 | help=u'Theme sub-commands') | |
27 | ||
28 | # Install command | |
29 | install_parser = theme_subparsers.add_parser( | |
30 | u'install', help=u'Install a theme to this mediagoblin instance') | |
31 | install_parser.add_argument( | |
32 | u'themefile', help=u'The theme archive to be installed') | |
33 | ||
34 | # # Uninstall command | |
35 | # theme_subparsers.add_parser( | |
36 | # u'uninstall', | |
37 | # help=u'Uninstall a theme... will default to the current theme.') | |
38 | ||
39 | # # List command | |
40 | # theme_subparsers.add_parser( | |
41 | # u'list', help=u'List installed themes') | |
42 | ||
43 | # Set theme command | |
44 | ||
45 | # Link theme assets command | |
46 | ||
47 | theme_subparsers.add_parser( | |
48 | u'assetlink', | |
49 | help=( | |
50 | u"Link the currently installed theme's assets " | |
51 | u"to the served theme asset directory")) | |
52 | ||
53 | ||
54 | def assetlink(args): | |
55 | """ | |
56 | Link the asset directory of the currently installed theme | |
57 | """ | |
58 | global_config, app_config = setup_global_and_app_config(args.conf_file) | |
59 | theme_registry, current_theme = register_themes(app_config) | |
60 | ||
61 | if current_theme is None: | |
62 | print "Cannot link theme... no theme set" | |
63 | return | |
64 | ||
65 | link_dir = app_config['theme_linked_assets_dir'] | |
66 | ||
67 | # Remove existing symlink if it exists | |
68 | if os.path.exists(link_dir): | |
69 | # make sure it's a symlink though | |
70 | assert os.path.islink(link_dir) | |
71 | os.unlink(link_dir) | |
72 | ||
73 | os.symlink(current_theme['assets_dir'].rstrip('/'), link_dir.rstrip('/')) | |
74 | ||
75 | ||
76 | SUBCOMMANDS = { | |
77 | 'assetlink': assetlink} | |
78 | ||
79 | ||
80 | def theme(args): | |
81 | SUBCOMMANDS[args.subcommand](args) |