예제 #1
0
def file_exists(location, file_name, path=''):
    """this is untested and probably not going to be used
    """
    try:
        LocationFiles.select(AND(LocationFiles.q.locationID==location,
                                 LocationFiles.q.attr_name==attr_name))[0]
        os.stat(path + attr_name)
        return True
    except:
        return False
예제 #2
0
def get_filepath(obj, prop, upload_dir, default=''):
    """obj should usually be a MetaWrapper
    """
    prop_val = getattr(obj, prop)
    try:
        val = int(prop_val)
    except:
        return default
    return upload_dir + LocationFiles.get(val).attr_name
예제 #3
0
def locally_unique_file_name(file_name, location):
    """give a file_name test.png it should iterate through test-1.png, test-2.png etc until we reach a unique one.
    """
    if LocationFiles.select(AND(LocationFiles.q.locationID==location, LocationFiles.q.attr_name==file_name)).count():
        file_name = file_name.rsplit('.', 1)
        extra = file_name[-2].rsplit('-', 1)
        try:
            extra[-1] = str(int(extra[-1])+1)
            extra = '-'.join(extra)
            file_name[-2] = extra
            return locally_unique_file_name('.'.join(file_name), location)
        except ValueError:
            extra[-1] += '-1'
            file_name[-2] = '-'.join(extra)
            return locally_unique_file_name('.'.join(file_name), location)            
        file_name = '.'.join(file_name)    
    return file_name