mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-23 01:21:28 +00:00
introduced cmd line args in script
This commit is contained in:
parent
8e8debb67a
commit
17065c116c
@ -8,7 +8,7 @@ pages:
|
||||
- [how_to.md, How to use BTstack]
|
||||
- [protocols.md, Supported Protocols]
|
||||
- [profiles.md, Supported Profiles]
|
||||
- [examples/generated.md, Embedded Examples]
|
||||
- [examples/examples.md, Embedded Examples]
|
||||
- [porting.md, Porting to Other Platforms]
|
||||
- [integration.md, Integrating with Existing Systems]
|
||||
- [appendix/apis.md, APIs]
|
||||
|
@ -1,7 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import os, sys, getopt, re
|
||||
|
||||
class State:
|
||||
SearchStartAPI = 0
|
||||
@ -9,11 +7,6 @@ class State:
|
||||
SearchEndAPI = 2
|
||||
DoneAPI = 3
|
||||
|
||||
docs_folder = "docs/appendix/"
|
||||
appendix_file = docs_folder + "apis.md"
|
||||
btstack_folder = "../../"
|
||||
code_identation = " "
|
||||
|
||||
api_header = """
|
||||
|
||||
## API_TITLE API {#sec:API_LABLEAPIAppendix}
|
||||
@ -23,31 +16,15 @@ api_header = """
|
||||
api_ending = """
|
||||
"""
|
||||
|
||||
# [file_name, api_title, api_lable]
|
||||
list_of_apis = [
|
||||
[btstack_folder+"include/btstack/run_loop.h", "Run Loop", "runLoop"],
|
||||
[btstack_folder+"src/hci.h", "HCI", "hci"],
|
||||
[btstack_folder+"src/l2cap.h", "L2CAP", "l2cap"],
|
||||
[btstack_folder+"src/rfcomm.h", "RFCOMM", "rfcomm"],
|
||||
[btstack_folder+"src/sdp.h", "SDP", "sdp"],
|
||||
[btstack_folder+"src/sdp_client.h", "SDP Client", "sdpClient"],
|
||||
[btstack_folder+"src/sdp_query_rfcomm.h", "SDP RFCOMM Query", "sdpQueries"],
|
||||
[btstack_folder+"ble/gatt_client.h", "GATT Client", "gattClient"],
|
||||
[btstack_folder+"src/pan.h", "PAN", "pan"],
|
||||
[btstack_folder+"src/bnep.h", "BNEP", "bnep"],
|
||||
[btstack_folder+"src/gap.h", "GAP", "gap"],
|
||||
[btstack_folder+"ble/sm.h", "SM", "sm"]
|
||||
]
|
||||
|
||||
def replacePlaceholder(template, title, lable):
|
||||
api_title = title + " API"
|
||||
snippet = template.replace("API_TITLE", title).replace("API_LABLE", lable)
|
||||
return snippet
|
||||
|
||||
def writeAPI(fout, infile_name):
|
||||
global code_identation
|
||||
def writeAPI(fout, api_filename, mk_codeidentation):
|
||||
state = State.SearchStartAPI
|
||||
with open(infile_name, 'rb') as fin:
|
||||
with open(api_filename, 'rb') as fin:
|
||||
for line in fin:
|
||||
if state == State.SearchStartAPI:
|
||||
parts = re.match('\s*(/\*).*API_START.*(\*/)',line)
|
||||
@ -65,24 +42,58 @@ def writeAPI(fout, infile_name):
|
||||
if parts:
|
||||
state = State.DoneAPI
|
||||
return
|
||||
fout.write(code_identation + line)
|
||||
|
||||
def process_and_write_api(fout, api_tuple):
|
||||
infile_name = api_tuple[0]
|
||||
if not infile_name:
|
||||
return
|
||||
|
||||
api_title = api_tuple[1]
|
||||
api_lable = api_tuple[2]
|
||||
|
||||
fout.write(replacePlaceholder(api_header, api_title, api_lable))
|
||||
writeAPI(fout, infile_name)
|
||||
|
||||
|
||||
with open(appendix_file, 'w') as aout:
|
||||
for api_tuple in list_of_apis:
|
||||
infile_name = api_tuple[0]
|
||||
if not infile_name:
|
||||
continue
|
||||
process_and_write_api(aout, api_tuple)
|
||||
fout.write(mk_codeidentation + line)
|
||||
|
||||
def main(argv):
|
||||
btstackfolder = "../../"
|
||||
docsfolder = "docs/"
|
||||
mk_codeidentation = " "
|
||||
|
||||
outputfile = docsfolder + "appendix/apis.md"
|
||||
|
||||
cmd = 'update_apis.py [-b <btstackfolder>] [-o <outputfile>]'
|
||||
try:
|
||||
opts, args = getopt.getopt(argv,"hiso:",["bfolder=","ofile="])
|
||||
except getopt.GetoptError:
|
||||
print cmd
|
||||
sys.exit(2)
|
||||
for opt, arg in opts:
|
||||
if opt == '-h':
|
||||
print cmd
|
||||
sys.exit()
|
||||
elif opt in ("-b", "--bfolder"):
|
||||
btstackfolder = arg
|
||||
elif opt in ("-o", "--ofile"):
|
||||
outputfile = arg
|
||||
print 'BTstack folder is ', btstackfolder
|
||||
print 'Output file is ', outputfile
|
||||
|
||||
|
||||
# [file_name, api_title, api_lable]
|
||||
list_of_apis = [
|
||||
[btstackfolder+"include/btstack/run_loop.h", "Run Loop", "runLoop"],
|
||||
[btstackfolder+"src/hci.h", "HCI", "hci"],
|
||||
[btstackfolder+"src/l2cap.h", "L2CAP", "l2cap"],
|
||||
[btstackfolder+"src/rfcomm.h", "RFCOMM", "rfcomm"],
|
||||
[btstackfolder+"src/sdp.h", "SDP", "sdp"],
|
||||
[btstackfolder+"src/sdp_client.h", "SDP Client", "sdpClient"],
|
||||
[btstackfolder+"src/sdp_query_rfcomm.h", "SDP RFCOMM Query", "sdpQueries"],
|
||||
[btstackfolder+"ble/gatt_client.h", "GATT Client", "gattClient"],
|
||||
[btstackfolder+"src/pan.h", "PAN", "pan"],
|
||||
[btstackfolder+"src/bnep.h", "BNEP", "bnep"],
|
||||
[btstackfolder+"src/gap.h", "GAP", "gap"],
|
||||
[btstackfolder+"ble/sm.h", "SM", "sm"]
|
||||
]
|
||||
|
||||
with open(outputfile, 'w') as fout:
|
||||
for api_tuple in list_of_apis:
|
||||
api_filename = api_tuple[0]
|
||||
api_title = api_tuple[1]
|
||||
api_lable = api_tuple[2]
|
||||
|
||||
fout.write(replacePlaceholder(api_header, api_title, api_lable))
|
||||
writeAPI(fout, api_filename, mk_codeidentation)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
|
@ -1,7 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import re
|
||||
import sys, getopt
|
||||
import os, sys, getopt, re
|
||||
|
||||
# Defines the names of example groups. Preserves the order in which the example groups will be parsed.
|
||||
list_of_groups = ["Hello World", "GAP", "SDP Queries", "SPP Server", "BNEP/PAN", "Low Energy", "Dual Mode"]
|
||||
@ -305,29 +303,34 @@ def processExamples(intro_file, examples_folder, examples_ofile):
|
||||
|
||||
|
||||
def main(argv):
|
||||
btstack_folder = "../../"
|
||||
docs_folder = "docs/examples/"
|
||||
inputfolder = btstack_folder + "example/embedded/"
|
||||
outputfile = docs_folder + "generated.md"
|
||||
intro_file = "docs/examples/intro.md"
|
||||
|
||||
btstackfolder = "../../"
|
||||
docsfolder = "docs/"
|
||||
|
||||
inputfolder = btstackfolder + "example/embedded/"
|
||||
introfile = docsfolder + "examples/intro.md"
|
||||
outputfile = docsfolder + "examples/examples.md"
|
||||
|
||||
cmd = 'update_listings.py [-f <inputfolder>] [-i <introfile>] [-o <outputfile>]'
|
||||
try:
|
||||
opts, args = getopt.getopt(argv,"hiso:",["ifolder=","ofile="])
|
||||
opts, args = getopt.getopt(argv,"hiso:",["ffolder=","ifile=","ofile="])
|
||||
except getopt.GetoptError:
|
||||
print 'update_listings.py [-i <inputfolder>] [-o <outputfile>]'
|
||||
print cmd
|
||||
sys.exit(2)
|
||||
for opt, arg in opts:
|
||||
if opt == '-h':
|
||||
print 'update_listings.py [-i <inputfolder>] [-s] [-o <outputfile>]'
|
||||
print cmd
|
||||
sys.exit()
|
||||
elif opt in ("-i", "--ifolder"):
|
||||
elif opt in ("-f", "--ffolder"):
|
||||
inputfolder = arg
|
||||
elif opt in ("-i", "--ifile"):
|
||||
introfile = arg
|
||||
elif opt in ("-o", "--ofile"):
|
||||
outputfile = arg
|
||||
print 'Input folder is ', inputfolder
|
||||
print 'Intro file is ', introfile
|
||||
print 'Output file is ', outputfile
|
||||
|
||||
processExamples(intro_file, inputfolder, outputfile)
|
||||
processExamples(introfile, inputfolder, outputfile)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
|
Loading…
x
Reference in New Issue
Block a user