Beispiel #1
0
def settings_file(request):
    """Set up settings directory and file."""
    settings_d = os.path.join(TEST_DIR, 'momo')
    settings_f = os.path.join(settings_d, 'settings.yml')

    mkdir_p(settings_d)
    open(settings_f, 'a').close()

    @request.addfinalizer
    def cleanup():
        if os.path.exists(settings_d):
            shutil.rmtree(settings_f)

    return settings_f
Beispiel #2
0
def settings_file(request):
    """Set up settings directory and file."""
    settings_d = os.path.join(TEST_DIR, 'momo')
    settings_f = os.path.join(settings_d, 'settings.yml')

    mkdir_p(settings_d)
    open(settings_f, 'a').close()

    @request.addfinalizer
    def cleanup():
        if os.path.exists(settings_d):
            shutil.rmtree(settings_f)

    return settings_f
Beispiel #3
0
 def _get_docs(self):
     if self.momo_configs['momo_docs_dir'] is None:
         return []
     src_momo_docs_dir = eval_path(self.momo_configs['momo_docs_dir'])
     if os.path.isdir(src_momo_docs_dir):
         markdown_paths = glob.glob(os.path.join(src_momo_docs_dir, '*.md'))
         momo_docs_dir = os.path.join(
             self.docs_dir, self.momo_configs['momo_docs_pathname'])
         mkdir_p(momo_docs_dir)
         docs = []
         for markdown_path in markdown_paths:
             shutil.copy(markdown_path, momo_docs_dir)
             markdown_basename = os.path.basename(markdown_path)
             doc_title = os.path.splitext(markdown_basename)[0].title()
             doc_path = os.path.join(
                 self.momo_configs['momo_docs_pathname'], markdown_basename)
             docs.append({doc_title: doc_path})
         return [{'Docs': docs}]
Beispiel #4
0
 def _make_index_page(self, elem, level):
     base = os.path.join(*elem.path) if elem.path else ''
     res = os.path.join(base, 'index.md')
     filename = os.path.join(self.docs_dir, res)
     dirname = os.path.dirname(filename)
     if dirname:
         mkdir_p(dirname)
     kwargs = {}
     lazy_load_size = self._get_lazy_load_size(elem)
     if lazy_load_size is not None:
         kwargs['lazy_load_size'] = lazy_load_size
     buf = []
     with open(filename, 'w') as f:
         buf.append(self._make_title(elem))
         buf.append(self._make_attrs(elem))
         buf.append(self._make_nodes(elem, index=True, level=level,
                                     **kwargs))
         f.write(utf8_encode('\n'.join(buf)))
     return res
Beispiel #5
0
 def _make_index_page(self, elem, level):
     base = os.path.join(*elem.path) if elem.path else ''
     res = os.path.join(base, 'index.md')
     filename = os.path.join(self.docs_dir, res)
     dirname = os.path.dirname(filename)
     if dirname:
         mkdir_p(dirname)
     kwargs = {}
     lazy_load_size = self._get_lazy_load_size(elem)
     if lazy_load_size is not None:
         kwargs['lazy_load_size'] = lazy_load_size
     buf = []
     with open(filename, 'w') as f:
         buf.append(self._make_title(elem))
         buf.append(self._make_attrs(elem))
         buf.append(
             self._make_nodes(elem, index=True, level=level, **kwargs))
         f.write(utf8_encode('\n'.join(buf)))
     return res
Beispiel #6
0
 def _get_docs(self):
     if self.momo_configs['momo_docs_dir'] is None:
         return []
     src_momo_docs_dir = eval_path(self.momo_configs['momo_docs_dir'])
     if os.path.isdir(src_momo_docs_dir):
         markdown_paths = glob.glob(
             os.path.join(src_momo_docs_dir, '*.md'))
         momo_docs_dir = os.path.join(
             self.docs_dir, self.momo_configs['momo_docs_pathname'])
         mkdir_p(momo_docs_dir)
         docs = []
         for markdown_path in markdown_paths:
             shutil.copy(markdown_path, momo_docs_dir)
             markdown_basename = os.path.basename(markdown_path)
             doc_title = os.path.splitext(markdown_basename)[0].title()
             doc_path = os.path.join(
                 self.momo_configs['momo_docs_pathname'], markdown_basename
             )
             docs.append({doc_title: doc_path})
         return [{'Docs': docs}]
Beispiel #7
0
 def _make_page(self, elem):
     res = '%s.md' % os.path.join(*elem.path)
     filename = os.path.join(self.docs_dir, res)
     dirname = os.path.dirname(filename)
     if dirname:
         mkdir_p(dirname)
     kwargs = {}
     this_kwargs = {}
     lazy_load_size = self._get_lazy_load_size(elem)
     this_lazy_load_size = self._get_this_lazy_load_size(elem)
     if lazy_load_size is not None:
         kwargs['lazy_load_size'] = lazy_load_size
     if this_lazy_load_size is not None:
         this_kwargs['lazy_load_size'] = this_lazy_load_size
     buf = []
     with open(filename, 'w') as f:
         buf.append(self._make_title(elem))
         buf.append(self._make_attrs(elem, **this_kwargs))
         buf.append(self._make_nodes(elem, **kwargs))
         f.write(utf8_encode('\n'.join(buf)))
     return res
Beispiel #8
0
 def _make_page(self, elem):
     res = '%s.md' % os.path.join(*elem.path)
     filename = os.path.join(self.docs_dir, res)
     dirname = os.path.dirname(filename)
     if dirname:
         mkdir_p(dirname)
     kwargs = {}
     this_kwargs = {}
     lazy_load_size = self._get_lazy_load_size(elem)
     this_lazy_load_size = self._get_this_lazy_load_size(elem)
     if lazy_load_size is not None:
         kwargs['lazy_load_size'] = lazy_load_size
     if this_lazy_load_size is not None:
         this_kwargs['lazy_load_size'] = this_lazy_load_size
     buf = []
     with open(filename, 'w') as f:
         buf.append(self._make_title(elem))
         buf.append(self._make_attrs(elem, **this_kwargs))
         buf.append(self._make_nodes(elem, **kwargs))
         f.write(utf8_encode('\n'.join(buf)))
     return res
Beispiel #9
0
    def setup(self):
        self.root = self.settings.bucket.root
        bucket_name = self.settings.bucket.name
        base_configs = self.settings.plugins.get(
            'mkdocs', {}).get(BASE_CONFIG_NAME, {})
        configs = self.settings.plugins.get(
            'mkdocs', {}).get(bucket_name, {})
        for k in base_configs:
            if k not in configs:
                configs[k] = base_configs[k]

        # mkdocs site_name defaults to bucket name
        self.mkdocs_configs['site_name'] = bucket_name

        for k in configs:
            if not k.startswith('momo_'):
                self.mkdocs_configs[k] = configs[k]
        for k in configs:
            if k.startswith('momo_'):
                self.momo_configs[k] = configs[k]

        self.mkdocs_root_dir = os.path.join(self.settings.settings_dir,
                                            'mkdocs')
        self.mkdocs_dir = os.path.join(self.mkdocs_root_dir,
                                       bucket_name)
        self.docs_dir = os.path.join(self.mkdocs_dir, 'docs')
        self.site_dir = os.path.join(self.mkdocs_dir, 'site')
        if os.path.exists(self.docs_dir):
            shutil.rmtree(self.docs_dir)
        mkdir_p(self.docs_dir)
        mkdir_p(self.site_dir)
        assets = glob.glob(os.path.join(self.mkdocs_dir, '*'))
        for asset in assets:
            filename = os.path.basename(asset)
            if filename not in set(['docs', 'site', 'mkdocs.yml']):
                os.symlink(asset, os.path.join(self.docs_dir, filename))

        self.root.name = self.momo_configs['momo_root_name']
Beispiel #10
0
    def setup(self):
        self.root = self.settings.bucket.root
        bucket_name = self.settings.bucket.name
        base_configs = self.settings.plugins.get('mkdocs',
                                                 {}).get(BASE_CONFIG_NAME, {})
        configs = self.settings.plugins.get('mkdocs', {}).get(bucket_name, {})
        for k in base_configs:
            if k not in configs:
                configs[k] = base_configs[k]

        # mkdocs site_name defaults to bucket name
        self.mkdocs_configs['site_name'] = bucket_name

        for k in configs:
            if not k.startswith('momo_'):
                self.mkdocs_configs[k] = configs[k]
        for k in configs:
            if k.startswith('momo_'):
                self.momo_configs[k] = configs[k]

        self.mkdocs_root_dir = os.path.join(self.settings.settings_dir,
                                            'mkdocs')
        self.mkdocs_dir = os.path.join(self.mkdocs_root_dir, bucket_name)
        self.docs_dir = os.path.join(self.mkdocs_dir, 'docs')
        self.site_dir = os.path.join(self.mkdocs_dir, 'site')
        if os.path.exists(self.docs_dir):
            shutil.rmtree(self.docs_dir)
        mkdir_p(self.docs_dir)
        mkdir_p(self.site_dir)
        assets = glob.glob(os.path.join(self.mkdocs_dir, '*'))
        for asset in assets:
            filename = os.path.basename(asset)
            if filename not in set(['docs', 'site', 'mkdocs.yml']):
                os.symlink(asset, os.path.join(self.docs_dir, filename))

        self.root.name = self.momo_configs['momo_root_name']
Beispiel #11
0
 def _create_empty_bucket(self, path):
     dirname = os.path.dirname(path)
     mkdir_p(dirname)
     if not os.path.exists(path):
         with open(path, "w") as f:
             f.write("%s: true" % PLACEHOLDER)
Beispiel #12
0
 def setup_log_file():
     mkdir_p(DEFAULT_SETTINGS_DIR)
     return SERVE_LOG_FILE
Beispiel #13
0
def testdir(request):
    mkdir_p(TEST_DIR)

    @request.addfinalizer
    def cleanup():
        shutil.rmtree(TEST_DIR)
Beispiel #14
0
 def _create_empty_bucket(self, path):
     dirname = os.path.dirname(path)
     mkdir_p(dirname)
     if not os.path.exists(path):
         with open(path, 'w') as f:
             f.write('%s: true' % PLACEHOLDER)
Beispiel #15
0
def testdir(request):
    mkdir_p(TEST_DIR)

    @request.addfinalizer
    def cleanup():
        shutil.rmtree(TEST_DIR)