コード例 #1
0
ファイル: backup.py プロジェクト: goliathdrakken/gatebot
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
ファイル: jsonfield.py プロジェクト: goliathdrakken/gatebot
 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
ファイル: jsonfield.py プロジェクト: goliathdrakken/gatebot
 def __repr__(self):
   return kbjson.dumps(self)
コード例 #5
0
ファイル: kbevent.py プロジェクト: goliathdrakken/gatebot
 def ToJson(self, indent=2):
   return kbjson.dumps(self.ToDict(), indent=indent)