~robru/cupstream2distro/stop-hardcoding-spreadsheet-column-numbers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2012 Canonical
#
# Authors:
#  Didier Roche
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 3.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

import argparse
import logging
import sys
import time

from cupstream2distro.stack import Stack
from cupstream2distro.settings import TIME_BETWEEN_STACK_CHECKS


if __name__ == '__main__':

    logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")

    parser = argparse.ArgumentParser(description="Wait on other stacks to finish their work to exit",
                                     epilog="Stack should be in a directory matching their current stack name stacks and all should have the same parent dir.")
    args = parser.parse_args()

    stack = Stack.get_current_stack()
    waiting_on_stacks = stack.get_direct_depending_stacks()

    if not waiting_on_stacks:
        logging.info("No depending stacks were found. This steps should even not be called.")
        sys.exit(0)

    while(True):
        for stack in waiting_on_stacks[:]:  # as we modify the list, makes a copy first
            logging.info("Waiting on {} ({})".format(stack.stack_name, stack.release))
            if not stack.is_started():
                logging.info("Stack {} ({}) is stopped".format(stack.stack_name, stack.release))
                waiting_on_stacks.remove(stack)
        if not waiting_on_stacks:
            break
        time.sleep(TIME_BETWEEN_STACK_CHECKS)