-
Notifications
You must be signed in to change notification settings - Fork 27
/
InstallsArrayFineTuning.py
64 lines (52 loc) · 1.95 KB
/
InstallsArrayFineTuning.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# 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 PackageInfoVersioner class."""
from __future__ import absolute_import
from autopkglib import Processor, ProcessorError
__all__ = ["InstallsArrayFineTuning"]
class InstallsArrayFineTuning(Processor):
"""Change an installs array to allow fine-tuning of a type."""
description = __doc__
input_variables = {
"additional_pkginfo": {
"required": True,
"description": ("Dictionary containing an installs array."),
},
"changes": {
"required": True,
"description": (
"List of dictionaries containing replacement values "
"for installs types. Each dictionary must contain a "
"path and the new type."
),
},
}
output_variables = {
"changed_pkginfo": {"description": "Fine tuned additional_pkginfo dictionary."}
}
__doc__ = description
def main(self):
"""Magic."""
current = self.env["additional_pkginfo"]["installs"]
changes = self.env["changes"]
for change in changes:
path = change.get("path", None)
if not path:
raise ProcessorError("No path found in change!")
newtype = change.get("type", None)
if not newtype:
raise ProcessorError("No type found in change!")
# Replace the installs
for install in current:
if install["path"] == path:
install["type"] = newtype
self.output("Replacing type for %s to %s" % (path, newtype))
self.env["changed_pkginfo"] = current
if __name__ == "__main__":
PROCESSOR = InstallsArrayFineTuning()
PROCESSOR.execute_shell()