Esempio n. 1
0
	def __init__(self):
		self.base_path = os.path.join(os.environ['postprompt'],'tables')
		self.db = Database()
Esempio n. 2
0
class DatabaseController:
	def __init__(self):
		self.base_path = os.path.join(os.environ['postprompt'],'tables')
		self.db = Database()
	def reload_cards(self):
		self.delete_cards()
		self.load_cards()
	def delete_cards(self):
		self.db.delete('play_cards')
		self.db.delete('play_starting_cards')
		self.db.delete('play_card_names')
	def load_cards(self):
		self.load_card_info()
		path = os.path.join(self.base_path,'starting_cards.json')
		obj = PPjo(filename=path)
		card_ids = obj.get_strings('card_ids')
		for key,card_id in enumerate(card_ids):
			key += 1
			self.db.update("insert into play_starting_cards values(%s,%s)"%(key,card_id))

	def reload_card_info(self):
		self.delete_card_info()
		self.load_card_info()
	def delete_card_info(self):
		self.db.delete('play_card_names')
	def load_card_info(self):
		pre_glob_path = os.path.join(self.base_path,'cards','*.json')
		card_files = glob.glob(pre_glob_path)
		for card_file in card_files:
			obj = PPjo(filename=card_file)
			card = obj.get_object('card')
			key = obj.get_string('index')
			name = card.get_string('name')
			effect = card.get_string('effect')
			self.db.update('insert into play_card_names values(%s,"%s","%s")'%
				(key,name,effect))

	def reload_users(self):
		self.delete_users()
		self.load_users()
	def delete_users(self):
		self.db.delete('auth_user')
	def load_users(self):
		path = os.path.join(self.base_path,'users.json')
		obj = PPjo(filename=path)
		users = obj.get_objects('users')
		for user in users:
			username = user.get_string("username")
			password = user.get_string("password")
			email = user.get_string("email")
			User.objects.create_user(username,email,password)
			register_add_cards(username)

	def delete_games(self):
		self.db.delete('play_games')

	def delete_all(self):
		self.delete_games()
		self.delete_users()
		self.delete_cards()

	def load_all(self):
		self.load_cards()
		self.load_users()

	def reload_all(self):
		self.reload_cards()
		self.reload_users()