Browse Source

Add version change to pre-commit hook

softuart
Xose Pérez 6 years ago
parent
commit
348f2d9a45
2 changed files with 28 additions and 13 deletions
  1. +1
    -1
      README.md
  2. +27
    -12
      pre-commit

+ 1
- 1
README.md View File

@ -3,7 +3,7 @@
ESPurna ("spark" in Catalan) is a custom firmware for ESP8266 based smart switches and sensors. ESPurna ("spark" in Catalan) is a custom firmware for ESP8266 based smart switches and sensors.
It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries. It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries.
[![version](https://badge.fury.io/gh/xoseperez%2Fespurna.svg)](CHANGELOG.md)
[![version](https://img.shields.io/badge/version-1.12.2b-brightgreen.svg)](CHANGELOG.md)
![branch](https://img.shields.io/badge/branch-dev-orange.svg) ![branch](https://img.shields.io/badge/branch-dev-orange.svg)
[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna) [![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna)
[![license](https://img.shields.io/github/license/xoseperez/espurna.svg)](LICENSE) [![license](https://img.shields.io/github/license/xoseperez/espurna.svg)](LICENSE)


+ 27
- 12
pre-commit View File

@ -19,32 +19,47 @@ import sys
import re import re
import subprocess import subprocess
README = os.path.dirname(os.path.realpath(__file__)) + "/../../README.md"
BASE = os.path.dirname(os.path.realpath(__file__)) + "/../../"
README = BASE + "README.md"
remote = subprocess.check_output(["git", "remote", "-v"]).strip().split('\n')[0] remote = subprocess.check_output(["git", "remote", "-v"]).strip().split('\n')[0]
parts = re.split('[/\.: ]', remote) parts = re.split('[/\.: ]', remote)
REPO = parts[ len(parts) - 3] REPO = parts[ len(parts) - 3]
USER = parts[ len(parts) - 4] USER = parts[ len(parts) - 4]
BRANCH=subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip()
BRANCH = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip()
def getVersion():
file_name = BASE + "code/espurna/config/version.h"
lines = open(file_name).readlines()
for line in lines:
if "APP_VERSION" in line:
parts = line.split('"')
return parts[1]
return "unknown"
VERSION = getVersion()
version = "[![version](https://img.shields.io/badge/version-{VERSION}-brightgreen.svg)](CHANGELOG.md)\n".format(
VERSION = VERSION
)
branch_mark = "![branch]"
branch = "![branch](https://img.shields.io/badge/branch-{BRANCH}-orange.svg)\n".format( branch = "![branch](https://img.shields.io/badge/branch-{BRANCH}-orange.svg)\n".format(
BRANCH=BRANCH
)
BRANCH = BRANCH
)
travis_mark = "![travis]"
travis = "[![travis](https://travis-ci.org/{USER}/{REPO}.svg?branch={BRANCH})]" \ travis = "[![travis](https://travis-ci.org/{USER}/{REPO}.svg?branch={BRANCH})]" \
"(https://travis-ci.org/{USER}/{REPO})\n".format( "(https://travis-ci.org/{USER}/{REPO})\n".format(
USER=USER,
REPO=REPO,
BRANCH=BRANCH
)
USER = USER,
REPO = REPO,
BRANCH = BRANCH
)
lines = open(README).readlines() lines = open(README).readlines()
with open(README, "w") as fh: with open(README, "w") as fh:
for line in lines: for line in lines:
if travis_mark in line:
if "![travis]" in line:
fh.write(travis) fh.write(travis)
elif branch_mark in line:
elif "![version]" in line:
fh.write(version)
elif "![branch]" in line:
fh.write(branch) fh.write(branch)
else: else:
fh.write(line) fh.write(line)


Loading…
Cancel
Save