#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import getopt
from optparse import OptionParser
import logging
import backup
import configparser

logging.basicConfig(format=u'[%(asctime)s] %(levelname)-8s  %(message)s', level=logging.DEBUG, filename="/var/log/backup.log")

parser = OptionParser()
parser.add_option("-c", "--config", dest="config_filename", default="config.ini", help="read from FILE", metavar="CONFIG")
parser.add_option("-l", "--log", dest="log_filename", default="backup.log", help="write report to FILE", metavar="FILE")
parser.add_option("-q", "--quiet", action="store_false", dest="verbose", default=True, help="don't print status messages to stdout")

(options, args) = parser.parse_args()

config = configparser.ConfigParser()

# read config file
config.read(options.config_filename)

# print config.sections()
# print config['DEFAULT']['StorageLocal']
# print config.sections()

# TODO: check exists need folders
logging.info("check system")

if "StorageLocal" in config['DEFAULT']:
	logging.info("check exists StorageLocal: %s [OK]" % config['DEFAULT']['StorageLocal'])
else:
	logging.error("check exists StorageLocal: ... [FAIL]")
	logging.info("update %s: add StorageLocal parameter to DEFAULT section" % options.config_filename)
	sys.exit()

if "Compression" in config['DEFAULT']:
	logging.info("check exists Compression: %s [OK]" % config['DEFAULT']['Compression'])
else:
	logging.error("check exists Compression: ... [FAIL]")
	logging.info("update %s: add Compression parameter to DEFAULT section" % options.config_filename)
	sys.exit()

if "CompressionLevel" in config['DEFAULT']:
	logging.info("check exists CompressionLevel: %s" % config['DEFAULT']['StorageLocal'])
else:
	logging.error("check exists CompressionLevel: ... [FAIL]")
	logging.info("update %s: add CompressionLevel parameter to DEFAULT section" % options.config_filename)
	sys.exit()

print len(config)

for x in config:
	print x
# 	if x == "DEFAULT":
# 		continue
#
# 	if not "Enabled" in config[x]:
# 		continue
#
# 	(datatype, jobname) = x.split(":")
#
# 	if datatype == "File":
# 		print "Backup files. Job: %s" % jobname
#  		# print x.split(":")[1]
#  		# print config[x]['Directory']
#
#  		do = backup.File(config[x]['Directory'], "%s/%s" % (config['DEFAULT']['StorageLocal'], jobname))
#
# 	# if datatype == "Database":
# 		# print "Backup database. Job: %s" % jobname
#
#
# # if __name__ == '__main__':
#     # backup.backup().main()

@@ -163,136 +163,8 @@
 er%0A%0A
-logging.basicConfig(format=u'%5B%25(asctime)s%5D %25(levelname)-8s  %25(message)s', level=logging.DEBUG, filename=%22/var/log/backup.log%22)%0A%0A
 pars
@@ -695,16 +695,143 @@
 ename)%0A%0A
+logging.basicConfig(format=u'%5B%25(asctime)s%5D %25(levelname)-8s  %25(message)s', level=logging.DEBUG, filename=options.log_filename)%0A%0A
 # print 
@@ -1670,24 +1670,29 @@
 ionLevel: %25s
+ %5BOK%5D
 %22 %25 config%5B'
@@ -1698,35 +1698,39 @@
 'DEFAULT'%5D%5B'
-StorageLoca
+CompressionLeve
 l'%5D)%0Aelse:%0A%09
@@ -1909,55 +1909,277 @@
 ()%0A%0A
-print len(config)%0A%0Afor x in config:%0A%09print x%0A# 
+if not os.path.isdir(config%5B'DEFAULT'%5D%5B'StorageLocal'%5D):%0A%09logging.error(%22check exists local storage folder: %25s %5BFAIL%5D%22 %25 config%5B'DEFAULT'%5D%5B'StorageLocal'%5D)%0A%09sys.exit()%0A%0A# if (len(config) - 1) %3C= 0:%0A%09# logging.error(%22no task to bakcup%22)%0A%09# sys.exit();%0A%0Afor x in config:%0A
 %09if 
@@ -2194,18 +2194,16 @@
 FAULT%22:%0A
-# 
 %09%09contin
@@ -2205,20 +2205,17 @@
 ontinue%0A
-#%0A# 
+%0A
 %09if not 
@@ -2238,18 +2238,16 @@
 fig%5Bx%5D:%0A
-# 
 %09%09contin
@@ -2249,20 +2249,17 @@
 ontinue%0A
-#%0A# 
+%0A
 %09(dataty
@@ -2286,20 +2286,17 @@
 it(%22:%22)%0A
-#%0A# 
+%0A
 %09if data
@@ -2311,18 +2311,16 @@
 %22File%22:%0A
-# 
 %09%09print 
@@ -2528,13 +2528,9 @@
 )%0A#%0A
-# %09# 
+%09
 if d
@@ -2556,14 +2556,10 @@
 e%22:%0A
-# %09%09# 
+%09%09
 prin

update readme file