This repository has been archived by the owner on Oct 19, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rsync should now handle all arguments correctly
- Loading branch information
1 parent
350bd41
commit 988332d
Showing
1 changed file
with
63 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |