107
109
self.mtx.release()
110
def set_contents(self, filename, data):
112
def set_contents(self, filename, data, mode="w"):
111
113
self.mtx.acquire()
113
ret = WbAdminSSH.set_contents(self, filename, data)
115
ret = WbAdminSSH.set_contents(self, filename, data, mode)
115
117
self.mtx.release()
898
900
output = StringIO.StringIO()
900
902
if skip_lines == 0:
901
command = 'cat %s' % quote_path(filename)
903
command = 'LC_ALL=C cat %s' % quote_path(filename)
903
command = 'tail -n+%d %s' % (skip_lines+1, quote_path(filename))
905
command = 'LC_ALL=C tail -n+%d %s' % (skip_lines+1, quote_path(filename))
905
907
res = self.process_ops.exec_cmd(command,
906
908
as_user = as_user,
1478
1480
def _create_temp_file(self, content):
1479
1482
tmpfilename = ''
1480
1484
if self.ssh is not None:
1481
homedir, status = self.process_ops.get_cmd_output("echo ~")
1482
if type(homedir) is unicode:
1483
homedir = homedir.encode("utf8")
1484
if type(homedir) is str:
1485
homedir = homedir.strip(" \r\t\n")
1488
log_debug2('%s: Got home dir: "%s"\n' % (self.__class__.__name__, homedir) )
1491
raise Exception("Unable to get path for remote home directory")
1493
tmpfilename = homedir + "/.wba.temp"
1495
self.ssh.set_contents(tmpfilename, content)
1488
tmpfilename = '/tmp/' + ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(16))
1490
# This uses file open mode as wx to make sure the temporary has been created
1491
# on this open attempt to avoid writing to an existing file.
1492
self.ssh.set_contents(tmpfilename, content, "wx")
1493
log_debug2('Created temp file: "%s".\n' % tmpfilename)
1495
except IOError, exc:
1496
# This is the only hting reported on a failure due to an attempt to
1497
# create a file that already exists
1498
if exc.message == "Failure":
1499
log_warning('WARNING: Unable to create temp file: "%s", trying a different name.\n' % tmpfilename)
1504
log_warning('ERROR: Unable to create temp file max number of attempts reached.\n')
1505
raise IOError('Unable to create temp file max number of attempts reached.')
1507
log_warning('ERROR: Unable to create temp file: "%s" : %s.\n' % (tmpfilename, exc))
1509
except Exception, exc:
1510
log_warning('ERROR: Unable to create temp file: "%s" : %s.\n' % (tmpfilename, exc))
1497
1513
raise Exception("No SSH session active, cannot save file remotely")
1499
1515
return tmpfilename