-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspruce
executable file
·158 lines (134 loc) · 6.76 KB
/
spruce
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/python
# Copyright 2016 Shea G. Craig
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
"""Spruce includes tools to analyze the quality of a Munki repo, as wll
as commands to automate archiving or removing unwanted items, and for
making bulk data changes to metadata as well as deployment settings
by product, category, etc.
"""
import argparse
import os
import sys
import spruce_tools
__version__ = "0.3.0"
def main():
"""Handle arguments and execute commands."""
try:
args = get_argument_parser().parse_args()
# We can't do anything without the repo. Bail early if it's not
# mounted.
if not os.path.exists(spruce_tools.get_repo_path()):
sys.exit("Repo is not mounted. Please mount and try again.")
args.func(args)
except KeyboardInterrupt:
print
sys.exit(1)
def get_argument_parser():
"""Create our argument parser."""
description = ("Spruce is a tool for improving the quality of your Munki "
"repo.")
parser = argparse.ArgumentParser(description=description)
subparser = parser.add_subparsers(help="Sub-command help")
# name arguments
phelp = (
"Output all unique product names present in the Munki all catalog.")
names_parser = subparser.add_parser("name", help=phelp)
phelp = "Search for items with names that contain this argument."
names_parser.add_argument("name", help=phelp, nargs="?")
names_parser.set_defaults(func=spruce_tools.run_names)
phelp = "Show each version of the software per name."
names_parser.add_argument("-v", "--version", help=phelp,
action="store_true")
# report arguments
phelp = "Report on unused or misconfigured items in the repo."
report_parser = subparser.add_parser("report", help=phelp)
report_parser.set_defaults(func=spruce_tools.run_reports)
phelp = "Output report in plist format (for use with other functions)."
report_parser.add_argument("-p", "--plist", help=phelp,
action="store_true")
# categories arguments
phelp = ("List all categories present in the repo, and the count of "
"pkginfo files in each, or show members of a single category.")
categories_parser = subparser.add_parser("category", help=phelp)
categories_parser.set_defaults(func=spruce_tools.run_categories)
phelp = "Name of one or more categories to display."
categories_parser.add_argument("category", help=phelp, nargs="*")
phelp = ("Output a plist representation of all pkginfo files organized by "
"category. This file can be used with the recategorize command.")
categories_parser.add_argument("-p", "--prepare", help=phelp,
action="store_true")
# recategorize arguments
phelp = ("Recategorize products based on an input plist generated by "
"the prepare command.")
update_parser = subparser.add_parser("recategorize", help=phelp)
phelp = ("Path to a plist file containing the desired changes to product "
"categories. This file may be generated by the category command. "
"See the documentation for more details.")
update_parser.add_argument("plist", help=phelp)
update_parser.set_defaults(func=spruce_tools.update_categories)
# deprecate arguments
phelp = (
"Remove unwanted products from a Munki repo. Pkg and pkginfo files "
"will be removed, or optionally can be archived in an archive repo. "
"All products to be completely removed will then have their names "
"removed from all manifests.")
dep_parser = subparser.add_parser("deprecate", help=phelp)
dep_parser.set_defaults(func=spruce_tools.deprecate)
phelp = ("Move, rather than delete, pkginfos and pkgs to the archive repo "
"rooted at 'ARCHIVE'. The original folder structure will be "
"preserved.")
dep_parser.add_argument("-a", "--archive", help=phelp)
phelp = "Don't prompt before removal or archiving procedure."
dep_parser.add_argument("-f", "--force", help=phelp, action="store_true")
phelp = "Use 'git rm' when deleting, or after archiving, to stage changes."
dep_parser.add_argument("-g", "--git", help=phelp, action="store_true")
phelp = ("Automatically deprecate out-of-date items, ignoring the 'NUM' "
"newest items (default of 1). If this argument is specified, "
"the -n, -c, and -p options will be ignored.")
dep_parser.add_argument("--auto", help=phelp, metavar="NUM",
const=1, nargs="?")
deprecator_parser = dep_parser.add_argument_group("Deprecation Arguments")
phelp = "Remove all pkginfos and pkgs with category 'CATEGORY'."
deprecator_parser.add_argument("-c", "--category", help=phelp, nargs="+")
phelp = "Remove all pkginfos and pkgs with name 'NAME'."
deprecator_parser.add_argument("-n", "--name", help=phelp, nargs="+")
phelp = ("Remove all products in the 'removals' section of supplied "
"plist.")
deprecator_parser.add_argument("-p", "--plist", help=phelp)
# icons arguments
phelp = "Report on unused icons and optionally remove or archive them."
icon_parser = subparser.add_parser("icons", help=phelp)
icon_parser.set_defaults(func=spruce_tools.handle_icons)
group = icon_parser.add_mutually_exclusive_group()
phelp = "Delete unused icons."
group.add_argument("-d", "--delete", help=phelp, action="store_true")
phelp = ("Move, rather than delete, icons to the archive repo "
"rooted at 'ARCHIVE'. The original folder structure will "
"be preserved.")
group.add_argument("-a", "--archive", help=phelp)
phelp = "Don't prompt before removal or archiving procedure."
icon_parser.add_argument("-f", "--force", help=phelp, action="store_true")
# docs arguments
phelp = "Generate markdown documentation from configured Munki repo."
doc_parser = subparser.add_parser("docs", help=phelp)
doc_parser.set_defaults(func=spruce_tools.handle_docs)
phelp = ("Directory to save output to.")
doc_parser.add_argument("outputdir", help=phelp)
phelp = ("Generate HTML output.")
doc_parser.add_argument("--html", help=phelp, action="store_true")
return parser
if __name__ == "__main__":
main()