Browse Source

Never print newline

rfm69
Maxim Prokhorov 6 years ago
parent
commit
5ae00f992d
1 changed files with 23 additions and 28 deletions
  1. +23
    -28
      pre-commit

+ 23
- 28
pre-commit View File

@ -80,17 +80,15 @@ def espurna_get_version(base, version_h="code/espurna/config/version.h"):
return version return version
SHIELD_TRAVIS = "[![travis](https://travis-ci.org/{USER}/{REPO}.svg?branch={BRANCH})]" \
"(https://travis-ci.org/{USER}/{REPO})"
SHIELD_VERSION = "[![version](https://img.shields.io/badge/version-{VERSION}-brightgreen.svg)](CHANGELOG.md)"
SHIELD_BRANCH = "[![branch](https://img.shields.io/badge/branch-{BRANCH}-orange.svg)]" \
"(https://github.org/{USER}/{REPO}/tree/{BRANCH}/)"
SHIELD_CODACY = "[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/{BRANCH}.svg)]" \
"(https://www.codacy.com/app/{USER}/{REPO}/dashboard)"
TEMPLATES = {
"![travis]": "[![travis](https://travis-ci.org/{USER}/{REPO}.svg?branch={BRANCH})]" \
"(https://travis-ci.org/{USER}/{REPO})\n",
"![version]": "[![version](https://img.shields.io/badge/version-{VERSION}-brightgreen.svg)](CHANGELOG.md)\n",
"![branch]": "[![branch](https://img.shields.io/badge/branch-{BRANCH}-orange.svg)]" \
"(https://github.org/{USER}/{REPO}/tree/{BRANCH}/)\n",
"![codacy]": "[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/{BRANCH}.svg)]" \
"(https://www.codacy.com/app/{USER}/{REPO}/dashboard)\n"
}
README = "README.md" README = "README.md"
@ -99,31 +97,28 @@ if __name__ == "__main__":
base = os.getcwd() base = os.getcwd()
user, repo = git_parse_remote() user, repo = git_parse_remote()
template = {
fmt = {
"USER": user, "USER": user,
"REPO": repo, "REPO": repo,
"BRANCH": git_branch(), "BRANCH": git_branch(),
"VERSION": espurna_get_version(base) "VERSION": espurna_get_version(base)
} }
templates = [
(k, tmpl.format(**fmt))
for k, tmpl in TEMPLATES.items()
]
def fmt_line(line):
for match, tmpl in templates:
if match in line:
return tmpl
shield_travis = SHIELD_TRAVIS.format(**template)
shield_version = SHIELD_VERSION.format(**template)
shield_branch = SHIELD_BRANCH.format(**template)
shield_codacy = SHIELD_CODACY.format(**template)
return line
path = os.path.join(base, README) path = os.path.join(base, README)
with FileInput(path, inplace=True) as readme: with FileInput(path, inplace=True) as readme:
for line in readme: for line in readme:
if "![travis]" in line:
print(shield_travis)
elif "![version]" in line:
print(shield_version)
elif "![branch]" in line:
print(shield_branch)
elif "![codacy]" in line:
print(shield_codacy)
else:
print(line, end="")
sys.exit(call(["git", "add", README], cwd=base))
print(fmt_line(line), end='')
sys.exit(call(["git", "add", README]))

Loading…
Cancel
Save