def share(self, with_user, roles=None, table=None): ''' Give cube access rights to another user Not, this method is NOT supported by SQLite3! ''' table = self.get_table(table) is_true(table is not None, 'invalid table: %s' % table) with_user = validate_username(with_user) roles = roles or ['SELECT'] roles = validate_roles(roles, self.VALID_SHARE_ROLES) roles = list2str(roles) logger.info('Sharing cube %s with %s (%s)' % (table, with_user, roles)) sql = 'GRANT %s ON %s TO %s' % (roles, table, with_user) return self.session_auto.execute(sql)
def get_last_field(self, field, table=None): '''Shortcut for querying to get the last field value for a given owner, cube. :param field: field name to query ''' field = field if is_array(field) else [field] table = self.get_table(table, except_=False) if table is None: last = None else: is_defined(field, 'field must be defined!') last = self.find(table=table, fields=field, scalar=True, sort=field, limit=1, descending=True, date='~', default_fields=False) logger.debug("last %s.%s: %s" % (table, list2str(field), last)) return last
def test_list2str(): from metrique.utils import list2str l = [1, 1.1, '1', None, 0] ok = '1,1.1,1,None,0' assert list2str(l) == ok ok = '1, 1.1, 1, None, 0' assert list2str(l, delim=', ') == ok ok = '1 1.1 1 None 0' assert list2str(l, delim=' ') == ok assert list2str(ok) == ok assert list2str(None) == '' try: list2str(list2str) except TypeError: pass else: assert False