Exemplo n.º 1
0
def fileCacheRefresh(f, sha):
    # Load yaml data from file.
    data = yaml.load(urlfetch.fetch(raw_path + f).content)

    # Format the data to be saved in the database
    data_json = json.dumps(data, separators=(',', ':'))

    # Attempt to load the record
    fc = FileCache.gql('WHERE project = :1', f).get()

    if fc:  # Save data to existing record
        fc.sha = sha
        fc.data = data_json
        fc.put()
    else:  # Create a new record
        fc = FileCache(filename=f, sha=sha, data=data_json)
        fc.put()

    return data