<s> import os <EOL> import fileinput <EOL> import distutils . core <EOL> from markup_formatter import * <EOL> from javadoc_parser import * <EOL> import markup_formatter <EOL> from xml . dom import HierarchyRequestErr <EOL> '''<STR_LIT>''' <EOL> class Wiki : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , appname , repodir , graph , wikidir ) : <EOL> self . appname = appname <EOL> self . repodir = repodir <EOL> self . wikidir = wikidir <EOL> self . graph = graph <EOL> self . create ( ) <EOL> self . pageName = None <EOL> self . text = None <EOL> '''<STR_LIT>''' <EOL> def create ( self ) : <EOL> src = os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) , '<STR_LIT>' ) <EOL> dest = self . wikidir <EOL> if not os . path . exists ( dest ) : <EOL> os . makedirs ( dest ) <EOL> for file in os . listdir ( dest ) : <EOL> if file [ <NUM_LIT:0> ] != '<STR_LIT:.>' : <EOL> path = os . path . join ( dest , file ) <EOL> try : <EOL> if os . path . isfile ( path ) : <EOL> os . unlink ( path ) <EOL> except Exception , e : <EOL> print e <EOL> distutils . dir_util . copy_tree ( src , dest ) <EOL> self . setTemplate ( '<STR_LIT:title>' , self . appname ) <EOL> self . setTemplate ( '<STR_LIT>' , self . getReadme ( ) ) <EOL> '''<STR_LIT>''' <EOL> def createPage ( self ) : <EOL> file = open ( os . path . join ( self . wikidir , self . pageName ) , '<STR_LIT:w>' ) <EOL> file . write ( self . text ) <EOL> file . close ( ) <EOL> self . pageName = None <EOL> self . text = None <EOL> '''<STR_LIT>''' <EOL> def appendTitlePage ( self , title , text ) : <EOL> titlemod = title + '<STR_LIT>' <EOL> file = open ( os . path . join ( self . wikidir , titlemod ) , '<STR_LIT:a>' ) <EOL> file . write ( text ) <EOL> file . close ( ) <EOL> '''<STR_LIT>''' <EOL> def buildClass ( self , javadoc ) : <EOL> self . pageName = javadoc . getContext ( ) . getFullName ( ) + '<STR_LIT>' <EOL> self . text = '<STR_LIT>' <EOL> self . text += self . formatJavadoc ( javadoc ) <EOL> self . text += '<STR_LIT:\n>' <EOL> def buildInnerClass ( self , javadoc ) : <EOL> self . text += '<STR_LIT>' <EOL> self . text += "<STR_LIT>" . format ( javadoc . getSourceLine ( ) . getDisplay ( ) ) <EOL> self . text += self . formatJavadoc ( javadoc ) <EOL> '''<STR_LIT>''' <EOL> def buildMethod ( self , javadoc ) : <EOL> self . text += "<STR_LIT>" . format ( javadoc . getSourceLine ( ) . getName ( ) ) <EOL> self . text += "<STR_LIT>" . format ( javadoc . getSourceLine ( ) . getText ( ) ) <EOL> self . text += self . formatJavadoc ( javadoc ) <EOL> '''<STR_LIT>''' <EOL> def buildField ( self , javadoc ) : <EOL> self . text += "<STR_LIT>" . format ( javadoc . getSourceLine ( ) . getName ( ) ) <EOL> self . text += "<STR_LIT>" . format ( javadoc . getSourceLine ( ) . getText ( ) ) <EOL> self . text += self . formatJavadoc ( javadoc ) <EOL> '''<STR_LIT>''' <EOL> def addToHomePage ( self , javadoc , hierarchy ) : <EOL> name = javadoc . sourceLine . name <EOL> if hierarchy == <NUM_LIT:0> : <EOL> type = '<STR_LIT>' <EOL> elif hierarchy == <NUM_LIT:1> : <EOL> type = '<STR_LIT>' <EOL> else : <EOL> type = '<STR_LIT>' <EOL> text = '<STR_LIT>' . format ( '<STR_LIT:U+0020>' * hierarchy , link ( name , name ) ) <EOL> self . appendTitlePage ( '<STR_LIT>' , text ) <EOL> self . appendTitlePage ( '<STR_LIT>' , text ) <EOL> '''<STR_LIT>''' <EOL> def getReadme ( self ) : <EOL> path = os . path . join ( self . repodir , '<STR_LIT>' ) <EOL> if os . path . isfile ( path ) : <EOL> readmeFile = open ( path , '<STR_LIT:r>' ) <EOL> readme = readmeFile . read ( ) <EOL> readmeFile . close ( ) <EOL> return readme <EOL> else : <EOL> return None <EOL> def formatJavadoc ( self , javadoc ) : <EOL> text = '<STR_LIT>' <EOL> if javadoc : <EOL> if javadoc . getMainDesc ( ) : <EOL> text += "<STR_LIT>" . format ( self . formatText ( javadoc . getMainDesc ( ) ) ) <EOL> if javadoc . getBlockTags ( ) : <EOL> text += self . formatTagSection ( javadoc . getBlockTags ( ) ) <EOL> return "<STR_LIT>" . format ( text ) <EOL> '''<STR_LIT>''' <EOL> def formatText ( self , mainDesc ) : <EOL> text = '<STR_LIT>' <EOL> for item in mainDesc . getContent ( ) : <EOL> if isinstance ( item , InlineTag ) : <EOL> text += self . formatLink ( item ) <EOL> else : <EOL> item = re . sub ( r'<STR_LIT>' , '<STR_LIT:U+0020>' , item ) <EOL> text += str ( item ) <EOL> return text <EOL> '''<STR_LIT>''' <EOL> def formatLink ( self , link ) : <EOL> if isinstance ( link , StringLink ) : <EOL> return "<STR_LIT>" . format ( link . getStr ( ) ) <EOL> elif isinstance ( link , HtmlLink ) : <EOL> return "<STR_LIT>" . format ( link . getLabel ( ) , link . getHref ( ) ) <EOL> elif isinstance ( link , JavadocLink ) : <EOL> clsName = self . graph . resolveLink ( link ) <EOL> if clsName : <EOL> return "<STR_LIT>" . format ( clsName , clsName ) <EOL> else : <EOL> return link . text <EOL> else : <EOL> return "<STR_LIT>" <EOL> '''<STR_LIT>''' <EOL> def formatTagSection ( self , blocktags , italic = False ) : <EOL> text = "<STR_LIT>" <EOL> def formatTextContent ( content ) : <EOL> text = "<STR_LIT>" <EOL> for something in content : <EOL> if isinstance ( something , basestring ) : <EOL> text += something <EOL> elif something . getLink ( ) : <EOL> text += self . formatLink ( something . getLink ( ) ) <EOL> return text <EOL> authorTag = [ blocktag for blocktag in blocktags if blocktag . getName ( ) == "<STR_LIT>" ] <EOL> if len ( authorTag ) > <NUM_LIT:0> : <EOL> text += "<STR_LIT>" . format ( self . formatText ( authorTag [ <NUM_LIT:0> ] . getText ( ) ) ) <EOL> versionTag = [ blocktag for blocktag in blocktags if blocktag . getName ( ) == "<STR_LIT:version>" ] <EOL> if len ( versionTag ) > <NUM_LIT:0> : <EOL> text += "<STR_LIT>" . format ( self . formatText ( versionTag [ <NUM_LIT:0> ] . getText ( ) ) ) <EOL> paramTags = [ blocktag for blocktag in blocktags if blocktag . getName ( ) == "<STR_LIT>" ] <EOL> if len ( paramTags ) > <NUM_LIT:0> : <EOL> text += "<STR_LIT>" <EOL> for paramTag in paramTags : <EOL> content = paramTag . getText ( ) . getContent ( ) <EOL> if len ( content ) > <NUM_LIT:0> : <EOL> first = re . split ( '<STR_LIT>' , content [ <NUM_LIT:0> ] ) <EOL> var = first [ <NUM_LIT:0> ] <EOL> text += "<STR_LIT>" . format ( var , '<STR_LIT:U+0020>' . join ( first [ <NUM_LIT:1> : ] ) , formatTextContent ( content [ <NUM_LIT:1> : ] ) ) <EOL> returnTag = [ blocktag for blocktag in blocktags if blocktag . getName ( ) == "<STR_LIT>" ] <EOL> if len ( returnTag ) > <NUM_LIT:0> : <EOL> content = returnTag [ <NUM_LIT:0> ] . getText ( ) . getContent ( ) <EOL> if len ( content ) > <NUM_LIT:0> : <EOL> text += "<STR_LIT>" . format ( formatTextContent ( content ) ) <EOL> throwsTags = [ blocktag for blocktag in blocktags if blocktag . getName ( ) == "<STR_LIT>" ] <EOL> if len ( throwsTags ) > <NUM_LIT:0> : <EOL> text += "<STR_LIT>" <EOL> for throwsTag in throwsTags : <EOL> content = throwsTag . getText ( ) . getContent ( ) <EOL> if len ( content ) > <NUM_LIT:0> : <EOL> first = re . split ( '<STR_LIT>' , content [ <NUM_LIT:0> ] ) <EOL> typ = first [ <NUM_LIT:0> ] <EOL> text += "<STR_LIT>" . format ( typ , '<STR_LIT:U+0020>' . join ( first [ <NUM_LIT:1> : ] ) , formatTextContent ( content [ <NUM_LIT:1> : ] ) ) <EOL> seeTags = [ blocktag for blocktag in blocktags if blocktag . getName ( ) == "<STR_LIT>" ] <EOL> if len ( seeTags ) > <NUM_LIT:0> : <EOL> text += "<STR_LIT>" <EOL> for seeTag in seeTags : <EOL> content = seeTag . getText ( ) . getContent ( ) <EOL> if len ( content ) > <NUM_LIT:0> : <EOL> text += "<STR_LIT>" . format ( formatTextContent ( content ) ) <EOL> sinceTag = [ blocktag for blocktag in blocktags if blocktag . getName ( ) == "<STR_LIT>" ] <EOL> if len ( sinceTag ) > <NUM_LIT:0> : <EOL> text += "<STR_LIT>" . format ( self . formatText ( sinceTag [ <NUM_LIT:0> ] . getText ( ) ) ) <EOL> deprecatedTag = [ blocktag for blocktag in blocktags if blocktag . getName ( ) == "<STR_LIT>" ] <EOL> if len ( deprecatedTag ) > <NUM_LIT:0> : <EOL> content = deprecatedTag . getText ( ) . getContent ( ) <EOL> if len ( content ) > <NUM_LIT:0> : <EOL> text += "<STR_LIT>" . format ( formatTextContent ( content ) ) <EOL> return text <EOL> '''<STR_LIT>''' <EOL> def setTemplate ( self , tag , text ) : <EOL> if isinstance ( text , list ) : <EOL> text = '<STR_LIT:\n>' . join ( text ) <EOL> for title in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> f = os . path . join ( self . wikidir , title ) <EOL> if os . path . isfile ( f ) : <EOL> strbuild = '<STR_LIT>' % tag <EOL> h = open ( f , '<STR_LIT:r>' ) <EOL> contents = h . read ( ) <EOL> contents = contents . replace ( strbuild , text ) <EOL> h . close ( ) <EOL> h = open ( f , '<STR_LIT:w>' ) <EOL> h . write ( contents ) </s>
