コード例 #1
0
 def testBasic(self):
     results = check_file_size(size=1)
     self.assertTrue(results)
コード例 #2
0
 def testBasic(self):
     results = check_file_size(size=1)
     self.assertTrue(results)
コード例 #3
0
ファイル: build.py プロジェクト: xuxiaobei1995/moose
def build(config_file=None,
          site_dir=None,
          num_threads=None,
          no_livereload=False,
          content=None,
          dump=False,
          clean=False,
          serve=False,
          host=None,
          port=None,
          template=None,
          init=False,
          **template_args):
    """
    The main build command.
    """

    if serve:
        clean = True
        site_dir = os.path.abspath(os.path.join(MooseDocs.TEMP_DIR, 'site'))

    # Clean/create site directory
    if clean and os.path.exists(site_dir):
        LOG.info('Cleaning build directory: %s', site_dir)
        shutil.rmtree(site_dir)

    # Create the "temp" directory
    if not os.path.exists(site_dir):
        os.makedirs(site_dir)

    # Check submodule for large_media
    if MooseDocs.ROOT_DIR == MooseDocs.MOOSE_DIR:
        status = common.submodule_status()
        if status['docs/content/media/large_media'] == '-':
            if init:
                subprocess.call([
                    'git', 'submodule', 'update', '--init',
                    'docs/content/media/large_media'
                ],
                                cwd=MooseDocs.MOOSE_DIR)
            else:
                LOG.warning(
                    "The 'large_media' submodule for storing images above 1MB is not "
                    "initialized, thus some images will not be visible within the "
                    "generated website. Run the build command with the --init flag to "
                    "initialize the submodule.")

    # Check media files size
    if MooseDocs.ROOT_DIR == MooseDocs.MOOSE_DIR:
        media = os.path.join(MooseDocs.MOOSE_DIR, 'docs', 'content', 'media')
        ignore = set()
        for base, _, files in os.walk(os.path.join(media, 'large_media')):
            for name in files:
                ignore.add(os.path.join(base, name))
        large = mooseutils.check_file_size(base=media, ignore=ignore)
        if large:
            msg = "Media files above the limit of 1 MB detected, these files should be stored in " \
                  "large media repository (docs/content/media/large_media):"
            for name, size in large:
                msg += '\n{}{} ({:.2f} MB)'.format(' ' * 4, name, size)
            LOG.error(msg)

    # Create the markdown parser
    config = MooseDocs.load_config(config_file,
                                   template=template,
                                   template_args=template_args)
    parser = MooseMarkdown(config)

    # Create the builder object and build the pages
    builder = WebsiteBuilder(parser=parser, site_dir=site_dir, content=content)
    builder.init()
    if dump:
        print builder
        return None
    builder.build(num_threads=num_threads)

    # Serve
    if serve:
        if not no_livereload:
            server = livereload.Server(
                watcher=MooseDocsWatcher(builder, num_threads))
        else:
            server = livereload.Server()
        server.serve(root=site_dir, host=host, port=port, restart_delay=0)

    return 0
コード例 #4
0
ファイル: build.py プロジェクト: aeslaughter/moose
def build(config_file=None, site_dir=None, num_threads=None, no_livereload=False, content=None,
          dump=False, clean=False, serve=False, host=None, port=None, template=None, init=False,
          **template_args):
    """
    The main build command.
    """

    if serve:
        clean = True
        site_dir = os.path.abspath(os.path.join(MooseDocs.TEMP_DIR, 'site'))

    # Clean/create site directory
    if clean and os.path.exists(site_dir):
        LOG.info('Cleaning build directory: %s', site_dir)
        shutil.rmtree(site_dir)

    # Create the "temp" directory
    if not os.path.exists(site_dir):
        os.makedirs(site_dir)

    # Check submodule for large_media
    if MooseDocs.ROOT_DIR == MooseDocs.MOOSE_DIR:
        status = submodule_status()
        if status['docs/content/media/large_media'] == '-':
            if init:
                subprocess.call(['git', 'submodule', 'update', '--init',
                                 'docs/content/media/large_media'], cwd=MooseDocs.MOOSE_DIR)
            else:
                LOG.warning("The 'large_media' submodule for storing images above 1MB is not "
                            "initialized, thus some images will not be visible within the "
                            "generated website. Run the build command with the --init flag to "
                            "initialize the submodule.")

    # Check media files size
    if MooseDocs.ROOT_DIR == MooseDocs.MOOSE_DIR:
        media = os.path.join(MooseDocs.MOOSE_DIR, 'docs', 'content', 'media')
        ignore = set()
        for base, _, files in os.walk(os.path.join(media, 'large_media')):
            for name in files:
                ignore.add(os.path.join(base, name))
        large = mooseutils.check_file_size(base=media, ignore=ignore)
        if large:
            msg = "Media files above the limit of 1 MB detected, these files should be stored in " \
                  "large media repository (docs/content/media/large_media):"
            for name, size in large:
                msg += '\n{}{} ({:.2f} MB)'.format(' '*4, name, size)
            LOG.error(msg)

    # Create the markdown parser
    config = MooseDocs.load_config(config_file, template=template, template_args=template_args)
    parser = MooseMarkdown(config)

    # Create the builder object and build the pages
    builder = WebsiteBuilder(parser=parser, site_dir=site_dir, content=content)
    builder.init()
    if dump:
        print builder
        return None
    builder.build(num_threads=num_threads)

    # Serve
    if serve:
        if not no_livereload:
            server = livereload.Server(watcher=MooseDocsWatcher(builder, num_threads))
        else:
            server = livereload.Server()
        server.serve(root=site_dir, host=host, port=port, restart_delay=0)

    return 0
コード例 #5
0
 def testBasic(self):
     results = check_file_size(size=1)  # No files greater than 1Mb
     self.assertEqual(results, [])
     results = check_file_size(size=0)
     self.assertNotEqual(results, [])
コード例 #6
0
ファイル: test_check_file_size.py プロジェクト: FHilty/moose
 def testBasic(self):
     results = check_file_size(size=1) # No files greater than 1Mb
     self.assertEqual(results, [])
     results = check_file_size(size=0)
     self.assertNotEqual(results, [])