def setupdomain(self, data):

    #for debug purpose
   # for key, value in data.items() :
   #     print (key, value)

    ee_domain_name = data['site_name']
    ee_site_webroot = data['webroot'] if 'webroot' in data.keys() else ''

    # Check if nginx configuration already exists
    # if os.path.isfile('/etc/nginx/sites-available/{0}'
    #                   .format(ee_domain_name)):
    #     raise SiteError("nginx configuration already exists for site")

    Log.info(self, "Setting up NGINX configuration \t", end='')
    # write nginx config for file
    try:
        ee_site_nginx_conf = open('/etc/nginx/sites-available/{0}'
                                  .format(ee_domain_name), encoding='utf-8',
                                  mode='w')
        if not data['php7']:
            self.app.render((data), 'virtualconf.mustache',
                          out=ee_site_nginx_conf)
        else:
            self.app.render((data), 'virtualconf-php7.mustache',
                          out=ee_site_nginx_conf)
        ee_site_nginx_conf.close()
    except __HOLE__ as e:
        Log.debug(self, "{0}".format(e))
        raise SiteError("create nginx configuration failed for site")
    except Exception as e:
        Log.debug(self, "{0}".format(e))
        raise SiteError("create nginx configuration failed for site")
    finally:
        # Check nginx -t and return status over it
        try:
            Log.debug(self, "Checking generated nginx conf, please wait...")
            FNULL = open('/dev/null', 'w')
            ret = subprocess.check_call(["nginx", "-t"], stdout=FNULL,
                                        stderr=subprocess.STDOUT)
            Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
        except CalledProcessError as e:
            Log.debug(self, "{0}".format(str(e)))
            Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail"
                     + Log.OKBLUE + "]")
            raise SiteError("created nginx configuration failed for site."
                            " check with `nginx -t`")


    # create symbolic link for
    EEFileUtils.create_symlink(self, ['/etc/nginx/sites-available/{0}'
                                      .format(ee_domain_name),
                                      '/etc/nginx/sites-enabled/{0}'
                                      .format(ee_domain_name)])

    if 'proxy' in data.keys() and data['proxy']:
        return

    # Creating htdocs & logs directory
    Log.info(self, "Setting up webroot \t\t", end='')
    try:
        if not os.path.exists('{0}/htdocs'.format(ee_site_webroot)):
            os.makedirs('{0}/htdocs'.format(ee_site_webroot))
        if not os.path.exists('{0}/logs'.format(ee_site_webroot)):
            os.makedirs('{0}/logs'.format(ee_site_webroot))
        if not os.path.exists('{0}/conf/nginx'.format(ee_site_webroot)):
            os.makedirs('{0}/conf/nginx'.format(ee_site_webroot))

        EEFileUtils.create_symlink(self, ['/var/log/nginx/{0}.access.log'
                                          .format(ee_domain_name),
                                          '{0}/logs/access.log'
                                          .format(ee_site_webroot)])
        EEFileUtils.create_symlink(self, ['/var/log/nginx/{0}.error.log'
                                          .format(ee_domain_name),
                                          '{0}/logs/error.log'
                                          .format(ee_site_webroot)])
    except Exception as e:
        Log.debug(self, "{0}".format(e))
        raise SiteError("setup webroot failed for site")
    finally:
        # TODO Check if directories are setup
        if (os.path.exists('{0}/htdocs'.format(ee_site_webroot)) and
           os.path.exists('{0}/logs'.format(ee_site_webroot))):
            Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
        else:
            Log.info(self, "[" + Log.ENDC + "Fail" + Log.OKBLUE + "]")
            raise SiteError("setup webroot failed for site")
dataset/ETHPy150Open EasyEngine/easyengine/ee/cli/plugins/site_functions.py/setupdomain