Last active
September 21, 2015 14:56
-
-
Save Bystroushaak/d702526390483339cd5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
# Interpreter version: python 2.7 | |
# | |
# Imports ===================================================================== | |
import os | |
import sys | |
import shutil | |
import os.path | |
import argparse | |
from virtualenvapi.manage import VirtualEnvironment | |
# Variables =================================================================== | |
DEFAULT_ENV_NAME = "./xex" | |
# Functions & classes ========================================================= | |
def install_package(pkg_name, keep, env_name): | |
env = VirtualEnvironment(os.path.abspath(env_name), cache="") | |
env.install(pkg_name) | |
installed = env.is_installed(pkg_name) | |
if installed: | |
print "Installation successful." | |
else: | |
print "FAIL!" | |
if not keep: | |
shutil.rmtree(env_name) | |
return installed | |
# Main program ================================================================ | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser( | |
description="Test installation of the package from PYPI." | |
) | |
parser.add_argument( | |
"-p", | |
"--package", | |
required=True, | |
help="Name of the PIP package which will be installed." | |
) | |
parser.add_argument( | |
"-k", | |
"--keep", | |
action="store_true", | |
help="Don't remove virtualenv's directory." | |
) | |
parser.add_argument( | |
"-e", | |
"--env-name", | |
default=DEFAULT_ENV_NAME, | |
help="Name of the environment. Default %s." % DEFAULT_ENV_NAME | |
) | |
args = parser.parse_args() | |
result = install_package( | |
pkg_name=args.package, | |
keep=args.keep, | |
env_name=args.env_name | |
) | |
sys.exit(not result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment