Coverage for r11k/main.py: 0%
46 statements
« prev ^ index » next coverage.py v7.2.1, created at 2023-02-27 12:17 +0100
« prev ^ index » next coverage.py v7.2.1, created at 2023-02-27 12:17 +0100
1"""Entry point for r11k."""
3import argparse
4import locale
5import logging
6import os
7import os.path
8import graphviz
10from r11k import util
11from r11k.puppetfile import (
12 load_puppetfile,
13 find_all_modules_for_environment,
14)
15import r11k.config
18logger = logging.getLogger(__name__)
20# TODO warn if not latest
23def __main() -> int:
25 locale.resetlocale()
27 parser = argparse.ArgumentParser(description='r10k, but good')
28 parser.add_argument('puppetfile', help='Puppetfile, but in yaml format')
29 parser.add_argument('--dest', help='Directory to deploy environment to',
30 dest='dest', default='/etc/puppetlabs/code/environments/')
31 parser.add_argument('--env-name', help='Force name of environment', dest='environment_name')
32 parser.add_argument('--force', help='Refresh all caches', dest='force',
33 action='store_true')
35 args = parser.parse_args()
37 if args.force:
38 r11k.config.config.http_ttl = 0
39 r11k.config.config.git_ttl = 0
41 logger.setLevel(logging.DEBUG)
42 ch = logging.StreamHandler()
43 ch.setLevel(logging.DEBUG)
44 formatter = logging.Formatter('%(name)s %(lineno)i - %(levelname)s - %(message)s')
45 ch.setFormatter(formatter)
46 logger.addHandler(ch)
48 puppetfile = load_puppetfile(args.puppetfile)
50 resolvedPuppetfile = find_all_modules_for_environment(puppetfile)
52 # ----- Publish to destination ---------------------
54 destdir = args.dest
55 util.ensure_directory(destdir)
57 if args.environment_name:
58 resolvedPuppetfile.environment_name = args.environment_name
60 if not resolvedPuppetfile.environment_name:
61 raise ValueError()
63 resolvedPuppetfile.publish(os.path.join(destdir, resolvedPuppetfile.environment_name))
65 # ----- Build Graphviz file ------------------------
67 dot = graphviz.Digraph()
68 dot.attr(rankdir='LR')
69 # print('graph [layout=dot rankdir=LR]', file=f)
70 for module in resolvedPuppetfile.modules.values():
71 # node_id = hashlib.md5(module.name.encode('UTF-8')).hexdigest()
72 # if module.name in puppetfile.modules:
73 if module.explicit:
74 dot.node(module.name, fillcolor='lightgreen', style='filled')
75 else:
76 dot.node(module.name)
77 # print(f'm{node_id} [label="{module.name}"]', file=f)
78 for dependency in module.metadata.dependencies:
79 # other_id = hashlib.md5(dependency.name.encode('UTF-8')).hexdigest()
80 # print(f'm{node_id} -> m{other_id} [label="{dependency.version_requirement}"]', file=f)
81 dot.edge(module.name, dependency.name, label=dependency.version_requirement)
83 dot.render('graph.dot')
85 return 0
87# possible mains:
88# install
89# installs everything from the given resolution file
90# update
91# updates (without checking) everything from the current resolution file
92# check
93# checks the given resolution file, and reports all possible errors
94# check-dist <dist>
95# checks if the given resolution file is valid for the current
96# distribution
97# check-update
98# check how an update of everything would resolve the dependency tree
99# / alternativly, check how much stuff can be updated without
100# breaking the dependency tree