1
0
mirror of https://github.com/moparisthebest/xeps synced 2024-11-28 12:12:22 -05:00

checkdeadlinks: Replace optparse with argparse to simplify argument parsing.

This commit is contained in:
Emmanuel Gil Peyrot 2016-10-03 22:34:37 +01:00
parent 9dbd567676
commit 52e64d545b

View File

@ -32,11 +32,15 @@
# #
## END LICENSE ## ## END LICENSE ##
'''
A script for checking XEPs for dead links.
'''
import glob import glob
import os import os
from select import select from select import select
import socket import socket
import getopt from argparse import ArgumentParser
from string import split,strip,join,find from string import split,strip,join,find
import sys import sys
import time import time
@ -46,31 +50,14 @@ import urllib2
from xml.dom.minidom import parse,parseString,Document from xml.dom.minidom import parse,parseString,Document
def usage(): def main():
print "checkdeadlinks.py" parser = ArgumentParser(description=__doc__)
print "" parser.add_argument('-v', '--verbose', action='store_true', help='Enables more verbosity')
print "-h, --help Print this help message" parser.add_argument('-x', '--xep', type=int, help='Defines the number of the XEP to check')
print "-x, --xep [number] Defines the number of the XEP to check" args = parser.parse_args()
print "-v, --verbose Enables more verbosity"
def main(argv): xepnum = '%04d' % args.xep
try: verbose = args.verbose
opts, args = getopt.gnu_getopt(argv, "hv:x", ["help", "verbose", "xep="])
except getopt.GetoptError:
usage()
sys.exit(2)
global verbose
verbose = 0
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
elif opt in ("-x", "--xep"):
global xepnum
xepnum = arg
elif opt in ("-v", "--verbose"):
verbose = 1
xepfile = 'xep-' + xepnum + '.xml' xepfile = 'xep-' + xepnum + '.xml'
thexep = parse(xepfile) thexep = parse(xepfile)
@ -106,4 +93,4 @@ def main(argv):
#print "all http/https links are good" #print "all http/https links are good"
if __name__ == "__main__": if __name__ == "__main__":
main(sys.argv[1:]) main()