コード例 #1
0
ファイル: fixture_helpers.py プロジェクト: Nullicopter/tethr
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)
コード例 #2
0
ファイル: projects.py プロジェクト: Emamatcyber90/Desio
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!
コード例 #3
0
ファイル: project.py プロジェクト: Emamatcyber90/Desio
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
コード例 #4
0
ファイル: users.py プロジェクト: Emamatcyber90/Desio
def short_uuid():
    return utils.uuid()[0:6]