<commit_before>#!/usr/bin/python3.4
# -*-coding:Utf-8 -*
'''module to manage preferences of Blender-Render-Manager'''
from save import *
from Preferences.Blender import *
from Preferences.Output import *

class Preferences:
	'''class to manage Blender-Render-Manager preferences'''
	
	
	def __init__(self, xml= None):
		'''load preferences object from XML or initialize default one'''
		if xml is None:
			self.defaultInit()
		else:
			self.fromXml(xml)
	
	
	
	
	
	def defaultInit(self):
		'''initialize default preferences object'''
		
		self.blender = Blender() # blender application path
		self.output = Output() # working directory path
		self.port = 55814 # socket port to communicate with blender thread
		self.archiveLimit = 1000 # max number of task to keep in archive list
		self.logLimit = 100 # max number of session log file to keep
	
	
	
	
	
	def fromXml(self, xml):
		'''Load preferences from xml'''
		
		self.blender = Blender( xml.find('blender') )
		self.output = Output( xml.find('output') )
		self.port = int(xml.get('port'))
		self.archiveLimit = int(xml.get('archive'))
		self.logLimit = int(xml.get('log'))
	
	
	
	
	
	def toXml(self, preset = True, head = True):
		'''export preferences settings into xml syntaxed string'''
		xml = ''
		
		if head:
			xml += '<?xml version="1.0" encoding="UTF-8"?>\n'
		
		xml += '<preferences archive="'+str(self.archiveLimit)\
				+'" log="'+str(self.logLimit)+'" port="'+str(self.port)+'">\n'
		
		if preset:
			# export blender path
			xml += self.blender.toXml()
		
		# export output path
		xml+= self.output.toXml()
		
		xml += '</preferences>\n'
		
		return xml
	
	
	
	
	
	def menu(self, log, tasks):
		'''access function to set preferences'''
		log.menuIn('Preferences')
		change = False
		
		while True:
			log.print()
			self.print()
			
			choice = input('''\n    \033[4mPreferences Menu :\033[0m
1- Edit Blender Path
2- Edit Work Path
3- Edit Log Limit
4- Edit Archive Size Limit
5- Edit Socket Port
0- Save and quit

menu choice?''').strip().lower()
			
			#treat available actions
			if choice in ['0', 'q', 'quit', 'cancel']:# quit preferences menu
				log.menuOut()
				return
				
			elif choice == '1':# edit blender application path
				change = self.blender.menu(log)
				
			elif choice == '2':# edit working directory path
				change = self.output.menu(log)
				
			elif choice in ['3', '4']:# edit log or archive limit
				change = self.editLimit(log, choice == '3' )
				
			elif choice == '5':# edit socket port for blender thread communication
				change = self.editPort(log)
				
			else:
				log.error('Unknow request!', False)
			
			if change:# save when preferences have been changed
				change = False
				savePreferences(self)
				log.write('New preferences saved')
	
	
	
	
	
	def print(self):
		'''display preference settings'''
		print('Blender Path : '+self.blender.path,\
				'Work Path : '+self.output.path,\<commit_msg>commenting and instruction emrging and useless method argument removed<commit_after>#!/usr/bin/python3.4
# -*-coding:Utf-8 -*
'''module to manage preferences of Blender-Render-Manager'''
from save import *
from Preferences.Blender import *
from Preferences.Output import *

class Preferences:
	'''class to manage Blender-Render-Manager preferences'''
	
	
	def __init__(self, xml= None):
		'''load preferences object from XML or initialize default one'''
		if xml is None:
			self.defaultInit()
		else:
			self.fromXml(xml)
	
	
	
	
	
	def defaultInit(self):
		'''initialize default preferences object'''
		
		self.blender = Blender() # blender application path
		self.output = Output() # working directory path
		self.port = 55814 # socket port to communicate with blender thread
		self.archiveLimit = 1000 # max number of task to keep in archive list
		self.logLimit = 100 # max number of session log file to keep
	
	
	
	
	
	def fromXml(self, xml):
		'''Load preferences from xml'''
		
		self.blender = Blender( xml.find('blender') )
		self.output = Output( xml.find('output') )
		self.port = int(xml.get('port'))
		self.archiveLimit = int(xml.get('archive'))
		self.logLimit = int(xml.get('log'))
	
	
	
	
	
	def toXml(self):
		'''export to xml'''
		xml= '<?xml version="1.0" encoding="UTF-8"?>\n'
		
		#export limit and socket port settings
		xml+= '<preferences archive="'+str(self.archiveLimit)\
				+'" log="'+str(self.logLimit)+'" port="'+str(self.port)+'">\n'
		
		# export blender and output path
		xml+= self.blender.toXml() + self.output.toXml() +'</preferences>\n'
		
		return xml
	
	
	
	
	
	def menu(self, log, tasks):
		'''access function to set preferences'''
		log.menuIn('Preferences')
		change = False
		
		while True:
			log.print()
			self.print()
			
			choice = input('''\n    \033[4mPreferences Menu :\033[0m
1- Edit Blender Path
2- Edit Work Path
3- Edit Log Limit
4- Edit Archive Size Limit
5- Edit Socket Port
0- Save and quit

menu choice?''').strip().lower()
			
			#treat available actions
			if choice in ['0', 'q', 'quit', 'cancel']:# quit preferences menu
				log.menuOut()
				return
				
			elif choice == '1':# edit blender application path
				change = self.blender.menu(log)
				
			elif choice == '2':# edit working directory path
				change = self.output.menu(log)
				
			elif choice in ['3', '4']:# edit log or archive limit
				change = self.editLimit(log, choice == '3' )
				
			elif choice == '5':# edit socket port for blender thread communication
				change = self.editPort(log)
				
			else:# bad choice
				log.error('Unknow request!', False)
			
			if change:# save when preferences have been changed
				change = False
				savePreferences(self)
				log.write('New preferences saved')
	
	
	
	
	
	def print(self):
		'''display preference settings'''
		print('Blender Path : '+self.blender.path,\
				'Work Path : '+self.output.path,\
{'fraction_non_alphanumeric': 0.13652053848809112, 'fraction_numerical': 0.013462202278218847, 'mean_word_length': 3.2767527675276753, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 2, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 35}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '892385', 'n_tokens_mistral': 2170, 'n_tokens_neox': 1751, 'n_words': 571}