def create_unique_str(pre=u'', extra=u"\u00bf"): """ @param pre: The string to prefix the unique string with. Defaults to nothing. @param extra: The string to append to the unique string. Default to a unicode character. @return: A unique string. """ return u"%s%s%s" % (pre, utils.uuid(), extra)
def get_unique_slug(organization, name, max=100): import re from pylons_common.lib.utils import uuid def gen_slug(input, addon=u''): return (u'-'.join(re.findall('[a-z0-9]+', input, flags=re.IGNORECASE)))[:max].lower() + addon for c in range(20): slug = gen_slug(name, addon=(c and unicode(c) or u'')) project = Session.query(Project ).filter(Project.organization==organization ).filter(Project.slug==slug ).first() if not project: return slug return utils.uuid() #they have 20 projects named similarly, now they get eids!
def get_structure(real_user, user, project, path=u'/'): """ For a given path will get all the files, directories and files within the top level directories. returns something like this: [(Directory(/), [ (File('bleh.png'), Change('latestversion')), ]), (Directory(/mydir), [ (File('bleh2.png'), Change('latestversion')), ]),] """ if path[-1] != u'/': path = path + u'/' def get_file_tuple(f): return (f, f.get_change()) entities = project.get_entities(filepath=path) res = [] cur_dir = None cur_dir_files = [] for entity in entities: if entity.type == projects.File.TYPE: cur_dir_files.append(get_file_tuple(entity)) #root dir is a special case... elif entity.type == projects.Directory.TYPE and not entity.name: cur_dir = entity #is directory else: res.append(_get_files_for_dir(project, entity)) if not cur_dir: if path[:-1]: cur_dir = project.get_entities(filepath=path[:-1]) else: #return fake dir for root cur_dir = projects.Directory(path=u'/', name=u'', eid=uuid()) res = [(cur_dir, cur_dir_files)] + res if not cur_dir_files and not cur_dir: return None return res
def short_uuid(): return utils.uuid()[0:6]