cbfb737834fb0c2de2f683b77f714124a8db52f6
[osm/RO.git] / osm_ro / vmware_utils / OVF_converter / format_converter / command_progress.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 ##
5 # Copyright 2016-2017 VMware Inc.
6 # This file is part of ETSI OSM
7 # All Rights Reserved.
8 #
9 # Licensed under the Apache License, Version 2.0 (the "License"); you may
10 # not use this file except in compliance with the License. You may obtain
11 # a copy of the License at
12 #
13 # http://www.apache.org/licenses/LICENSE-2.0
14 #
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18 # License for the specific language governing permissions and limitations
19 # under the License.
20 #
21 # For those usages not covered by the Apache License, Version 2.0 please
22 # contact: osslegalrouting@vmware.com
23 ##
24
25 import threading
26 import sys
27
28 class RepeatingTimer(threading._Timer):
29 """ Class to run thread parally """
30 def run(self):
31 """ Method to run thread """
32 while True:
33 self.finished.wait(self.interval)
34 if self.finished.is_set():
35 return
36 else:
37 self.function(*self.args, **self.kwargs)
38
39
40 class CommandProgressbar(object):
41 """ Class to show progressbar while waiting fro command output """
42
43 def __init__(self):
44 self.timer = None
45
46 def __show_progressbar(self):
47 """
48 Private method to show progressbar while waiting for command to complete
49 Args : None
50 Return : None
51 """
52 print '\b.',
53 sys.stdout.flush()
54
55 def start_progressbar(self):
56 """
57 Method to start progressbar thread
58 Args : None
59 Return : None
60 """
61 self.timer = RepeatingTimer(1.0, self.__show_progressbar)
62 self.timer.daemon = True # Allows program to exit if only the thread is alive
63 self.timer.start()
64
65 def stop_progressbar(self):
66 """
67 Method to stop progressbar thread
68 Args : None
69 Return : None
70 """
71 self.timer.cancel()