diff --git a/progit/lib.py b/progit/lib.py index 33f5105..4b50c10 100644 --- a/progit/lib.py +++ b/progit/lib.py @@ -12,7 +12,9 @@ import datetime import json import os +import random import shutil +import string import tempfile import uuid @@ -48,6 +50,19 @@ def create_session(db_url, debug=False, pool_recycle=3600): return scopedsession +def id_generator(size=15, chars=string.ascii_uppercase + string.digits): + """ Generates a random identifier for the given size and using the + specified characters. + If no size is specified, it uses 15 as default. + If no characters are specified, it uses ascii char upper case and + digits. + :arg size: the size of the identifier to return. + :arg chars: the list of characters that can be used in the + idenfitier. + """ + return ''.join(random.choice(chars) for x in range(size)) + + def commit_to_patch(repo_obj, commits): ''' For a given commit (PyGit2 commit object) of a specified git repo, returns a string representation of the changes the commit did in a