Revision 76d4a1c9

b/image_creator/main.py
78 78
        default=None, action="callback", callback=check_writable_dir,
79 79
        help="dump image to FILE", metavar="FILE")
80 80

  
81
    parser.add_option("--print-sysprep", dest="print_sysprep", default=False,
82
        help="Print the enabled and disable sysprep actions for this image",
83
        action="store_true")
84

  
85
    parser.add_option("--print-data-cleanup", dest="print_data_cleanup",
86
        default=False, help="Print the enabled and disable data cleanup "
87
        "operations actions for this source", action="store_true")
88

  
81 89
    parser.add_option("-s", "--silent", dest="silent", default=False,
82 90
        help="silent mode, only output error", action="store_true")
83 91

  
......
98 106
    if options.register:
99 107
        options.upload = True
100 108

  
101
    if options.outfile is None and not options.upload:
102
        parser.error('either outfile (-o) or upload (-u) must be set.')
103

  
104 109
    return options
105 110

  
106 111

  
......
110 115
    if options.silent:
111 116
        util.silent = True
112 117

  
118
    if options.outfile is None and not options.upload \
119
        and not options.print_sysprep and not options.print_data_cleanup:
120
        FatalError("At least one of the following: `-o', `-u', "
121
        "`--print-sysprep' `--print-data-cleanup' must be set")
122

  
113 123
    output('snf-image-creator %s\n' % version)
114 124

  
115 125
    if os.geteuid() != 0:
......
134 144

  
135 145
        output()
136 146

  
147
        if options.print_sysprep:
148
            image_os.print_sysprep()
149
            output()
150

  
151
        if options.print_data_cleanup:
152
            image_os.print_data_cleanup()
153
            output()
154

  
155
        if options.outfile is None and not options.upload:
156
            return 0
157

  
137 158
        if options.sysprep:
138 159
            image_os.sysprep()
139 160

  
b/image_creator/os_type/__init__.py
54 54
        self.root = rootdev
55 55
        self.g = ghandler
56 56

  
57
        self.sysprep_regexp = re.compile('^sysprep_')
58
        self.data_cleanup_regexp = re.compile('^data_cleanup_')
59

  
60
    def _print_task(self, task):
61
        name = task.__name__
62

  
63
        if self.sysprep_regexp.match(name):
64
            name = self.sysprep_regexp.sub("", name)
65
        elif self.data_cleanup_regexp.match(name):
66
            name = self.data_cleanup_regexp.sub("", name)
67
        else:
68
            raise FatalError("%s is not a task" % name)
69

  
70
        name = name.replace('_', '-')
71

  
72
        output("  %s:\n    %s" % (name, task.__doc__))
73

  
57 74
    @add_prefix
58 75
    def ls(self, directory):
59 76
        """List the name of all files under a directory"""
......
116 133

  
117 134
        return meta
118 135

  
136
    def list_sysprep(self):
137
        """List all sysprep actions"""
138

  
139
        is_sysprep = lambda x: x.startswith('sysprep_') and \
140
                                                    callable(getattr(self, x))
141
        tasks = [getattr(self, x) for x in dir(self) if is_sysprep(x)]
142

  
143
        included = [t for t in tasks if not getattr(t, "excluded", False)]
144
        excluded = [t for t in tasks if getattr(t, "excluded", False)]
145

  
146
        return included, excluded
147

  
148
    def list_data_cleanup(self):
149
        """List all data_cleanup actions"""
150

  
151
        is_cleanup = lambda x: x.startswith('data_cleanup_') and \
152
                                                    callable(getattr(self, x))
153
        tasks = [getattr(self, x) for x in dir(self) if is_cleanup(x)]
154

  
155
        included = [t for t in tasks if not getattr(t, "excluded", False)]
156
        excluded = [t for t in tasks if getattr(t, "excluded", False)]
157

  
158
        return included, excluded
159

  
119 160
    def data_cleanup(self):
120 161
        """Cleanup sensitive data out of the OS image."""
121 162

  
......
144 185
            task()
145 186
        output()
146 187

  
147
    def list_sysprep(self):
148
        """List all sysprep actions"""
149

  
150
        is_sysprep = lambda x: x.startswith('sysprep_') and \
151
                                                    callable(getattr(self, x))
152
        tasks = [getattr(self, x) for x in dir(self) if is_sysprep(x)]
153

  
154
        included = [t for t in tasks if not getattr(t, "excluded", False)]
155
        excluded = [t for t in tasks if getattr(t, "excluded", False)]
156

  
157
        return included, excluded
158

  
159
    def list_data_cleanup(self):
160
        """List all data_cleanup actions"""
161

  
162
        is_cleanup = lambda x: x.startswith('data_cleanup_') and \
163
                                                    callable(getattr(self, x))
164
        tasks = [getattr(self, x) for x in dir(self) if is_cleanup(x)]
165

  
166
        included = [t for t in tasks if not getattr(t, "excluded", False)]
167
        excluded = [t for t in tasks if getattr(t, "excluded", False)]
168

  
169
        return included, excluded
188
    def print_task(self, task):
189
        name = task.__name__
190

  
191
        if self.sysprep_regexp.match(name):
192
            name = self.sysprep_regexp.sub("", name)
193
        elif self.data_cleanup_regexp.match(name):
194
            name = self.data_cleanup_regexp.sub("", name)
195
        else:
196
            raise FatalError("%s is not a task" % name)
197

  
198
        name = name.replace('_', '-')
199

  
200
        output("  %s:\n    %s" % (name, task.__doc__))
201

  
202
    def print_data_cleanup(self):
203
        included, excluded = self.list_data_cleanup()
204

  
205
        output("Included data cleanup operations:")
206
        if len(included) == 0:
207
            ouput("(none)")
208
        else:
209
            for task in included:
210
                self._print_task(task)
211
        output("Ommited data cleanup operations:")
212
        if len(excluded) == 0:
213
            ouput("(none)")
214
        else:
215
            for task in excluded:
216
                self._print_task(task)
217

  
218
    def print_sysprep(self):
219
        included, excluded = self.list_sysprep()
220

  
221
        output("Included sysprep operations:")
222
        if len(included) == 0:
223
            ouput("(none)")
224
        else:
225
            for task in included:
226
                self._print_task(task)
227
        output("Ommited sysprep operations:")
228
        if len(excluded) == 0:
229
            output("(none)")
230
        else:
231
            for task in excluded:
232
                self._print_task(task)
170 233

  
171 234
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :

Also available in: Unified diff