| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | """ |
|---|
| 3 | zine.environment |
|---|
| 4 | ~~~~~~~~~~~~~~~~ |
|---|
| 5 | |
|---|
| 6 | This module can figure how Zine is installed and where it has to look |
|---|
| 7 | for shared information. Currently it knows about two modes: development |
|---|
| 8 | environment and installation on a posix system. OS X should be special |
|---|
| 9 | cased later and Windows support is missing by now. |
|---|
| 10 | |
|---|
| 11 | File Locations |
|---|
| 12 | -------------- |
|---|
| 13 | |
|---|
| 14 | The files are located at different places depending on the environment. |
|---|
| 15 | |
|---|
| 16 | development |
|---|
| 17 | in development mode all the files are relative to the zine |
|---|
| 18 | package:: |
|---|
| 19 | |
|---|
| 20 | zine/ application code |
|---|
| 21 | plugins/ builtin plugins |
|---|
| 22 | shared/ core shared data |
|---|
| 23 | templates/ core templates |
|---|
| 24 | i18n/ translations |
|---|
| 25 | |
|---|
| 26 | posix |
|---|
| 27 | On a posix system (including Linux) the files are distributed to |
|---|
| 28 | different locations on the file system below the prefix which is |
|---|
| 29 | /usr in the following example:: |
|---|
| 30 | |
|---|
| 31 | /usr/lib/zine/ |
|---|
| 32 | zine/ application code |
|---|
| 33 | plugins/ builtin plugins with symlinks |
|---|
| 34 | to stuff in /usr/share/zine |
|---|
| 35 | /usr/share/zine/ |
|---|
| 36 | htdocs/core core shared data |
|---|
| 37 | templates/core core templates |
|---|
| 38 | i18n/ translations |
|---|
| 39 | |
|---|
| 40 | :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. |
|---|
| 41 | :license: BSD, see LICENSE for more details. |
|---|
| 42 | """ |
|---|
| 43 | from os.path import realpath, dirname, join, pardir, isdir |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | # the platform name |
|---|
| 47 | from os import name as PLATFORM |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | # the path to the contents of the zine package |
|---|
| 51 | PACKAGE_CONTENTS = realpath(dirname(__file__)) |
|---|
| 52 | |
|---|
| 53 | # the path to the folder where the "zine" package is stored in. |
|---|
| 54 | PACKAGE_LOCATION = realpath(join(PACKAGE_CONTENTS, pardir)) |
|---|
| 55 | |
|---|
| 56 | # name of the domain for the builtin translations |
|---|
| 57 | LOCALE_DOMAIN = 'messages' |
|---|
| 58 | |
|---|
| 59 | # true if the LC_MESSAGES folder is in use for the core domains |
|---|
| 60 | # (gettext based lookup is used then). This does not affect |
|---|
| 61 | # translations from non-core plugins |
|---|
| 62 | USE_GETTEXT_LOOKUP = False |
|---|
| 63 | |
|---|
| 64 | # check development mode first. If there is a shared folder we must be |
|---|
| 65 | # in development mode. |
|---|
| 66 | SHARED_DATA = join(PACKAGE_CONTENTS, 'shared') |
|---|
| 67 | if isdir(SHARED_DATA): |
|---|
| 68 | MODE = 'development' |
|---|
| 69 | BUILTIN_PLUGIN_FOLDER = join(PACKAGE_CONTENTS, 'plugins') |
|---|
| 70 | BUILTIN_TEMPLATE_PATH = join(PACKAGE_CONTENTS, 'templates') |
|---|
| 71 | LOCALE_PATH = join(PACKAGE_CONTENTS, 'i18n') |
|---|
| 72 | |
|---|
| 73 | # a Zine installation on a posix system |
|---|
| 74 | elif PLATFORM == 'posix': |
|---|
| 75 | MODE = 'posix' |
|---|
| 76 | share = join(PACKAGE_LOCATION, pardir, pardir, 'share') |
|---|
| 77 | BUILTIN_PLUGIN_FOLDER = realpath(join(PACKAGE_LOCATION, 'plugins')) |
|---|
| 78 | BUILTIN_TEMPLATE_PATH = realpath(join(share, 'zine', 'templates', 'core')) |
|---|
| 79 | SHARED_DATA = realpath(join(share, 'zine', 'htdocs', 'core')) |
|---|
| 80 | LOCALE_PATH = realpath(join(share, 'locale')) |
|---|
| 81 | LOCALE_DOMAIN = 'zine' |
|---|
| 82 | USE_GETTEXT_LOOKUP = True |
|---|
| 83 | del share |
|---|
| 84 | |
|---|
| 85 | # a Zine installation on windows |
|---|
| 86 | elif PLATFORM == 'nt': |
|---|
| 87 | raise NotImplementedError('Installation on windows is currently not ' |
|---|
| 88 | 'possible. Consider using Zine in development ' |
|---|
| 89 | 'mode.') |
|---|
| 90 | |
|---|
| 91 | else: |
|---|
| 92 | raise EnvironmentError('Could not determine Zine environment') |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | # get rid of the helpers |
|---|
| 96 | del realpath, dirname, join, pardir, isdir |
|---|