blob: 8ccef6c466592b362ed5adc0ec8cfacc353d1901 (
plain)
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
|
import subprocess
import time
_logger = None
def set_logger(logger):
global _logger
_logger = logger
def run(args, log=None, test=False, retry=0):
print " ".join(args)
if test:
return
full_args = args[:]
if log is not None:
full_args.insert(0, _logger)
full_args.append(log)
tries = 0
while tries < retry + 1:
try:
tries = tries + 1
subprocess.check_call(full_args)
return
except subprocess.CalledProcessError, e:
if tries < retry + 1:
print "Retrying (attempt %d) in 1 minute" % tries
time.sleep(60)
else:
raise e
def run_with_sudo(args, test=False, retry=0):
args_with_sudo = ["sudo"]
args_with_sudo.extend(args)
run(args_with_sudo, test=test, retry=retry)
|