PageRenderTime 142ms CodeModel.GetById 60ms app.highlight 4ms RepoModel.GetById 77ms app.codeStats 0ms

/silverlining/mgr-scripts/disable.py

https://bitbucket.org/ianb/silverlining/
Python | 39 lines | 32 code | 6 blank | 1 comment | 11 complexity | fb4010cfec7a32c8a294ee0a3d9fa414 MD5 | raw file
 1#!/usr/bin/env python
 2
 3import sys
 4sys.path.insert(0, '/usr/local/share/silverlining/lib')
 5import optparse
 6from silversupport import disabledapps
 7from silversupport import appdata
 8
 9parser = optparse.OptionParser(
10    usage='%prog application')
11
12parser.add_option(
13    '--enable',
14    action='store_true',
15    help='renable a previously disabled application')
16
17
18def main():
19    options, args = parser.parse_args()
20    application, = args
21    in_use = any(True for instance, uses in appdata.all_app_instances().items()
22                 if instance.startswith(application + '.') and uses)
23    if not in_use:
24        sys.stderr.write("%s is not in use in appdata.map\n" % application)
25        return 1
26    if options.enable:
27        if not disabledapps.is_disabled(application):
28            sys.stderr.write("%s is not disabled\n" % application)
29            return 1
30        disabledapps.enable_application(application)
31    else:
32        if disabledapps.is_disabled(application):
33            sys.stderr.write("%s is already disabled\n" % application)
34            return 1
35        disabledapps.disable_application(application)
36    return 0
37
38if __name__ == '__main__':
39    sys.exit(main())