# Configuration module

#
## tmp note: you should add logger module and modify this module
#

from ConfigParser import SafeConfigParser
import os


program_name = "migmig"
# config file short path (hard coded !)
cfg_short_path = "~/." + program_name + ".ini"
server_address = "localhost"
server_port = "50001"


class Configuration():

	def __init__(self, logger):
		self.logger = logger
		self.parser = SafeConfigParser()
		self.cfg_path = self.validate_path(cfg_short_path)

		if not self.cfg_path:
			# create config file and initate configurations
			self.cfg_path = os.path.expanduser(cfg_short_path)
			self.initate()

		self.parser.read(self.cfg_path)


	def initate(self):
		# Sections
		self.parser.add_section("Setting")
		self.parser.add_section("Client")

		# Options
		self.parser.set("Setting", "default_download_path", os.path.expanduser("~/Downloads/" + program_name))
		self.parser.set("Setting", "default_merge_path", os.path.expanduser("~/Downloads/" + program_name + "/merged"))
		self.parser.set("Setting", "max_connections", "6")
		self.parser.set("Setting", "number_of_tries", "3")
		self.parser.set("Setting", "verbose_level", "1")

		self.parser.set('Setting', 'server_address', server_address)
		self.parser.set('Setting', 'server_port', server_port)

		# write settings to ini file
		with open(self.cfg_path, "wb") as tmp:
				self.parser.write(tmp)



	def get(self, value):
		'''
			This method only returns values from "Client" section.
		'''
		try:
			return self.parser.get('Client', value)
		except:
			return None

	def set(self, name, value):
		'''
			Like get method, this only works for "Client" section.
		'''
		try:
			self.parser.set('Client', name, value)
			return True
		except:
			# log !
			return None

	def get_server(self):
		addr = self.parser.get('Setting','server_address')
		port = self.parser.get('Setting','server_port')
		return addr + ':' + port


	def default_download_path(self, new_path):
		new_path = self.validate_path(new_path)
		if not new_path:
			self.parser.set("Setting", "default_download_path", new_path)

	
	def validate_path(self, path):
		'''
			Check whether path exists or not
		'''
		path = os.path.expanduser(path)
		if os.path.exists(path):
			return path
		return None

@@ -358,16 +358,97 @@
 ogger):%0A
+%09%09# constant variables%0A%09%09self.OK = 99%0A%09%09self.BAD_URL = 98%0A%09%09self.BLAHBLAH = 97%0A%0A%0A
 %09%09self.l
@@ -1358,103 +1358,193 @@
 %0A%0A%09%09
-# write settings to ini file%0A%09%09with open(self.cfg_path, %22wb%22) as tmp:%0A%09
+self.parser.set('Client', 'identifier', 'None')%0A%09%09self.parser.set('Client', 'URL', 'None')%0A%09%09self.parser.set('Client', 'client_id', 'None')%0A%0A%09%09# write settings to ini file%0A
 %09%09
-%09
 self.
-parser.
 write(
-tmp
 )%0A%0A%0A
@@ -1728,27 +1728,24 @@
 t(self, 
-name, value
+**kwargs
 ):%0A%09%09'''
@@ -1816,16 +1816,54 @@
 %0A%09%09try:%0A
+%09%09%09for key, value in kwargs.items():%0A%09
 %09%09%09self.
@@ -1887,20 +1887,19 @@
 t', 
-name
+key
 , value)
 %0A%09%09%09
@@ -1894,16 +1894,33 @@
 , value)
+%0A%0A%09%09%09self.write()
 %0A%09%09%09retu
@@ -1950,24 +1950,217 @@
 log 
-!%0A%09%09%09return None
+the python error. how?%0A%09%09%09return False%0A%0A%09def write(self):%0A%09%09'''%0A%09%09%09Write (synchronize) the parser object to .ini file !%0A%09%09'''%0A%09%09# TO-DO : ...%0A%09%09with open(self.cfg_path, %22wb%22) as tmp:%0A%09%09%09%09self.parser.write(tmp)
 %0A%0A%09d
@@ -2291,16 +2291,28 @@
 %09%09return
+ %22http://%22 +
  addr + 
@@ -2322,16 +2322,19 @@
  + port%0A
+%09%09%0A
 %0A%0A%09def d

Add constant variables. modify "write" method