~jcsackett/charmworld/bac-tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/jobs/ingest.py

  • Committer: Tarmac
  • Author(s): Abel Deuring
  • Date: 2013-08-07 13:31:20 UTC
  • mfrom: (334.1.5 etags)
  • Revision ID: tarmac-20130807133120-euu4igaar08e89iy
[r=abentley][bug=][author=adeuring] Add an Etag header to the API response for charm details.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
    datetime,
9
9
    timedelta,
10
10
)
 
11
import hashlib
 
12
import json
11
13
import logging
12
14
import os
13
15
import shutil
227
229
    return True
228
230
 
229
231
 
 
232
def update_hash(charm_data):
 
233
    hashable_data = charm_data.copy()
 
234
    hashable_data.pop('hash', None)
 
235
    h = hashlib.sha256()
 
236
    h.update(json.dumps(hashable_data, sort_keys=True))
 
237
    charm_data['hash'] = h.hexdigest()
 
238
 
 
239
 
230
240
def update_charm(charm_data, db, store):
231
241
    # Drop existing error data so that charms can lose their error status.
232
242
    charm_data.pop('error', None)
242
252
        update_from_revisions(charm_data)
243
253
        update_date_created(charm_data, log)
244
254
        scan_charm(charm_data, db, fs, log)
 
255
        update_hash(charm_data)
245
256
    except Exception as e:
246
257
        err_msg = "%s error: %s" % (charm_data, str(e))
247
258
        log.exception(err_msg)