1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

build: change FWTAG replacement to keep suffix intact and trim branch/tag only

This commit is contained in:
Oleg Semyonov 2011-05-26 12:19:48 +03:00 committed by Stacey Sheldon
parent 75d4f19d30
commit 41b03c92ee

View File

@ -235,12 +235,20 @@ def sha1(file):
hex_stream = lambda s:",".join(['0x'+hex(ord(c))[2:].zfill(2) for c in s])
return hex_stream(sha1.digest())
def xtrim(string, length):
"""Trim string up to length bytes, adding '+' if truncated"""
if len(string) <= length:
return string
def xtrim(string, suffix, length):
"""Return string+suffix concatenated and trimmed up to length characters
This function appends suffix to the end of string and returns the result
up to length characters. If it does not fit then the string will be
truncated and the '+' will be put between it and the suffix.
"""
if len(string) + len(suffix) <= length:
return ''.join([string, suffix])
else:
return string[:length-1] + '+'
n = length-1-len(suffix)
assert n > 0, "length of truncated string+suffix exceeds maximum length"
return ''.join([string[:n], '+', suffix])
def main():
"""This utility uses git repository in the current working directory
@ -313,7 +321,7 @@ dependent targets.
TAG_OR_BRANCH = r.tag(r.branch('unreleased')),
TAG_OR_HASH8 = r.tag(r.hash(8, 'untagged')),
DIRTY = r.dirty(),
FWTAG = xtrim(r.tag(r.branch('unreleased')) + r.dirty(), 25),
FWTAG = xtrim(r.tag(r.branch('unreleased')), r.dirty(), 25),
UNIXTIME = r.time(),
DATE = r.time('%Y%m%d'),
DATETIME = r.time('%Y%m%d %H:%M'),