diff options
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/git-obsolete-branch.py | 54 | ||||
-rwxr-xr-x | tools/kea-breeder/kb.py | 29 | ||||
-rw-r--r-- | tools/reorder_message_file.py | 3 |
3 files changed, 39 insertions, 47 deletions
diff --git a/tools/git-obsolete-branch.py b/tools/git-obsolete-branch.py index 2639b21a7d..d1485aa1cb 100755 --- a/tools/git-obsolete-branch.py +++ b/tools/git-obsolete-branch.py @@ -15,7 +15,7 @@ # git pull # git remote prune origin # -# This script requires python 2.7 or 3. +# This script requires python 3. # # I have limited experience in Python. If things are done in a strange or # uncommon way, there are no obscure reasons to do it that way, just plain @@ -23,9 +23,7 @@ # # tomek -import string -import sys -from optparse import OptionParser +import argparse # [B404:blacklist] Consider possible security implications associated with subprocess module. import subprocess # nosec B404 @@ -157,39 +155,31 @@ def check_output(cmd): return subprocess.check_output(cmd) # nosec B603 -def parse_args(args=sys.argv[1:], Parser=OptionParser): - - parser = Parser(description="This script prints out merged and/or unmerged" - " branches of a GIT tree.") - - parser.add_option("-c", "--csv", action="store_true", - default=False, help="generates CSV output") - parser.add_option("-u", "--unmerged", action="store_true", - default=False, help="lists unmerged branches") - parser.add_option("-m", "--skip-merged", action="store_true", - default=False, help="omits listing merged branches") - parser.add_option("-s", "--stats", action="store_true", - default=False, help="prints also statistics") - - (options, args) = parser.parse_args(args) +def parse_args(): + parser = argparse.ArgumentParser( + description="This script prints out merged and/or unmerged branches of a GIT tree.", + usage="""%prog + Lists all obsolete (fully merged into master) branches. +""") - if args: - parser.print_help() - sys.exit(1) + parser.add_argument("-c", "--csv", action="store_true", + default=False, help="generates CSV output") + parser.add_argument("-u", "--unmerged", action="store_true", + default=False, help="lists unmerged branches") + parser.add_argument("-m", "--skip-merged", action="store_true", + default=False, help="omits listing merged branches") + parser.add_argument("-s", "--stats", action="store_true", + default=False, help="prints also statistics") - return options + return parser.parse_args() def main(): - usage = """%prog - Lists all obsolete (fully merged into master) branches. - """ - - options = parse_args() - csv = options.csv - merged = not options.skip_merged - unmerged = options.unmerged - stats = options.stats + args = parse_args() + csv = args.csv + merged = not args.skip_merged + unmerged = args.unmerged + stats = args.stats if csv: print("branch name,status,date,last commit(mail),last commit(name)") diff --git a/tools/kea-breeder/kb.py b/tools/kea-breeder/kb.py index 3122b0f720..4ee8d5c5d2 100755 --- a/tools/kea-breeder/kb.py +++ b/tools/kea-breeder/kb.py @@ -1,14 +1,14 @@ #!/usr/bin/env python3 import argparse -from termcolor import colored, cprint -from io import StringIO import json import os import re -import sqlalchemy as db -from sqlalchemy.sql import select import sys +from io import StringIO + +import sqlalchemy as db # pylint: disable=import-error +from termcolor import cprint # pylint: disable=import-error def convert_to_db(entity_name, make_singular=True): @@ -86,6 +86,7 @@ class State: class ConfigFile: def __init__(self, filename): + self.config = {} self.filename = filename def load(self): @@ -93,7 +94,7 @@ class ConfigFile: print('The all keys file %s does not exist.' % self.filename) sys.exit(1) - with open(self.filename) as f: + with open(self.filename, encoding='utf-8') as f: self.config = json.load(f) f.close() @@ -232,17 +233,17 @@ def main(): sys.exit(1) sanitized_contents = '' - f = open(args.all_keys_file) - for line in f: - sanitized_line = line.strip() - if not sanitized_line: - continue + with open(args.all_keys_file, encoding='utf-8') as f: + for line in f: + sanitized_line = line.strip() + if not sanitized_line: + continue - if sanitized_line.find('//') != -1 or sanitized_line.find('#') != -1: - continue + if sanitized_line.find('//') != -1 or sanitized_line.find('#') != -1: + continue - sanitized_line = sanitized_line.replace(': .', ': 0.') - sanitized_contents = sanitized_contents + sanitized_line + sanitized_line = sanitized_line.replace(': .', ': 0.') + sanitized_contents = sanitized_contents + sanitized_line f.close() diff --git a/tools/reorder_message_file.py b/tools/reorder_message_file.py index 9483a58d96..368282dd13 100644 --- a/tools/reorder_message_file.py +++ b/tools/reorder_message_file.py @@ -160,7 +160,8 @@ def process_file(filename): Parameters: filename Name of the message file to process """ - lines = open(filename).read().splitlines() + with open(filename, encoding='utf-8') as f: + lines = f.read().splitlines() # Search for the first line starting with the percent character. Everything # before it is considered the file header and is copied to the output with |