mirror of
https://github.com/ejwa/gitinspector.git
synced 2024-11-16 08:38:26 +01:00
Rewrote the config module into a class (GitConfig).
This class takes the initialization variable "global_only" which will be set in the future whenever multiple repositories are specified (See issue #24). This will make sure that the git configuration is only read from the global settings instead of per-repository.
This commit is contained in:
parent
5af89f798a
commit
c01a59430c
2 changed files with 62 additions and 55 deletions
|
@ -1,6 +1,6 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
#
|
#
|
||||||
# Copyright © 2013 Ejwa Software. All rights reserved.
|
# Copyright © 2013-2015 Ejwa Software. All rights reserved.
|
||||||
#
|
#
|
||||||
# This file is part of gitinspector.
|
# This file is part of gitinspector.
|
||||||
#
|
#
|
||||||
|
@ -22,10 +22,16 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
from . import extensions, filtering, format, interval, optval
|
from . import extensions, filtering, format, interval, optval
|
||||||
|
|
||||||
def __read_git_config__(repo, variable):
|
class GitConfig(object):
|
||||||
|
def __init__(self, run, global_only=False):
|
||||||
|
self.run = run
|
||||||
|
self.global_only = global_only
|
||||||
|
|
||||||
|
def __read_git_config__(self, variable):
|
||||||
previous_directory = os.getcwd()
|
previous_directory = os.getcwd()
|
||||||
os.chdir(repo)
|
os.chdir(self.run.repo)
|
||||||
setting = subprocess.Popen(["git", "config", "inspector." + variable], bufsize=1, stdout=subprocess.PIPE).stdout
|
setting = subprocess.Popen(filter(None, ["git", "config", "--global" if self.global_only else "",
|
||||||
|
"inspector." + variable]), bufsize=1, stdout=subprocess.PIPE).stdout
|
||||||
os.chdir(previous_directory)
|
os.chdir(previous_directory)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -36,51 +42,51 @@ def __read_git_config__(repo, variable):
|
||||||
|
|
||||||
return setting
|
return setting
|
||||||
|
|
||||||
def __read_git_config_bool__(repo, variable):
|
def __read_git_config_bool__(self, variable):
|
||||||
try:
|
try:
|
||||||
variable = __read_git_config__(repo, variable)
|
variable = self.__read_git_config__(variable)
|
||||||
return optval.get_boolean_argument(False if variable == "" else variable)
|
return optval.get_boolean_argument(False if variable == "" else variable)
|
||||||
except optval.InvalidOptionArgument:
|
except optval.InvalidOptionArgument:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def __read_git_config_string__(repo, variable):
|
def __read_git_config_string__(self, variable):
|
||||||
string = __read_git_config__(repo, variable)
|
string = self.__read_git_config__(variable)
|
||||||
return (True, string) if len(string) > 0 else (False, None)
|
return (True, string) if len(string) > 0 else (False, None)
|
||||||
|
|
||||||
def init(run):
|
def read(self):
|
||||||
var = __read_git_config_string__(run.repo, "file-types")
|
var = self.__read_git_config_string__("file-types")
|
||||||
if var[0]:
|
if var[0]:
|
||||||
extensions.define(var[1])
|
extensions.define(var[1])
|
||||||
|
|
||||||
var = __read_git_config_string__(run.repo, "exclude")
|
var = self.__read_git_config_string__("exclude")
|
||||||
if var[0]:
|
if var[0]:
|
||||||
filtering.add(var[1])
|
filtering.add(var[1])
|
||||||
|
|
||||||
var = __read_git_config_string__(run.repo, "format")
|
var = self.__read_git_config_string__("format")
|
||||||
if var[0] and not format.select(var[1]):
|
if var[0] and not format.select(var[1]):
|
||||||
raise format.InvalidFormatError(_("specified output format not supported."))
|
raise format.InvalidFormatError(_("specified output format not supported."))
|
||||||
|
|
||||||
run.hard = __read_git_config_bool__(run.repo, "hard")
|
self.run.hard = self.__read_git_config_bool__("hard")
|
||||||
run.list_file_types = __read_git_config_bool__(run.repo, "list-file-types")
|
self.run.list_file_types = self.__read_git_config_bool__("list-file-types")
|
||||||
run.localize_output = __read_git_config_bool__(run.repo, "localize-output")
|
self.run.localize_output = self.__read_git_config_bool__("localize-output")
|
||||||
run.metrics = __read_git_config_bool__(run.repo, "metrics")
|
self.run.metrics = self.__read_git_config_bool__("metrics")
|
||||||
run.responsibilities = __read_git_config_bool__(run.repo, "responsibilities")
|
self.run.responsibilities = self.__read_git_config_bool__("responsibilities")
|
||||||
run.useweeks = __read_git_config_bool__(run.repo, "weeks")
|
self.run.useweeks = self.__read_git_config_bool__("weeks")
|
||||||
|
|
||||||
var = __read_git_config_string__(run.repo, "since")
|
var = self.__read_git_config_string__("since")
|
||||||
if var[0]:
|
if var[0]:
|
||||||
interval.set_since(var[1])
|
interval.set_since(var[1])
|
||||||
|
|
||||||
var = __read_git_config_string__(run.repo, "until")
|
var = self.__read_git_config_string__("until")
|
||||||
if var[0]:
|
if var[0]:
|
||||||
interval.set_until(var[1])
|
interval.set_until(var[1])
|
||||||
|
|
||||||
run.timeline = __read_git_config_bool__(run.repo, "timeline")
|
self.run.timeline = self.__read_git_config_bool__("timeline")
|
||||||
|
|
||||||
if __read_git_config_bool__(run.repo, "grading"):
|
if self.__read_git_config_bool__("grading"):
|
||||||
run.hard = True
|
self.run.hard = True
|
||||||
run.list_file_types = True
|
self.run.list_file_types = True
|
||||||
run.metrics = True
|
self.run.metrics = True
|
||||||
run.responsibilities = True
|
self.run.responsibilities = True
|
||||||
run.timeline = True
|
self.run.timeline = True
|
||||||
run.useweeks = True
|
self.run.useweeks = True
|
||||||
|
|
|
@ -24,7 +24,8 @@ import getopt
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from .changes import Changes
|
from .changes import Changes
|
||||||
from . import (basedir, clone, config, extensions, filtering, format, help, interval,
|
from .config import GitConfig
|
||||||
|
from . import (basedir, clone, extensions, filtering, format, help, interval,
|
||||||
localization, optval, terminal, version)
|
localization, optval, terminal, version)
|
||||||
from .output import outputable
|
from .output import outputable
|
||||||
from .output.blameoutput import BlameOutput
|
from .output.blameoutput import BlameOutput
|
||||||
|
@ -104,14 +105,14 @@ def main():
|
||||||
"localize-output:true", "metrics:true", "responsibilities:true",
|
"localize-output:true", "metrics:true", "responsibilities:true",
|
||||||
"since=", "grading:true", "timeline:true", "until=", "version",
|
"since=", "grading:true", "timeline:true", "until=", "version",
|
||||||
"weeks:true"])
|
"weeks:true"])
|
||||||
for arg in __args__:
|
if len(__args__) > 0:
|
||||||
__run__.repo = arg
|
__run__.repo = __args__[-1]
|
||||||
|
|
||||||
#Try to clone the repo or return the same directory and bail out.
|
#Try to clone the repo or return the same directory and bail out.
|
||||||
__run__.repo = clone.create(__run__.repo)
|
__run__.repo = clone.create(__run__.repo)
|
||||||
|
|
||||||
#We need the repo above to be set before we read the git config.
|
#We need the repo above to be set before we read the git config.
|
||||||
config.init(__run__)
|
GitConfig(__run__).read()
|
||||||
clear_x_on_next_pass = True
|
clear_x_on_next_pass = True
|
||||||
|
|
||||||
for o, a in __opts__:
|
for o, a in __opts__:
|
||||||
|
|
Loading…
Reference in a new issue