123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
-
- from urllib.parse import urlparse
- from paste.deploy.converters import asbool
- from tracim.lib.utils.logger import logger
- from depot.manager import DepotManager
-
- from pyramid.request import Request
-
-
- class RequestWithCFG(Request):
-
- def app_config(self):
- cfg = CFG(self.registry.settings)
- cfg.configure_filedepot()
- return cfg
-
-
- class CFG(object):
- """Object used for easy access to config file parameters."""
-
- def __setattr__(self, key, value):
- """
- Log-ready setter.
-
- Logs all configuration parameters except password.
- :param key:
- :param value:
- :return:
- """
- if 'PASSWORD' not in key and \
- ('URL' not in key or type(value) == str) and \
- 'CONTENT' not in key:
-
-
-
-
- logger.info(self, 'CONFIG: [ {} | {} ]'.format(key, value))
- else:
- logger.info(self, 'CONFIG: [ {} | <value not shown> ]'.format(key))
-
- self.__dict__[key] = value
-
- def __init__(self, settings):
- """Parse configuration file."""
-
-
-
-
-
- mandatory_msg = \
- 'ERROR: {} configuration is mandatory. Set it before continuing.'
- self.DEPOT_STORAGE_DIR = settings.get(
- 'depot_storage_dir',
- )
- if not self.DEPOT_STORAGE_DIR:
- raise Exception(
- mandatory_msg.format('depot_storage_dir')
- )
- self.DEPOT_STORAGE_NAME = settings.get(
- 'depot_storage_name',
- )
- if not self.DEPOT_STORAGE_NAME:
- raise Exception(
- mandatory_msg.format('depot_storage_name')
- )
- self.PREVIEW_CACHE_DIR = settings.get(
- 'preview_cache_dir',
- )
- if not self.PREVIEW_CACHE_DIR:
- raise Exception(
- 'ERROR: preview_cache_dir configuration is mandatory. '
- 'Set it before continuing.'
- )
-
- self.DATA_UPDATE_ALLOWED_DURATION = int(settings.get(
- 'content.update.allowed.duration',
- 0,
- ))
-
- self.WEBSITE_TITLE = settings.get(
- 'website.title',
- 'TRACIM',
- )
-
- self.WEBSITE_BASE_URL = settings.get(
- 'website.base_url',
- '',
- )
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- self.WEBSITE_SERVER_NAME = settings.get(
- 'website.server_name',
- None,
- )
-
- if not self.WEBSITE_SERVER_NAME:
- self.WEBSITE_SERVER_NAME = urlparse(self.WEBSITE_BASE_URL).hostname
- logger.warning(
- self,
- 'NOTE: Generated website.server_name parameter from '
- 'website.base_url parameter -> {0}'
- .format(self.WEBSITE_SERVER_NAME)
- )
-
- self.WEBSITE_HOME_TAG_LINE = settings.get(
- 'website.home.tag_line',
- '',
- )
- self.WEBSITE_SUBTITLE = settings.get(
- 'website.home.subtitle',
- '',
- )
- self.WEBSITE_HOME_BELOW_LOGIN_FORM = settings.get(
- 'website.home.below_login_form',
- '',
- )
-
- self.WEBSITE_TREEVIEW_CONTENT = settings.get(
- 'website.treeview.content',
- )
-
- self.USER_AUTH_TOKEN_VALIDITY = int(settings.get(
- 'user.auth_token.validity',
- '604800',
- ))
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- self.EMAIL_NOTIFICATION_ACTIVATED = asbool(settings.get(
- 'email.notification.activated',
- ))
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- def configure_filedepot(self):
- depot_storage_name = self.DEPOT_STORAGE_NAME
- depot_storage_path = self.DEPOT_STORAGE_DIR
- depot_storage_settings = {'depot.storage_path': depot_storage_path}
- DepotManager.configure(
- depot_storage_name,
- depot_storage_settings,
- )
-
- class CST(object):
- ASYNC = 'ASYNC'
- SYNC = 'SYNC'
-
- TREEVIEW_FOLDERS = 'folders'
- TREEVIEW_ALL = 'all'
|