# -*- coding: utf-8 -*-
from setuphelpers import *
import json
import re
r"""
Usable WAPT package functions: install(), uninstall(), session_setup(), audit(), update_package()
Configuration procedure: https://supunkavinda.blog/vscode-editing-settings-json
File -> Preferences -> Settings -> Extensions -> Scroll down and find "Edit in settings.json"
Or in these paths in your OS :
Windows : %APPDATA%\Code\User\settings.json
macOS : $HOME/Library/Application Support/Code/User/settings.json
Linux : $HOME/.config/Code/User/settings.json
https://code.visualstudio.com/docs/editor/extension-marketplace#_workspace-recommended-extensions
"""
def install():
pass
def session_setup():
print("Applying: VSCode configuration")
# Initializing variables
if get_os_name() == "Windows":
user_conf_dir = makepath(user_appdata, "Code", "User")
elif get_os_name() == "Linux":
user_conf_dir = makepath(user_home_directory(), ".config", "Code", "User")
elif get_os_name() == "Darwin":
user_conf_dir = makepath(user_home_directory(), "Library", "Application Support", "Code", "User")
user_conf_file = makepath(user_conf_dir, "settings.json")
user_conf_content = r"""{
"update.mode": "none",
"update.enableWindowsBackgroundUpdates": false,
"update.showReleaseNotes": false,
"powershell.promptToUpdatePowerShell": false,
"extensions.autoCheckUpdates": false,
"extensions.autoUpdate": false,
"extensions.ignoreRecommendations": true,
"telemetry.telemetryLevel": "off",
"redhat.telemetry.enabled": false,
"npm.fetchOnlinePackageInfo": false,
"json.schemaDownload.enable": false,
"editor.wordWrap": "on",
"editor.minimap.enabled": false,
"workbench.activityBar.visible": true,
"workbench.startupEditor": "none",
"restructuredtext.preview.scrollEditorWithPreview": false,
"restructuredtext.preview.scrollPreviewWithEditor": false,
"markdown.preview.scrollEditorWithPreview": false,
"markdown.preview.scrollPreviewWithEditor": false,
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
"150"
],
"python.languageServer": "Jedi",
"git.openRepositoryInParentFolders": "always",
"git.autofetch": true,
"files.associations": {
"control": "yaml"
}
}"""
user_conf_data = load_dirty_json(user_conf_content)
if not isdir(user_conf_dir):
mkdirs(user_conf_dir)
if not isfile(user_conf_file):
print("Creating: %s" % user_conf_file)
json_write_file(user_conf_file, user_conf_data)
else:
new_user_conf_data = load_dirty_json(str(json_load_file(user_conf_file)))
new_user_conf_data.update(user_conf_data)
print("Updating: %s" % user_conf_file)
json_write_file(user_conf_file, new_user_conf_data)
def load_dirty_json(dirty_json):
regex_replace = [(r"([ \{,:\[])(u)?'([^']+)'", r'\1"\3"'), (r" False([, \}\]])", r" false\1"), (r" True([, \}\]])", r" true\1")]
for r, s in regex_replace:
dirty_json = re.sub(r, s, dirty_json)
clean_json = json.loads(dirty_json)
return clean_json