X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a9a4f7d43340f4f317fb041c93b9aa9c1b6e51c8..35895ee91c820680bb7df9696ab2e92525ead2ac:/sdk/python/arvados/util.py diff --git a/sdk/python/arvados/util.py b/sdk/python/arvados/util.py index c383d529e8..a4b7e64a05 100644 --- a/sdk/python/arvados/util.py +++ b/sdk/python/arvados/util.py @@ -500,3 +500,20 @@ def get_vocabulary_once(svc): if not hasattr(svc, '_cached_vocabulary'): svc._cached_vocabulary = svc.vocabularies().get().execute() return svc._cached_vocabulary + +def trim_name(collectionname): + """ + trim_name takes a record name (collection name, project name, etc) + and trims it to fit the 255 character name limit, with additional + space for the timestamp added by ensure_unique_name, by removing + excess characters from the middle and inserting an ellipse + """ + + max_name_len = 254 - 28 + + if len(collectionname) > max_name_len: + over = len(collectionname) - max_name_len + split = int(max_name_len/2) + collectionname = collectionname[0:split] + "…" + collectionname[split+over:] + + return collectionname