当前位置: 首页>>代码示例>>Python>>正文


Python Repo.config_reader方法代码示例

本文整理汇总了Python中git.Repo.config_reader方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.config_reader方法的具体用法?Python Repo.config_reader怎么用?Python Repo.config_reader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在git.Repo的用法示例。


在下文中一共展示了Repo.config_reader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: tweet_commit

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import config_reader [as 别名]
def tweet_commit():
	repo = Repo(git_path)
	assert repo.bare == False
	repo.config_reader()
	last_commit = repo.head.commit.message.strip("\n")
	api = twitter_authorize()
	tweet = "#Tweetuoso - The #Twitter Commandline client written in #Python updated: " + last_commit + " | http://is.gd/piWhzm"
	try:
		api.update_status(tweet)
		print "Last commit tweeted successfully!"
	except tweepy.TweepError as error:
		print("Error occured: " + Fore.RED + "%s" % error + Fore.RESET)
开发者ID:heyudude,项目名称:tweetuoso,代码行数:14,代码来源:tweet_commit.py

示例2: handle

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import config_reader [as 别名]
 def handle(self, *args, **options):
     repo = Repo(git_path) # Connect to your repository
     assert repo.bare == False
     repo.config_reader() # Get a config reader for read-only access
     last_commit =  repo.head.commit.message # Get the last commit
     print "Your last commit is '{0}'".format(last_commit.rstrip())
     self.twitter_authorize()
     tweet = last_commit.capitalize() # Capitalize first letter. We are serious gentlemen. Yeah :)
     # Update status on Twitter
     try:
         self.api.update_status(tweet)
         print "Commit successfully tweeted."
     except tweepy.error.TweepError, e:
         print e, "You have this commit in the Twitter timeline."
开发者ID:UnforbiddenYet,项目名称:TweetPyGit,代码行数:16,代码来源:tweet_new_commit.py

示例3: push_to_repo

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import config_reader [as 别名]
def push_to_repo():
    repo = Repo(ROOTPATH)
    [repo.git.add(file) for file in repo.git.diff(None, name_only=True).split('\n')]

    config = repo.config_reader()
    config.set_value("user", "username", CONFIG['Github']['user_name'])
    config.set_value("user", "password", CONFIG['Github']['token'])

    repo.git.commit(m='Update assortment')
    repo.git.push()
开发者ID:Qluxzz,项目名称:compare-assortment,代码行数:12,代码来源:convert_to_json.py

示例4: GitSuspect

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import config_reader [as 别名]
class GitSuspect(object):
    def __init__(self, window):
        self.window = window

    def parse_settings(self):
        self.proj_dir = self.window.settings.get_string('project-dir')
        self.repo = None
        try:
            self.repo = Repo(self.proj_dir)
            logger.debug(self.repo)
        except Exception as e:
            logger.exception(e)

    def current_user(self):
        if not self.repo:
            return (None, None)

        user_email = self.repo.config_reader().get_value('user', 'email')
        user_name = self.repo.config_reader().get_value('user', 'name')
        return (user_email, user_name)
开发者ID:firodj,项目名称:jenkins-ycny,代码行数:22,代码来源:JenkinsWindow.py

示例5: git_properties

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import config_reader [as 别名]
    def git_properties(self):
        namespace = PropertyNamespace('git', _(u'Git repository'))

        try:
            repo = Repo(settings.PROJECT_ROOT)
        except:
            namespace.add_property(Property('is_git_repo', _(u'Running from a Git repository'), False))
        else:
            repo.config_reader()
            headcommit = repo.head.commit
            namespace.add_property('is_git_repo', _(u'Running from a Git repository'), True)
            namespace.add_property('repo_remotes', _(u'Repository remotes'), ', '.join([unicode(remote) for remote in repo.remotes]), report=True)
            namespace.add_property('repo_remotes_urls', _(u'Repository remotes URLs'), ', '.join([unicode(remote.url) for remote in repo.remotes]), report=True)
            namespace.add_property('repo_head_reference', _(u'Branch'), repo.head.reference, report=True)
            namespace.add_property('headcommit_hexsha', _(u'HEAD commit hex SHA'), headcommit.hexsha, report=True)
            namespace.add_property('headcommit_author', _(u'HEAD commit author'), headcommit.author)
            namespace.add_property('headcommit_authored_date', _(u'HEAD commit authored date'), time.asctime(time.gmtime(headcommit.authored_date)), report=True)
            namespace.add_property('headcommit_committer', _(u'HEAD commit committer'), headcommit.committer)
            namespace.add_property('headcommit_committed_date', _(u'HEAD commit committed date'), time.asctime(time.gmtime(headcommit.committed_date)), report=True)
            namespace.add_property('headcommit_message', _(u'HEAD commit message'), headcommit.message, report=True)
开发者ID:Code4PuertoRico,项目名称:mayan,代码行数:22,代码来源:models.py

示例6: test_setup

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import config_reader [as 别名]
    def test_setup(self):
        self.assertTrue(self.workspace.sm.storage_exists())
        repo = self.workspace.sm.repo
        branch = repo.active_branch
        self.assertTrue(self.workspace.im.index_exists(branch.name))
        self.assertTrue(self.workspace.exists())

        repo = Repo(repo.working_dir)
        config = repo.config_reader()
        self.assertEqual(
            config.get_value('user', 'name'), 'Test Kees')
        self.assertEqual(
            config.get_value('user', 'email'), '[email protected]')
开发者ID:fuckthe-code,项目名称:elastic-git,代码行数:15,代码来源:test_workspace.py

示例7: git_properties

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import config_reader [as 别名]
    def git_properties(self):
        namespace = PropertyNamespace('git', _('Git repository'))

        try:
            repo = Repo(os.path.abspath(settings.BASE_DIR))
        except:
            namespace.add_property('is_git_repo', _('Running from a Git repository'), False)
        else:
            try:
                repo.config_reader()
                headcommit = repo.active_branch.commit
                namespace.add_property('is_git_repo', _('Running from a Git repository'), True)
                namespace.add_property('repo_remotes', _('Repository remotes'), ', '.join([unicode(remote) for remote in repo.remotes]), report=True)
                namespace.add_property('repo_remotes_urls', _('Repository remotes URLs'), ', '.join([unicode(remote.url) for remote in repo.remotes]), report=True)
                namespace.add_property('repo_head_reference', _('Branch'), repo.head.reference, report=True)
                namespace.add_property('headcommit_hexsha', _('HEAD commit hex SHA'), headcommit.hexsha, report=True)
                namespace.add_property('headcommit_author', _('HEAD commit author'), headcommit.author)
                namespace.add_property('headcommit_authored_date', _('HEAD commit authored date'), time.asctime(time.gmtime(headcommit.authored_date)), report=True)
                namespace.add_property('headcommit_committer', _('HEAD commit committer'), headcommit.committer)
                namespace.add_property('headcommit_committed_date', _('HEAD commit committed date'), time.asctime(time.gmtime(headcommit.committed_date)), report=True)
                namespace.add_property('headcommit_message', _('HEAD commit message'), headcommit.message, report=True)
            except:
                # Error getting git information, leave blank
                pass
开发者ID:SSE2000,项目名称:mayan-edms,代码行数:26,代码来源:models.py

示例8: get_custom_gitlab_url

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import config_reader [as 别名]
def get_custom_gitlab_url():
    """Return the custom gitlab uri from the git configuration.

    :raises: NotFound if no custom GitLab URL is configured.
    """
    try:
        repo = Repo('.')
    except InvalidGitRepositoryError:
        config_reader = get_global_config_parser()
    else:
        config_reader = repo.config_reader()

    try:
        return config_reader.get_value('gitlab', 'url')
    except (NoOptionError, NoSectionError):
        raise NotFound("No custom uri configured")
开发者ID:3onyc,项目名称:gitgitlab,代码行数:18,代码来源:client.py

示例9: info

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import config_reader [as 别名]
    def info(self, repo_path):
        try:
            repo = Repo(repo_path)
        except InvalidGitRepositoryError:
            print _("Looks like %s is not a git repo" % repo_path)
            exit(1)

        git_config = repo.config_reader()
        remotes = [section for section 
                           in git_config.sections() 
                           if 'remote' in section]

        # get user and repo values
        values = None
        for remote in remotes:
            try:
                remote_url = git_config.get(remote, 'url')
            except:
                continue
            else:
                values = extract_username_and_repo(remote_url)
                if values:
                    break

        if not values:
            print _("Unable to find a remote on GitHub")
            exit(2)

        # fetch repo info
        user, repo = values[0], values[1]
        gh_repo = self.repos.get(user=user, repo=repo)

        # print 
        defaults = ({
            'name': gh_repo.name,
            'description': gh_repo.description,
            'language': '',
            'watchers': gh_repo.watchers,
            'forks': gh_repo.forks,
            'updated_at': gh_repo.updated_at,
        })
        if gh_repo.language:
            defaults.update({
                'language': gh_repo.language,
            })
        print unicode(INFO_TEMPLATE).format(**defaults)
开发者ID:gigigi,项目名称:gg,代码行数:48,代码来源:core.py

示例10: test_init_repo_object

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import config_reader [as 别名]
    def test_init_repo_object(self, rw_dir):
        # [1-test_init_repo_object]
        from git import Repo
        join = os.path.join

        # rorepo is a a Repo instance pointing to the git-python repository.
        # For all you know, the first argument to Repo is a path to the repository
        # you want to work with
        repo = Repo(self.rorepo.working_tree_dir)
        assert not repo.bare
        # ![1-test_init_repo_object]

        # [2-test_init_repo_object]
        bare_repo = Repo.init(join(rw_dir, 'bare-repo'), bare=True)
        assert bare_repo.bare
        # ![2-test_init_repo_object]

        # [3-test_init_repo_object]
        repo.config_reader()             # get a config reader for read-only access
        cw = repo.config_writer()        # get a config writer to change configuration
        cw.release()                     # call release() to be sure changes are written and locks are released
        # ![3-test_init_repo_object]

        # [4-test_init_repo_object]
        assert not bare_repo.is_dirty()  # check the dirty state
        repo.untracked_files             # retrieve a list of untracked files
        # ['my_untracked_file']
        # ![4-test_init_repo_object]

        # [5-test_init_repo_object]
        cloned_repo = repo.clone(join(rw_dir, 'to/this/path'))
        assert cloned_repo.__class__ is Repo     # clone an existing repository
        assert Repo.init(join(rw_dir, 'path/for/new/repo')).__class__ is Repo
        # ![5-test_init_repo_object]

        # [6-test_init_repo_object]
        repo.archive(open(join(rw_dir, 'repo.tar'), 'wb'))
        # ![6-test_init_repo_object]

        # repository paths
        # [7-test_init_repo_object]
        assert os.path.isdir(cloned_repo.working_tree_dir)                    # directory with your work files
        assert cloned_repo.git_dir.startswith(cloned_repo.working_tree_dir)   # directory containing the git repository
        assert bare_repo.working_tree_dir is None                             # bare repositories have no working tree
        # ![7-test_init_repo_object]

        # heads, tags and references
        # heads are branches in git-speak
        # [8-test_init_repo_object]
        assert repo.head.ref == repo.heads.master                   # head is a symbolic reference pointing to master
        assert repo.tags['0.3.5'] == repo.tag('refs/tags/0.3.5')    # you can access tags in various ways too
        assert repo.refs.master == repo.heads['master']             # .refs provides access to all refs, i.e. heads ...
        assert repo.refs['origin/master'] == repo.remotes.origin.refs.master  # ... remotes ...
        assert repo.refs['0.3.5'] == repo.tags['0.3.5']             # ... and tags
        # ![8-test_init_repo_object]

        # create a new head/branch
        # [9-test_init_repo_object]
        new_branch = cloned_repo.create_head('feature')               # create a new branch ...
        assert cloned_repo.active_branch != new_branch                # which wasn't checked out yet ...
        assert new_branch.commit == cloned_repo.active_branch.commit  # and which points to the checked-out commit
        # It's easy to let a branch point to the previous commit, without affecting anything else
        # Each reference provides access to the git object it points to, usually commits
        assert new_branch.set_commit('HEAD~1').commit == cloned_repo.active_branch.commit.parents[0]
        # ![9-test_init_repo_object]

        # create a new tag reference
        # [10-test_init_repo_object]
        past = cloned_repo.create_tag('past', ref=new_branch,
                                      message="This is a tag-object pointing to %s" % new_branch.name)
        assert past.commit == new_branch.commit        # the tag points to the specified commit
        assert past.tag.message.startswith("This is")  # and its object carries the message provided

        now = cloned_repo.create_tag('now')            # This is a tag-reference. It may not carry meta-data
        assert now.tag is None
        # ![10-test_init_repo_object]

        # Object handling
        # [11-test_init_repo_object]
        assert now.commit.message != past.commit.message
        # You can read objects directly through binary streams, no working tree required
        assert (now.commit.tree / 'VERSION').data_stream.read().decode('ascii').startswith('0')

        # You can traverse trees as well to handle all contained files of a particular commit
        file_count = 0
        tree_count = 0
        tree = past.commit.tree
        for item in tree.traverse():
            file_count += item.type == 'blob'
            tree_count += item.type == 'tree'
        assert file_count and tree_count                        # we have accumulated all directories and files
        assert len(tree.blobs) + len(tree.trees) == len(tree)   # a tree is iterable itself to traverse its children
        # ![11-test_init_repo_object]

        # remotes allow handling push, pull and fetch operations
        # [12-test_init_repo_object]
        from git import RemoteProgress

        class MyProgressPrinter(RemoteProgress):
            def update(self, op_code, cur_count, max_count=None, message=''):
#.........这里部分代码省略.........
开发者ID:dbaxa,项目名称:GitPython,代码行数:103,代码来源:test_docs.py

示例11: Repo

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import config_reader [as 别名]
#! /usr/bin/env python

import os
from git import Repo
join = os.path.join

repo = Repo('/home/colm/git/prototypes/')

repo.config_reader()
cw = repo.config_writer()
cw.release()

print cw
开发者ID:colmoneill,项目名称:prototypes,代码行数:15,代码来源:gitpublish.py

示例12: GitFlow

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import config_reader [as 别名]

#.........这里部分代码省略.........
    def init(self, master=None, develop=None, prefixes={}, names={},
             force_defaults=False):
        self._enforce_git_repo()
        self._init_config(master, develop, prefixes, names, force_defaults)
        self._init_initial_commit()
        self._init_develop_branch()
        return self

    def is_initialized(self):
        return (self.repo and
                self.is_set('gitflow.branch.master') and
                self.is_set('gitflow.branch.develop') and
                self.is_set('gitflow.prefix.feature') and
                self.is_set('gitflow.prefix.release') and
                self.is_set('gitflow.prefix.hotfix') and
                self.is_set('gitflow.prefix.support') and
                self.is_set('gitflow.prefix.versiontag'))

    def _parse_setting(self, setting):
        groups = setting.split('.', 2)
        if len(groups) == 2:
            section, option = groups
        elif len(groups) == 3:
            section, subsection, option = groups
            section = '%s "%s"' % (section, subsection)
        else:
            raise ValueError('Invalid setting name: %s' % setting)
        return (section, option)

    @requires_repo
    def get(self, setting, default=_NONE):
        section, option = self._parse_setting(setting)
        try:
            return self.repo.config_reader().get_value(section, option)
        except (NoSectionError, NoOptionError):
            if default is not _NONE:
                return default
            raise

    def get_prefix(self, identifier):
        return self._safe_get('gitflow.prefix.%s' % (identifier,))

    @requires_repo
    def set(self, setting, value):
        section, option = self._parse_setting(setting)
        writer = self.repo.config_writer()
        writer.set_value(section, option, value)
        writer.release()
        del writer

    def is_set(self, setting):
        return self.get(setting, None) is not None

    @requires_repo
    def _safe_get(self, setting_name):
        try:
            return self.get(setting_name)
        except (NoSectionError, NoOptionError):
            raise NotInitialized('This repo has not yet been initialized.')

    def master_name(self):
        return self._safe_get('gitflow.branch.master')

    def develop_name(self):
        return self._safe_get('gitflow.branch.develop')
开发者ID:chassing,项目名称:gitflow,代码行数:69,代码来源:core.py

示例13: set_properties

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import config_reader [as 别名]
    def set_properties(self):
        self._properties = SortedDict()
        if LSB:
            self.add_property(Property('is_lsb', _(u'LSB OS'), True))
            self.add_property(Property('distributor_id', _(u'Distributor ID'), lsb_release('-i', '-s')))
            self.add_property(Property('description', _(u'Description'), lsb_release('-d', '-s')))
            self.add_property(Property('release', _(u'Release'), lsb_release('-r', '-s')))
            self.add_property(Property('codename', _(u'Codename'), lsb_release('-c', '-s')))
            self.add_property(Property('sysinfo', _(u'System info'), uname('-a')))
        else:
            self.add_property(Property('is_lsb', _(u'LSB OS'), False))

        self.add_property(Property('architecture', _(u'OS architecture'), platform.architecture()))
        self.add_property(Property('python_version', _(u'Python version'), platform.python_version()))
        self.add_property(Property('hostname', _(u'Hostname'), platform.node()))
        self.add_property(Property('platform', _(u'Platform'), sys.platform))
        self.add_property(Property('machine', _(u'Machine'), platform.machine()))
        self.add_property(Property('processor', _(u'Processor'), platform.processor()))
        self.add_property(Property('cpus', _(u'Number of CPUs'), psutil.NUM_CPUS))
        self.add_property(Property('total_phymem', _(u'Total physical memory'), pretty_size(psutil.TOTAL_PHYMEM)))
        self.add_property(Property('disk_partitions', _(u'Disk partitions'), '; '.join(['%s %s %s %s' % (partition.device, partition.mountpoint, partition.fstype, partition.opts) for partition in psutil.disk_partitions()])))

        tesseract = pbs.Command(TESSERACT_PATH)
        try:
            self.add_property(Property('tesseract', _(u'tesseract version'), tesseract('-v').stderr))
        except pbs.CommandNotFound:
            self.add_property(Property('tesseract', _(u'tesseract version'), _(u'not found')))
        except Exception:
            self.add_property(Property('tesseract', _(u'tesseract version'), _(u'error getting version')))

        unpaper = pbs.Command(UNPAPER_PATH)
        try:
            self.add_property(Property('unpaper', _(u'unpaper version'), unpaper('-V').stdout))
        except pbs.CommandNotFound:
            self.add_property(Property('unpaper', _(u'unpaper version'), _(u'not found')))
        except Exception:
            self.add_property(Property('unpaper', _(u'unpaper version'), _(u'error getting version')))

        pdftotext = pbs.Command(PDFTOTEXT_PATH)
        try:
            self.add_property(Property('pdftotext', _(u'pdftotext version'), pdftotext('-v').stderr))
        except pbs.CommandNotFound:
            self.add_property(Property('pdftotext', _(u'pdftotext version'), _(u'not found')))
        except Exception:
            self.add_property(Property('pdftotext', _(u'pdftotext version'), _(u'error getting version')))

        self.add_property(Property('mayan_version', _(u'Mayan EDMS version'), mayan_version))
        self.add_property(Property('fabfile', _(u'Installed via fabfile'), os.path.exists(FABFILE_MARKER)))

        try:
            repo = Repo(settings.PROJECT_ROOT)
        except:
            self.add_property(Property('is_git_repo', _(u'Running from a Git repository'), False))
        else:
            repo.config_reader()
            headcommit = repo.head.commit
            self.add_property(Property('is_git_repo', _(u'Running from a Git repository'), True))
            self.add_property(Property('repo_remotes', _(u'Repository remotes'), ', '.join([unicode(remote) for remote in repo.remotes])))
            self.add_property(Property('repo_remotes_urls', _(u'Repository remotes URLs'), ', '.join([unicode(remote.url) for remote in repo.remotes])))
            self.add_property(Property('repo_head_reference', _(u'Branch'), repo.head.reference))
            self.add_property(Property('headcommit_hexsha', _(u'HEAD commit hex SHA'), headcommit.hexsha))
            self.add_property(Property('headcommit_author', _(u'HEAD commit author'), headcommit.author))
            self.add_property(Property('headcommit_authored_date', _(u'HEAD commit authored date'), time.asctime(time.gmtime(headcommit.authored_date))))
            self.add_property(Property('headcommit_committer', _(u'HEAD commit committer'), headcommit.committer))
            self.add_property(Property('headcommit_committed_date', _(u'HEAD commit committed date'), time.asctime(time.gmtime(headcommit.committed_date))))
            self.add_property(Property('headcommit_message', _(u'HEAD commit message'), headcommit.message))
开发者ID:eschipul,项目名称:mayan,代码行数:68,代码来源:models.py

示例14: GitFlow

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import config_reader [as 别名]

#.........这里部分代码省略.........
             force_defaults=False):
        self._enforce_git_repo()
        self._init_config(master, develop, prefixes, names, force_defaults)
        self._init_initial_commit()
        self._init_develop_branch()
        return self

    def is_initialized(self):
        return (self.repo and
                self.is_set('gitflow.branch.master') and
                self.is_set('gitflow.branch.develop') and
                self.is_set('gitflow.prefix.feature') and
                self.is_set('gitflow.prefix.release') and
                self.is_set('gitflow.prefix.hotfix') and
                self.is_set('gitflow.prefix.support') and
                self.is_set('gitflow.prefix.versiontag') and
                self.is_set('gitflow.release.versionmatcher'))

    def _parse_setting(self, setting):
        groups = setting.split('.', 2)
        if len(groups) == 2:
            section, option = groups
        elif len(groups) == 3:
            section, subsection, option = groups
            section = '%s "%s"' % (section, subsection)
        else:
            raise ValueError('Invalid setting name: %s' % setting)
        return (section, option)

    @requires_repo
    def get(self, setting, default=_NONE):
        section, option = self._parse_setting(setting)
        try:
            return self.repo.config_reader().get_value(section, option)
        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
            if default is not _NONE:
                return default
            raise

    def get_prefix(self, identifier):
        return self._safe_get('gitflow.prefix.%s' % (identifier,))

    @requires_repo
    def set(self, setting, value):
        section, option = self._parse_setting(setting)
        self.repo.config_writer().set_value(section, option, value)

    def is_set(self, setting):
        return self.get(setting, None) is not None


    @requires_repo
    def _safe_get(self, setting_name):
        try:
            return self.get(setting_name)
        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
            raise NotInitialized('This repo has not yet been initialized.')

    def master_name(self):
        return self._safe_get('gitflow.branch.master')

    def develop_name(self):
        return self._safe_get('gitflow.branch.develop')

    def origin_name(self, name=None):
        origin = self.get('gitflow.origin', self.defaults['gitflow.origin'])
开发者ID:opicacek,项目名称:gitflow,代码行数:70,代码来源:core.py

示例15: main

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import config_reader [as 别名]
def main():
    global TAB_WIDTH

    git_exec = Git()
    output = git_exec.rev_parse('--show-toplevel', with_extended_output=True,
                                with_exceptions=False)
    err_no, git_root, err_msg = output
    if err_no:
        print >> sys.stderr, err_msg
        sys.exit(1)

    git_repo = Repo(git_root)
    git_config = git_repo.config_reader()

    ws_config = {
        'blank-at-eol': True,
        'space-before-tab': True,
        'indent-with-non-tab': False,
        'tab-in-indent': False,
        'blank-at-eof': False,
        'trailing-space': False,
        'cr-at-eol': False,
    }
    try:
        _config_whitespace = git_config.get('core', 'whitespace')
        for c in _config_whitespace.split(','):
            c = c.strip()

            if 'tabwidth' in c:
                ws_config['tabwidth'] = int(c.split('=').pop())
            else:
                if c[0] == '-':  # e.g. -tab-in-indent
                    ws_config[c[1:]] = False
                else:
                    ws_config[c] = True
    except:
        pass

    if ws_config.get('tab-in-indent', False) and \
       ws_config.get('indent-with-non-tab', False):
        print >> sys.stderr, \
                 'Cannot enforce both tab-in-indent and indent-with-non-tab.'
        sys.exit(1)

    TAB_WIDTH = ws_config.get('tabwidth')
    sanitizers = []

    if ws_config.get('trailing-space', False):
        ws_config['blank-at-eol'] = True
        ws_config['blank-at-eof'] = True

    # Allow overrides gitconfig by cli argument
    arg_parser = argparse.ArgumentParser()
    arg_parser.set_defaults(**ws_config)

    arg_parser.add_argument('--trailing-space', dest='trailing-space',
                            type=ast.literal_eval, metavar='True|False',
                            help='trailing-space is a short-hand to cover '
                                 'both blank-at-eol and blank-at-eof')
    arg_parser.add_argument('--blank-at-eol', dest='blank-at-eol',
                            type=ast.literal_eval, metavar='True|False',
                            help='treats trailing whitespaces at the end of '
                                 'the line as an error')
    arg_parser.add_argument('--space-before-tab', dest='space-before-tab',
                            type=ast.literal_eval, metavar='True|False',
                            help='treats a space character that appears '
                                 'immediately before a tab character in the '
                                 'initial indent part of the line as an error')
    arg_parser.add_argument('--indent-with-non-tab',
                            dest='indent-with-non-tab',
                            type=ast.literal_eval, metavar='True|False',
                            help='treats a line that is indented with 8 or '
                                 'more space characters as an error')
    arg_parser.add_argument('--tab-in-indent', dest='tab-in-indent',
                            type=ast.literal_eval, metavar='True|False',
                            help='treats a tab character in the initial '
                                 'indent part of the line as an error')
#    arg_parser.add_argument('--blank-at-eof', dest='blank-at-eof',
#                            type=ast.literal_eval, metavar='True|False',
#                            help='treats blank lines added at the end of '
#                                 'file as an error')
    arg_parser.add_argument('--cr-at-eol', dest='cr-at-eol',
                            type=ast.literal_eval, metavar='True|False',
                            help='treats a carriage-return at the end of '
                                 'line as part of the line terminator, i.e. '
                                 'with it, trailing-space does not trigger '
                                 'if the character before such a '
                                 'carriage-return is not a whitespace')
    arg_parser.add_argument('--tabwidth', type=int, metavar='',
                            help='tells how many character positions a tab '
                                 'occupies; this is relevant for '
                                 'indent-with-non-tab and when git fixes '
                                 'tab-in-indent errors. The default tab '
                                 'width is 8.')

    arg_parser.add_argument('-d', '--debug', action='store_true',
                            help='Print the whitespace config')

    args = arg_parser.parse_args()
    ws_config = vars(args)
#.........这里部分代码省略.........
开发者ID:mrkschan,项目名称:git-fix-whitespace,代码行数:103,代码来源:git_fix_whitespace.py


注:本文中的git.Repo.config_reader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。