From: Jihoon Lee Date: Thu, 2 Apr 2020 01:56:54 +0000 (+0900) Subject: [Tools/dev] Check if *.py is running on shell X-Git-Tag: submit/tizen/20200407.071404~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=25da8ff58a243dde15298df5299afbf36698cd64;p=platform%2Fupstream%2Fnnstreamer.git [Tools/dev] Check if *.py is running on shell Add `if __name__ == '__main__'` to check if *.py is running on shell to prevent unwanted crash if users happen to import those files to customize tools. Signed-off-by: Jihoon Lee --- diff --git a/tools/development/count_test_cases.py b/tools/development/count_test_cases.py index 88ef224..9eec259 100644 --- a/tools/development/count_test_cases.py +++ b/tools/development/count_test_cases.py @@ -51,12 +51,12 @@ def readSSAT(filename): print("No SSAT results.") return (0, 0, 0, 0, 0) -def main(): +if __name__ == '__main__': if len(sys.argv) != 3: print("Usage:") print(" $ "+sys.argv[0]+" ") print("") - return 1 + sys.exit(1) tg = 0 pg = 0 @@ -84,6 +84,5 @@ def main(): print(" Passed: " + str(p) + " / Failed: " + str(f) + " / Ignored: " + str(i) + " | Positive: " + str(t - n) + " / Negative: " + str(n)) print("Grand Total: " + str(pg + t) + " cases (negatives : " + str(ng + n) + ")") print(" Passed: " + str(pg+p) + " / Failed: " + str(fg + f) + " / Ignored: " + str(ig + i)) - return 0 + sys.exit(0) -main() diff --git a/tools/development/nnstreamerCodeGenCustomFilter.py b/tools/development/nnstreamerCodeGenCustomFilter.py index 5c56509..76656bc 100644 --- a/tools/development/nnstreamerCodeGenCustomFilter.py +++ b/tools/development/nnstreamerCodeGenCustomFilter.py @@ -411,56 +411,57 @@ shared_library('{fname}', """ -## This is for debugging. To be removed. -today = date.today() - -## 1. Ask for name. -name = getinput('Please enter the name of the nnstreamer custom filter: ') -sname = ''.join(re.findall(r"([a-zA-Z0-9_]+)", name)) -def_fname = ''.join(re.findall(r"([a-zA-Z0-9_]+)", name)) -## @todo @warning We may require prefix for all custom filter in later versions. -## 2. Ask/Check for fname (file & official custom filter name) -print('Please enter the custom filter name registered to tensor_filter.') -fname = getinput('Or press enter without name if ['+def_fname+'] is ok: ') -fname = ''.join(re.findall(r"([a-zA-Z0-9_]+)", fname)) -if len(fname) < 1: - fname = def_fname - -result = common_head - -## 3. Ask for options (dimension configuration modes) -while 1: - option = getinput('Are dimensions of input/output tensors fixed? (yes/no):') - option = option.lower() - if option == 'y' or option == 'yes': - result += dim_fixed - break - if option == 'n' or option == 'no': - result += dim_variable - break - print("Please enter yes/y or no/n") - -## 4. Ask for options (memory allocation modes) -while 1: - option = getinput('Are you going to allocate output buffer in your code? (yes/no):') - option = option.lower() - if option == 'y' or option == 'yes': - result += invoke_allocate - break - if option == 'n' or option == 'no': - result += invoke_no_allocate - break - print("Please enter yes/y or no/n") - -## 5. Generate .C file -result += common_tail -ccode = result.format(fname=fname, name=name, sname=sname, today=today) -cfile = open(fname+".c", "w") -cfile.write(ccode) -cfile.close() - -## 6. Generate .meson file -mesoncode = meson_script.format(fname=fname, name=name, sname=sname, today=today) -mesonfile = open("meson.build", "w") -mesonfile.write(mesoncode) -mesonfile.close() +if __name__ == '__main__': + ## This is for debugging. To be removed. + today = date.today() + + ## 1. Ask for name. + name = getinput('Please enter the name of the nnstreamer custom filter: ') + sname = ''.join(re.findall(r"([a-zA-Z0-9_]+)", name)) + def_fname = ''.join(re.findall(r"([a-zA-Z0-9_]+)", name)) + ## @todo @warning We may require prefix for all custom filter in later versions. + ## 2. Ask/Check for fname (file & official custom filter name) + print('Please enter the custom filter name registered to tensor_filter.') + fname = getinput('Or press enter without name if ['+def_fname+'] is ok: ') + fname = ''.join(re.findall(r"([a-zA-Z0-9_]+)", fname)) + if len(fname) < 1: + fname = def_fname + + result = common_head + + ## 3. Ask for options (dimension configuration modes) + while 1: + option = getinput('Are dimensions of input/output tensors fixed? (yes/no):') + option = option.lower() + if option == 'y' or option == 'yes': + result += dim_fixed + break + if option == 'n' or option == 'no': + result += dim_variable + break + print("Please enter yes/y or no/n") + + ## 4. Ask for options (memory allocation modes) + while 1: + option = getinput('Are you going to allocate output buffer in your code? (yes/no):') + option = option.lower() + if option == 'y' or option == 'yes': + result += invoke_allocate + break + if option == 'n' or option == 'no': + result += invoke_no_allocate + break + print("Please enter yes/y or no/n") + + ## 5. Generate .C file + result += common_tail + ccode = result.format(fname=fname, name=name, sname=sname, today=today) + cfile = open(fname+".c", "w") + cfile.write(ccode) + cfile.close() + + ## 6. Generate .meson file + mesoncode = meson_script.format(fname=fname, name=name, sname=sname, today=today) + mesonfile = open("meson.build", "w") + mesonfile.write(mesoncode) + mesonfile.close()