# -*- coding: utf-8 -*-
from setuphelpers import *
import json
import platform
uninstallkey = []
# Defining variables
ext_name = 'ms-python-release.vsix'
app_from_path = 'code'
def install():
# Initializing variables
if get_os_name() == 'Windows':
app_dir = makepath(programfiles, 'Microsoft VS Code')
elif get_os_name() == 'Linux':
app_dir = '/usr/share/code/'
elif get_os_name() == 'Darwin':
app_dir = '/Applications/Visual Studio Code.app/'
ext_path = makepath(app_dir, ext_name)
# Copying extension to app_dir
print("Copying %s to %s" % (ext_name, app_dir))
filecopyto(ext_name, app_dir)
def session_setup():
# Initializing variables
if get_os_name() == 'Windows':
app_dir = makepath(programfiles, 'Microsoft VS Code')
elif get_os_name() == 'Linux':
app_dir = '/usr/share/code/'
elif get_os_name() == 'Darwin':
app_dir = '/Applications/Visual Studio Code.app/'
ext_path = makepath(app_dir, ext_name)
# Installing extension in user env
print("Installing %s extension in user env" % ext_name)
run_notfatal('%s --install-extension "%s"' % (app_from_path, ext_path))
def update_package():
# Initializing variables
proxies = get_proxies()
if not proxies:
proxies = get_proxies_from_wapt_console()
app_name = control.name
git_repo = 'microsoft/vscode-python'
url_api = 'https://api.github.com/repos/%s/releases/latest' % git_repo
# Getting latest version from official sources
print('API used is: %s' % url_api)
json_load = json.loads(wgets(url_api, proxies=proxies))
for download in json_load['assets']:
if download['name'] == ext_name:
url_dl = download['browser_download_url']
break
version = json_load['tag_name']
latest_bin = ext_name
print("Latest %s version is %s" % (app_name, version))
print("Download url is %s" % url_dl)
# Downloading latest binaries
print('Downloading %s' % latest_bin)
wget(url_dl, latest_bin, proxies=proxies)
# Changing version of the package
control.version = '%s-%s' % (version, control.version.split('-', 1)[-1])
control.save_control_to_wapt()
print("Changing package version to %s in WAPT\\control" % control.version)
def get_os_name():
return platform.system()
def get_proxies():
import platform
if platform.python_version_tuple()[0] == '3':
from urllib.request import getproxies
else:
from urllib import getproxies
return getproxies()
def get_proxies_from_wapt_console():
proxies = {}
if platform.system() == 'Windows':
waptconsole_ini_path = makepath(user_local_appdata(), 'waptconsole', 'waptconsole.ini')
else:
waptconsole_ini_path = makepath(user_home_directory(), '.config', 'waptconsole', 'waptconsole.ini')
if isfile(waptconsole_ini_path):
proxy_wapt = inifile_readstring(waptconsole_ini_path, 'global', 'http_proxy')
if proxy_wapt:
proxies = {'http': proxy_wapt, 'https': proxy_wapt}
return proxies