def _init_large_media(): """Check submodule for large_media.""" log = logging.getLogger('MooseDocs._init_large_media') status = common.submodule_status() large_media = os.path.realpath(os.path.join(MooseDocs.MOOSE_DIR, 'large_media')) for submodule, status in status.iteritems(): if ((os.path.realpath(os.path.join(MooseDocs.MOOSE_DIR, submodule)) == large_media) and (status == '-')): log.info("Initializing the 'large_media' submodule for storing images above 1MB.") subprocess.call(['git', 'submodule', 'update', '--init', 'large_media'], cwd=MooseDocs.MOOSE_DIR)
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
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 os.path.realpath(MooseDocs.ROOT_DIR) == os.path.realpath(MooseDocs.MOOSE_DIR): status = common.submodule_status() large_media = os.path.realpath(os.path.join(MooseDocs.ROOT_DIR, 'large_media')) for submodule, status in status.iteritems(): if ((os.path.realpath(os.path.join(MooseDocs.MOOSE_DIR, submodule)) == large_media) and (status == '-')): if init: subprocess.call(['git', 'submodule', 'update', '--init', '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 os.path.realpath(MooseDocs.ROOT_DIR) == os.path.realpath(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) # Add custom CSS to the config if template_args['css']: if os.path.exists(template_args['css']): config['MooseDocs.extensions.template']['template_args']['moose_css'] = 'css/' +\ os.path.basename(template_args['css']) else: LOG.warning("supplied css file does not exist") parser = MooseMarkdown(config) # Create the builder object and build the pages builder = WebsiteBuilder(parser=parser, site_dir=site_dir, content=content, custom_css=template_args['css']) 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