1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import sys
17
18 from config_common import handler_base, cfg_exceptions
19 from config_common.rhn_log import log_debug, die
20
21 -class Handler(handler_base.HandlerBase):
22 _usage_options = "[options] file"
23 _options_table = [
24 handler_base.HandlerBase._option_class(
25 '-c', '--channel', action="append",
26 help="Use this config channel",
27 ),
28 handler_base.HandlerBase._option_class(
29 '-r', '--revision', action="append",
30 help="Use this revision",
31 ),
32 ]
34 log_debug(2)
35 r = self.repository
36
37 if len(self.args) != 1:
38 die(3, "One file needs to be specified")
39
40 path = self.args[0]
41
42 channel_dst = None
43 ns_count = len(self.options.channel or [])
44 if ns_count == 0:
45 die(3, "At least one config channel has to be specified")
46
47 channel_src = self.options.channel[0]
48 if ns_count > 2:
49 die(3, "At most two config channels can be specified")
50
51 if not r.config_channel_exists(channel_src):
52 die(4, "Source config channel %s does not exist" % channel_src)
53
54 if ns_count == 2:
55 channel_dst = self.options.channel[1]
56
57 if not r.config_channel_exists(channel_dst):
58 die(4, "Config channel %s does not exist" % channel_dst)
59
60 revision_dst = None
61 rev_count = len(self.options.revision or [])
62 if rev_count == 0:
63 die(3, "At least one revision has to be specified")
64
65 revision_src = self.options.revision[0]
66 if rev_count > 2:
67 die(3, "At most two revisions can be specified")
68
69 if rev_count == 2:
70 revision_dst = self.options.revision[1]
71
72 try:
73 result = r.diff_file_revisions(path, channel_src,
74 revision_src, channel_dst, revision_dst)
75 except cfg_exceptions.RepositoryFileMissingError:
76 e = sys.exc_info()[1]
77 die(2, e[0])
78 except cfg_exceptions.BinaryFileDiffError:
79 e = sys.exc_info()[1]
80 die(3, e[0])
81
82 sys.stdout.write(result)
83