Skip to content

Commit

Permalink
Changes required to let mcdoc generate output in "docdir"
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Willendrup committed Jul 31, 2024
1 parent 70a3079 commit 9ed32ce
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ if( BUILD_MCSTAS )
if ( ENABLE_COMPONENTS )
add_subdirectory(mcstas-comps)
endif()
add_subdirectory(docpkg/manuals/mcstas)
endif()

if ( BUILD_MCXTRACE )
Expand All @@ -61,6 +62,7 @@ if ( BUILD_MCXTRACE )
if ( ENABLE_COMPONENTS )
add_subdirectory(mcxtrace-comps)
endif()
add_subdirectory(docpkg/manuals/mcxtrace)
endif()

if ( BUILD_TOOLS )
Expand Down
3 changes: 2 additions & 1 deletion cmake/Modules/Locations.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function( configure_destination_dirs resultvarname )
destset( DEST_DATADIR_TOPENVFILES "${CMAKE_INSTALL_DATADIR}/${FLAVOR}" )
destset( DEST_DATADIR_INFO "${CMAKE_INSTALL_DATADIR}/${FLAVOR}/info" )
destset( DEST_DATADIR_EDITORS "${CMAKE_INSTALL_DATADIR}/${FLAVOR}/editors" )
destset( DEST_DATADIR_DOC "${CMAKE_INSTALL_DATADIR}/${FLAVOR}/resources/doc/manuals" )
destset( DEST_DATADIR_DOC "share/doc/${FLAVOR}" )
destset( DEST_TOOLDIR "${CMAKE_INSTALL_DATADIR}/${FLAVOR}/tools" )
endif()
set(${resultvarname} "${provided_vars}" PARENT_SCOPE)
Expand Down Expand Up @@ -86,6 +86,7 @@ file(RELATIVE_PATH MCCODE_RELPATH_BINDIR2RESOURCEDIR "${PROJECT_BINARY_DIR}/${D
file(RELATIVE_PATH MCCODE_RELPATH_BINDIR2TOOLDIR "${PROJECT_BINARY_DIR}/${DEST_BINDIR}" "${PROJECT_BINARY_DIR}/${DEST_TOOLDIR}" )
file(RELATIVE_PATH MCCODE_RELPATH_TOOLDIR2BINDIR "${PROJECT_BINARY_DIR}/${DEST_TOOLDIR}" "${PROJECT_BINARY_DIR}/${DEST_BINDIR}" )
file(RELATIVE_PATH MCCODE_RELPATH_TOOLDIR2LIBDIR "${PROJECT_BINARY_DIR}/${DEST_TOOLDIR}" "${PROJECT_BINARY_DIR}/${DEST_LIBDIR}" )
file(RELATIVE_PATH MCCODE_RELPATH_TOOLDIR2DOCDIR "${PROJECT_BINARY_DIR}/${DEST_TOOLDIR}" "${PROJECT_BINARY_DIR}/${DEST_DATADIR_DOC}" )
file(RELATIVE_PATH MCCODE_RELPATH_TOOLDIR2RESOURCEDIR "${PROJECT_BINARY_DIR}/${DEST_TOOLDIR}" "${PROJECT_BINARY_DIR}/${DEST_RESOURCEDIR}" )

#Standard preamble for bash .in scripts (expanded from @MCCODE_BASH_STANDARD_PREAMBLE@):
Expand Down
4 changes: 2 additions & 2 deletions docpkg/manuals/mcstas/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required( VERSION 3.17.0 )

# This will install McStas components
# This will install McStas manuals
set(FLAVOR mcstas)
project(${FLAVOR}_manuals C)
project(${FLAVOR} C)

set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake/Modules/")

Expand Down
4 changes: 2 additions & 2 deletions docpkg/manuals/mcxtrace/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required( VERSION 3.17.0 )

# This will install McStas components
# This will install McXtrace manuals
set(FLAVOR mcxtrace)
project(${FLAVOR}_manuals C)
project(${FLAVOR} C)

set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake/Modules/")

Expand Down
2 changes: 2 additions & 0 deletions tools/Python/mccodelib/mccode_config.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ tooldir = ( thisdir / '..' / '..' ).absolute().resolve()
resourcedir = ( tooldir / '@MCCODE_RELPATH_TOOLDIR2RESOURCEDIR@' ).absolute().resolve()
bindir = ( tooldir / '@MCCODE_RELPATH_TOOLDIR2BINDIR@' ).absolute().resolve()
libdir = ( tooldir / '@MCCODE_RELPATH_TOOLDIR2LIBDIR@' ).absolute().resolve()
docdir = ( tooldir / '@MCCODE_RELPATH_TOOLDIR2DOCDIR@' ).absolute().resolve()

def check_env_vars():
''' checks the OS environment variables '''
Expand Down Expand Up @@ -112,6 +113,7 @@ def load_config(path=None):
# Finally, set dynamically deduced directory paths:
directories['bindir'] = str( bindir )
directories['libdir'] = str( libdir )
directories['docdir'] = str( docdir )
directories['tooldir'] = str( tooldir )
directories['resourcedir'] = str( resourcedir )
directories['pydir'] = str( tooldir / 'Python' )
Expand Down
31 changes: 21 additions & 10 deletions tools/Python/mcdoc/mcdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@

def get_html_filepath(filepath):
''' transform from .anything to .html '''
return os.path.splitext(filepath)[0] + '.html'
h = os.path.splitext(filepath)[0] + '.html'
h = re.sub(mccode_config.directories['resourcedir'], mccode_config.directories['docdir'],h)
return h

class OverviewDocWriter:
''' Creates the mcdoc overview html page. '''
def __init__(self, comp_info_lst, instr_info_lst, comp_info_local_lst, instr_info_local_lst, mccode_libdir):
def __init__(self, comp_info_lst, instr_info_lst, comp_info_local_lst, instr_info_local_lst, mccode_libdir, mccode_docdir):
self.comp_info_lst = comp_info_lst
self.instr_info_lst = instr_info_lst
self.comp_info_local_lst = comp_info_local_lst
self.instr_info_local_lst = instr_info_local_lst
self.mccode_libdir = mccode_libdir
self.mccode_docdir = mccode_docdir
self.text = ''

def create(self):
Expand Down Expand Up @@ -132,6 +135,7 @@ def create(self):
text = text.replace('%TABLE_ASTROX%', '')

text = text.replace('%MCCODE_LIBDIR%', self.mccode_libdir)
text = text.replace('%MCCODE_DOCDIR%', self.mccode_docdir)
text = text.replace('%TAB_HEAD%', self.tab_header)
text = text.replace('%TAB_LINES_SOURCES%', sources_tab)
text = text.replace('%TAB_LINES_OPTICS%', optics_tab)
Expand Down Expand Up @@ -223,8 +227,8 @@ def create(self):
| <A href="%LINK_FILECOLON_SHARE%">share</A> ]
</P>
<P ALIGN=CENTER>
[ <a href="file://%MCCODE_LIBDIR%/doc/manuals/mcstas-manual.pdf">User Manual</a>
| <a href="file://%MCCODE_LIBDIR%/doc/manuals/mcstas-components.pdf">Component Manual</a> ]
[ <a href="file://%MCCODE_DOCDIR%/mcstas-manual.pdf">User Manual</a>
| <a href="file://%MCCODE_DOCDIR%/mcstas-components.pdf">Component Manual</a> ]
| <a href="file://%MCCODE_LIBDIR%/">McCode lib dir</a> ]
</P>
Expand Down Expand Up @@ -838,6 +842,10 @@ def create(self):

def write_file(filename, text, failsilent=False):
try:
dirname = os.path.dirname(filename)

if not os.path.exists(dirname):
os.makedirs(dirname)
f = open(filename, 'w')
f.write(text)
f.close()
Expand Down Expand Up @@ -897,6 +905,7 @@ def write_doc_files_or_continue(comp_infos, instr_infos, comp_files, instr_files
doc = CompDocWriter(p)
text = doc.create()
h = os.path.splitext(f)[0] + '.html'
h = re.sub(mccode_config.directories['resourcedir'], mccode_config.directories['docdir'],h)
if printlog:
print("writing doc file... %s" % h)
write_file(h, text, failsilent=True)
Expand All @@ -907,6 +916,7 @@ def write_doc_files_or_continue(comp_infos, instr_infos, comp_files, instr_files
doc = InstrDocWriter(p)
text = doc.create()
h = os.path.splitext(f)[0] + '.html'
h = re.sub(mccode_config.directories['resourcedir'], mccode_config.directories['docdir'],h)
if printlog:
print("writing doc file... %s" % h)
write_file(h, text, failsilent=True)
Expand All @@ -916,28 +926,29 @@ def main(args):
logging.basicConfig(level=logging.INFO)

usedir = mccode_config.configuration["MCCODE_LIB_DIR"]
docdir = mccode_config.directories["docdir"]

if args.dir==None and args.install==False and args.searchterm==None and args.manual==False and args.comps==False and args.web==False:
''' browse system docs and exit '''
if not os.path.isfile(os.path.join(usedir,mccode_config.get_mccode_prefix()+'doc.html')):
if not os.path.isfile(os.path.join(docdir,mccode_config.get_mccode_prefix()+'doc.html')):
try:
sub=subprocess.Popen('%s%s -i' % (mccode_config.get_mccode_prefix(), 'doc'), shell=True)
sub.wait()
except:
print("Could not write main mcdoc page, you may need admin permissions!")
quit()

subprocess.Popen('%s %s' % (mccode_config.configuration['BROWSER'], os.path.join(usedir,mccode_config.get_mccode_prefix()+'doc.html')), shell=True)
subprocess.Popen('%s %s' % (mccode_config.configuration['BROWSER'], os.path.join(docdir,mccode_config.get_mccode_prefix()+'doc.html')), shell=True)
quit()

elif args.manual == True:
''' open manual and exit '''
subprocess.Popen('%s %s' % (mccode_config.configuration['BROWSER'], os.path.join(usedir,'doc','manuals',mccode_config.configuration['MCCODE']+'-manual.pdf')), shell=True)
subprocess.Popen('%s %s' % (mccode_config.configuration['BROWSER'], os.path.join(docdir,'doc','manuals',mccode_config.configuration['MCCODE']+'-manual.pdf')), shell=True)
quit()

elif args.comps == True:
''' open component manual and exit '''
subprocess.Popen('%s %s' % (mccode_config.configuration['BROWSER'], os.path.join(usedir,'doc','manuals',mccode_config.configuration['MCCODE']+'-components.pdf')), shell=True)
subprocess.Popen('%s %s' % (mccode_config.configuration['BROWSER'], os.path.join(docdir,'doc','manuals',mccode_config.configuration['MCCODE']+'-components.pdf')), shell=True)
quit()

elif args.web == True:
Expand All @@ -958,10 +969,10 @@ def main(args):
comp_infos, instr_infos, comp_files, instr_files = parse_and_filter(usedir, recursive=True, printlog=args.verbose)
write_doc_files_or_continue(comp_infos, instr_infos, comp_files, instr_files, args.verbose)

masterdoc = OverviewDocWriter(comp_infos, instr_infos, [], [], mccode_config.configuration['MCCODE_LIB_DIR'])
masterdoc = OverviewDocWriter(comp_infos, instr_infos, [], [], mccode_config.configuration['MCCODE_LIB_DIR'], mccode_config.directories['docdir'])
text = masterdoc.create()

mcdoc_html_filepath = os.path.join(usedir,mccode_config.get_mccode_prefix()+'doc.html')
mcdoc_html_filepath = os.path.join(docdir,mccode_config.get_mccode_prefix()+'doc.html')
try:
write_file(mcdoc_html_filepath, text)
print("master doc file: %s" % mcdoc_html_filepath)
Expand Down

0 comments on commit 9ed32ce

Please sign in to comment.