manual: script takes cmd line params

This commit is contained in:
Milanka Ringwald 2015-04-24 10:00:17 +02:00
parent 88f21ad11b
commit 4b0c7d42c3
2 changed files with 61 additions and 41 deletions

View File

@ -1,11 +1,11 @@
pdf: clean
python update_listings.py
./update_listings.py
pdflatex btstack_gettingstarted.tex
pdflatex btstack_gettingstarted.tex
open btstack_gettingstarted.pdf
example:
python update_listings.py
./update_listings.py -s 1
subl examples.tex
pdflatex examples.tex
open examples.pdf

View File

@ -1,11 +1,7 @@
#!/usr/bin/env python
import os
import re
import sys
docs_folder = ""
appendix_file = docs_folder + "examples.tex"
stand_alone_doc = 1
import sys, getopt
lst_header = """
\\begin{lstlisting}
@ -75,12 +71,12 @@ list_of_examples = {
class State:
SearchExampleStart = 0
SearchListingStart = 2
SearchListingPause = 4
SearchListingResume = 5
SearchListingEnd = 6
SearchItemizeEnd = 7
ReachedExampleEnd = 8
SearchListingStart = 1
SearchListingPause = 2
SearchListingResume = 3
SearchListingEnd = 4
SearchItemizeEnd = 5
ReachedExampleEnd = 6
def replacePlaceholder(template, title, lable):
snippet = template.replace("API_TITLE", title).replace("API_LABLE", lable)
@ -132,7 +128,7 @@ def processTextLine(line):
return ""
def writeListings(fout, infile_name):
def writeListings(aout, infile_name):
itemText = None
state = State.SearchExampleStart
code_in_listing = ""
@ -234,7 +230,8 @@ def writeListings(fout, infile_name):
# write list of examples
with open(appendix_file, 'w') as aout:
def processExamples(examples_file, stand_alone_doc):
with open(examples_file, 'w') as aout:
if stand_alone_doc:
aout.write(document_begin)
aout.write(examples_header)
@ -264,3 +261,26 @@ with open(appendix_file, 'w') as aout:
if stand_alone_doc:
aout.write(document_end)
def main(argv):
outputfile = "examples.tex"
standalone_flag = 0
try:
opts, args = getopt.getopt(argv,"hs:o:",["sflag=","ofile="])
except getopt.GetoptError:
print 'test.py [-s <standaloneflag>] [-o <outputfile>]'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'update_listings.py [-s <standalone_flag>] [-o <outputfile>]'
sys.exit()
elif opt in ("-s", "--sflag"):
standalone_flag = arg
elif opt in ("-o", "--ofile"):
outputfile = arg
print 'Standalone flag is ', standalone_flag
print 'Output file is ', outputfile
processExamples(outputfile, standalone_flag)
if __name__ == "__main__":
main(sys.argv[1:])