[Pylint] optparse is deprecated -> argparse.

This commit is contained in:
mkarolin
2021-06-29 16:37:30 -04:00
parent 6c479e329e
commit a70b15f758
6 changed files with 166 additions and 211 deletions
+15 -19
View File
@@ -5,30 +5,26 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
import optparse
import argparse
import subprocess
import sys
def Main(argv):
parser = optparse.OptionParser('%prog [options]')
parser.add_option('--sign-update', dest='sign_update_path', action='store',
type='string', default=None, help='The path of sign_update binary')
parser.add_option('--sign-key-file', dest='sign_key_file', action='store',
type='string', default=None, help='The private key to sign patch file')
parser.add_option('--target', dest='target', action='store',
type='string', default=None, help='Target file path for signing.')
parser.add_option('--output', dest='output', action='store',
type='string', default=None, help='The path of dsa output.')
(options, args) = parser.parse_args(argv)
if len(args) > 0:
print(parser.get_usage(), file=sys.stderr)
return 1
def Main():
parser = argparse.ArgumentParser(usage='%(prog)s [options]')
parser.add_argument('--sign-update', dest='sign_update_path', action='store',
help='The path of sign_update binary', required=True)
parser.add_argument('--sign-key-file', dest='sign_key_file', action='store',
help='The private key to sign patch file', required=True)
parser.add_argument('--target', dest='target', action='store',
help='Target file path for signing.', required=True)
parser.add_argument('--output', dest='output', action='store',
help='The path of dsa output.', required=True)
args = parser.parse_args()
# sign file with dsa
file = open(options.output, 'w')
command = [options.sign_update_path, options.target, options.sign_key_file]
file = open(args.output, 'w')
command = [args.sign_update_path, args.target, args.sign_key_file]
try:
subprocess.check_call(command, stdout=file)
except subprocess.CalledProcessError as e:
@@ -40,4 +36,4 @@ def Main(argv):
if __name__ == '__main__':
sys.exit(Main(sys.argv[1:]))
sys.exit(Main())
+15 -19
View File
@@ -5,30 +5,26 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
import optparse
import argparse
import subprocess
import sys
def Main(argv):
parser = optparse.OptionParser('%prog [options]')
parser.add_option('--sign-update', dest='sign_update_path', action='store',
type='string', default=None, help='The path of sign_update binary')
parser.add_option('--sign-key', dest='sign_key', action='store',
type='string', default=None, help='The private key to sign patch file')
parser.add_option('--target', dest='target', action='store',
type='string', default=None, help='Target file path for signing.')
parser.add_option('--output', dest='output', action='store',
type='string', default=None, help='The path of eddsa output.')
(options, args) = parser.parse_args(argv)
if len(args) > 0:
print(parser.get_usage(), file=sys.stderr)
return 1
def Main():
parser = argparse.ArgumentParser(usage='%(prog)s [options]')
parser.add_argument('--sign-update', dest='sign_update_path', action='store',
help='The path of sign_update binary', required=True)
parser.add_argument('--sign-key', dest='sign_key', action='store',
help='The private key to sign patch file', required=True)
parser.add_argument('--target', dest='target', action='store',
help='Target file path for signing.', required=True)
parser.add_argument('--output', dest='output', action='store',
help='The path of eddsa output.', required=True)
args = parser.parse_args()
# sign file with eddsa
file = open(options.output, 'w')
command = [options.sign_update_path, '-s', options.sign_key, options.target]
file = open(args.output, 'w')
command = [args.sign_update_path, '-s', args.sign_key, args.target]
try:
subprocess.check_call(command, stdout=file)
except subprocess.CalledProcessError as e:
@@ -40,4 +36,4 @@ def Main(argv):
if __name__ == '__main__':
sys.exit(Main(sys.argv[1:]))
sys.exit(Main())
+31 -35
View File
@@ -21,7 +21,7 @@
# by the time the app target is done, the info.plist is correct.
#
import optparse
import argparse
import os
import plistlib
import re
@@ -59,60 +59,56 @@ def _OverrideVersionKey(plist, brave_version):
plist['CFBundleVersion'] = str(adjusted_minor) + '.' + version_values[2]
def Main(argv):
parser = optparse.OptionParser('%prog [options]')
parser.add_option('--plist', dest='plist_path', action='store',
type='string', default=None, help='The path of the plist to tweak.')
parser.add_option('--output', dest='plist_output', action='store',
type='string', default=None, help='If specified, the path to output ' + \
def Main():
parser = argparse.ArgumentParser(usage='%(prog)s [options]')
parser.add_argument('--plist', dest='plist_path', action='store',
default=None, help='The path of the plist to tweak.')
parser.add_argument('--output', dest='plist_output', action='store',
default=None, help='If specified, the path to output ' + \
'the tweaked plist, rather than overwriting the input.')
parser.add_option('--brave_channel', dest='brave_channel', action='store',
type='string', default=None, help='Channel (beta, dev, nightly)')
parser.add_option('--brave_product_dir_name', dest='brave_product_dir_name',
action='store', type='string', default=None,
parser.add_argument('--brave_channel', dest='brave_channel', action='store',
default=None, help='Channel (beta, dev, nightly)')
parser.add_argument('--brave_product_dir_name', dest='brave_product_dir_name',
action='store', default=None,
help='Product directory name')
parser.add_option('--brave_eddsa_key', dest='brave_eddsa_key', action='store',
type='string', default=None, help='Public EdDSA key for update')
parser.add_option('--brave_version', dest='brave_version', action='store',
type='string', default=None, help='brave version string')
parser.add_option('--format', choices=('binary1', 'xml1', 'json'),
parser.add_argument('--brave_eddsa_key', dest='brave_eddsa_key', action='store',
default=None, help='Public EdDSA key for update')
parser.add_argument('--brave_version', dest='brave_version', action='store',
default=None, help='brave version string')
parser.add_argument('--format', choices=('binary1', 'xml1', 'json'),
default='xml1', help='Format to use when writing property list '
'(default: %(default)s)')
parser.add_option('--skip_signing', dest='skip_signing', action='store_true')
(options, args) = parser.parse_args(argv)
parser.add_argument('--skip_signing', dest='skip_signing', action='store_true')
args = parser.parse_args()
if len(args) > 0:
print(parser.get_usage(), file=sys.stderr)
return 1
if not options.plist_path:
if not args.plist_path:
print('No --plist specified.', file=sys.stderr)
return 1
# Read the plist into its parsed format. Convert the file to 'xml1' as
# plistlib only supports that format in Python 2.7.
with tempfile.NamedTemporaryFile() as temp_info_plist:
retcode = _ConvertPlist(options.plist_path, temp_info_plist.name, 'xml1')
retcode = _ConvertPlist(args.plist_path, temp_info_plist.name, 'xml1')
if retcode != 0:
return retcode
plist = plistlib.readPlist(temp_info_plist.name)
output_path = options.plist_path
if options.plist_output is not None:
output_path = options.plist_output
output_path = args.plist_path
if args.plist_output is not None:
output_path = args.plist_output
if options.skip_signing:
plist['KSChannelID'] = options.brave_channel
if args.skip_signing:
plist['KSChannelID'] = args.brave_channel
elif 'KSChannelID' in plist:
# 'KSChannelID' is set at _modify_plists() of modification.py.
del plist['KSChannelID']
plist['CrProductDirName'] = options.brave_product_dir_name
plist['CrProductDirName'] = args.brave_product_dir_name
if options.brave_eddsa_key:
plist['SUPublicEDKey'] = options.brave_eddsa_key
if args.brave_eddsa_key:
plist['SUPublicEDKey'] = args.brave_eddsa_key
_OverrideVersionKey(plist, options.brave_version)
_OverrideVersionKey(plist, args.brave_version)
# Explicitly disable profiling
plist['SUEnableSystemProfiling'] = False
@@ -126,8 +122,8 @@ def Main(argv):
# Convert Info.plist to the format requested by the --format flag. Any
# format would work on Mac but iOS requires specific format.
return _ConvertPlist(temp_info_plist.name, output_path, options.format)
return _ConvertPlist(temp_info_plist.name, output_path, args.format)
if __name__ == '__main__':
sys.exit(Main(sys.argv[1:]))
sys.exit(Main())
+66 -74
View File
@@ -3,77 +3,69 @@
# Copyright (c) 2021 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
import optparse
import os
import subprocess
import sys
cert = os.environ.get('CERT')
signtool_args = (os.environ.get('SIGNTOOL_ARGS') or
'sign /t http://timestamp.digicert.com /sm '
'/fd sha256')
assert (cert or signtool_args), 'One or both of the CERT or SIGNTOOL_ARGS '
'must be set. CERT by default is the name in the //CurrentUser/My windows '
'certificate store. `SIGNTOOL_ARGS` can be used in combination `CERT` or '
'by it self.'
def get_sign_cmd(file):
# https://docs.microsoft.com/en-us/dotnet/framework/tools/signtool-exe
# signtool should be in the path if it was set up correctly by gn through
# src/build/vs_toolchain.py
cmd = 'signtool {}'.format(signtool_args)
if cert:
cmd = cmd + ' /n "' + cert + '"'
return (cmd + ' "' + file + '"')
def run_cmd(cmd):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
for line in p.stdout:
print(line)
p.wait()
assert p.returncode == 0, "Error signing"
def sign_binaries(base_dir, endswidth=('.exe', '.dll')):
matches = []
for root, dirnames, filenames in os.walk(base_dir):
for filename in filenames:
if filename.endswith(endswidth):
matches.append(os.path.join(root, filename))
for binary in matches:
sign_binary(binary)
def sign_binary(binary):
cmd = get_sign_cmd(binary)
run_cmd(cmd)
def _ParseOptions():
parser = optparse.OptionParser()
parser.add_option(
'-b', '--build_dir',
help='Build directory. The paths in input_file are relative to this.')
options, _ = parser.parse_args()
if not options.build_dir:
parser.error('You must provide a build dir.')
options.build_dir = os.path.normpath(options.build_dir)
return options
def main(options):
sign_binaries(options.build_dir, ('brave.exe', 'chrome.dll'))
if '__main__' == __name__:
options = _ParseOptions()
sys.exit(main(options))
# You can obtain one at http://mozilla.org/MPL/2.0/.
import argparse
import os
import subprocess
import sys
cert = os.environ.get('CERT')
signtool_args = (os.environ.get('SIGNTOOL_ARGS') or
'sign /t http://timestamp.digicert.com /sm '
'/fd sha256')
assert (cert or signtool_args), 'One or both of the CERT or SIGNTOOL_ARGS '
'must be set. CERT by default is the name in the //CurrentUser/My windows '
'certificate store. `SIGNTOOL_ARGS` can be used in combination `CERT` or '
'by it self.'
def get_sign_cmd(file):
# https://docs.microsoft.com/en-us/dotnet/framework/tools/signtool-exe
# signtool should be in the path if it was set up correctly by gn through
# src/build/vs_toolchain.py
cmd = 'signtool {}'.format(signtool_args)
if cert:
cmd = cmd + ' /n "' + cert + '"'
return (cmd + ' "' + file + '"')
def run_cmd(cmd):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
for line in p.stdout:
print(line)
p.wait()
assert p.returncode == 0, "Error signing"
def sign_binaries(base_dir, endswidth=('.exe', '.dll')):
matches = []
for root, dirnames, filenames in os.walk(base_dir):
for filename in filenames:
if filename.endswith(endswidth):
matches.append(os.path.join(root, filename))
for binary in matches:
sign_binary(binary)
def sign_binary(binary):
cmd = get_sign_cmd(binary)
run_cmd(cmd)
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'-b', '--build_dir', required=True,
help='Build directory. The paths in input_file are relative to this.')
args = parser.parse_args()
args.build_dir = os.path.normpath(args.build_dir)
sign_binaries(args.build_dir, ('brave.exe', 'chrome.dll'))
if '__main__' == __name__:
sys.exit(main())
+19 -38
View File
@@ -12,7 +12,7 @@ platforms is planned.
"""
import errno
import optparse
import argparse
import os
import queue
import re
@@ -230,40 +230,23 @@ def GenerateSymbols(options, binaries):
def main():
parser = optparse.OptionParser()
parser.add_option('', '--build-dir', default='',
help='The build output directory.')
parser.add_option('', '--symbols-dir', default='',
help='The directory where to write the symbols file.')
parser.add_option('', '--libchromiumcontent-dir', default='',
help='The directory where libchromiumcontent is downloaded.')
parser.add_option('', '--binary', default='',
help='The path of the binary to generate symbols for.')
parser.add_option('', '--clear', default=False, action='store_true',
help='Clear the symbols directory before writing new '
'symbols.')
parser.add_option('-j', '--jobs', default=CONCURRENT_TASKS, action='store',
type='int', help='Number of parallel tasks to run.')
parser.add_option('-v', '--verbose', action='store_true',
help='Print verbose status output.')
parser = argparse.ArgumentParser()
parser.add_argument('--build-dir', required=True,
help='The build output directory.')
parser.add_argument('--symbols-dir', required=True,
help='The directory where to write the symbols file.')
parser.add_argument('--libchromiumcontent-dir', required=True,
help='The directory where libchromiumcontent is downloaded.')
parser.add_argument('--binary', required=True,
help='The path of the binary to generate symbols for.')
parser.add_argument('--clear', default=False, action='store_true',
help='Clear the symbols directory before writing new symbols.')
parser.add_argument('-j', '--jobs', default=CONCURRENT_TASKS, action='store',
type=int, help='Number of parallel tasks to run.')
parser.add_argument('-v', '--verbose', action='store_true',
help='Print verbose status output.')
(options, _) = parser.parse_args()
if not options.symbols_dir:
print("Required option --symbols-dir missing.")
return 1
if not options.build_dir:
print("Required option --build-dir missing.")
return 1
if not options.libchromiumcontent_dir:
print("Required option --libchromiumcontent-dir missing.")
return 1
if not options.binary:
print("Required option --binary missing.")
return 1
options = parser.parse_args()
if options.clear:
try:
@@ -271,10 +254,8 @@ def main():
except:
pass
binary = []
if options.binary:
parser = gn_helpers.GNValueParser(options.binary)
binary = parser.ParseList()
parser = gn_helpers.GNValueParser(options.binary)
binary = parser.ParseList()
# Build the transitive closure of all dependencies.
binaries = set(binary)
+20 -26
View File
@@ -9,7 +9,7 @@
import errno
import glob
import optparse
import argparse
import os
import queue
import re
@@ -100,41 +100,35 @@ def GenerateSymbols(options, binaries):
def main():
parser = optparse.OptionParser()
parser.add_option('', '--build-dir', default='',
help='The build output directory.')
parser.add_option('', '--symbols-dir', default='',
help='The directory where to write the symbols file.')
parser.add_option('', '--clear', default=False, action='store_true',
help='Clear the symbols directory before writing new '
'symbols.')
parser.add_option('-j', '--jobs', default=CONCURRENT_TASKS, action='store',
type='int', help='Number of parallel tasks to run.')
parser.add_option('-v', '--verbose', action='store_true',
help='Print verbose status output.')
parser = argparse.ArgumentParser()
parser.add_argument('directories', nargs='+',
help='Directories in which to look for pdbs.')
parser.add_argument('--build-dir', required=True,
help='The build output directory.')
parser.add_argument('--symbols-dir', required=True,
help='The directory where to write the symbols file.')
parser.add_argument('--clear', default=False, action='store_true',
help='Clear the symbols directory before writing new '
'symbols.')
parser.add_argument('-j', '--jobs', default=CONCURRENT_TASKS, action='store',
type=int, help='Number of parallel tasks to run.')
parser.add_argument('-v', '--verbose', action='store_true',
help='Print verbose status output.')
(options, directories) = parser.parse_args()
args = parser.parse_intermixed_args()
if not options.build_dir:
print("Required option --build-dir missing.")
return 1
if not options.symbols_dir:
print("Required option --symbols-dir missing.")
return 1
if options.clear:
if args.clear:
try:
shutil.rmtree(options.symbols_dir)
shutil.rmtree(args.symbols_dir)
except:
pass
pdbs = []
for directory in directories:
for directory in args.directories:
pdbs += glob.glob(os.path.join(directory, '*.exe.pdb'))
pdbs += glob.glob(os.path.join(directory, '*.dll.pdb'))
GenerateSymbols(options, pdbs)
GenerateSymbols(args, pdbs)
return 0