Exemplo n.º 1
0
def hash_file(fname):
    h = sha_hash()
    if os.path.exists(str(fname)):
        h.update(open(fname, "rb").read())
    else:
        h.update(str(fname))
    return h.hexdigest()
Exemplo n.º 2
0
def hash_file(fname):
    h = sha_hash()
    if os.path.exists(str(fname)):
        h.update(open(fname, "rb").read())
    else:
        h.update(str(fname))
    return h.hexdigest()
Exemplo n.º 3
0
def get_geo_dname(geofolder, geotype, otherdata):
    '''given a geometry type (i.e upload:some_shapefile)
    and a dictionary of the column/features we'll be using
    returns a short fname in the format:
    some_shapefile_n where in is a unique number, incremented once for each time
    a new column/feature is used.
    
    This info is stored in a pickled dict in the geofolder
    '''
    geofolder_abs = os.path.join(get_root_dir(), geofolder)
    if not os.path.exists(geofolder_abs):
        os.makedirs(geofolder_abs)

    feature_geoms = get_hash_entry_pickle(geotype, geofolder_abs, "geo.dat")
    if not feature_geoms:
        feature_geoms = {}


    other_geo = sha_hash()
    other_geo.update(str(otherdata))
    other_geo_hash = other_geo.hexdigest()

    if feature_geoms.has_key(other_geo_hash):
        dname = geotype + "_" + str(feature_geoms[other_geo_hash])
    else:
        vals = [v for k, v in feature_geoms.iteritems() if k != 'date_run']
        if vals:
            next_val = max(vals)+1
        else:
            next_val = 1 
        feature_geoms[other_geo_hash] = next_val
        dname = geotype + "_" + str(next_val)
        write_hash_entry_pickle(geotype, feature_geoms, geofolder_abs, "geo.dat")
        
    return dname
Exemplo n.º 4
0
def get_geo_dname(geofolder, geotype, otherdata):
    '''given a geometry type (i.e upload:some_shapefile)
    and a dictionary of the column/features we'll be using
    returns a short fname in the format:
    some_shapefile_n where in is a unique number, incremented once for each time
    a new column/feature is used.
    
    This info is stored in a pickled dict in the geofolder
    '''
    geofolder_abs = os.path.join(get_root_dir(), geofolder)
    if not os.path.exists(geofolder_abs):
        os.makedirs(geofolder_abs)

    feature_geoms = get_hash_entry_pickle(geotype, geofolder_abs, "geo.dat")
    if not feature_geoms:
        feature_geoms = {}

    other_geo = sha_hash()
    other_geo.update(str(otherdata))
    other_geo_hash = other_geo.hexdigest()

    if feature_geoms.has_key(other_geo_hash):
        dname = geotype + "_" + str(feature_geoms[other_geo_hash])
    else:
        vals = [v for k, v in feature_geoms.iteritems() if k != 'date_run']
        if vals:
            next_val = max(vals) + 1
        else:
            next_val = 1
        feature_geoms[other_geo_hash] = next_val
        dname = geotype + "_" + str(next_val)
        write_hash_entry_pickle(geotype, feature_geoms, geofolder_abs,
                                "geo.dat")

    return dname