Skip to content

Commit

Permalink
Merge pull request #18 from dmuhs/feature/logging
Browse files Browse the repository at this point in the history
Replace print statements with logging calls
  • Loading branch information
iamdefinitelyahuman authored Sep 5, 2019
2 parents dc63f47 + 52f12ea commit a21fdb7
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions solcx/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import sys
import tarfile
import zipfile
import logging

from .exceptions import SolcNotInstalled

Expand All @@ -26,6 +27,7 @@
'linux': "solc-static-linux",
'win32': "solidity-windows.zip"
}
LOGGER = logging.getLogger("solcx")

solc_version = None

Expand Down Expand Up @@ -107,7 +109,7 @@ def set_solc_version(version, silent=False):
global solc_version
solc_version = version
if not silent:
print("Using solc version {}".format(solc_version))
LOGGER.info("Using solc version {}".format(solc_version))


def set_solc_version_pragma(pragma_string, silent=False, check_new=False):
Expand All @@ -123,11 +125,11 @@ def set_solc_version_pragma(pragma_string, silent=False, check_new=False):
global solc_version
solc_version = version
if not silent:
print("Using solc version {}".format(solc_version))
LOGGER.info("Using solc version {}".format(solc_version))
if check_new:
latest = install_solc_pragma(pragma_string, False)
if Version(latest) > Version(version):
print("Newer compatible solc version exists: {}".format(latest))
LOGGER.info("Newer compatible solc version exists: {}".format(latest))


def install_solc_pragma(pragma_string, install=True):
Expand Down Expand Up @@ -205,7 +207,7 @@ def install_solc(version, allow_osx=False):
)
if not solc_version:
set_solc_version(version)
print("solc {} successfully installed at: {}".format(version, binary_path))
LOGGER.info("solc {} successfully installed at: {}".format(version, binary_path))


def _check_version(version):
Expand All @@ -215,10 +217,10 @@ def _check_version(version):
return "v" + str(version)


def _check_subprocess_call(command, message=None, verbose=True, **proc_kwargs):
def _check_subprocess_call(command, message=None, verbose=False, **proc_kwargs):
if message:
print(message)
print("Executing: {0}".format(" ".join(command)))
LOGGER.debug(message)
LOGGER.info("Executing: {0}".format(" ".join(command)))

return subprocess.check_call(
command,
Expand Down Expand Up @@ -246,7 +248,7 @@ def _wget(url, path):
def _check_for_installed_version(version):
path = get_solc_folder().joinpath("solc-" + version)
if path.exists():
print("solc {} already installed at: {}".format(version, path))
LOGGER.info("solc {} already installed at: {}".format(version, path))
return False
return path

Expand Down Expand Up @@ -274,7 +276,7 @@ def _install_solc_windows(version):
install_folder = _check_for_installed_version(version)
if install_folder:
temp_path = _get_temp_folder()
print("Downloading solc {} from {}".format(version, download))
LOGGER.info("Downloading solc {} from {}".format(version, download))
request = requests.get(download)
with zipfile.ZipFile(BytesIO(request.content)) as zf:
zf.extractall(str(temp_path))
Expand Down Expand Up @@ -331,7 +333,7 @@ def _install_solc_osx(version, allow):
try:
version = sys.argv[1]
except IndexError:
print("Invocation error. Should be invoked as `./install_solc.py <release-tag>`")
LOGGER.error("Invocation error. Should be invoked as `./install_solc.py <release-tag>`")
sys.exit(1)

install_solc(version)

0 comments on commit a21fdb7

Please sign in to comment.