#!/usr/bin/python3.4
# -*-coding:Utf-8 -*
'''module to manage list of all know version of Blender in the system'''
import xml.etree.ElementTree as xmlMod
import os

class VersionList:
	'''class dedicated to Blender version managing'''
	
	
	def __init__(self, xml= None):
		'''initialize Blender version list with default value or values extracted from an xml object'''
		if xml is None:
			self.defaultInit()
		else:
			self.fromXml(xml)
	
	
	
	
	
	def defaultInit(self):
		'''initialize Blender version list with default value'''
		
		self.list = {'Standard Blender':'blender'}
		
	
	
	
	
	
	def fromXml(self, xml):
		'''initialize Blender version list with values extracted from an xml object'''
		self.list = {}
		for version in xml.findall('version'):
			self.list[version.get('alias')] = version.get('path')
	
	
	
	
	
	def toXml(self):
		'''export Blender version list into xml syntaxed string'''
		
		xml = '  <versionsList>\n'
		for k, v in self.list.items():
			xml += '    <version alias="'+k+'" path="'+v+'" />'
		xml = '  </versionsList>\n'
		
		return xml
	
	
	
	
	
	def see(self, log):
		'''method to see Blender version list and access edition menu'''
		change = False
		log.menuIn('Blender Version List')
		
		while True:
			#print log and preferences
			os.system('clear')
			log.print()
			
			self.print()
			
			print('''\n    \033[4mMenu :\033[0m
1- Add version
0- Quit

''')
			
			
		
			#treat available actions
			choice= input('menu?').strip().lower()
			if choice in ['0', 'q', 'quit', 'cancel']:
				log.menuOut()# quit preferences menu
				return change
			else:
				log.write('\033[31munknow request\033[0m\n')
	
	
	
	
	
	def print(self, index = False, std = True):
		'''a method to display the Blender version list'''
		print('\n            \033[4mBlender Version List :\033[0m\n')
		
		keys = list(self.list.keys())
		keys.sort()
		
		if not std:
			# don't display Standard Blender version if std is False
			keys.remove('Standard Blender')
		
		if index:
			for i, k in enumerate(keys):
				print(str(i)+'- '+k+' :\n    '+self.list[k]+'\n')
		else:
			for k in keys:
				print(k+' :\n    '+self.list[k]+'\n')
	
	
	
	
	
	
	
	
	
	

@@ -1234,16 +1234,17 @@
 ue:%0A%09%09%09#
+ 
 print lo
@@ -1249,27 +1249,37 @@
 log and 
-preferences
+Blender versions list
 %0A%09%09%09os.s
@@ -1586,16 +1586,78 @@
  change%0A
+%09%09%09elif choice == '1':%0A%09%09%09%09change = (self.add(log) or change)%0A
 %09%09%09else:
@@ -2208,28 +2208,570 @@
 %5D+'%5Cn')%0A%09%0A%09%0A%09%0A%09%0A
-
 %09%0A
+%09def add(self, log):%0A%09%09'''a method to add a Blender version to the list'''%0A%09%09confirm = False%0A%09%09log.menuIn('Add A Version')%0A%09%09%0A%09%09while True:%0A%09%09%09# print log %0A%09%09%09os.system('clear')%0A%09%09%09log.print()%0A%09%09%09%0A%09%09%09# get new version path%0A%09%09%09choice= input('path of the version?').strip().lower()%0A%09%09%09%0A%09%09%09if choice == '':%0A%09%09%09%09log.menuOut()# quit preferences menu%0A%09%09%09%09return confirm%0A%09%09%09%0A%09%09%09# check version path%0A%09%09%09# get blender version from blender path%0A%09%09%09# get user alias confirmation%0A%09%09%09# add version%0A%09%09%09%0A%09%09%09log.write('%5C033%5B31mnot yet implemented%5C033%5B0m%5Cn')%0A
 %09%0A%09%0A%09%0A%09%0A%09%0A

implement VersionList.add() method to add version to the blender versions list : define global structure of the method