示例#1
0
def get_config_path():
    """Get the path of the indico config file.

    This may return the location of a symlink.  Resolving a link is up
    to the caller if needed.
    """
    # In certain environments (debian+uwsgi+no-systemd) Indico may run
    # with an incorrect $HOME (such as /root), resulting in the config
    # files being searched in the wrong place. By clearing $HOME, Python
    # will get the home dir from passwd which has the correct path.
    old_home = os.environ.pop('HOME', None)
    # env var has priority
    try:
        return os.path.expanduser(os.environ['INDICO_CONFIG'])
    except KeyError:
        pass
    # try finding the config in various common paths
    paths = [os.path.expanduser('~/.indico.conf'), '/etc/indico.conf']
    # Keeping HOME unset wouldn't be too bad but let's not have weird side-effects
    if old_home is not None:
        os.environ['HOME'] = old_home
    # If it's an editable setup (ie usually a dev instance) allow having
    # the config in the package's root path
    if package_is_editable('indico'):
        paths.insert(0, os.path.normpath(os.path.join(get_root_path('indico'), 'indico.conf')))
    for path in paths:
        if os.path.exists(path):
            return path
    raise Exception('No indico config found. Point the INDICO_CONFIG env var to your config file or '
                    'move/symlink the config in one of the following locations: {}'.format(', '.join(paths)))
示例#2
0
文件: base.py 项目: bkolobara/indico
    def run(self, template_name, **kwargs):
        template_dir = os.path.join(get_root_path('indico'), 'legacy/webinterface/tpls/latex')
        template = tpl_render(os.path.join(template_dir, template_name), kwargs)

        self._dir = tempfile.mkdtemp(prefix="indico-texgen-", dir=config.TEMP_DIR)
        chmod_umask(self._dir, execute=True)
        source_filename = os.path.join(self._dir, template_name + '.tex')
        target_filename = os.path.join(self._dir, template_name + '.pdf')
        log_filename = os.path.join(self._dir, 'output.log')
        log_file = open(log_filename, 'a+')

        with open(source_filename, 'w') as f:
            f.write(template)

        try:
            self.run_latex(source_filename, log_file)
            if self.has_toc:
                self.run_latex(source_filename, log_file)
        finally:
            log_file.close()

            if not os.path.exists(target_filename):
                # something went terribly wrong, no LaTeX file was produced
                raise LaTeXRuntimeException(source_filename, log_filename)

        return target_filename
示例#3
0
 def _render_template(self, template_name, kwargs):
     template_dir = os.path.join(get_root_path('indico'), 'legacy/pdfinterface/latex_templates')
     env = Environment(loader=FileSystemLoader(template_dir),
                       autoescape=False,
                       trim_blocks=True,
                       keep_trailing_newline=True,
                       auto_reload=config.DEBUG,
                       extensions=[LatexEscapeExtension],
                       undefined=StrictUndefined,
                       block_start_string=r'\JINJA{', block_end_string='}',
                       variable_start_string=r'\VAR{', variable_end_string='}',
                       comment_start_string=r'\#{', comment_end_string='}')
     env.filters['format_date'] = EnsureUnicodeExtension.wrap_func(format_date)
     env.filters['format_time'] = EnsureUnicodeExtension.wrap_func(format_time)
     env.filters['format_duration'] = lambda delta: format_human_timedelta(delta, 'minutes')
     env.filters['latex'] = _latex_escape
     env.filters['rawlatex'] = RawLatex
     env.filters['markdown'] = kwargs.pop('markdown')
     env.globals['_'] = _
     env.globals['ngettext'] = ngettext
     env.globals['session'] = session
     template = env.get_or_select_template(template_name)
     distribution = pkg_resources.get_distribution('indico-fonts')
     font_dir = os.path.join(distribution.location, 'indico_fonts', '')  # XXX: trailing slash required
     return template.render(font_dir=font_dir, **kwargs)
示例#4
0
 def settings(self):
     core_path = os.path.join(get_root_path('indico'), 'modules', 'events', 'themes.yaml')
     with open(core_path) as f:
         core_data = f.read()
     core_settings = yaml.safe_load(core_data)
     # YAML doesn't give us access to anchors so we need to include the base yaml.
     # Since duplicate keys are invalid (and may start failing in the future) we
     # rename them - this also makes it easy to throw them away after parsing the
     # file provided by a plugin.
     core_data = re.sub(r'^(\S+:)$', r'__core_\1', core_data, flags=re.MULTILINE)
     for plugin, path in values_from_signal(signals.plugin.get_event_themes_files.send(), return_plugins=True):
         with open(path) as f:
             data = f.read()
         settings = {k: v
                     for k, v in yaml.safe_load(core_data + '\n' + data).viewitems()
                     if not k.startswith('__core_')}
         # We assume there's no more than one theme plugin that provides defaults.
         # If that's not the case the last one "wins". We could reject this but it
         # is quite unlikely that people have multiple theme plugins in the first
         # place, even more so theme plugins that specify defaults.
         core_settings['defaults'].update(settings.get('defaults', {}))
         # Same for definitions - we assume plugin authors are responsible enough
         # to avoid using definition names that are likely to cause collisions.
         # Either way, if someone does this on purpose chances are good they want
         # to override a default style so let them do so...
         for name, definition in settings.get('definitions', {}).viewitems():
             definition['plugin'] = plugin
             definition.setdefault('user_visible', False)
             core_settings['definitions'][name] = definition
     return core_settings
示例#5
0
    def _import_plugins(self, app):
        """Imports the plugins for an application.

        :param app: A Flask application
        :return: A dict mapping plugin names to plugin classes
        """
        state = get_state(app)
        plugins = {}
        for name in state.app.config['PLUGINENGINE_PLUGINS']:
            entry_points = list(iter_entry_points(app.config['PLUGINENGINE_NAMESPACE'], name))
            if not entry_points:
                state.logger.error('Plugin {} does not exist'.format(name))
                state.failed.add(name)
                continue
            elif len(entry_points) > 1:
                state.logger.error('Plugin name {} is not unique (defined in {})'
                                   .format(name, ', '.join(ep.module_name for ep in entry_points)))
                state.failed.add(name)
                continue
            entry_point = entry_points[0]
            try:
                plugin_class = entry_point.load()
            except ImportError:
                state.logger.exception('Could not load plugin {}'.format(name))
                state.failed.add(name)
                continue
            if not issubclass(plugin_class, self.plugin_class):
                state.logger.error('Plugin {} does not inherit from {}'.format(name, self.plugin_class.__name__))
                state.failed.add(name)
                continue
            plugin_class.package_name = entry_point.module_name.split('.')[0]
            plugin_class.name = name
            plugin_class.root_path = get_root_path(entry_point.module_name)
            plugins[name] = plugin_class
        return plugins
示例#6
0
def lte(app: Flask):
    for blueprint in app.blueprints.values():
        blueprint.jinja_loader = jinja2.ChoiceLoader([
            jinja2.FileSystemLoader(os.path.join(get_root_path('flask_admin_lte'), 'templates/lte')),
            blueprint.jinja_loader,
        ])
    app.register_blueprint(Blueprint('admin_lte', __name__, static_folder='static', static_url_path='/static/lte'))
示例#7
0
文件: offline.py 项目: jas01/indico
 def __init__(self, rh, event):
     self._rh = rh
     self.event = event
     self._display_tz = self.event.display_tzinfo.zone
     self._zip_file = None
     self._content_dir = _normalize_path(u'OfflineWebsite-{}'.format(event.title))
     self._web_dir = os.path.join(get_root_path('indico'), 'web')
     self._static_dir = os.path.join(self._web_dir, 'static')
示例#8
0
def _define_lookup():
    tpl_dir = os.path.join(get_root_path('indico'), 'legacy/webinterface/tpls')
    return IndicoTemplateLookup(directories=[tpl_dir],
                                disable_unicode=True,
                                input_encoding='utf-8',
                                default_filters=['encode_if_unicode', 'str'],
                                filesystem_checks=True,
                                imports=FILTER_IMPORTS,
                                cache_enabled=True)
示例#9
0
文件: core.py 项目: jmcarp/pycrawl
    def __init__(self, import_name, middlewares=None, loop=None, session=None):
        self.import_name = import_name
        self.root_path = get_root_path(import_name)
        self.config = Config(self.root_path, default_config)

        self._context = {}
        self._loop = loop or asyncio.get_event_loop()
        self._middlewares = SpiderMiddlewareManager(self, middlewares)
        self._session = session or aiohttp.ClientSession(loop=self._loop)
示例#10
0
 def __init__(self, rh, event):
     self._rh = rh
     self.event = event
     self._display_tz = self.event.display_tzinfo.zone
     self._html = ""
     self._fileHandler = None
     self._mainPath = ""
     self._staticPath = ""
     self._failed_paths = set()
     self._css_files = set()
     self._downloaded_files = {}
     self._htdocs_dir = os.path.join(get_root_path('indico'), 'htdocs')
示例#11
0
def setup_templates(app):
    '''
    Takes in a Flask app and sets up the templates and staticfiles from
    this project (via jinja2 loader and blueprint).

    Thanks to https://github.com/lex009/flask-admin-lte for inspiration
    '''
    extra_template_path = os.path.join(get_root_path('flask_admin_material'), 'templates')
    my_loader = jinja2.ChoiceLoader([
            app.jinja_loader,
            jinja2.FileSystemLoader(extra_template_path),
        ])
    app.jinja_loader = my_loader
    app.register_blueprint(Blueprint('admin_theme', __name__, static_folder='static', static_url_path='/static/admin_theme'))
    return app
示例#12
0
 def run(self, dev):
     self._check_root()
     self._check_venv()
     self._prompt_root_path(dev=dev)
     self.config_dir_path = (get_root_path('indico') if dev else os.path.join(self.root_path, 'etc'))
     self.config_path = os.path.join(self.config_dir_path, 'indico.conf')
     self._check_configured()
     self._check_directories(dev=dev)
     self._prompt_indico_url(dev=dev)
     self._prompt_db_uri()
     self._prompt_redis_uris()
     self._prompt_emails()
     self._prompt_smtp_data(dev=dev)
     self._prompt_defaults()
     self._prompt_misc()
     if not dev:
         self._prompt_migration()
     self._setup(dev=dev)
示例#13
0
文件: util.py 项目: indico/indico
def discover_blueprints():
    """Discovers all blueprints inside the indico package

    Only blueprints in a ``blueprint.py`` module or inside a
    ``blueprints`` package are loaded. Any other files are not touched
    or even imported.

    :return: a ``blueprints, compat_blueprints`` tuple containing two
             sets of blueprints
    """
    package_root = get_root_path('indico')
    modules = set()
    for root, dirs, files in os.walk(package_root):
        for name in files:
            if not name.endswith('.py') or name.endswith('_test.py'):
                continue
            segments = ['indico'] + os.path.relpath(root, package_root).replace(os.sep, '.').split('.') + [name[:-3]]
            if segments[-1] == 'blueprint':
                modules.add('.'.join(segments))
            elif 'blueprints' in segments[:-1]:
                if segments[-1] == '__init__':
                    modules.add('.'.join(segments[:-1]))
                else:
                    modules.add('.'.join(segments))

    blueprints = set()
    compat_blueprints = set()
    for module_name in sorted(modules):
        module = import_module(module_name)
        for name in dir(module):
            obj = getattr(module, name)
            if name.startswith('__') or not isinstance(obj, Blueprint):
                continue
            if obj.name.startswith('compat_'):
                compat_blueprints.add(obj)
            else:
                blueprints.add(obj)
    return blueprints, compat_blueprints
示例#14
0
    def _setup(self, dev=False):
        storage_backends = {
            'default': 'fs:' + os.path.join(self.data_root_path, 'archive')
        }
        if self.old_archive_dir:
            storage_backends['legacy'] = 'fs-readonly:' + self.old_archive_dir

        config_link_path = os.path.expanduser('~/.indico.conf')
        if not dev:
            create_config_link = _confirm(
                'Create symlink?',
                default=True,
                help='By creating a symlink to indico.conf in {}, you can run '
                'indico without having to set the INDICO_CONFIG '
                'environment variable'.format(config_link_path))
        else:
            create_config_link = False

        config_data = [
            b'# General settings', b'SQLALCHEMY_DATABASE_URI = {!r}'.format(
                self.db_uri.encode('utf-8')), b'SECRET_KEY = {!r}'.format(
                    os.urandom(32)), b'BASE_URL = {!r}'.format(
                        self.indico_url.encode('utf-8')),
            b'CELERY_BROKER = {!r}'.format(
                self.redis_uri_celery.encode('utf-8')),
            b'REDIS_CACHE_URL = {!r}'.format(
                self.redis_uri_cache.encode('utf-8')),
            b"CACHE_BACKEND = 'redis'", b'DEFAULT_TIMEZONE = {!r}'.format(
                self.default_timezone.encode('utf-8')),
            b'DEFAULT_LOCALE = {!r}'.format(
                self.default_locale.encode('utf-8')),
            b'ENABLE_ROOMBOOKING = {!r}'.format(self.rb_active),
            b'CACHE_DIR = {!r}'.format(
                os.path.join(self.data_root_path, 'cache').encode('utf-8')),
            b'TEMP_DIR = {!r}'.format(
                os.path.join(self.data_root_path,
                             'tmp').encode('utf-8')), b'LOG_DIR = {!r}'.format(
                                 os.path.join(self.data_root_path,
                                              'log').encode('utf-8')),
            b'ASSETS_DIR = {!r}'.format(
                os.path.join(self.data_root_path, 'assets').encode('utf-8')),
            b'STORAGE_BACKENDS = {!r}'.format({
                k.encode('utf-8'): v.encode('utf-8')
                for k, v in storage_backends.iteritems()
            }), b"ATTACHMENT_STORAGE = 'default'",
            b'ROUTE_OLD_URLS = True' if self.old_archive_dir else None, b'',
            b'# Email settings', b'SMTP_SERVER = {!r}'.format(
                (self.smtp_host.encode('utf-8'),
                 self.smtp_port)), b'SMTP_USE_TLS = {!r}'.format(
                     bool(self.smtp_user and self.smtp_password)),
            b'SMTP_LOGIN = {!r}'.format(self.smtp_user.encode('utf-8')),
            b'SMTP_PASSWORD = {!r}'.format(self.smtp_password.encode('utf-8')),
            b'SUPPORT_EMAIL = {!r}'.format(self.admin_email.encode('utf-8')),
            b'PUBLIC_SUPPORT_EMAIL = {!r}'.format(
                self.contact_email.encode('utf-8')),
            b'NO_REPLY_EMAIL = {!r}'.format(self.noreply_email.encode('utf-8'))
        ]

        if dev:
            config_data += [
                b'', b'# Development options', b'DB_LOG = True',
                b'DEBUG = True'
            ]

        config = b'\n'.join(x for x in config_data if x is not None)

        if dev:
            if not os.path.exists(self.data_root_path):
                os.mkdir(self.data_root_path)

        _echo()
        for path in self._missing_dirs:
            _echo(
                cformat('%{magenta}Creating %{magenta!}{}%{reset}%{magenta}').
                format(path))
            os.mkdir(path)

        _echo(
            cformat(
                '%{magenta}Creating %{magenta!}{}%{reset}%{magenta}').format(
                    self.config_path))
        with open(self.config_path, 'wb') as f:
            f.write(config + b'\n')

        package_root = get_root_path('indico')
        _copy(
            os.path.normpath(os.path.join(package_root,
                                          'logging.yaml.sample')),
            os.path.join(self.config_dir_path, 'logging.yaml'))

        if not dev:
            _link(os.path.join(package_root, 'htdocs'),
                  os.path.join(self.data_root_path, 'web', 'htdocs'))
            _copy(os.path.join(package_root, 'web', 'indico.wsgi'),
                  os.path.join(self.data_root_path, 'web', 'indico.wsgi'),
                  force=True)

        if create_config_link:
            _link(self.config_path, config_link_path)

        _echo()
        _echo(cformat('%{green}Indico has been configured successfully!'))
        if not create_config_link:
            _echo(
                cformat(
                    'Run %{green!}export INDICO_CONFIG={}%{reset} to use your config file'
                ).format(self.config_path))

        if self.old_archive_dir:
            _echo(
                cformat(
                    'Check %{green!}https://git.io/vHP6o%{reset} for a guide on how to '
                    'import data from Indico v1.2'))
        else:
            _echo(
                cformat(
                    'You can now run %{green!}indico db prepare%{reset} to initialize your Indico database'
                ))
示例#15
0
文件: i18n.py 项目: bkolobara/indico
def cli():
    os.chdir(os.path.join(get_root_path('indico'), '..'))
示例#16
0
 def _get_themes_yaml(self, sender, **kwargs):
     return os.path.join(get_root_path('indico_custom_themes'),
                         self.THEME_YAML)
示例#17
0
 def getLoggingConfigFilePath(self):
     config_path = self.getFinalConfigFilePath()
     if config_path is None:
         return os.path.join(get_root_path('indico'), 'logging.conf.sample')
     return os.path.join(os.path.dirname(config_path),
                         self.getLoggingConfigFile())
示例#18
0
文件: app.py 项目: indico/indico
def configure_webpack(app):
    pkg_path = os.path.dirname(get_root_path('indico'))
    project = WebpackBundleProject(pkg_path, None)
    app.config['WEBPACKEXT_PROJECT'] = project
    app.config['WEBPACKEXT_MANIFEST_LOADER'] = IndicoManifestLoader
    app.config['WEBPACKEXT_MANIFEST_PATH'] = os.path.join('dist', 'manifest.json')
示例#19
0
    def _setup(self, dev=False):
        storage_backends = {'default': 'fs:' + os.path.join(self.data_root_path, 'archive')}
        if self.old_archive_dir:
            storage_backends['legacy'] = 'fs-readonly:' + self.old_archive_dir

        config_link_path = os.path.expanduser('~/.indico.conf')
        if not dev:
            create_config_link = _confirm('Create symlink?', default=True,
                                          help='By creating a symlink to indico.conf in {}, you can run '
                                               'indico without having to set the INDICO_CONFIG '
                                               'environment variable'.format(config_link_path))
        else:
            create_config_link = False

        config_data = [
            b'# General settings',
            b'SQLALCHEMY_DATABASE_URI = {!r}'.format(self.db_uri.encode('utf-8')),
            b'SECRET_KEY = {!r}'.format(os.urandom(32)),
            b'BASE_URL = {!r}'.format(self.indico_url.encode('utf-8')),
            b'CELERY_BROKER = {!r}'.format(self.redis_uri_celery.encode('utf-8')),
            b'REDIS_CACHE_URL = {!r}'.format(self.redis_uri_cache.encode('utf-8')),
            b"CACHE_BACKEND = 'redis'",
            b'DEFAULT_TIMEZONE = {!r}'.format(self.default_timezone.encode('utf-8')),
            b'DEFAULT_LOCALE = {!r}'.format(self.default_locale.encode('utf-8')),
            b'ENABLE_ROOMBOOKING = {!r}'.format(self.rb_active),
            b'CACHE_DIR = {!r}'.format(os.path.join(self.data_root_path, 'cache').encode('utf-8')),
            b'TEMP_DIR = {!r}'.format(os.path.join(self.data_root_path, 'tmp').encode('utf-8')),
            b'LOG_DIR = {!r}'.format(os.path.join(self.data_root_path, 'log').encode('utf-8')),
            b'STORAGE_BACKENDS = {!r}'.format({k.encode('utf-8'): v.encode('utf-8')
                                              for k, v in storage_backends.iteritems()}),
            b"ATTACHMENT_STORAGE = 'default'",
            b'ROUTE_OLD_URLS = True' if self.old_archive_dir else None,
            b'',
            b'# Email settings',
            b'SMTP_SERVER = {!r}'.format((self.smtp_host.encode('utf-8'), self.smtp_port)),
            b'SMTP_USE_TLS = {!r}'.format(bool(self.smtp_user and self.smtp_password)),
            b'SMTP_LOGIN = {!r}'.format(self.smtp_user.encode('utf-8')),
            b'SMTP_PASSWORD = {!r}'.format(self.smtp_password.encode('utf-8')),
            b'SUPPORT_EMAIL = {!r}'.format(self.admin_email.encode('utf-8')),
            b'PUBLIC_SUPPORT_EMAIL = {!r}'.format(self.contact_email.encode('utf-8')),
            b'NO_REPLY_EMAIL = {!r}'.format(self.noreply_email.encode('utf-8'))
        ]

        if dev:
            config_data += [
                b'',
                b'# Development options',
                b'DB_LOG = True',
                b'DEBUG = True',
                b'SMTP_USE_CELERY = False'
            ]

        config = b'\n'.join(x for x in config_data if x is not None)

        if dev:
            if not os.path.exists(self.data_root_path):
                os.mkdir(self.data_root_path)

        _echo()
        for path in self._missing_dirs:
            _echo(cformat('%{magenta}Creating %{magenta!}{}%{reset}%{magenta}').format(path))
            os.mkdir(path)

        _echo(cformat('%{magenta}Creating %{magenta!}{}%{reset}%{magenta}').format(self.config_path))
        with open(self.config_path, 'wb') as f:
            f.write(config + b'\n')

        package_root = get_root_path('indico')
        _copy(os.path.normpath(os.path.join(package_root, 'logging.yaml.sample')),
              os.path.join(self.config_dir_path, 'logging.yaml'))

        if not dev:
            _link(os.path.join(package_root, 'web', 'static'), os.path.join(self.data_root_path, 'web', 'static'))
            _copy(os.path.join(package_root, 'web', 'indico.wsgi'),
                  os.path.join(self.data_root_path, 'web', 'indico.wsgi'),
                  force=True)

        if create_config_link:
            _link(self.config_path, config_link_path)

        _echo()
        _echo(cformat('%{green}Indico has been configured successfully!'))
        if not dev and not create_config_link:
            _echo(cformat('Run %{green!}export INDICO_CONFIG={}%{reset} to use your config file')
                  .format(self.config_path))

        if self.old_archive_dir:
            _echo(cformat('Check %{green!}https://git.io/vHP6o%{reset} for a guide on how to '
                          'import data from Indico v1.2'))
        else:
            _echo(cformat('You can now run %{green!}indico db prepare%{reset} to initialize your Indico database'))
示例#20
0
文件: app.py 项目: rama270677/indico
def configure_webpack(app):
    pkg_path = os.path.dirname(get_root_path('indico'))
    project = WebpackBundleProject(pkg_path, None)
    app.config['WEBPACKEXT_PROJECT'] = project
    app.config['WEBPACKEXT_MANIFEST_LOADER'] = IndicoManifestLoader
    app.config['WEBPACKEXT_MANIFEST_PATH'] = os.path.join('dist', 'manifest.json')
示例#21
0
def _get_htdocs_path():
    return os.path.join(get_root_path('indico'), 'htdocs')
示例#22
0
文件: setup.py 项目: javfg/indico
    def _setup(self, dev=False):
        storage_backends = {
            'default': 'fs:' + os.path.join(self.data_root_path, 'archive')
        }

        config_link_path = os.path.expanduser('~/.indico.conf')
        if not dev:
            create_config_link = _confirm(
                'Create symlink?',
                default=True,
                help='By creating a symlink to indico.conf in {}, you can run '
                'indico without having to set the INDICO_CONFIG '
                'environment variable'.format(config_link_path))
        else:
            create_config_link = False

        config_data = [
            '# General settings', f'SQLALCHEMY_DATABASE_URI = {self.db_uri!r}',
            f'SECRET_KEY = {os.urandom(32)!r}',
            f'BASE_URL = {self.indico_url!r}',
            f'CELERY_BROKER = {self.redis_uri_celery!r}',
            f'REDIS_CACHE_URL = {self.redis_uri_cache!r}',
            f'DEFAULT_TIMEZONE = {self.default_timezone!r}',
            f'DEFAULT_LOCALE = {self.default_locale!r}',
            f'ENABLE_ROOMBOOKING = {self.rb_active!r}',
            'CACHE_DIR = {!r}'.format(
                os.path.join(self.data_root_path,
                             'cache')), 'TEMP_DIR = {!r}'.format(
                                 os.path.join(self.data_root_path, 'tmp')),
            'LOG_DIR = {!r}'.format(os.path.join(
                self.data_root_path,
                'log')), 'STORAGE_BACKENDS = {!r}'.format({
                    k: v
                    for k, v in storage_backends.items()
                }), "ATTACHMENT_STORAGE = 'default'", '', '# Email settings',
            f'SMTP_SERVER = {(self.smtp_host, self.smtp_port)!r}',
            f'SMTP_USE_TLS = {bool(self.smtp_user and self.smtp_password)!r}',
            f'SMTP_LOGIN = {self.smtp_user!r}',
            f'SMTP_PASSWORD = {self.smtp_password!r}',
            f'SUPPORT_EMAIL = {self.admin_email!r}',
            f'PUBLIC_SUPPORT_EMAIL = {self.contact_email!r}',
            f'NO_REPLY_EMAIL = {self.noreply_email!r}'
        ]

        if dev:
            config_data += [
                '', '# Development options', 'DB_LOG = True', 'DEBUG = True',
                'SMTP_USE_CELERY = False'
            ]

        if not self.system_notices:
            config_data += [
                '', '# Disable system notices', 'SYSTEM_NOTICES_URL = None'
            ]

        config = '\n'.join(x for x in config_data if x is not None)

        if dev:
            if not os.path.exists(self.data_root_path):
                os.mkdir(self.data_root_path)

        _echo()
        for path in self._missing_dirs:
            _echo(
                cformat('%{magenta}Creating %{magenta!}{}%{reset}%{magenta}').
                format(path))
            os.mkdir(path)

        _echo(
            cformat(
                '%{magenta}Creating %{magenta!}{}%{reset}%{magenta}').format(
                    self.config_path))
        with open(self.config_path, 'w') as f:
            f.write(config + '\n')

        package_root = get_root_path('indico')
        _copy(
            os.path.normpath(os.path.join(package_root,
                                          'logging.yaml.sample')),
            os.path.join(self.config_dir_path, 'logging.yaml'))

        if not dev:
            _link(os.path.join(package_root, 'web', 'static'),
                  os.path.join(self.data_root_path, 'web', 'static'))
            _copy(os.path.join(package_root, 'web', 'indico.wsgi'),
                  os.path.join(self.data_root_path, 'web', 'indico.wsgi'),
                  force=True)

        if create_config_link:
            _link(self.config_path, config_link_path)

        _echo()
        _echo(cformat('%{green}Indico has been configured successfully!'))
        if not dev and not create_config_link:
            _echo(
                cformat(
                    'Run %{green!}export INDICO_CONFIG={}%{reset} to use your config file'
                ).format(self.config_path))

        _echo(
            cformat(
                'You can now run %{green!}indico db prepare%{reset} to initialize your Indico database'
            ))
示例#23
0
文件: setup.py 项目: javfg/indico
 def _get_all_locales():
     # get all directories in indico/translations
     root = Path(get_root_path('indico')) / 'translations'
     return [ent.name for ent in root.iterdir() if ent.is_dir()]
def searchable_db_path():
    return str(Path(get_root_path('tests'), 'AppData', 'searchable_db'))
示例#25
0
def cli():
    os.chdir(os.path.join(get_root_path('indico'), '..'))
示例#26
0
# coding=utf-8
import logging
import flask
import re
import os
from settings import *
from flask import Blueprint, _request_ctx_stack
from flask.helpers import get_root_path
from werkzeug.utils import cached_property, import_string

from .exception import AppNotExist, BlueprintNotExist
from .ext.flask_config import FlaskConfig


__author__ = 'GaoJie'
config = FlaskConfig(get_root_path(__name__))
DEBUG = False


def open_debug(b):
    global DEBUG
    DEBUG = b


def create_app(app_name, call_back=None):
    """
    根据AppName来加载app,设定配置信息,初始化app信息
    """
    init_config()
    if app_name not in ALLOW_APP:
        raise AppNotExist(app_name, allow=False)
示例#27
0
from pathlib import Path, PurePath
import logging
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
from flask.helpers import get_root_path
from .dash_app.account import Account
from .dash_app.layout import TAB_STYLE, TAB_SELECTED_STYLE
from .dash_app.content import (main_header, tab_balance,
                               tab_category_breakdown,
                               tab_sub_category_breakdown, tab_transaction)

logger = logging.getLogger('finances.dash_app')

ASSETS_PATH = os.path.join(get_root_path('__main__'),
                           r'finances\dash_app\assets')


def run_app(project_folder: str, database_name: str):
    """
    Run the app
    :param project_folder: folder of the project
    :param database_name: name of the database
    """
    database = Path(PurePath(project_folder, database_name))
    account_name = 'HSBC UK'  # Whren more accounts are supported, this will be selected via callback in the dash_app
    account = Account(database=database, account_name=account_name)
    app = dash.Dash(__name__, assets_folder=ASSETS_PATH)
    app.title = 'Transactions Analysis'
    app.layout = html.Div(children=[
示例#28
0
 def _get_all_locales():
     # get all directories in indico/translations
     return os.walk(os.path.join(get_root_path('indico'), 'translations')).next()[1]
示例#29
0
'''
Configuration specific to development environment. Do *not* use this
configuration in production.

'''
import os
import logging

from flask.helpers import get_root_path
from psephology._util import token_urlsafe

logging.warning('Using development config. DO NOT DO THIS IN PRODUCTION.')

DEBUG = True
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(
    get_root_path('psephology'), 'db.sqlite')
SECRET_KEY = token_urlsafe()
DEBUG_TB_INTERCEPT_REDIRECTS = False
示例#30
0
def _get_dirs(target_dir):
    if not os.path.isdir(target_dir):
        _echo(cformat('%{red}Directory not found:%{red!} {}').format(target_dir))
        sys.exit(1)
    return get_root_path('indico'), os.path.abspath(target_dir)
示例#31
0
文件: app.py 项目: zenador/dashcam
def make_full_path(filename):
    # file_dir = os.path.dirname(os.path.realpath('__file__'))
    # file_dir = sys.path[0]
    file_dir = get_root_path(__name__)
    full_path = os.path.join(file_dir, filename)
    return full_path
def tests_root():
    return get_root_path('tests')
示例#33
0
def _get_htdocs_path():
    return os.path.join(get_root_path('fossir'), 'htdocs')
示例#34
0
 def getHtdocsDir(self):
     return os.path.join(get_root_path('indico'), 'htdocs')
示例#35
0
def cli():
    os.chdir(os.path.join(get_root_path('fossir'), '..'))
def create_app(test_config=None):
    """The application factory function

    This function creates and configures the Flask application object. For
    more on application factories, see the Flask documentation/tutorial:

    http://flask.pocoo.org/docs/1.0/tutorial/factory/

    http://flask.pocoo.org/docs/1.0/patterns/appfactories/

    Parameters
    ----------
    test_config : dict
        A dictionary containing configuration parameters for use during unit
        testing. If this parameter is `None`, the configuration will be loaded
        from `config.py` in the instance folder.

    Returns
    -------
    Flask
        A flask app
    """

    # create and configure the app
    app = Flask(__name__,
                instance_path=os.path.join(get_root_path(__name__),
                                           'instance'),
                instance_relative_config=True)

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    from ucsd_bisb_unofficial.models import (db, migrate, Role, get_db, Post,
                                             WhisperPost)
    from ucsd_bisb_unofficial.login import login
    from ucsd_bisb_unofficial.email import mail
    from ucsd_bisb_unofficial.principals import principals
    from ucsd_bisb_unofficial.errors import forbidden
    from ucsd_bisb_unofficial.misaka import md
    from ucsd_bisb_unofficial.fts import fts

    for ext in db, login, mail, principals, md, fts:
        ext.init_app(app)
    migrate.init_app(app, db)
    login.login_view = 'auth.login'

    for error, handler in ((403, forbidden), ):
        app.register_error_handler(403, forbidden)

    from ucsd_bisb_unofficial import (auth, blog, jumbotron, protected, lab,
                                      career, tech, whisper, residency, ta,
                                      search, seminars, mental_health, news,
                                      stats, committee, gbic, fellowships,
                                      townhall, settings, courses, td, exam,
                                      anti_racism, outreach)
    for bp in (auth.bp, blog.bp, jumbotron.bp, protected.bp, lab.bp, career.bp,
               tech.bp, whisper.bp, residency.bp, ta.bp, search.bp,
               seminars.bp, mental_health.bp, news.bp, stats.bp, committee.bp,
               gbic.bp, fellowships.bp, townhall.bp, settings.bp, courses.bp,
               td.bp, exam.bp, anti_racism.bp, outreach.bp):
        app.register_blueprint(bp)

    from ucsd_bisb_unofficial import uploads
    app.register_blueprint(uploads.uploads_mod)

    app.add_url_rule('/', endpoint='auth.login')

    from ucsd_bisb_unofficial.uploads import documents, images
    configure_uploads(app, documents)
    configure_uploads(app, images)

    @app.before_first_request
    def populate_databse():
        with app.app_context():
            db = get_db()
            db.create_all()
            commit = False
            for name, description in (('admin', 'site administrator'),
                                      ('whisper_user', 'whisper app user'),
                                      ('named_user', 'named user')):
                if not Role.query.filter_by(name=name).first():
                    role = Role(name=name, description=description)
                    db.session.add(role)
                    commit = True
            if commit:
                db.session.commit()

    @app.before_first_request
    def reindex():
        with app.app_context():
            Post.reindex()
            WhisperPost.reindex()

    return app
示例#37
0
from flask.helpers import get_root_path

assets_folder = get_root_path(__name__) + '/assets/'
示例#38
0
 def _get_all_locales():
     # get all directories in indico/translations
     return os.walk(
         os.path.join(get_root_path('indico'),
                      'translations')).next()[1]
示例#39
0
 def __init__(self, import_name, folder, **kwargs):
     """Initialize bundle."""
     super(WebpackBundle,
           self).__init__(join(get_root_path(import_name), folder),
                          **kwargs)
示例#40
0
def _get_dirs(target_dir):
    if not os.path.isdir(target_dir):
        _echo(
            cformat('%{red}Directory not found:%{red!} {}').format(target_dir))
        sys.exit(1)
    return get_root_path('indico'), os.path.abspath(target_dir)
示例#41
0
def _get_htdocs_path():
    return os.path.join(get_root_path('indico'), 'htdocs')
示例#42
0
import os
from flask.helpers import get_root_path
from bitsbox._util import token_urlsafe

DEBUG = True
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(get_root_path('bitsbox'),
                                                      'db.sqlite')
SECRET_KEY = token_urlsafe()
DEBUG_TB_INTERCEPT_REDIRECTS = False
示例#43
0
# coding=utf-8
import logging
import flask
import re
import os
from settings import *
from flask import Blueprint, _request_ctx_stack
from flask.helpers import get_root_path
from werkzeug.utils import cached_property, import_string

from .exception import AppNotExist, BlueprintNotExist
from .ext.flask_config import FlaskConfig

__author__ = 'GaoJie'
config = FlaskConfig(get_root_path(__name__))
DEBUG = False


def open_debug(b):
    global DEBUG
    DEBUG = b


def create_app(app_name, call_back=None):
    """
    根据AppName来加载app,设定配置信息,初始化app信息
    """
    init_config()
    if app_name not in ALLOW_APP:
        raise AppNotExist(app_name, allow=False)
    else:
示例#44
0
    def _setup(self):
        storage_backends = {
            'default': 'fs:' + os.path.join(self.root_path, 'archive')
        }
        if self.old_archive_dir:
            storage_backends['legacy'] = 'fs-readonly:' + self.old_archive_dir

        config_link_path = os.path.expanduser('~/.indico.conf')
        create_config_link = _confirm(
            'Create symlink?',
            default=True,
            help='By creating a symlink to indico.conf in {}, you can run '
            'indico without having to set the INDICO_CONFIG '
            'environment variable'.format(config_link_path))

        config_data = [
            b'# General settings', b'SQLAlchemyDatabaseURI = {!r}'.format(
                self.db_uri.encode('utf-8')), b'SecretKey = {!r}'.format(
                    os.urandom(32)), b'BaseURL = {!r}'.format(
                        self.indico_url.encode('utf-8')),
            b'CeleryBroker = {!r}'.format(
                self.redis_uri_celery.encode('utf-8')),
            b'RedisCacheURL = {!r}'.format(
                self.redis_uri_cache.encode('utf-8')),
            b"CacheBackend = 'redis'", b'DefaultTimezone = {!r}'.format(
                self.default_timezone.encode('utf-8')),
            b'DefaultLocale = {!r}'.format(
                self.default_locale.encode('utf-8')),
            b'IsRoomBookingActive = {!r}'.format(self.rb_active),
            b'CacheDir = {!r}'.format(
                os.path.join(self.root_path, 'cache').encode('utf-8')),
            b'TempDir = {!r}'.format(
                os.path.join(self.root_path,
                             'tmp').encode('utf-8')), b'LogDir = {!r}'.format(
                                 os.path.join(self.root_path,
                                              'log').encode('utf-8')),
            b'AssetsDir = {!r}'.format(
                os.path.join(self.root_path, 'assets').encode('utf-8')),
            b'StorageBackends = {!r}'.format({
                k.encode('utf-8'): v.encode('utf-8')
                for k, v in storage_backends.iteritems()
            }), b"AttachmentStorage = 'default'",
            b'RouteOldURLs = True' if self.old_archive_dir else None, b'',
            b'# Email settings', b'SmtpServer = {!r}'.format(
                (self.smtp_host.encode('utf-8'),
                 self.smtp_port)), b'SmtpUseTLS = {!r}'.format(
                     bool(self.smtp_user
                          and self.smtp_password)), b'SmtpLogin = {!r}'.format(
                              self.smtp_user.encode('utf-8')),
            b'SmtpPassword = {!r}'.format(self.smtp_password.encode('utf-8')),
            b'SupportEmail = {!r}'.format(self.admin_email.encode('utf-8')),
            b'PublicSupportEmail = {!r}'.format(
                self.contact_email.encode('utf-8')),
            b'NoReplyEmail = {!r}'.format(self.noreply_email.encode('utf-8'))
        ]
        config = b'\n'.join(x for x in config_data if x is not None)

        _echo()
        for path in self._missing_dirs:
            _echo(
                cformat('%{magenta}Creating %{magenta!}{}%{reset}%{magenta}').
                format(path))
            os.mkdir(path)

        _echo(
            cformat(
                '%{magenta}Creating %{magenta!}{}%{reset}%{magenta}').format(
                    self.config_path))
        with open(self.config_path, 'wb') as f:
            f.write(config + b'\n')

        package_root = get_root_path('indico')
        _copy(
            os.path.normpath(os.path.join(package_root,
                                          'logging.conf.sample')),
            os.path.join(self.root_path, 'etc', 'logging.conf'))
        _link(os.path.join(package_root, 'htdocs'),
              os.path.join(self.root_path, 'web', 'htdocs'))
        _copy(os.path.join(package_root, 'web', 'indico.wsgi'),
              os.path.join(self.root_path, 'web', 'indico.wsgi'),
              force=True)

        if create_config_link:
            _link(self.config_path, config_link_path)

        _echo()
        _echo(cformat('%{green}Indico has been configured successfully!'))
        if not create_config_link:
            _echo(
                cformat(
                    'Run %{green!}export INDICO_CONFIG={}%{reset} to use your config file'
                ).format(self.config_path))

        if self.old_archive_dir:
            _echo(
                cformat(
                    'Check %{green!}https://git.io/vHP6o%{reset} for a guide on how to '
                    'import data from Indico v1.2'))
        else:
            _echo(
                cformat(
                    'You can now run %{green!}indico db prepare%{reset} to initialize your Indico database'
                ))
示例#45
0
def register_dashapps(app):

    # Split file into layout and callbacks scripts:
    from app.scada_stg1.layout import layout
    from app.scada_stg1.callbacks import register_callbacks

    # Meta tags for viewport responsiveness:
    meta_viewport = {
        "name": "viewport",
        "content": "width=device-width, initial-scale=1, shrink-to-fit=no"
    }

    layout_ess = [
        'https://cdn.rawgit.com/plotly/dash-app-stylesheets/2d266c578d2a6e8850ebce48fdb52759b2aef506/stylesheet-oil-and-gas.css'
    ]
    scada_stg1 = dash.Dash(__name__,
                           server=app,
                           url_base_pathname='/scada_stg1/',
                           assets_folder=get_root_path(__name__) +
                           '/dashboard/assets/',
                           meta_tags=[meta_viewport],
                           external_stylesheets=layout_ess)

    scada_stg1.title = 'Scada Stg1'
    scada_stg1.layout = layout
    register_callbacks(scada_stg1)
    # Use Flask login security:
    # _protect_dashviews(scada_stg1)

    inv_stg2 = dash.Dash(__name__,
                         server=app,
                         url_base_pathname='/inv_stg2/',
                         assets_folder=get_root_path(__name__) +
                         '/dashboard/assets/',
                         meta_tags=[meta_viewport],
                         external_stylesheets=layout_ess)

    inv_stg2.title = 'Inverter Stg2'
    inv_stg2.layout = layout
    register_callbacks(inv_stg2)

    dte_stg3 = dash.Dash(__name__,
                         server=app,
                         url_base_pathname='/dte_stg3/',
                         assets_folder=get_root_path(__name__) +
                         '/dashboard/assets/',
                         meta_tags=[meta_viewport],
                         external_stylesheets=layout_ess)

    dte_stg3.title = 'DownTime Stg3'
    dte_stg3.layout = layout
    register_callbacks(dte_stg3)

    fact_stg4 = dash.Dash(__name__,
                          server=app,
                          url_base_pathname='/fact_stg4/',
                          assets_folder=get_root_path(__name__) +
                          '/dashboard/assets/',
                          meta_tags=[meta_viewport],
                          external_stylesheets=layout_ess)

    fact_stg4.title = 'Fact Stg4'
    fact_stg4.layout = layout
    register_callbacks(fact_stg4)