Remove function parameters, remove class variables, move todos

This commit is contained in:
Marcel Schwarz 2019-12-28 06:13:25 +01:00
parent ad900097dc
commit f92cb202b3

View File

@ -19,17 +19,16 @@ class VimModule(AbstractModule):
with open("modules/vim/vimrc_conf.json") as plugins: with open("modules/vim/vimrc_conf.json") as plugins:
self.json_config = json.load(plugins) self.json_config = json.load(plugins)
self.plugins = self.json_config['plugins']
self.settings = self.json_config['settings']
def create_folder_structure(self): def create_folder_structure(self):
# Create necessary folder structure for vim # Create necessary folder structure for vim
os.makedirs(str(get_vim_root().joinpath("autoload")), exist_ok=True) os.makedirs(str(get_vim_root().joinpath("autoload")), exist_ok=True)
os.makedirs(str(get_vim_root().joinpath("plugged")), exist_ok=True) os.makedirs(str(get_vim_root().joinpath("plugged")), exist_ok=True)
def create_plugin_section(self, vimrc_content): def create_plugin_section(self):
vimrc_content = []
mapped_list = [] mapped_list = []
for choice in self.plugins.keys(): plugins = self.json_config['plugins']
for choice in plugins.keys():
mapped_list.append({ mapped_list.append({
"name": choice "name": choice
}) })
@ -49,22 +48,29 @@ class VimModule(AbstractModule):
try: try:
index = vimrc_content.index("call plug#begin('~/.vim/plugged')\n") + 1 index = vimrc_content.index("call plug#begin('~/.vim/plugged')\n") + 1
for plugin in selected_plugins: for plugin in selected_plugins:
vimrc_content.insert(index, self.plugins[plugin] + "\n") vimrc_content.insert(index, plugins[plugin] + "\n")
except ValueError: except ValueError:
vimrc_content.append("call plug#begin('~/.vim/plugged')\n") vimrc_content.append("call plug#begin('~/.vim/plugged')\n")
for element in selected_plugins: for element in selected_plugins:
vimrc_content.append(self.plugins[element] + "\n") vimrc_content.append(plugins[element] + "\n")
vimrc_content.append("call plug#end()\n") vimrc_content.append("call plug#end()\n")
def create_setting_section(self, vimrc_content): # TODO: check if existing plugin manager file
default_settings = list(self.settings.values()) # TODO: else download plugin manager
return vimrc_content
def create_setting_section(self):
vimrc_content = []
settings = self.json_config['settings']
default_settings = list(settings.values())
print("\n\033[4mDefault settings:\033[0m") print("\n\033[4mDefault settings:\033[0m")
[print(i) for i in default_settings] [print(i) for i in default_settings]
default_settings.reverse() default_settings.reverse()
for setting in default_settings: for setting in default_settings:
vimrc_content.insert(0, setting + "\n") vimrc_content.insert(0, setting + "\n")
return vimrc_content
def get_vimfile_working_copy(self): def get_vimfile_working_copy(self):
vimrc_path = str(get_vim_root().joinpath(".vimrc")) vimrc_path = str(get_vim_root().joinpath(".vimrc"))
@ -89,10 +95,6 @@ class VimModule(AbstractModule):
def run(self): def run(self):
self.create_folder_structure() self.create_folder_structure()
vimrc_content = self.get_vimfile_working_copy() plugin_section = self.create_plugin_section()
self.create_plugin_section(vimrc_content) settings_section = self.create_setting_section()
self.create_setting_section(vimrc_content) self.write_vimfile(settings_section + plugin_section)
self.write_vimfile(vimrc_content)
# TODO: check if existing plugin manager file
# TODO: else download plugin manager