public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: make copyright.py interface a bit nicer
@ 2022-01-01 18:14 Mike Frysinger
  2022-10-23 19:22 ` Mike Frysinger
  2022-10-25  1:26 ` Simon Marchi
  0 siblings, 2 replies; 3+ messages in thread
From: Mike Frysinger @ 2022-01-01 18:14 UTC (permalink / raw)
  To: gdb-patches

This way people can run `./copyright.py --help` and get some info as
to what this does without it going and modifying the tree.
---
 gdb/copyright.py | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
 mode change 100644 => 100755 gdb/copyright.py

diff --git a/gdb/copyright.py b/gdb/copyright.py
old mode 100644
new mode 100755
index 0de15b8a3053..a78f7f2aa9b0
--- a/gdb/copyright.py
+++ b/gdb/copyright.py
@@ -22,7 +22,7 @@
 This script updates the list of years in the copyright notices in
 most files maintained by the GDB project.
 
-Usage: cd src/gdb && python copyright.py
+Usage: cd src/gdb && ./copyright.py
 
 Always review the output of this script before committing it!
 A useful command to review the output is:
@@ -30,12 +30,14 @@ A useful command to review the output is:
 This removes the bulk of the changes which are most likely to be correct.
 """
 
+import argparse
 import datetime
 import locale
 import os
 import os.path
 import subprocess
 import sys
+from typing import List, Optional
 
 
 def get_update_list():
@@ -158,16 +160,25 @@ def may_have_copyright_notice(filename):
     return False
 
 
-def main():
+def get_parser() -> argparse.ArgumentParser:
+    """Get a command line parser."""
+    parser = argparse.ArgumentParser(
+        description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
+    )
+    return parser
+
+
+def main(argv: List[str]) -> Optional[int]:
     """The main subprogram."""
+    parser = get_parser()
+    _ = parser.parse_args(argv)
     root_dir = os.path.dirname(os.getcwd())
     os.chdir(root_dir)
 
     if not (
         os.path.isdir("gdb") and os.path.isfile("gnulib/import/extra/update-copyright")
     ):
-        print("Error: This script must be called from the gdb directory.")
-        sys.exit(1)
+        sys.exit("Error: This script must be called from the gdb directory.")
 
     update_list = get_update_list()
     update_files(update_list)
@@ -416,4 +427,4 @@ NOT_FSF_LIST = (
 )
 
 if __name__ == "__main__":
-    main()
+    sys.exit(main(sys.argv[1:]))
-- 
2.33.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: make copyright.py interface a bit nicer
  2022-01-01 18:14 [PATCH] gdb: make copyright.py interface a bit nicer Mike Frysinger
@ 2022-10-23 19:22 ` Mike Frysinger
  2022-10-25  1:26 ` Simon Marchi
  1 sibling, 0 replies; 3+ messages in thread
From: Mike Frysinger @ 2022-10-23 19:22 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 2398 bytes --]

ping ...
-mike

On 01 Jan 2022 13:14, Mike Frysinger via Gdb-patches wrote:
> This way people can run `./copyright.py --help` and get some info as
> to what this does without it going and modifying the tree.
> ---
>  gdb/copyright.py | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
>  mode change 100644 => 100755 gdb/copyright.py
> 
> diff --git a/gdb/copyright.py b/gdb/copyright.py
> old mode 100644
> new mode 100755
> index 0de15b8a3053..a78f7f2aa9b0
> --- a/gdb/copyright.py
> +++ b/gdb/copyright.py
> @@ -22,7 +22,7 @@
>  This script updates the list of years in the copyright notices in
>  most files maintained by the GDB project.
>  
> -Usage: cd src/gdb && python copyright.py
> +Usage: cd src/gdb && ./copyright.py
>  
>  Always review the output of this script before committing it!
>  A useful command to review the output is:
> @@ -30,12 +30,14 @@ A useful command to review the output is:
>  This removes the bulk of the changes which are most likely to be correct.
>  """
>  
> +import argparse
>  import datetime
>  import locale
>  import os
>  import os.path
>  import subprocess
>  import sys
> +from typing import List, Optional
>  
>  
>  def get_update_list():
> @@ -158,16 +160,25 @@ def may_have_copyright_notice(filename):
>      return False
>  
>  
> -def main():
> +def get_parser() -> argparse.ArgumentParser:
> +    """Get a command line parser."""
> +    parser = argparse.ArgumentParser(
> +        description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
> +    )
> +    return parser
> +
> +
> +def main(argv: List[str]) -> Optional[int]:
>      """The main subprogram."""
> +    parser = get_parser()
> +    _ = parser.parse_args(argv)
>      root_dir = os.path.dirname(os.getcwd())
>      os.chdir(root_dir)
>  
>      if not (
>          os.path.isdir("gdb") and os.path.isfile("gnulib/import/extra/update-copyright")
>      ):
> -        print("Error: This script must be called from the gdb directory.")
> -        sys.exit(1)
> +        sys.exit("Error: This script must be called from the gdb directory.")
>  
>      update_list = get_update_list()
>      update_files(update_list)
> @@ -416,4 +427,4 @@ NOT_FSF_LIST = (
>  )
>  
>  if __name__ == "__main__":
> -    main()
> +    sys.exit(main(sys.argv[1:]))
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: make copyright.py interface a bit nicer
  2022-01-01 18:14 [PATCH] gdb: make copyright.py interface a bit nicer Mike Frysinger
  2022-10-23 19:22 ` Mike Frysinger
@ 2022-10-25  1:26 ` Simon Marchi
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2022-10-25  1:26 UTC (permalink / raw)
  To: Mike Frysinger, gdb-patches



On 2022-01-01 13:14, Mike Frysinger via Gdb-patches wrote:
> This way people can run `./copyright.py --help` and get some info as
> to what this does without it going and modifying the tree.
> ---
>  gdb/copyright.py | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
>  mode change 100644 => 100755 gdb/copyright.py
> 
> diff --git a/gdb/copyright.py b/gdb/copyright.py
> old mode 100644
> new mode 100755
> index 0de15b8a3053..a78f7f2aa9b0
> --- a/gdb/copyright.py
> +++ b/gdb/copyright.py
> @@ -22,7 +22,7 @@
>  This script updates the list of years in the copyright notices in
>  most files maintained by the GDB project.
>  
> -Usage: cd src/gdb && python copyright.py
> +Usage: cd src/gdb && ./copyright.py
>  
>  Always review the output of this script before committing it!
>  A useful command to review the output is:
> @@ -30,12 +30,14 @@ A useful command to review the output is:
>  This removes the bulk of the changes which are most likely to be correct.
>  """
>  
> +import argparse
>  import datetime
>  import locale
>  import os
>  import os.path
>  import subprocess
>  import sys
> +from typing import List, Optional
>  
>  
>  def get_update_list():
> @@ -158,16 +160,25 @@ def may_have_copyright_notice(filename):
>      return False
>  
>  
> -def main():
> +def get_parser() -> argparse.ArgumentParser:
> +    """Get a command line parser."""
> +    parser = argparse.ArgumentParser(
> +        description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
> +    )
> +    return parser
> +
> +
> +def main(argv: List[str]) -> Optional[int]:
>      """The main subprogram."""
> +    parser = get_parser()
> +    _ = parser.parse_args(argv)
>      root_dir = os.path.dirname(os.getcwd())
>      os.chdir(root_dir)
>  
>      if not (
>          os.path.isdir("gdb") and os.path.isfile("gnulib/import/extra/update-copyright")
>      ):
> -        print("Error: This script must be called from the gdb directory.")
> -        sys.exit(1)
> +        sys.exit("Error: This script must be called from the gdb directory.")
>  
>      update_list = get_update_list()
>      update_files(update_list)
> @@ -416,4 +427,4 @@ NOT_FSF_LIST = (
>  )
>  
>  if __name__ == "__main__":
> -    main()
> +    sys.exit(main(sys.argv[1:]))

LGTM, thanks.

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-10-25  1:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-01 18:14 [PATCH] gdb: make copyright.py interface a bit nicer Mike Frysinger
2022-10-23 19:22 ` Mike Frysinger
2022-10-25  1:26 ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).