mongo_suppor_6.py 870 B

1234567891011121314151617181920212223242526272829
  1. def upload(to_upload):
  2. filename = '/tmp/what_the_duck'
  3. S = shelve.open(filename)
  4. try:
  5. # logger.debug('New records: %s previous: %s' % (len(to_upload), len(S)))
  6. for u in to_upload:
  7. S[u['_id']] = u
  8. if not is_internet_connected():
  9. msg = 'Internet is not connected: cannot upload results.'
  10. logger.warning(msg)
  11. else:
  12. remaining = []
  13. for k in S:
  14. remaining.append(S[k])
  15. collection = get_upload_collection()
  16. logger.info('Uploading %s test results' % len(remaining))
  17. collection.insert_many(remaining)
  18. logger.info('done')
  19. for r in remaining:
  20. del S[r['_id']]
  21. finally:
  22. # logger.info('Remaining %s' % (len(S)))
  23. S.close()