Removing unused files.
This commit is contained in:
parent
d153fba7d0
commit
c4200eb3a4
|
@ -1,67 +0,0 @@
|
||||||
import sys
|
|
||||||
import os.path
|
|
||||||
import gettext
|
|
||||||
try:
|
|
||||||
import configparser
|
|
||||||
except ImportError as e:
|
|
||||||
import ConfigParser as configparser
|
|
||||||
|
|
||||||
|
|
||||||
_ = gettext.gettext
|
|
||||||
|
|
||||||
|
|
||||||
# (commandLineDictionary, repositoryLocation) -> (configurationFilePath | exit)
|
|
||||||
|
|
||||||
def find_config_file(options, base):
|
|
||||||
""" Returns the configuration file from a prioritized list of locations.
|
|
||||||
|
|
||||||
Locations are prioritized as:
|
|
||||||
1. From the command line. Fail if specified but not found
|
|
||||||
2. The repository's root directory, as the file .git-lint
|
|
||||||
3. The repository's root directory, as the file .git-lint/config
|
|
||||||
4. The user's home directory, as file .git-lint
|
|
||||||
5. The user's home directory, as the file .git-lint/config
|
|
||||||
|
|
||||||
If no configuration file is found, this is an error.
|
|
||||||
"""
|
|
||||||
|
|
||||||
if 'config' in options:
|
|
||||||
config = options['config']
|
|
||||||
configpath = os.path.abspath(config)
|
|
||||||
if not os.path.isfile(configpath):
|
|
||||||
sys.exit(_('Configuration file not found: {}\n').format(config))
|
|
||||||
return configpath
|
|
||||||
|
|
||||||
home = os.path.join(os.environ.get('HOME'))
|
|
||||||
possibles = (os.path.join(base, '.git-lint'),
|
|
||||||
os.path.join(base, '.git-lint/config'),
|
|
||||||
os.path.join(home, '.git-lint'),
|
|
||||||
os.path.join(home, '.git-lint/config'))
|
|
||||||
|
|
||||||
matches = [p for p in possibles if os.path.isfile(p)]
|
|
||||||
if len(matches) == 0:
|
|
||||||
sys.exit(_('No configuration file found'))
|
|
||||||
|
|
||||||
return matches[0]
|
|
||||||
|
|
||||||
|
|
||||||
# (commandLineDictionary, repositoryLocation) -> (configurationDictionary | exit)
|
|
||||||
|
|
||||||
def get_config(options, base):
|
|
||||||
"""Loads the git-lint configuration file.
|
|
||||||
|
|
||||||
Returns the configuration file as a dictionary of dictionaries.
|
|
||||||
Performs substitutions as specified in the SafeConfigParser
|
|
||||||
specification; the only one performed currently is the 'repodir'
|
|
||||||
will be replaced with the base directory of the repository.
|
|
||||||
Combined with the option to specify the .git-lint configuration as
|
|
||||||
a directory, this allows users to keep per-project configuration
|
|
||||||
files for specific linters.
|
|
||||||
"""
|
|
||||||
|
|
||||||
path = find_config_file(options, base)
|
|
||||||
configloader = configparser.SafeConfigParser()
|
|
||||||
configloader.read(path)
|
|
||||||
configloader.set('DEFAULT', 'repodir', base)
|
|
||||||
return {section: {k: v for (k, v) in configloader.items(section)}
|
|
||||||
for section in configloader.sections()}
|
|
|
@ -1,75 +0,0 @@
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import getopt
|
|
||||||
import gettext
|
|
||||||
|
|
||||||
_ = gettext.gettext
|
|
||||||
|
|
||||||
|
|
||||||
def make_rational_options(optlist, args):
|
|
||||||
|
|
||||||
# OptionTupleList -> (getOptOptions -> dictionaryOfOptions)
|
|
||||||
def make_options_rationalizer(optlist):
|
|
||||||
"""Takes a list of option tuples, and returns a function that takes
|
|
||||||
the output of getopt and reduces it to the longopt key and
|
|
||||||
associated values as a dictionary.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def make_opt_assoc(prefix, pos):
|
|
||||||
def associater(acc, it):
|
|
||||||
acc[(prefix + it[pos])] = it[1]
|
|
||||||
return acc
|
|
||||||
return associater
|
|
||||||
|
|
||||||
short_opt_assoc = make_opt_assoc('-', 0)
|
|
||||||
long_opt_assoc = make_opt_assoc('--', 1)
|
|
||||||
|
|
||||||
def make_full_set(acc, i):
|
|
||||||
return long_opt_assoc(short_opt_assoc(acc, i), i)
|
|
||||||
|
|
||||||
fullset = reduce(make_full_set, optlist, {})
|
|
||||||
|
|
||||||
def rationalizer(acc, it):
|
|
||||||
acc[fullset[it[0]]] = it[1]
|
|
||||||
return acc
|
|
||||||
|
|
||||||
return rationalizer
|
|
||||||
|
|
||||||
|
|
||||||
# (OptionTupleList, dictionaryOfOptions) -> (dictionaryOfOptions, excludedOptions)
|
|
||||||
def remove_conflicted_options(optlist, request):
|
|
||||||
"""Takes our list of option tuples, and a cleaned copy of what was
|
|
||||||
requested from getopt, and returns a copy of the request
|
|
||||||
without any options that are marked as superseded, along with
|
|
||||||
the list of superseded options
|
|
||||||
"""
|
|
||||||
def get_excluded_keys(memo, opt):
|
|
||||||
return memo + (len(opt) > 4 and opt[4] or [])
|
|
||||||
|
|
||||||
keys = request.keys()
|
|
||||||
marked = [option for option in optlist if option[1] in keys]
|
|
||||||
exclude = reduce(get_excluded_keys, marked, [])
|
|
||||||
excluded = [key for key in keys if key in exclude]
|
|
||||||
cleaned = {key: request[key] for key in keys
|
|
||||||
if key not in excluded}
|
|
||||||
return (cleaned, excluded)
|
|
||||||
|
|
||||||
def shortoptstogo(i):
|
|
||||||
return i[0] + (i[2] and ':' or '')
|
|
||||||
|
|
||||||
def longoptstogo(i):
|
|
||||||
return i[1] + (i[2] and '=' or '')
|
|
||||||
|
|
||||||
optstringsshort = ''.join([shortoptstogo(opt) for opt in optlist])
|
|
||||||
optstringslong = [longoptstogo(opt) for opt in optlist]
|
|
||||||
(options, filenames) = getopt.getopt(args[1:], optstringsshort,
|
|
||||||
optstringslong)
|
|
||||||
|
|
||||||
# Turns what getopt returns into something more human-readable
|
|
||||||
rationalize_options = make_options_rationalizer(optlist)
|
|
||||||
|
|
||||||
# Remove any options that
|
|
||||||
(retoptions, excluded) = remove_conflicted_options(
|
|
||||||
optlist, reduce(rationalize_options, options, {}))
|
|
||||||
|
|
||||||
return (retoptions, filenames, excluded)
|
|
Loading…
Reference in New Issue