# Path: openedoo/core/libs/get_modul.py
# def create_requirement(name_module=None,version_module=None,url_endpoint=None,requirement=None,comment=None,url=None):
# 	if comment is None:
# 		comment = "my module name is {name}".format(name=name_module)
# 	if requirement is None:
# 		requirement = "openedoo_core"
# 	if name_module==None:
# 		return "please insert name module"
# 	if version_module is None:
# 		version_module = "0.1.0"
# 	if url_endpoint is None:
# 		url_endpoint = {'url_endpoint':''.format(url=name_module),'type':'function'}
# 	else:
# 		url_endpoint = {'url_endpoint':url_endpoint,'type':'end_point'}
# 	data_json = {"name":name_module,
# 	"version": version_module,
# 	"requirement":requirement,
# 	"pip_library":[],
# 	"comment":comment,
# 	"type":url_endpoint['type'],
# 	"url":url,
# 	"url_endpoint":url_endpoint['url_endpoint']}
# 	filename = 'requirement.json'
# 	with open('modules/{folder}/{filename}'.format(folder=name_module,filename=filename),'w') as data_file:
# 		json.dump(data_json, data_file)
# 	return "module has created"


from flask_script import Command, Option
from openedoo.core.libs.get_modul import create_requirement
import os
import re
import openedoo
import git
import time
import json

    def __init__(self):
        pass

    def get_module_name(self):
        return "modules"

    def get_base_path(self):
        BASE_DIR = os.path.dirname(os.path.realpath(__name__))
        BASE = os.path.join(BASE_DIR, get_root_project())
        return BASE

    def add_route(self, name):
        try:
            with open(os.path.join(self.get_base_path(), "route.py"), "a") as f:
                f.write("\n \nfrom modules.{module} import {module}".format(module=name))
                f.write("\napp.register_blueprint({modulename}, url_prefix='/{modulename}')".format(modulename=name))
                f.close()
                print("/route.py edited")
            time.sleep(0.2)
            create_requirement(name_module=name,url_endpoint="/{name}".format(name=name))
        except Exception as e:
            print e
            print "Error Writing route.py"

    def git_init(self, dir):
        git.Repo.init(dir)
        print "... Git init finished ..."

    def git_remote(self, dir, remote_git):

# Path: openedoo/core/libs/get_modul.py
# def create_requirement(name_module=None,version_module=None,url_endpoint=None,requirement=None,comment=None,url=None):
# 	if comment is None:
# 		comment = "my module name is {name}".format(name=name_module)
# 	if requirement is None:
# 		requirement = "openedoo_core"
# 	if name_module==None:
# 		return "please insert name module"
# 	if version_module is None:
# 		version_module = "0.1.0"
# 	if url_endpoint is None:
# 		url_endpoint = {'url_endpoint':''.format(url=name_module),'type':'function'}
# 	else:
# 		url_endpoint = {'url_endpoint':url_endpoint,'type':'end_point'}
# 	data_json = {"name":name_module,
# 	"version": version_module,
# 	"requirement":requirement,
# 	"pip_library":[],
# 	"comment":comment,
# 	"type":url_endpoint['type'],
# 	"url":url,
# 	"url_endpoint":url_endpoint['url_endpoint']}
# 	filename = 'requirement.json'
# 	with open('modules/{folder}/{filename}'.format(folder=name_module,filename=filename),'w') as data_file:
# 		json.dump(data_json, data_file)
# 	return "module has created"


# Path: openedoo/template_conf/project_template/project_name/management/commands/create_module_app.py
from flask_script import Command, Option
from openedoo.core.libs.get_modul import create_requirement
import os
import re
import openedoo
import git
import time
import json


    def __init__(self):
        pass

    def get_module_name(self):
        return "modules"

    def get_base_path(self):
        BASE_DIR = os.path.dirname(os.path.realpath(__name__))
        BASE = os.path.join(BASE_DIR, get_root_project())
        return BASE

    def add_route(self, name):
        try:
            with open(os.path.join(self.get_base_path(), "route.py"), "a") as f:
                f.write("\n \nfrom modules.{module} import {module}".format(module=name))
                f.write("\napp.register_blueprint({modulename}, url_prefix='/{modulename}')".format(modulename=name))
                f.close()
                print("/route.py edited")
            time.sleep(0.2)
            create_requirement(name_module=name,url_endpoint="/{name}".format(name=name))
        except Exception as e:
            print e
            print "Error Writing route.py"

    def git_init(self, dir):
        git.Repo.init(dir)
        print "... Git init finished ..."

    def git_remote(self, dir, remote_git):

        repo = git.Repo.init(dir)