Exemplo n.º 1
0
    def run(self, project_name, config_template):
        workdir = os.getcwd()

        if os.getuid() == 0:
            raise FatalError('Do not initialize a configuration as root!')

        if not os.access(workdir, os.W_OK):
            raise FatalError('''No write access to '{}'.'''.format(workdir))

        if os.listdir(workdir):
            raise FatalError(
                'Please initialize your new configuration within an empty folder!'
            )

        source = get_project_tree()
        copy_tree(source, workdir)
        template = ConfigurationTemplate(workdir)
        with open(get_template(config_template), encoding="UTF-8",
                  mode="r") as template_file:
            t = Template(template_file.read())
            template_dict = yaml.load(t.render(get_base_dictionary())).get(
                'parameters', {})

        template_dict['edi_project_name'] = project_name
        template_dict["edi_edi_version"] = get_stripped_version(
            get_edi_version())
        template.render(template_dict)

        print_success(
            '''Configuration for project '{}' generated in folder '{}'.'''.
            format(project_name, workdir))
Exemplo n.º 2
0
def get_base_dictionary():
    base_dict = {}
    current_user_name = get_user()
    base_dict["edi_current_user_name"] = current_user_name
    base_dict["edi_current_user_group_name"] = get_user_group()
    base_dict["edi_current_user_ssh_pub_keys"] = get_user_ssh_pub_keys()
    base_dict["edi_current_user_uid"] = get_user_uid()
    base_dict["edi_current_user_gid"] = get_user_gid()
    base_dict[
        "edi_current_user_host_home_directory"] = get_user_home_directory(
            current_user_name)
    base_dict["edi_current_user_target_home_directory"] = "/home/{}".format(
        current_user_name)
    base_dict["edi_host_hostname"] = get_hostname()
    base_dict["edi_edi_plugin_directory"] = get_edi_plugin_directory()
    proxy_setup = ProxySetup()
    base_dict["edi_host_http_proxy"] = proxy_setup.get('http_proxy',
                                                       default='')
    base_dict["edi_host_https_proxy"] = proxy_setup.get('https_proxy',
                                                        default='')
    base_dict["edi_host_ftp_proxy"] = proxy_setup.get('ftp_proxy', default='')
    base_dict["edi_host_socks_proxy"] = proxy_setup.get('all_proxy',
                                                        default='')
    base_dict["edi_host_no_proxy"] = proxy_setup.get('no_proxy', default='')
    base_dict["edi_edi_version"] = get_edi_version()
    base_dict["edi_lxd_version"] = get_lxd_version()
    base_dict["edi_current_display"] = get_current_display()
    return base_dict
Exemplo n.º 3
0
 def _verify_version_compatibility(self):
     current_version = get_edi_version()
     required_version = str(self._get_general_item('edi_required_minimal_edi_version', current_version))
     if Version(get_stripped_version(current_version)) < Version(get_stripped_version(required_version)):
         raise FatalError(('The current configuration requires a newer version of edi (>={}).\n'
                           'Please update your edi installation!'
                           ).format(get_stripped_version(required_version)))
Exemplo n.º 4
0
 def run():
     return get_edi_version()