def disconnect(self): """ Disconnects the UNC path. If the command fails, this will raise a `ShellCommandError`. """ identifier = (self.disk_drive.get_drive() if self.disk_drive else S.sanitize_path(self.unc.get_normalized_path())) self.logger('Disconnecting the network UNC path "{path}".'.format(path=self.get_path())) run('NET USE "{id}" /DELETE /YES'.format(id=identifier), self.logger)
def disconnect(self): """ Disconnects the UNC path. If the command fails, this will raise a `ShellCommandError`. """ identifier = (self.disk_drive.get_drive() if self.disk_drive else S.sanitize_path(self.unc.get_normalized_path())) self.logger('Disconnecting the network UNC path "{path}".'.format( path=self.get_path())) run('NET USE "{id}" /DELETE /YES'.format(id=identifier), self.logger)
def _connect_with_creds(self, username=None, password=None): """ Constructs and executes the Windows connecting command to connect this `UncDirectoryConnection`. `username` and/or `password` are used as credentials if they are supplied. If there is an error a `ShellCommandError` is raised. """ command = self._get_connection_command(username, password) self.logger(self._get_connection_command(username, '-----') if password else command) run(command)
def _connect_with_creds(self, username=None, password=None): """ Constructs and executes the Windows connecting command to connect this `UncDirectoryConnection`. `username` and/or `password` are used as credentials if they are supplied. If there is an error a `ShellCommandError` is raised. """ command = self._get_connection_command(username, password) self.logger( self._get_connection_command(username, '-----' ) if password else command) run(command)
def get_current_net_use_table(): """ Returns a `NetUseTable` that describes the current Windows session's status regarding all UNC paths. """ stdout, _ = run('NET USE') return parse_net_use_table(stdout)
def disconnect_localhost(self): if self.localhost_is_connected(): run('NET USE ' + self.LOCALHOST_UNC + ' /DELETE')
def connect_localhost(self): if not self.localhost_is_connected(): run('NET USE ' + self.LOCALHOST_UNC)
def disconnect_localhost(self): if self.localhost_is_connected(): run("NET USE " + LOCALHOST_UNC + " /DELETE")
def test_valid(self): self.assertIsNotNone(run('dir'))