0
+ − 1 #!/ur/bin/env python2
+ − 2
+ − 3 import os.path
+ − 4 from twisted.internet import defer
+ − 5 from sat.core.i18n import _
+ − 6 from sat.core.log import getLogger
+ − 7 from sat.tools.common import regex
+ − 8 log = getLogger ( __name__ )
+ − 9
+ − 10 WATCH_DIRS = []
+ − 11 DOC_DIRS_DEFAULT = ( u 'doc' , u 'docs' )
+ − 12
+ − 13
+ − 14 def prepare ( self ):
+ − 15 to_watch = set ()
+ − 16 doc_path = self . getConfig ( "doc_path" )
+ − 17 if doc_path is not None :
+ − 18 to_watch . add ( doc_path )
+ − 19 sub_docs = self . getConfig ( "sub_docs_dict" , value_type = u "path" )
+ − 20 if sub_docs is not None :
+ − 21 for d in sub_docs . values ():
+ − 22 to_watch . add ( d )
+ − 23 global WATCH_DIRS
+ − 24 WATCH_DIRS = list ( to_watch )
+ − 25
+ − 26
+ − 27 @defer . inlineCallbacks
+ − 28 def start ( self ):
+ − 29 # root documentation
+ − 30 doc_path = self . getConfig ( "doc_path" )
+ − 31 # sub docs will be generated before the root documentation
+ − 32 sub_docs = self . getConfig ( "sub_docs_dict" , value_type = u "path" )
+ − 33
+ − 34 if doc_path is None :
+ − 35 # we check if there is documentation inside the site
+ − 36 for dirname in DOC_DIRS_DEFAULT :
+ − 37 path = os . path . join ( self . site_path , dirname )
+ − 38 conf_file = os . path . join ( path , 'conf.py' )
+ − 39 if os . path . isdir ( path ) and os . path . exists ( conf_file ):
+ − 40 doc_path = path
+ − 41 break
+ − 42
+ − 43 if doc_path is None and sub_docs is None :
+ − 44 log . info ( u "No documentation found for {site_name} , skipping" . format (
+ − 45 site_name = self . site_name ))
+ − 46 return
+ − 47
+ − 48 sphinx = self . findCommand ( 'sphinx-build2' , 'sphinx-build' )
+ − 49
+ − 50 # we first generate the sub documentations
+ − 51 for name , sub_doc_path in sub_docs . iteritems ():
+ − 52 sub_dir = regex . pathEscape ( name or u '' )
+ − 53 build_path = os . path . join ( self . build_path , u 'doc' , sub_dir )
+ − 54 yield self . runCommand ( sphinx , sub_doc_path , build_path )
+ − 55
+ − 56 # then the root one
+ − 57 if doc_path is not None :
+ − 58 build_path = os . path . join ( self . build_path , u 'doc' )
+ − 59 yield self . runCommand ( sphinx , doc_path , build_path )
+ − 60
+ − 61 log . info ( _ ( u "documentation has been generated" ))