~larry-e-works/uci-engine/amqp-to-kombu

« back to all changes in this revision

Viewing changes to cupstream2distro/wait-on-stacks

  • Committer: Francis Ginther
  • Date: 2014-06-10 20:42:46 UTC
  • mto: This revision was merged to the branch mainline in revision 571.
  • Revision ID: francis.ginther@canonical.com-20140610204246-b1bsrik7nlcolqy7
Import lp:cupstream2distro rev 605.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- coding: utf-8 -*-
 
3
# Copyright (C) 2012 Canonical
 
4
#
 
5
# Authors:
 
6
#  Didier Roche
 
7
#
 
8
# This program is free software; you can redistribute it and/or modify it under
 
9
# the terms of the GNU General Public License as published by the Free Software
 
10
# Foundation; version 3.
 
11
#
 
12
# This program is distributed in the hope that it will be useful, but WITHOUT
 
13
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
14
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
15
# details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License along with
 
18
# this program; if not, write to the Free Software Foundation, Inc.,
 
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
20
 
 
21
import argparse
 
22
import logging
 
23
import sys
 
24
import time
 
25
 
 
26
from cupstream2distro.stack import Stack
 
27
from cupstream2distro.settings import TIME_BETWEEN_STACK_CHECKS
 
28
 
 
29
 
 
30
if __name__ == '__main__':
 
31
 
 
32
    logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
 
33
 
 
34
    parser = argparse.ArgumentParser(description="Wait on other stacks to finish their work to exit",
 
35
                                     epilog="Stack should be in a directory matching their current stack name stacks and all should have the same parent dir.")
 
36
    args = parser.parse_args()
 
37
 
 
38
    stack = Stack.get_current_stack()
 
39
    waiting_on_stacks = stack.get_direct_depending_stacks()
 
40
 
 
41
    if not waiting_on_stacks:
 
42
        logging.info("No depending stacks were found. This steps should even not be called.")
 
43
        sys.exit(0)
 
44
 
 
45
    while(True):
 
46
        for stack in waiting_on_stacks[:]:  # as we modify the list, makes a copy first
 
47
            logging.info("Waiting on {} ({})".format(stack.stack_name, stack.release))
 
48
            if not stack.is_started():
 
49
                logging.info("Stack {} ({}) is stopped".format(stack.stack_name, stack.release))
 
50
                waiting_on_stacks.remove(stack)
 
51
        if not waiting_on_stacks:
 
52
            break
 
53
        time.sleep(TIME_BETWEEN_STACK_CHECKS)