~timrchavez/ubuntu-system-image/server-cli-scripts-wip

« back to all changes in this revision

Viewing changes to bin/remove-channel

  • Committer: Timothy Chavez
  • Date: 2014-01-13 20:48:29 UTC
  • Revision ID: timothy.chavez@canonical.com-20140113204829-ej8pjni6na86do16
Add some CLI scripts to add and remove channels and devices and generate keys.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- coding: utf-8 -*-
 
3
#
 
4
# Copyright (C) 2014 Canonical Ltd.
 
5
# Author: Timothy Chavez <timothy.chavez@canonical.com>
 
6
#
 
7
# This program is free software: you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation; version 3 of the License.
 
10
#
 
11
# This program is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
import argparse
 
20
import fcntl
 
21
import os
 
22
import sys
 
23
sys.path.insert(0, "lib")
 
24
 
 
25
from systemimage import config
 
26
from systemimage import tree
 
27
 
 
28
 
 
29
def main():
 
30
    parser = argparse.ArgumentParser(description="Remove an update channel.")
 
31
    parser.add_argument("--name", dest="name", required=True,
 
32
                        help="The name of the update channel")
 
33
    args = parser.parse_args()
 
34
 
 
35
    conf = config.Config()
 
36
 
 
37
    print "I: Removing channel: {0}".format(args.name)
 
38
 
 
39
    lock_file = os.path.join(conf.state_path, "global.lock")
 
40
    fd = open(lock_file, "w")
 
41
 
 
42
    try:
 
43
        fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
 
44
    except IOError:
 
45
        print("E: Something else holds the global lock. Exiting.")
 
46
        sys.exit(0)
 
47
 
 
48
    pub = tree.Tree(conf)
 
49
    try:
 
50
        pub.remove_channel(args.name)
 
51
    except KeyError, err:
 
52
        print "E: {0}".format(err.message),
 
53
    else:
 
54
        print "I: Done",
 
55
 
 
56
    os.remove(lock_file)
 
57
    print
 
58
 
 
59
 
 
60
if __name__ == "__main__":
 
61
    main()