def articleListGen(fromFolder, saveFolder, webResourceRoot): # article list pregenerate categoryStruct = articleCmp.fileStruct(fromFolder) # article list generate articleListString = '' for c in categoryStruct: categoryStruct[c] = sorted(categoryStruct[c], key=str.lower) articleListString += '<div class="category">\n' articleListString += '<div class="categoryTitle">' + c + '</div>\n' articleListString += '<div class="categoryList">\n' for f in categoryStruct[c]: articleListString += '<div class="articleLink"><a href="' + webResourceRoot + saveFolder + '/' + c + '/' + f + '.html' + '">' + f + '</a></div>\n' articleListString += '</div>\n' articleListString += '</div>\n' return articleListString
def main(argv): # json file confJsonFile = open('json/conf.json', 'r') confJsonString = confJsonFile.read() confJson = json.loads(confJsonString) confJson = bytify.byteify(confJson) # templete file templeteFile = open(confJson['templetePath'], 'r') templeteString = templeteFile.read() # other generate settings webResourceRoot = confJson['webResourceRoot'] fromFolder = confJson['sourcePath'] saveFolder = confJson['destinationPath'] # commandline args fetch try: opts, args = getopt.getopt(argv, "sgn", ["status", "generate", "nongenerated"]) except getopt.GetoptError: print 'anthoGen.py -s --status' print 'anthoGen.py -n --nongenerated' sys.exit(2) # jobs for opt, arg in opts: if opt in ("-s", "--status"): print "nothing." sys.exit() elif opt in ("-g", "--generate"): # MODULE: article list generate articleListString = pageGen.articleListGen(fromFolder, saveFolder, webResourceRoot) # MODULE: HTML content generate pageGen.articleGen(fromFolder, saveFolder, webResourceRoot, articleListString, templeteString) # MODULE: Index page generate indexTempletePath = confJson['indexTempletePath'] pageGen.indexPageGen(indexTempletePath, articleListString) sys.exit() elif opt in ("-n", "--nongenerated"): src = articleCmp.fileStruct(fromFolder) dst = articleCmp.fileStruct(saveFolder) notgencat, notgenart = articleCmp.fileStructCmp(src, dst) print '' print '[not generated categories:]' print notgencat print '' print '[not generated articles:]' print notgenart sys.exit() print 'Nothing is done.'