import os import subprocess import time def bitvise_exists(): paths = [ r"C:\Program Files\Bitvise SSH Client", r"C:\Program Files (x86)\Bitvise SSH Client" ] for p in paths: if os.path.exists(p): return True return False def spm_uninstall(dir, args): uninstallers = [ r"C:\Program Files\Bitvise SSH Client\uninst.exe", r"C:\Program Files (x86)\Bitvise SSH Client\uninst.exe" ] # If Bitvise is already not installed, report success immediately if not bitvise_exists(): print 'retcode' + str(0) + 'retcode' return found = False for uninst in uninstallers: if os.path.exists(uninst): found = True try: # Run uninstaller - ignore its exit code (it may return 1 even on success) subprocess.call('"%s" -unat "BvSshClient"' % uninst, shell=True) except Exception: pass break # Stop after first found uninstaller if not found: # No uninstaller found but folder exists — force remove print 'retcode' + str(1) + 'retcode' return # Wait for uninstall to fully complete time.sleep(15) # Verify removal by checking installation folder if not bitvise_exists(): print 'retcode' + str(0) + 'retcode' else: print 'retcode' + str(1) + 'retcode' def spm_install(dir, args): try: os.chdir(dir) subprocess.check_call(args.split()) print 'retcode' + str(0) + 'retcode' except subprocess.CalledProcessError as e: print 'retcode' + str(e.returncode) + 'retcode' def spm_update(dir, args): try: os.chdir(dir) subprocess.check_call(args.split()) print 'retcode' + str(0) + 'retcode' except subprocess.CalledProcessError as e: print 'retcode' + str(e.returncode) + 'retcode'