Class: Synqa::SshContentHost

Inherits:
DirContentHost show all
Defined in:
lib/synqa.rb

Overview

Representation of a remote system accessible via SSH

Instance Attribute Summary collapse

Attributes inherited from DirContentHost

#hashCommand, #pathPrefix

Instance Method Summary collapse

Methods inherited from DirContentHost

#findDirectoriesCommand, #findFilesCommand, #getContentTree, #listFileHashes

Constructor Details

#initialize(userAtHost, hashCommand, sshAndScp = nil) ⇒ SshContentHost

Returns a new instance of SshContentHost.



300
301
302
303
304
# File 'lib/synqa.rb', line 300

def initialize(userAtHost, hashCommand, sshAndScp = nil)
  super(hashCommand)
  @sshAndScp = sshAndScp != nil ?  sshAndScp : InternalSshScp.new()
  @userAtHost = userAtHost
end

Instance Attribute Details

#sshAndScpObject (readonly)

The remote userAtHost, e.g. “[email protected]



298
299
300
# File 'lib/synqa.rb', line 298

def sshAndScp
  @sshAndScp
end

#userAtHostObject (readonly)

The remote userAtHost, e.g. “[email protected]



298
299
300
# File 'lib/synqa.rb', line 298

def userAtHost
  @userAtHost
end

Instance Method Details

#copyLocalFileToRemoteDirectory(sourcePath, destinationPath, dryRun) ⇒ Object

copy a local file to a remote directory, if dryRun is false



336
337
338
# File 'lib/synqa.rb', line 336

def copyLocalFileToRemoteDirectory(sourcePath, destinationPath, dryRun)
  sshAndScp.copyLocalFileToRemoteDirectory(userAtHost, sourcePath, destinationPath, dryRun)
end

#copyLocalToRemoteDirectory(sourcePath, destinationPath, dryRun) ⇒ Object

copy a local directory to a remote directory, if dryRun is false



331
332
333
# File 'lib/synqa.rb', line 331

def copyLocalToRemoteDirectory(sourcePath, destinationPath, dryRun)
  sshAndScp.copyLocalToRemoteDirectory(userAtHost, sourcePath, destinationPath, dryRun)
end

#deleteDirectory(dirPath, dryRun) ⇒ Object

delete a remote directory, if dryRun is false



321
322
323
# File 'lib/synqa.rb', line 321

def deleteDirectory(dirPath, dryRun)
  sshAndScp.deleteDirectory(userAtHost, dirPath, dryRun)
end

#deleteFile(filePath, dryRun) ⇒ Object

delete a remote file, if dryRun is false



326
327
328
# File 'lib/synqa.rb', line 326

def deleteFile(filePath, dryRun)
  sshAndScp.deleteFile(userAtHost, filePath, dryRun)
end

#listDirectories(baseDir) ⇒ Object

Return a list of all subdirectories of the base directory (as paths relative to the base directory)



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/synqa.rb', line 341

def listDirectories(baseDir)
  baseDir = normalisedDir(baseDir)
  puts "Listing directories ..."
  directories = []
  baseDirLen = baseDir.length
  ssh(findDirectoriesCommand(baseDir).join(" ")) do |line|
    puts " #{line}"
    if line.start_with?(baseDir)
      directories << line[baseDirLen..-1]
    else
      raise "Directory #{line} is not a sub-directory of base directory #{baseDir}"
    end
  end
  return directories
end

#listFileHashLines(baseDir) ⇒ Object

Yield lines of output from the command to display hash values and file names of all files within the base directory



359
360
361
362
363
364
365
366
# File 'lib/synqa.rb', line 359

def listFileHashLines(baseDir)
  baseDir = normalisedDir(baseDir)
  remoteFileHashLinesCommand = findFilesCommand(baseDir) + ["|", "xargs", "-r"] + @hashCommand.command
  ssh(remoteFileHashLinesCommand.join(" ")) do |line| 
    puts " #{line}"
    yield line 
  end
end

#listFiles(baseDir) ⇒ Object

List all files within the base directory to stdout



369
370
371
372
373
374
# File 'lib/synqa.rb', line 369

def listFiles(baseDir)
  baseDir = normalisedDir(baseDir)
  ssh(findFilesCommand(baseDir).join(" ")) do |line| 
    puts " #{line}"
  end
end

#locationDescriptor(baseDir) ⇒ Object

Return readable description of base directory on remote system



307
308
309
310
# File 'lib/synqa.rb', line 307

def locationDescriptor(baseDir)
  baseDir = normalisedDir(baseDir)
  return "#{userAtHost}:#{baseDir} (connect = #{shell}/#{scpProgram}, hashCommand = #{hashCommand})"
end

#ssh(commandString, dryRun = false) ⇒ Object

execute an SSH command on the remote system, yielding lines of output (or don’t actually execute, if dryRun is false)



314
315
316
317
318
# File 'lib/synqa.rb', line 314

def ssh(commandString, dryRun = false)
  sshAndScp.ssh(userAtHost, commandString, dryRun) do |line|
    yield line
  end
end