def for_user(self, domain, username, bucket): dir = os.path.join(self.dir, urllib.quote(domain, ''), urllib.quote(username, ''), urllib.quote(bucket, '')) if not os.path.exists(dir): os.makedirs(dir) col_filename = os.path.join(dir, 'collection_id.txt') if not os.path.exists(col_filename): collection_id = str(int(self.timer() * 100) % 1000000) with open(col_filename, 'wb') as fp: fp.write(collection_id) else: with open(col_filename, 'rb') as fp: collection_id = fp.read() db_name = os.path.join(dir, 'database') db = Database(db_name) db.collection_id = collection_id return db