Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Rsync should now handle all arguments correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
nmcspadden committed Jun 5, 2019
1 parent 350bd41 commit 988332d
Showing 1 changed file with 63 additions and 61 deletions.
124 changes: 63 additions & 61 deletions Shared_Processors/Rsync.py
@@ -1,61 +1,63 @@
#!/usr/bin/python
#
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.#
"""See docstring for Rsync class"""

# Disabling warnings for env members and imports that only affect recipe-
# specific processors.
# pylint: disable=e1101,f0401

import subprocess

from autopkglib import Processor, ProcessorError

__all__ = ["Rsync"]


class Rsync(Processor):
"""Rsyncs a file/directory to another file/directory"""
description = __doc__
input_variables = {
"source_path": {
"required": True,
"description": ("Path to file or directory to copy from.")
},
"destination_path": {
"required": True,
"description": ("Path to file or directory to copy to.")
},
"rsync_arguments": {
"required": False,
"description": ("Arguments passed to rsync directly.")
},
"rsync_path": {
"required": False,
"description": ("Custom path to rsync. Defaults to /usr/bin/rsync.")
}
}
output_variables = {
}

__doc__ = description

def main(self):
rsync_location = self.env.get("rsync_path", "/usr/bin/rsync")
rsync_args = self.env.get("rsync_arguments", "")
cmd = [rsync_location, rsync_args, self.env["source_path"],
self.env["destination_path"]]
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(rout, rerr) = proc.communicate()
if rerr:
raise ProcessorError(rerr)
self.output(rout)

if __name__ == "__main__":
PROCESSOR = Rsync()
PROCESSOR.execute_shell()
#!/usr/bin/python
#
# Copyright (c) 2015, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
"""See docstring for Rsync class"""

import subprocess

from autopkglib import Processor, ProcessorError


__all__ = ["Rsync"]


class Rsync(Processor):
"""Rsyncs a path to another path."""

description = __doc__
input_variables = {
"source_path": {
"required": True,
"description": ("Path to file or directory to copy from."),
},
"destination_path": {
"required": True,
"description": ("Path to file or directory to copy to."),
},
"rsync_arguments": {
"required": False,
"description": ("List of arguments passed to rsync directly."),
},
"rsync_path": {
"required": False,
"description": ("Custom path to rsync. Defaults to /usr/bin/rsync."),
},
}
output_variables = {}

__doc__ = description

def main(self):
rsync_location = self.env.get("rsync_path", "/usr/bin/rsync")
rsync_args = self.env.get("rsync_arguments", [])
if isinstance(rsync_args, basestring):
raise ProcessorError("rsync_args must be a list!")
cmd = [rsync_location]
if rsync_args:
cmd.extend(rsync_args)
cmd.extend([self.env["source_path"], self.env["destination_path"]])
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(rout, rerr) = proc.communicate()
if rerr:
raise ProcessorError(rerr)
self.output(rout)


if __name__ == "__main__":
PROCESSOR = Rsync()
PROCESSOR.execute_shell()

0 comments on commit 988332d

Please sign in to comment.