示例#1
0
def dump(output_fp, kbsite, indent=None, log_cb=_no_log):
  """Produce a dump of this Gatebot system to the given filestream.

  In its current format, the dump is plaintext JSON string consisting of all
  important data, including tap configuration, drink history, and user account
  details.

  All "derived" tables are NOT backed up.  These are tables with data that can
  be regenerated at any time without any loss of history.  Specifically:
    - session chunks
    - user session chunks
    - keg session chunks
    - keg stats
    - user stats
    - session stats
    - system events
  """
  res = {}
  items = (
      ('gates', kbsite.gates.all().order_by('id')),
      ('users', models.User.objects.all().order_by('id')),
      ('profiles', models.UserProfile.objects.all().order_by('id')),
      ('entries', kbsite.entries.valid().order_by('id')),
      ('tokens', kbsite.tokens.all().order_by('id')),
      ('configs', kbsite.configs.all()),
  )

  log_cb('Generating backup data ...')
  for name, qs in items:
    log_cb('  .. dumping %s' % name)
    res[name] = list(protolib.ToProto(qs, full=True))

  log_cb('Serializing and writing backup data ...')
  output_fp.write(kbjson.dumps(res, indent=indent))
示例#2
0
 def do_GET(self):
   self._ExtractParams()
   client = self.server.client
   result = {
     'ok': False,
   }
   username = self.params.get('username')
   if username:
     username = username[0]
   if self.path == '/add' and username:
     self.server._logger.info('adding: %s' % username)
     client.SendAuthTokenAdd(FLAGS.gate_name, 'core.user', username)
     result['ok'] = True
   elif self.path == '/remove' and username:
     self.server._logger.info('removing: %s' % username)
     client.SendAuthTokenRemove(FLAGS.gate_name, 'core.user', username)
     result['ok'] = True
   elif self.path == '/latches':
     result['ok'] = True
     flow_dict = dict((k, v.ToDict()['data']) for k, v in self.server.client.latches.iteritems())
     result['latches'] = flow_dict
   elif self.path == '/status':
     result['ok'] = True
   return self._DoResponse(body=kbjson.dumps(result), type="application/json")
示例#3
0
 def get_db_prep_save(self, value):
   """Convert our JSON object to a string before we save"""
   if not value:
     return super(JSONField, self).get_db_prep_save("")
   else:
     return super(JSONField, self).get_db_prep_save(kbjson.dumps(value))
示例#4
0
 def __repr__(self):
   return kbjson.dumps(self)
示例#5
0
 def ToJson(self, indent=2):
   return kbjson.dumps(self.ToDict(), indent=indent)