<commit_before>#!/usr/bin/python3.4
# -*-coding:Utf-8 -*
'''module to manage metapreset'''
import xml.etree.ElementTree as xmlMod
from usefullFunctions import *
import os

class Metapreset:
	'''class to manage metapreset'''
	
	def __init__(self, xml= None):
		'''initialize metapreset with default value or values extracted from an xml object'''
		if xml is None:
			self.defaultInit()
		else:
			self.fromXml(xml)
	
	
	
	
	
	def defaultInit(self):
		'''initialize metapreset with default value'''
		self.default = None
		self.groups = {}
	
	
	
	
	
	def fromXml(self, xml):
		'''initialize metapreset with values extracted from an xml object'''
		self.default = xml.get('default')
		
		self.groups = {}
		for node in xml.findall('group'):
			self.groups[node.get('name')] = node.get('preset')
		
	
	
	
	
	
	def toXml(self, alias):
		'''export metapreset into xml syntaxed string'''
		if self.default is None:
			txt = '<metapreset alias="'+alias+'" >\n'
		else:
			txt = '<metapreset alias="'+alias+'" default="'+self.default+'" >\n'
		
		for group, preset in self.groups.items():
			print('  <group name="'+group+'" preset="'+preset+'" />')
		
		txt += '</metapreset>\n'
		return txt
	
	
	
	
	
	def see(self, log, alias, presets):
		'''menu to explore and edit metapreset settings'''
		change = False
		log.menuIn(alias+' Metapreset')
		
		while True:
			log.print()
			
			print('\n\n        «'+alias+'» Metapreset')
			
			self.print()
			
			print('''\n\n        Menu :
1- Add Group
2- Edit Group
3- Remove Group
4- Set Default Preset
0- Save and quit

''')
			
			choice = input('Action?').strip().lower()
			
			if choice in ['0', 'q', 'quit', 'cancel']:
				log.menuOut()
				return change
			elif choice == '1':
				change = (self.add(log, alias, groups, presets) or change)
			elif choice == '2':
				change = (self.edit(log, alias, presets) or change)
			elif choice == '3':
				change = (self.remove(log, alias) or change)
			elif choice == '4':
				change = (self.setDefault(log, alias, presets) or change)
			else:
				log.error('Unvalid menu choice', False)
		
	
	
	
	
	
	def print(self):
		'''a method to print Metapreset'''
		if self.default is None:
			print('Default Preset : \033[31mnot set!\033[0m')
		else:
			print('Default Preset : '+self.default)
		print()
		
		for group, preset in self.groups.items():
			print(columnLimit(group, 25, sep = ''),' : ',columnLimit(preset, 25, sep = ''))
	
	
	
	
	
	def copy(self):
		'''A method to get a copy of current object'''
		xml = '<?xml version="1.0" encoding="UTF-8"?>\n'<commit_msg>implement a method to list all the group of a metapreset<commit_after>#!/usr/bin/python3.4
# -*-coding:Utf-8 -*
'''module to manage metapreset'''
import xml.etree.ElementTree as xmlMod
from usefullFunctions import *
import os

class Metapreset:
	'''class to manage metapreset'''
	
	def __init__(self, xml= None):
		'''initialize metapreset with default value or values extracted from an xml object'''
		if xml is None:
			self.defaultInit()
		else:
			self.fromXml(xml)
	
	
	
	
	
	def defaultInit(self):
		'''initialize metapreset with default value'''
		self.default = None
		self.groups = {}
	
	
	
	
	
	def fromXml(self, xml):
		'''initialize metapreset with values extracted from an xml object'''
		self.default = xml.get('default')
		
		self.groups = {}
		for node in xml.findall('group'):
			self.groups[node.get('name')] = node.get('preset')
		
	
	
	
	
	
	def toXml(self, alias):
		'''export metapreset into xml syntaxed string'''
		if self.default is None:
			txt = '<metapreset alias="'+alias+'" >\n'
		else:
			txt = '<metapreset alias="'+alias+'" default="'+self.default+'" >\n'
		
		for group, preset in self.groups.items():
			print('  <group name="'+group+'" preset="'+preset+'" />')
		
		txt += '</metapreset>\n'
		return txt
	
	
	
	
	
	def see(self, log, alias, presets):
		'''menu to explore and edit metapreset settings'''
		change = False
		log.menuIn(alias+' Metapreset')
		
		while True:
			log.print()
			
			print('\n\n        «'+alias+'» Metapreset')
			
			self.print()
			
			print('''\n\n        Menu :
1- Add Group
2- Edit Group
3- Remove Group
4- Set Default Preset
0- Save and quit

''')
			
			choice = input('Action?').strip().lower()
			
			if choice in ['0', 'q', 'quit', 'cancel']:
				log.menuOut()
				return change
			elif choice == '1':
				change = (self.add(log, alias, groups, presets) or change)
			elif choice == '2':
				change = (self.edit(log, alias, presets) or change)
			elif choice == '3':
				change = (self.remove(log, alias) or change)
			elif choice == '4':
				change = (self.setDefault(log, alias, presets) or change)
			else:
				log.error('Unvalid menu choice', False)
	
	
	
	
	
	def list(self, index = False):
		'''a method to list all the group of the metapreset'''
		keys = list(self.groups.keys())
		keys.sort(key = str.lower)
		
		if index:
			for i,k in enumerate(keys):
				print(str(i)+'- '+k)
		else:
			for k in keys:
				print(k)
		
		return keys
	
	
	
	
	
	def print(self):
		'''a method to print Metapreset'''
		if self.default is None:
			print('Default Preset : \033[31mnot set!\033[0m')
		else:
			print('Default Preset : '+self.default)
		print()
		
		for group, preset in self.groups.items():
			print(columnLimit(group, 25, sep = ''),' : ',columnLimit(preset, 25, sep = ''))
	
	
	
	
	
	def copy(self):
		'''A method to get a copy of current object'''
		xml = '<?xml version="1.0" encoding="UTF-8"?>\n'
{'fraction_non_alphanumeric': 0.16049382716049382, 'fraction_numerical': 0.010687304219642528, 'mean_word_length': 3.109008327024981, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 2, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 26}, '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': '6529328', 'n_tokens_mistral': 2195, 'n_tokens_neox': 1809, 'n_words': 551}