[tor-commits] [tor/master] annotate_ifdef_directives: Allow it to be imported as a module.

asn at torproject.org asn at torproject.org
Mon Sep 30 10:45:36 UTC 2019


commit d229399e77f17a8ad19a793fcc7252027c0d3758
Author: Nick Mathewson <nickm at torproject.org>
Date:   Thu Sep 26 15:36:20 2019 -0400

    annotate_ifdef_directives: Allow it to be imported as a module.
---
 scripts/maint/annotate_ifdef_directives | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/scripts/maint/annotate_ifdef_directives b/scripts/maint/annotate_ifdef_directives
index 514b5e58b..6ff9b8ec4 100755
--- a/scripts/maint/annotate_ifdef_directives
+++ b/scripts/maint/annotate_ifdef_directives
@@ -274,14 +274,16 @@ def translate(f_in, f_out):
     if len(stack) or cur_level != whole_file:
         raise Problem("Missing #endif")
 
-import sys,os
+if __name__ == '__main__':
 
-if sys.argv[1] == "--self-test":
-    import doctest
-    doctest.testmod()
-    sys.exit(0)
+    import sys,os
 
-for fn in sys.argv[1:]:
-    with open(fn+"_OUT", 'w') as output_file:
-        translate(open(fn, 'r'), output_file)
-    os.rename(fn+"_OUT", fn)
+    if sys.argv[1] == "--self-test":
+        import doctest
+        doctest.testmod()
+        sys.exit(0)
+
+    for fn in sys.argv[1:]:
+        with open(fn+"_OUT", 'w') as output_file:
+            translate(open(fn, 'r'), output_file)
+        os.rename(fn+"_OUT", fn)





More information about the tor-commits mailing list