mirror of
https://github.com/AsahiLinux/u-boot
synced 2025-02-17 22:49:02 +00:00
patman: fix pep8 warnings in settings module
Remove extraneous imports, variables and comply to PEP 8 maximum line width, among other PEP 8 changes suggested by Pyflake. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
3052930714
commit
872f3a4ce2
1 changed files with 21 additions and 17 deletions
|
@ -4,16 +4,13 @@
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import configparser as ConfigParser
|
import configparser as ConfigParser
|
||||||
except:
|
except Exception:
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from patman import command
|
|
||||||
from patman import tools
|
|
||||||
|
|
||||||
"""Default settings per-project.
|
"""Default settings per-project.
|
||||||
|
|
||||||
These are used by _ProjectConfigParser. Settings names should match
|
These are used by _ProjectConfigParser. Settings names should match
|
||||||
|
@ -32,6 +29,7 @@ _default_settings = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _ProjectConfigParser(ConfigParser.SafeConfigParser):
|
class _ProjectConfigParser(ConfigParser.SafeConfigParser):
|
||||||
"""ConfigParser that handles projects.
|
"""ConfigParser that handles projects.
|
||||||
|
|
||||||
|
@ -83,8 +81,8 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser):
|
||||||
def __init__(self, project_name):
|
def __init__(self, project_name):
|
||||||
"""Construct _ProjectConfigParser.
|
"""Construct _ProjectConfigParser.
|
||||||
|
|
||||||
In addition to standard SafeConfigParser initialization, this also loads
|
In addition to standard SafeConfigParser initialization, this
|
||||||
project defaults.
|
also loads project defaults.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
project_name: The name of the project.
|
project_name: The name of the project.
|
||||||
|
@ -155,6 +153,7 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser):
|
||||||
item_dict.update(project_items)
|
item_dict.update(project_items)
|
||||||
return {(item, val) for item, val in item_dict.items()}
|
return {(item, val) for item, val in item_dict.items()}
|
||||||
|
|
||||||
|
|
||||||
def ReadGitAliases(fname):
|
def ReadGitAliases(fname):
|
||||||
"""Read a git alias file. This is in the form used by git:
|
"""Read a git alias file. This is in the form used by git:
|
||||||
|
|
||||||
|
@ -170,7 +169,7 @@ def ReadGitAliases(fname):
|
||||||
print("Warning: Cannot find alias file '%s'" % fname)
|
print("Warning: Cannot find alias file '%s'" % fname)
|
||||||
return
|
return
|
||||||
|
|
||||||
re_line = re.compile('alias\s+(\S+)\s+(.*)')
|
re_line = re.compile(r'alias\s+(\S+)\s+(.*)')
|
||||||
for line in fd.readlines():
|
for line in fd.readlines():
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if not line or line[0] == '#':
|
if not line or line[0] == '#':
|
||||||
|
@ -190,6 +189,7 @@ def ReadGitAliases(fname):
|
||||||
|
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
|
|
||||||
def CreatePatmanConfigFile(gitutil, config_fname):
|
def CreatePatmanConfigFile(gitutil, config_fname):
|
||||||
"""Creates a config file under $(HOME)/.patman if it can't find one.
|
"""Creates a config file under $(HOME)/.patman if it can't find one.
|
||||||
|
|
||||||
|
@ -200,12 +200,12 @@ def CreatePatmanConfigFile(gitutil, config_fname):
|
||||||
None
|
None
|
||||||
"""
|
"""
|
||||||
name = gitutil.get_default_user_name()
|
name = gitutil.get_default_user_name()
|
||||||
if name == None:
|
if name is None:
|
||||||
name = input("Enter name: ")
|
name = input("Enter name: ")
|
||||||
|
|
||||||
email = gitutil.get_default_user_email()
|
email = gitutil.get_default_user_email()
|
||||||
|
|
||||||
if email == None:
|
if email is None:
|
||||||
email = input("Enter email: ")
|
email = input("Enter email: ")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -220,7 +220,8 @@ me: %s <%s>
|
||||||
[bounces]
|
[bounces]
|
||||||
nxp = Zhikang Zhang <zhikang.zhang@nxp.com>
|
nxp = Zhikang Zhang <zhikang.zhang@nxp.com>
|
||||||
''' % (name, email), file=f)
|
''' % (name, email), file=f)
|
||||||
f.close();
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def _UpdateDefaults(main_parser, config):
|
def _UpdateDefaults(main_parser, config):
|
||||||
"""Update the given OptionParser defaults based on config.
|
"""Update the given OptionParser defaults based on config.
|
||||||
|
@ -242,8 +243,8 @@ def _UpdateDefaults(main_parser, config):
|
||||||
# Find all the parsers and subparsers
|
# Find all the parsers and subparsers
|
||||||
parsers = [main_parser]
|
parsers = [main_parser]
|
||||||
parsers += [subparser for action in main_parser._actions
|
parsers += [subparser for action in main_parser._actions
|
||||||
if isinstance(action, argparse._SubParsersAction)
|
if isinstance(action, argparse._SubParsersAction)
|
||||||
for _, subparser in action.choices.items()]
|
for _, subparser in action.choices.items()]
|
||||||
|
|
||||||
# Collect the defaults from each parser
|
# Collect the defaults from each parser
|
||||||
defaults = {}
|
defaults = {}
|
||||||
|
@ -270,8 +271,9 @@ def _UpdateDefaults(main_parser, config):
|
||||||
# Set all the defaults and manually propagate them to subparsers
|
# Set all the defaults and manually propagate them to subparsers
|
||||||
main_parser.set_defaults(**defaults)
|
main_parser.set_defaults(**defaults)
|
||||||
for parser, pdefs in zip(parsers, parser_defaults):
|
for parser, pdefs in zip(parsers, parser_defaults):
|
||||||
parser.set_defaults(**{ k: v for k, v in defaults.items()
|
parser.set_defaults(**{k: v for k, v in defaults.items()
|
||||||
if k in pdefs })
|
if k in pdefs})
|
||||||
|
|
||||||
|
|
||||||
def _ReadAliasFile(fname):
|
def _ReadAliasFile(fname):
|
||||||
"""Read in the U-Boot git alias file if it exists.
|
"""Read in the U-Boot git alias file if it exists.
|
||||||
|
@ -298,6 +300,7 @@ def _ReadAliasFile(fname):
|
||||||
if bad_line:
|
if bad_line:
|
||||||
print(bad_line)
|
print(bad_line)
|
||||||
|
|
||||||
|
|
||||||
def _ReadBouncesFile(fname):
|
def _ReadBouncesFile(fname):
|
||||||
"""Read in the bounces file if it exists
|
"""Read in the bounces file if it exists
|
||||||
|
|
||||||
|
@ -311,6 +314,7 @@ def _ReadBouncesFile(fname):
|
||||||
continue
|
continue
|
||||||
bounces.add(line.strip())
|
bounces.add(line.strip())
|
||||||
|
|
||||||
|
|
||||||
def GetItems(config, section):
|
def GetItems(config, section):
|
||||||
"""Get the items from a section of the config.
|
"""Get the items from a section of the config.
|
||||||
|
|
||||||
|
@ -323,10 +327,9 @@ def GetItems(config, section):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return config.items(section)
|
return config.items(section)
|
||||||
except ConfigParser.NoSectionError as e:
|
except ConfigParser.NoSectionError:
|
||||||
return []
|
return []
|
||||||
except:
|
|
||||||
raise
|
|
||||||
|
|
||||||
def Setup(gitutil, parser, project_name, config_fname=''):
|
def Setup(gitutil, parser, project_name, config_fname=''):
|
||||||
"""Set up the settings module by reading config files.
|
"""Set up the settings module by reading config files.
|
||||||
|
@ -358,6 +361,7 @@ def Setup(gitutil, parser, project_name, config_fname=''):
|
||||||
|
|
||||||
_UpdateDefaults(parser, config)
|
_UpdateDefaults(parser, config)
|
||||||
|
|
||||||
|
|
||||||
# These are the aliases we understand, indexed by alias. Each member is a list.
|
# These are the aliases we understand, indexed by alias. Each member is a list.
|
||||||
alias = {}
|
alias = {}
|
||||||
bounces = set()
|
bounces = set()
|
||||||
|
|
Loading…
Add table
Reference in a new issue