def unmount_unix(self, mount_point): if os.path.exists(mount_point): p = Subprocess('umount %s' % mount_point) out, err = p.communicate() if p.returncode: logger.debug('"umount %s" output: %s %s' % (mount_point, out, err))
def cmd_call(cmd, err_msg=''): p = Subprocess(cmd) cout, cerr = p.communicate() if p.returncode != 0: cerr = ' '.join([cout, cerr]) raise Exception('%s "%s" failed with message "%s"'%(err_msg, cmd, cerr)) return cout
def update_linux_mountpoint(self, url): p = Subprocess('df') out, err = p.communicate() for line in out.splitlines(): if url in line: self.__mountpoint = line.split()[-1] return
def isMgmtServerStarted(cls): proc = Subprocess(MGMT_CLI_RUNCMD+' status', env=ENV) cout, cerr = proc.communicate() print (cout) if proc.returncode: return False return True
def unmount_media_device(cls, device, force=False): logic_drives = [] #found logical drives on device import win32com.client import pythoncom import win32file import win32con import win32api pythoncom.CoInitialize() strComputer = "." objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator") objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2") logger.debug('unmounting %s ... %s'%(device, type(device))) device_id = device.replace('\\', '\\\\') partitions= objSWbemServices.ExecQuery('ASSOCIATORS OF {Win32_DiskDrive.DeviceID="%s"} \ WHERE AssocClass = Win32_DiskDriveToDiskPartition'%device_id) for part in partitions: logical_disks = objSWbemServices.ExecQuery('ASSOCIATORS OF \ {Win32_DiskPartition.DeviceID="%s"} \ WHERE AssocClass = Win32_LogicalDiskToPartition'%part.DeviceID) for logic in logical_disks: logic_drives.append(logic.DeviceID) #unmounting all logical drives FSCTL_DISMOUNT_VOLUME = 0x00090020 for vol in logic_drives: if force: p = Subprocess('mountvol %s /d'%vol) out, err = p.communicate() if p.returncode: logger.warning('"mountvol %s /d" failed with message: %s %s'%(vol, out, err)) continue try: hh = win32file.CreateFile('\\\\.\\%s'%str(vol), win32con.GENERIC_READ, win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE, None, win32file.OPEN_EXISTING, win32file.FILE_ATTRIBUTE_NORMAL, None) except Exception, err: raise Exception('Volume %s does not opened: %s'%(vol, err)) try: ret = win32file.DeviceIoControl(hh, FSCTL_DISMOUNT_VOLUME, None, None) if ret: raise Exception('Volume %s does not unmounted! Error code: %s'%(str(vol), win32api.GetLastError())) finally: win32file.CloseHandle(hh)
def mount_linux(self, bind_host, bind_port): mount_point = '/media/iDepositBox' if os.path.exists(mount_point): self.unmount_unix(mount_point) else: os.makedirs(mount_point) p = Subprocess('mount -t davfs -o rw,user,dir_mode=0777 http://%s:%s/ %s'\ % (bind_host, bind_port, mount_point), with_input=True) out, err = p.communicate('anonymous\nanonymous') if p.returncode: sys.stderr.write('%s\n'%err) return p.returncode
def mount_linux(self, bind_host, bind_port): mount_point = '/media/iDepositBox' if os.path.exists(mount_point): self.unmount_unix(mount_point) else: os.makedirs(mount_point) p = Subprocess('mount -t davfs -o rw,user,dir_mode=0777 http://%s:%s/ %s'\ % (bind_host, bind_port, mount_point), with_input=True) out, err = p.communicate('anonymous\nanonymous') if p.returncode: sys.stderr.write('%s\n' % err) return p.returncode
def onClose(self): if not self.show_question('Exit?', 'Are you sure that you want to exit?!', self): return try: proc = Subprocess(MGMT_CLI_RUNCMD+' stop', env=ENV) cout, cerr = proc.communicate() print (cout) if proc.returncode: self.show_error('Management console does not stopped!\nDetails: %s'%cerr) self.check_sync_status_thr.stop() self.check_sync_status_thr.wait() except Exception, err: self.show_error('Unexpected error: %s'%err)
def mount_windows(self, host, port): self.umount_windows() drive = self.__get_win_unused_drive() self.__mountpoint = 'drive %s' % drive p = Subprocess(['sc', 'create', 'iDepositBoxMount', 'binPath=', 'cmd /b /c net use %s http://%s:%s/'%\ (drive, host, port), 'type=', 'share']) p = Subprocess(['sc', 'create', 'iDepositBoxUnmount', 'binPath=', 'cmd /b /c net use /delete %s /Y'%\ drive, 'type=', 'share']) out, err = p.communicate() logger.debug('sc create iDepositBoxUnmount: [%s] %s %s' % (p.returncode, out, err)) p = Subprocess('net start iDepositBoxMount') p.communicate() return 0
def umount_windows(self): p = Subprocess('sc query iDepositBoxUnmount') out, err = p.communicate() if p.returncode: logger.debug('no iDepositBoxUnmount service found...') return p = Subprocess('net start iDepositBoxUnmount') p.communicate() p = Subprocess('sc delete iDepositBoxMount') out, err = p.communicate() logger.debug('sc delete iDepositBoxMount: %s %s'%(out, err)) p = Subprocess('sc delete iDepositBoxUnmount') out, err = p.communicate() logger.debug('sc delete iDepositBoxUnmount: %s %s'%(out, err))
def __init__(self, parent=None): super(MainWind, self).__init__(parent) self.__first_event = True self.systray = SystemTrayIcon(self) self.changed_service_status.connect(self.on_changed_service_status) self.systray.manage_act.triggered.connect(self.onManage) self.systray.exit_act.triggered.connect(self.onClose) self.setWindowIcon(QIcon(APP_ICON)) self.setWindowState(Qt.WindowMaximized) self.setVisible(False) Subprocess(MGMT_CLI_RUNCMD + ' restart', env=ENV) self.check_sync_status_thr = CheckSyncStatusThread(self) self.check_sync_status_thr.start() if sys.platform != 'darwin': self.systray.activated.connect(self.on_icon_activated) self.__show_splash_screen()
def mount_windows(self, host, port): self.umount_windows() drive = self.__get_win_unused_drive() self.__mountpoint = 'drive %s'%drive p = Subprocess(['sc', 'create', 'iDepositBoxMount', 'binPath=', 'cmd /b /c net use %s http://%s:%s/'%\ (drive, host, port), 'type=', 'share']) p = Subprocess(['sc', 'create', 'iDepositBoxUnmount', 'binPath=', 'cmd /b /c net use /delete %s /Y'%\ drive, 'type=', 'share']) out, err = p.communicate() logger.debug('sc create iDepositBoxUnmount: [%s] %s %s'%(p.returncode, out, err)) p = Subprocess('net start iDepositBoxMount') p.communicate() return 0
def __run_linux_mounter(self, cmd): proc = Subprocess('%s %s'%(LINUX_MOUNTER_BIN, cmd)) cout, cerr = proc.communicate() if proc.returncode: logger.error('webdav mounter error: %s %s'%(cout, cerr)) return proc.returncode
def unmount_unix(self, mount_point): if os.path.exists(mount_point): p = Subprocess('umount %s'%mount_point) out, err = p.communicate() if p.returncode: logger.debug('"umount %s" output: %s %s'%(mount_point, out, err))
def umount_windows(self): p = Subprocess('sc query iDepositBoxUnmount') out, err = p.communicate() if p.returncode: logger.debug('no iDepositBoxUnmount service found...') return p = Subprocess('net start iDepositBoxUnmount') p.communicate() p = Subprocess('sc delete iDepositBoxMount') out, err = p.communicate() logger.debug('sc delete iDepositBoxMount: %s %s' % (out, err)) p = Subprocess('sc delete iDepositBoxUnmount') out, err = p.communicate() logger.debug('sc delete iDepositBoxUnmount: %s %s' % (out, err))
def __run_linux_mounter(self, cmd): proc = Subprocess('%s %s' % (LINUX_MOUNTER_BIN, cmd)) cout, cerr = proc.communicate() if proc.returncode: logger.error('webdav mounter error: %s %s' % (cout, cerr)) return proc.returncode