Guest User

Untitled

a guest
Sep 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. class VirtualEnvironment(object):
  2. def __init__(self, path):
  3. super(VirtualEnvironment, self).__init__()
  4.  
  5. self.path = path
  6.  
  7. @classmethod
  8. def command_method(cls, environment_path):
  9. """"""
  10. environment_scripts_path = os.path.join(environment_path, "Scripts")
  11. environment_activate_batch = os.path.join(environment_scripts_path, "activate.bat")
  12. environment_deactivate_batch = os.path.join(environment_scripts_path, "deactivate.bat")
  13.  
  14. def deco(func):
  15. def wrapper(*args, **kwargs):
  16. if os.path.exists(environment_activate_batch):
  17.  
  18. command_string = environment_activate_batch
  19. command_string += " && {} ".format(func())
  20. command_string += " && {} ".format(environment_deactivate_batch)
  21.  
  22. process = subprocess.Popen(command_string, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
  23.  
  24. cache = list()
  25. while True:
  26. # pkg_info = dict()
  27. output = process.stdout.readline()
  28. if output == '' and process.poll() is not None:
  29. break
  30. if output:
  31. output_ = output.strip()
  32. print output
  33.  
  34. return cache
  35. return wrapper
  36. return deco
  37.  
  38. def run_command(self, command):
  39. @VirtualEnvironment.command_method(self.path)
  40. def runner():
  41. return command
  42.  
  43. runner()
  44.  
  45.  
  46. venv = VirtualEnvironment("E:\\my_venv_path")
  47. venv.run_command("pip list --format json")
Add Comment
Please, Sign In to add comment