mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-05-21 19:22:05 +00:00
the man1,man3,man5,man8 subdirectories. Created the index file to display a glob of the generated rst files
66 lines
2.2 KiB
Python
Executable File
66 lines
2.2 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import glob
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
from glob import glob
|
|
import shutil
|
|
|
|
#TODO: Delete the old files to support removing a man page
|
|
|
|
def cmd_exists(cmd):
|
|
return subprocess.call("type " + cmd, shell=True,
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0
|
|
|
|
if not cmd_exists("pod2rst"):
|
|
print "ERROR, %s requires pod2rst to continue!" %(os.path.basename(__file__))
|
|
sys.exit(1)
|
|
|
|
# the location relativate to xcat-core where the man pages will go
|
|
MANPAGE_DEST="./docs/source/guides/admin-guides/references/man"
|
|
|
|
#
|
|
# add the following to delete the generate files before creating them
|
|
# essentially this allows us to remove man pages and they will be
|
|
# removed in the generation
|
|
print "Cleaning up the generated man pages in %s" %(MANPAGE_DEST)
|
|
allfiles = glob("%s*/*.rst" %(MANPAGE_DEST))
|
|
for d in allfiles:
|
|
# Skip over the index.rst file
|
|
if not "index.rst" in d:
|
|
print "Removing file %s" %(d)
|
|
os.remove(d)
|
|
|
|
# List the xCAT component directory which contain pod pages
|
|
COMPONENTS = ['xCAT-SoftLayer', 'xCAT-test', 'xCAT-client', 'xCAT-vlan']
|
|
|
|
for component in COMPONENTS:
|
|
for root,dirs,files in os.walk("%s" %(component)):
|
|
|
|
for file in files:
|
|
# only interested in .pod files
|
|
if file.endswith(".pod"):
|
|
pod_input = os.path.join(root,file)
|
|
|
|
filename = os.path.basename(pod_input)
|
|
# get the man version (1,3,5,8,etc)
|
|
man_ver = filename.split('.')[1]
|
|
# title is needed to pass to pod2rst
|
|
title = filename.split('.')[0]
|
|
|
|
DESTINATION = "%s%s" %(MANPAGE_DEST, man_ver)
|
|
try:
|
|
os.stat(DESTINATION)
|
|
except:
|
|
# Create the directory if it does not exist
|
|
os.mkdir(DESTINATION)
|
|
|
|
outputFile = filename.replace("pod", "rst")
|
|
rst_output = "%s/%s" %(DESTINATION, outputFile)
|
|
|
|
# generate the pod2rst command
|
|
cmd = "pod2rst --infile=%s --outfile=%s --title=%s.%s" %(pod_input, rst_output, title, man_ver)
|
|
print cmd
|
|
os.system(cmd)
|