~marcoceppi/charm-tools/fix-user-cfg

« back to all changes in this revision

Viewing changes to charmtools/charms.py

  • Committer: Marco Ceppi
  • Date: 2013-12-14 23:22:57 UTC
  • Revision ID: marco@ceppi.net-20131214232257-mkkb0n1qf8otrrye
Fix proof messages

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
 
50
50
 
51
51
class CharmLinter(Linter):
52
 
    def check_hook(self, hook, hooks_path, required=True, recommended=False):
 
52
    def check_hook(self, hook, hooks_path, recommended=False):
53
53
        hook_path = os.path.join(hooks_path, hook)
54
54
 
55
55
        try:
56
56
            mode = os.stat(hook_path)[ST_MODE]
57
57
            if not mode & S_IXUSR:
58
 
                self.warn(hook + " not executable")
 
58
                self.info(hook + " not executable")
59
59
            with open(hook_path, 'r') as hook_file:
60
60
                count = 0
61
61
                for line in hook_file:
71
71
            return True
72
72
 
73
73
        except OSError:
74
 
            if required:
75
 
                self.err("missing hook " + hook)
76
 
            elif recommended:
77
 
                self.warn("missing recommended hook " + hook)
 
74
            if recommended:
 
75
                self.info("missing recommended hook " + hook)
78
76
            return False
79
77
 
80
78
    def check_relation_hooks(self, relations, subordinate, hooks_path):
111
109
 
112
110
            has_one = False
113
111
            has_one = has_one or self.check_hook(
114
 
                r + '-relation-changed', hooks_path, required=False)
115
 
            has_one = has_one or self.check_hook(
116
 
                r + '-relation-departed', hooks_path, required=False)
117
 
            has_one = has_one or self.check_hook(
118
 
                r + '-relation-joined', hooks_path, required=False)
119
 
            has_one = has_one or self.check_hook(
120
 
                r + '-relation-broken', hooks_path, required=False)
 
112
                r + '-relation-changed', hooks_path)
 
113
            has_one = has_one or self.check_hook(
 
114
                r + '-relation-departed', hooks_path)
 
115
            has_one = has_one or self.check_hook(
 
116
                r + '-relation-joined', hooks_path)
 
117
            has_one = has_one or self.check_hook(
 
118
                r + '-relation-broken', hooks_path)
121
119
 
122
120
            if not has_one and not subordinate:
123
121
                self.info("relation " + r + " has no hooks")
283
281
                        with open(os.path.join(charm_path, 'icon.svg')) as ci:
284
282
                            icon_sha1.update(ci.read())
285
283
                    if template_sha1.hexdigest() == icon_sha1.hexdigest():
286
 
                        lint.err("Includes template icon.svg file.")
 
284
                        lint.warn("Includes template icon.svg file.")
287
285
                except IOError as e:
288
 
                    lint.err(
 
286
                    lint.warn(
289
287
                        "Error while opening %s (%s)" %
290
288
                        (e.filename, e.strerror))
291
289
 
292
290
            # Must have a hooks dir
293
291
            if not os.path.exists(hooks_path):
294
 
                lint.err("no hooks directory")
 
292
                lint.info("no hooks directory")
295
293
 
296
294
            # Must have a copyright file
297
295
            if not os.path.exists(os.path.join(charm_path, 'copyright')):
298
 
                lint.err("no copyright file")
 
296
                lint.warn("no copyright file")
299
297
 
300
298
            # should have a readme
301
299
            root_files = os.listdir(charm_path)
305
303
                    found_readmes.add(filename)
306
304
            if len(found_readmes):
307
305
                if 'README.ex' in found_readmes:
308
 
                    lint.err("Includes template README.ex file")
 
306
                    lint.warn("Includes template README.ex file")
309
307
                try:
310
308
                    with open(TEMPLATE_README) as tr:
311
309
                        bad_lines = []
324
322
                                    if l in readme_content:
325
323
                                        err_msg = ('%s Includes boilerplate '
326
324
                                                   'README.ex line %d')
327
 
                                        lint.err(err_msg % (readme, lc))
 
325
                                        lint.warn(err_msg % (readme, lc))
328
326
                except IOError as e:
329
 
                    lint.err(
 
327
                    lint.warn(
330
328
                        "Error while opening %s (%s)" %
331
329
                        (e.filename, e.strerror))
332
330
            else:
342
340
                lint.check_relation_hooks(provides, subordinate, hooks_path)
343
341
            else:
344
342
                if not subordinate:
345
 
                    lint.warn("all charms should provide at least one thing")
 
343
                    lint.info("all charms should provide at least one thing")
346
344
 
347
345
            if subordinate:
348
346
                try:
382
380
                except (TypeError, ValueError):
383
381
                    lint.warn("revision should be a positive integer")
384
382
 
385
 
            lint.check_hook('install', hooks_path)
386
 
            lint.check_hook('start', hooks_path, required=False,
387
 
                            recommended=True)
388
 
            lint.check_hook('stop', hooks_path, required=False,
389
 
                            recommended=True)
390
 
            lint.check_hook('config-changed', hooks_path, required=False)
 
383
            lint.check_hook('install', hooks_path, recommended=True)
 
384
            lint.check_hook('start', hooks_path, recommended=True)
 
385
            lint.check_hook('stop', hooks_path, recommended=True)
 
386
            if os.path.exists(os.path.join(charm_path, 'config.yaml')):
 
387
                lint.check_hook('config-changed', hooks_path, recommended=True)
 
388
            else:
 
389
                lint.check_hook('config-changed', hooks_path)
391
390
        except IOError:
392
391
            lint.err("could not find metadata file for " + charm_name)
393
392
            lint.exit_code = -1
394
393
 
395
394
        # Should not have autogen test
396
395
        if os.path.exists(os.path.join(charm_path, 'tests', '00-autogen')):
397
 
            lint.warn('has templated 00-autogen test file')
 
396
            lint.warn('Includes template test file, tests/00-autogen')
398
397
 
399
398
        rev_path = os.path.join(charm_path, 'revision')
400
399
        if os.path.exists(rev_path):