import os import subprocess # dir: string -> directory where installer exist # args: string -> which includes all parameters with space delimiter def spm_install(dir, args): import time c=os.environ['SYSTEMDRIVE'] fromURL='https://patchportal.one.comodo.com/portal/packages/spm/MobaXterm/x64/MobaXterm_installer.dat'## Here mention the download url kp=os.path.join(c,"\\Windows\\Temp") os.chdir(kp) destination_folder=kp if not os.path.exists(destination_folder): os.makedirs(destination_folder) import ctypes class disable_file_system_redirection: _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection def __enter__(self): self.old_value = ctypes.c_long() self.success = self._disable(ctypes.byref(self.old_value)) def __exit__(self, type, value, traceback): if self.success: self._revert(self.old_value) import subprocess with disable_file_system_redirection(): import urllib Down_path=os.environ['PROGRAMDATA'] fileName = fromURL.split('/')[-1] DownTo = os.path.join(Down_path, fileName) def downloadFile(DownTo, fromURL): try: with open(DownTo, 'wb') as f: f.write(urllib.urlopen(fromURL).read()) if os.path.isfile(DownTo): return '{} - {}KB'.format(DownTo, os.path.getsize(DownTo)/1000) except: return 'Please Check URL or Download Path!' if __name__=='__main__': print downloadFile(DownTo, fromURL ) import shutil try: shutil.copy2(DownTo, destination_folder) #print("%s is copied to %s"%(DownTo, destination_folder)) print "File copied successfully" print DownTo time.sleep(30) except Exception as err : print err os.chdir(dir) #os.remove(DownTo) argslist = args.split() try: subprocess.check_call(argslist) print 'retcode' + str(0) + 'retcode' except subprocess.CalledProcessError as e: print 'retcode' + str(e.returncode) + 'retcode' # dir: string -> directory where installer exist # args: string -> which includes all parameters with space delimiter def spm_uninstall(dir, args): os.chdir(dir) argslist = args.split() try: subprocess.check_call(argslist) print 'retcode' + str(0) + 'retcode' except subprocess.CalledProcessError as e: print 'retcode' + str(e.returncode) + 'retcode' # dir: string -> directory where installer exist # args: string -> which includes all parameters with space delimiter def spm_update(dir, args): import time c=os.environ['SYSTEMDRIVE'] fromURL='https://patchportal.one.comodo.com/portal/packages/spm/MobaXterm/x86/MobaXterm_installer.dat'## Here mention the download url if 'PROGRAMFILES(X86)' in os.environ.keys(): kp=os.path.join(c,"\\Program Files (x86)\\") os.chdir(kp) destination_folder=os.path.join(kp,"MobaTek\\MobaxTerm") if not os.path.exists(destination_folder): os.makedirs(destination_folder) else: kp=os.path.join(c,"\\Program Files\\") os.chdir(kp) destination_folder=os.path.join(kp,"MobaTek\\MobaxTerm") if not os.path.exists(destination_folder): os.makedirs(destination_folder) import ctypes class disable_file_system_redirection: _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection def __enter__(self): self.old_value = ctypes.c_long() self.success = self._disable(ctypes.byref(self.old_value)) def __exit__(self, type, value, traceback): if self.success: self._revert(self.old_value) import subprocess with disable_file_system_redirection(): import urllib Down_path=os.environ['PROGRAMDATA'] fileName = fromURL.split('/')[-1] DownTo = os.path.join(Down_path, fileName) def downloadFile(DownTo, fromURL): try: with open(DownTo, 'wb') as f: f.write(urllib.urlopen(fromURL).read()) if os.path.isfile(DownTo): return '{} - {}KB'.format(DownTo, os.path.getsize(DownTo)/1000) except: return 'Please Check URL or Download Path!' if __name__=='__main__': print downloadFile(DownTo, fromURL ) import shutil try: shutil.copy2(DownTo, destination_folder) #print("%s is copied to %s"%(DownTo, destination_folder)) print "File copied successfully" print DownTo time.sleep(30) except Exception as err : print err os.chdir(dir) #os.remove(DownTo) argslist = args.split() try: subprocess.check_call(argslist) print 'retcode' + str(0) + 'retcode' except subprocess.CalledProcessError as e: print 'retcode' + str(e.returncode) + 'retcode'