summaryrefslogtreecommitdiffstats
path: root/Tools/scripts
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-07-15 10:23:58 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-07-15 10:23:58 (GMT)
commit992334127e72c058cf5bd83ed458203e5ebfd74a (patch)
tree085c72769035a1b0014337b195b9576b6773fbf3 /Tools/scripts
parent24fb2d4012d6bc89284f5160b7415e98d294d569 (diff)
downloadcpython-992334127e72c058cf5bd83ed458203e5ebfd74a.zip
cpython-992334127e72c058cf5bd83ed458203e5ebfd74a.tar.gz
cpython-992334127e72c058cf5bd83ed458203e5ebfd74a.tar.bz2
Issue #18974: Tools/scripts/diff.py now uses argparse instead of optparse.
Diffstat (limited to 'Tools/scripts')
-rwxr-xr-xTools/scripts/diff.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/Tools/scripts/diff.py b/Tools/scripts/diff.py
index 8be527f..9720a43 100755
--- a/Tools/scripts/diff.py
+++ b/Tools/scripts/diff.py
@@ -8,7 +8,7 @@
"""
-import sys, os, time, difflib, optparse
+import sys, os, time, difflib, argparse
from datetime import datetime, timezone
def file_mtime(path):
@@ -18,23 +18,25 @@ def file_mtime(path):
def main():
- usage = "usage: %prog [options] fromfile tofile"
- parser = optparse.OptionParser(usage)
- parser.add_option("-c", action="store_true", default=False, help='Produce a context format diff (default)')
- parser.add_option("-u", action="store_true", default=False, help='Produce a unified format diff')
- parser.add_option("-m", action="store_true", default=False, help='Produce HTML side by side diff (can use -c and -l in conjunction)')
- parser.add_option("-n", action="store_true", default=False, help='Produce a ndiff format diff')
- parser.add_option("-l", "--lines", type="int", default=3, help='Set number of context lines (default 3)')
- (options, args) = parser.parse_args()
-
- if len(args) == 0:
- parser.print_help()
- sys.exit(1)
- if len(args) != 2:
- parser.error("need to specify both a fromfile and tofile")
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-c', action='store_true', default=False,
+ help='Produce a context format diff (default)')
+ parser.add_argument('-u', action='store_true', default=False,
+ help='Produce a unified format diff')
+ parser.add_argument('-m', action='store_true', default=False,
+ help='Produce HTML side by side diff '
+ '(can use -c and -l in conjunction)')
+ parser.add_argument('-n', action='store_true', default=False,
+ help='Produce a ndiff format diff')
+ parser.add_argument('-l', '--lines', type=int, default=3,
+ help='Set number of context lines (default 3)')
+ parser.add_argument('fromfile')
+ parser.add_argument('tofile')
+ options = parser.parse_args()
n = options.lines
- fromfile, tofile = args
+ fromfile = options.fromfile
+ tofile = options.tofile
fromdate = file_mtime(fromfile)
todate = file_mtime(tofile)