Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class VirtualEnvironment(object):
- def __init__(self, path):
- super(VirtualEnvironment, self).__init__()
- self.path = path
- @classmethod
- def command_method(cls, environment_path):
- """"""
- environment_scripts_path = os.path.join(environment_path, "Scripts")
- environment_activate_batch = os.path.join(environment_scripts_path, "activate.bat")
- environment_deactivate_batch = os.path.join(environment_scripts_path, "deactivate.bat")
- def deco(func):
- def wrapper(*args, **kwargs):
- if os.path.exists(environment_activate_batch):
- command_string = environment_activate_batch
- command_string += " && {} ".format(func())
- command_string += " && {} ".format(environment_deactivate_batch)
- process = subprocess.Popen(command_string, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
- cache = list()
- while True:
- # pkg_info = dict()
- output = process.stdout.readline()
- if output == '' and process.poll() is not None:
- break
- if output:
- output_ = output.strip()
- print output
- return cache
- return wrapper
- return deco
- def run_command(self, command):
- @VirtualEnvironment.command_method(self.path)
- def runner():
- return command
- runner()
- venv = VirtualEnvironment("E:\\my_venv_path")
- venv.run_command("pip list --format json")
Add Comment
Please, Sign In to add comment