MCPcopy Create free account
hub / github.com/StackStorm/st2 / put_dir

Method put_dir

st2common/st2common/runners/paramiko_ssh.py:234–296  ·  view source on GitHub ↗

Upload a dir to the remote node. :type local_path: ``str`` :param local_path: Dir path on the local node. :type remote_path: ``str`` :param remote_path: Base dir path on the remote node. :type mode: ``int`` :param mode: Permissions mode for

(self, local_path, remote_path, mode=None, mirror_local_mode=False)

Source from the content-addressed store, hash-verified

232 return rattrs
233
234 def put_dir(self, local_path, remote_path, mode=None, mirror_local_mode=False):
235 """
236 Upload a dir to the remote node.
237
238 :type local_path: ``str``
239 :param local_path: Dir path on the local node.
240
241 :type remote_path: ``str``
242 :param remote_path: Base dir path on the remote node.
243
244 :type mode: ``int``
245 :param mode: Permissions mode for the file. E.g. 0744.
246
247 :type mirror_local_mode: ``int``
248 :param mirror_local_mode: Should remote file mirror local mode.
249
250 :return: List of files created on remote node.
251 :rtype: ``list`` of ``str``
252 """
253
254 extra = {
255 "_local_path": local_path,
256 "_remote_path": remote_path,
257 "_mode": mode,
258 "_mirror_local_mode": mirror_local_mode,
259 }
260 self.logger.debug("Uploading dir", extra=extra)
261
262 if os.path.basename(local_path):
263 strip = os.path.dirname(local_path)
264 else:
265 strip = os.path.dirname(os.path.dirname(local_path))
266
267 remote_paths = []
268
269 for context, dirs, files in os.walk(local_path):
270 rcontext = context.replace(strip, "", 1)
271 # normalize pathname separators with POSIX separator
272 rcontext = rcontext.replace(os.sep, "/")
273 rcontext = rcontext.lstrip("/")
274 rcontext = posixpath.join(remote_path, rcontext)
275
276 if not self.exists(rcontext):
277 self.sftp.mkdir(rcontext)
278
279 for d in dirs:
280 n = posixpath.join(rcontext, d)
281 if not self.exists(n):
282 self.sftp.mkdir(n)
283
284 for f in files:
285 local_path = os.path.join(context, f)
286 n = posixpath.join(rcontext, f)
287 # Note that quote_unix is done by put anyways.
288 p = self.put(
289 local_path=local_path,
290 remote_path=n,
291 mirror_local_mode=mirror_local_mode,

Callers 2

test_put_dirMethod · 0.80
_put_filesMethod · 0.80

Calls 3

existsMethod · 0.95
putMethod · 0.95
mkdirMethod · 0.45

Tested by 1

test_put_dirMethod · 0.64