diff --git a/makeJargon.py b/makeJargon.py index 015737b..29012f3 100755 --- a/makeJargon.py +++ b/makeJargon.py @@ -1,6 +1,7 @@ import os import string import operator +import time def jargonParseEntry(filename): if not os.path.isfile(filename): @@ -64,7 +65,17 @@ def jargonGetEntries(entriesDir): entries.sort(key=operator.itemgetter(0)) return entries -def jargonManpageWithDefinitions(text, definitions): +# saves the license details +def saveLicense(fp, year, publishername): + fp.write("Copyright (c) " + str(year) + " " + publishername + "\n") + fp.write("Permission is granted to copy, distribute and/or modify this document\n") + fp.write("under the terms of the GNU Free Documentation License, Version 1.3\n") + fp.write("or any later version published by the Free Software Foundation;\n") + fp.write("with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.\n") + fp.write("A copy of the license is included in the section entitled \"GNU\n") + fp.write("Free Documentation License\".\n\n") + +def jargonWithDefinitions(text, definitions): result = '' prevpos = 0 for i in range(definitions): @@ -76,23 +87,29 @@ def jargonManpageWithDefinitions(text, definitions): prevpos = pos return result + "\n\n" + text[prevpos:] -def jargonToManpage(manpageFilename, entries, version): - if not os.path.isdir("man"): - os.system("mkdir man") +def jargonToManpage(manpageFilename, entries, version, publishername): + year = int(time.strftime("%Y")) + + if not os.path.isdir("docs"): + os.system("mkdir docs") if os.path.isfile(manpageFilename + ".gz"): os.system("rm " + manpageFilename + ".gz") fp = open(manpageFilename,'w') - fp.write(".TH \"The Jargon File\" 1 \"April 26, 2014\" \"\" \"" + version + "\"\n\n") + fp.write(".TH \"The Jargon File\" 1 \"" + time.strftime("%x") + \ + "\" \"\" \"" + version + "\"\n\n") + + fp.write(".SH LICENSE\n\n") + saveLicense(fp, year, publishername) for entry in entries: title = entry[0] text = entry[1] definitions = jargonSubdefinitions(entry[1]) if definitions > 1: - text = jargonManpageWithDefinitions(text, definitions) + text = jargonWithDefinitions(text, definitions) fp.write(".SH " + title + "\n") fp.write(text + "\n\n") @@ -103,7 +120,46 @@ def jargonToManpage(manpageFilename, entries, version): print "manpage can be installed with the command:" print "sudo install -m 644 " + manpageFilename + ".gz /usr/local/share/man/man1" +def jargonToOrgMode(orgFilename, entries, version, publishername): + year = int(time.strftime("%Y")) + + if not os.path.isdir("docs"): + os.system("mkdir docs") + + if os.path.isfile(orgFilename): + os.system("rm " + orgFilename) + + fp = open(orgFilename,'w') + + fp.write("#+TITLE: The Jaqrgon File\n") + fp.write("#+VERSION " + version + "\n") + fp.write("#+OPTIONS: ^:nil\n") + fp.write("#+STYLE: \n\n") + + fp.write("#+BEGIN_CENTER\n") + fp.write("*Yet more Jargon*\n") + fp.write("#+END_CENTER\n\n") + + fp.write("* License\n\n") + saveLicense(fp, year, publishername) + + fp.write("* Glossary\n") + + for entry in entries: + title = entry[0] + text = entry[1] + definitions = jargonSubdefinitions(entry[1]) + if definitions > 1: + text = jargonWithDefinitions(text, definitions) + + fp.write("** " + title + "\n") + fp.write(text + "\n\n") + fp.close() + + if __name__ == "__main__": version = "x.xx" + publishername = "My Name" entries = jargonGetEntries('entries') - jargonToManpage("man/jargon.1", entries, version) + jargonToManpage("docs/jargon.1", entries, version, publishername) + jargonToOrgMode("docs/jargon-org.txt", entries, version, publishername)