Skip to content

Commit 08a0f1a

Browse files
committed
pep8 cleanup
1 parent 21e066b commit 08a0f1a

16 files changed

+490
-348
lines changed

automaton.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def __init__(self, config, clusters):
2121
Thread.__init__(self)
2222
self.config = config
2323
self.clusters = clusters
24+
2425
def run(self):
2526
LOG.info("Starting Automaton")
2627
#TODO(pdmars): do something
@@ -47,7 +48,7 @@ def run(self):
4748
cluster.launch()
4849
if self.config.options.terminate_cluster:
4950
cluster.connect()
50-
if self.config.options.terminate_cluster=="all":
51+
if self.config.options.terminate_cluster == "all":
5152
cluster.terminate_all()
5253
else:
5354
cluster.terminate(self.config.options.terminate_cluster)
@@ -60,20 +61,22 @@ def run(self):
6061
if self.config.options.excute_benchmarks:
6162
cluster.connect()
6263
cluster.excute_benchmarks()
63-
64+
65+
6466
def clean_exit(signum, frame):
6567
global SIGEXIT
6668
SIGEXIT = True
6769
LOG.critical("Exit signal received. Exiting at the next sane time. "
6870
"Please stand by.")
6971

72+
7073
def main():
7174
(options, args) = parse_options()
7275
configure_logging(options.debug)
73-
76+
7477
config = Config(options)
7578
clusters = Clusters(config)
76-
79+
7780
signal.signal(signal.SIGINT, clean_exit)
7881
automaton = Automaton(config, clusters)
7982
automaton.start()
@@ -83,4 +86,4 @@ def main():
8386
automaton.join(timeout=1.0)
8487

8588
if __name__ == "__main__":
86-
main()
89+
main()

deployment/common.py

+18-11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from lib import util
88

9+
910
def get_run_levels(dir_path):
1011
"""Return sorted list of directory content
1112
@@ -21,7 +22,8 @@ def get_run_levels(dir_path):
2122
for item in folder_contents:
2223
item_first_chr = item.split("-")[0]
2324
try:
24-
if os.path.isdir(os.path.join(dir_path,item)) and item_first_chr.isdigit():
25+
if os.path.isdir(os.path.join(dir_path, item)) and \
26+
item_first_chr.isdigit():
2527
contents.append(item)
2628
except:
2729
continue
@@ -30,10 +32,12 @@ def get_run_levels(dir_path):
3032
except OSError:
3133
return False
3234

35+
3336
def get_executable_files(run_level_dir):
3437
"""get executable files from a directory
3538
36-
Given a directory, walk into it and return absolute path of files that are executable
39+
Given a directory, walk into it and return absolute path of files
40+
that are executable
3741
3842
Args:
3943
run_level_dir ( string ) : directory path
@@ -45,25 +49,27 @@ def get_executable_files(run_level_dir):
4549
scripts_list = []
4650
for root, dirs, files in os.walk(run_level_dir):
4751
for afile in files:
48-
file_abs_path = os.path.join(root,afile)
52+
file_abs_path = os.path.join(root, afile)
4953
if util.is_executable_file(file_abs_path):
50-
scripts_list.append(os.path.join(root,afile))
54+
scripts_list.append(os.path.join(root, afile))
5155
return scripts_list
5256

5357

5458
def get_stages(mode, levels_dir, remote_dir=""):
55-
""" Get the stages of execution in a dict format
59+
"""Get the stages of execution in a dict format
5660
57-
Given a root directory of the stages, loop over those levels and extract all executable scripts
58-
based on given mode, i.e : client or server.
61+
Given a root directory of the stages, loop over those levels and
62+
extract all executable scripts based on given mode, i.e : client
63+
or server.
5964
6065
Args:
6166
mode (string) : client or server
6267
levels_dir (string) : deployment stage root dir
6368
6469
return:
65-
stages_dict (dict) : every key represent an execution level, the value of that key is list of all
66-
executable scripts in that level.
70+
stages_dict (dict) : every key represent an execution level,
71+
the value of that key is list of all executable scripts in
72+
that level.
6773
6874
"""
6975
stages_dict = {}
@@ -80,6 +86,7 @@ def get_stages(mode, levels_dir, remote_dir=""):
8086
stages_dict[level] = get_executable_files(abs_path_w_mode)
8187

8288
for key, value in stages_dict.iteritems():
83-
stages_dict[key] = [ x.replace(levels_dir,remote_dir,1) for x in value ]
89+
stages_dict[key] = [x.replace(levels_dir, remote_dir, 1)
90+
for x in value]
8491

85-
return stages_dict
92+
return stages_dict

deployment/engine.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
order of execution
44
"""
55

6+
67
class StagedDeploymentEngine(object):
78

89
def __init__(self):

deployment/executor.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ def execute_one_level(self, run_level):
1818
cmds_in_run_level = self.staged_dict[run_level]
1919

2020
for command in cmds_in_run_level:
21-
remote_command = util.RemoteCommand(self.hostname, self.private_key, command)
21+
remote_command = util.RemoteCommand(self.hostname,
22+
self.private_key, command)
2223
return_code = remote_command.execute()
23-
result_dict[command] = (return_code, remote_command.stdout, remote_command.stderr)
24+
result_dict[command] = (return_code, remote_command.stdout,
25+
remote_command.stderr)
2426

2527
if return_code != 0:
2628
break

etc/global.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[DEFAULT]
22
key_name = automaton
3-
key_path = /Users/suiyuan0226/.ssh/id_rsa.pub
3+
key_path = /Users/voran/.ssh/id_rsa.pub
44
ssh_priv_key = /Users/suiyuan0226/.ssh/automaton.pem
55
git_repo_home = /home/staged-deployment-scripts
66
git_repo_location = https://github.com/alal3177/staged-deployment-scripts.git

examples/engine.py

+22-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
"""
2-
This entire file is just an example to demonstrate functionality of staged deployment.
3-
We will implement the execution workflow here when we have more time.
1+
"""This entire file is just an example to demonstrate functionality
2+
of staged deployment. We will implement the execution workflow here
3+
when we have more time.
4+
45
"""
56

67
import shutil
@@ -13,38 +14,39 @@
1314
config_file = "../etc/global.conf"
1415

1516
# clone the repo locally
16-
my_local_folder = util.clone_git_repo(util.read_config(config_file).get("DEFAULT","git_repo_location"))
17+
git_repo_location = util.read_config(config_file).get("DEFAULT",
18+
"git_repo_location")
19+
my_local_folder = util.clone_git_repo(git_repo_location)
1720

1821
# we fill a dict with our stages
19-
stages = common.get_stages("client", my_local_folder, util.read_config(config_file).get("DEFAULT","git_repo_home"))
20-
22+
git_repo_home = util.read_config(config_file).get("DEFAULT", "git_repo_home")
23+
stages = common.get_stages("client", my_local_folder, git_repo_home)
2124

2225
# remove the directory since it is not needed anymore
23-
shutil.rmtree(my_local_folder,ignore_errors=True)
26+
shutil.rmtree(my_local_folder, ignore_errors=True)
2427

2528
# clone the repo to the vm
26-
remote_clone_result = util.RemoteCommand("vm-148-120.uc.futuregrid.org",\
27-
util.read_config(config_file).get("DEFAULT", "ssh_priv_key"),
28-
"git clone %s %s" % (util.read_config(config_file).get("DEFAULT","git_repo_location") ,
29-
util.read_config(config_file).get("DEFAULT","git_repo_home"))).execute()
29+
ssh_priv_key = util.read_config(config_file).get("DEFAULT", "ssh_priv_key")
30+
cmd = "git clone %s %s" % (git_repo_location, git_repo_home)
31+
remote_clone_result = util.RemoteCommand("vm-148-120.uc.futuregrid.org",
32+
ssh_priv_key, cmd).execute()
3033

3134
# initiate executor class with the stages
32-
exec_obj = Executor("vm-148-120.uc.futuregrid.org",
33-
util.read_config(config_file).get("DEFAULT", "ssh_priv_key"),
34-
stages)
35+
exec_obj = Executor("vm-148-120.uc.futuregrid.org", ssh_priv_key,
36+
stages)
3537

36-
# loop over all available stages that has a script with execution bit set and execute it
37-
# if any of the commands at stage 0 failed for example, then we abort the execution and do not go
38-
# to next stage
38+
# loop over all available stages that has a script with execution bit
39+
# set and execute it. if any of the commands at stage 0 failed for
40+
# example, then we abort the execution and do not go to next stage
3941

4042
abort = False
4143
for each_stage in stages:
4244
if not abort:
4345
all_commands_result = exec_obj.execute_one_level(each_stage)
44-
print "done with %s and all commands results are : %s" % (each_stage, str(all_commands_result))
46+
print "done with %s and all commands results are : %s" % \
47+
(each_stage, str(all_commands_result))
4548
for command_result in all_commands_result:
46-
result, stdout, stderr = all_commands_result[command_result]
49+
result, stdout, stderr = all_commands_result[command_result]
4750
if result != 0:
4851
abort = True
4952
break
50-

graphing/graphing.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
from parser import Parser
33
from lib.util import read_path
44

5+
56
class Graph(object):
6-
def __init__(self,config):
7+
def __init__(self, config):
78
self.config = config
89
self.parser = Parser(self.config)
910
self.graph_path = self.config.globals.graph_path
@@ -13,26 +14,26 @@ def __init__(self,config):
1314
def generate_graph(self):
1415
raw_data = self.parser.get_mean()
1516
for item in raw_data:
16-
data=list()
17+
data = list()
1718
for n in range(len(self.attributes)):
1819
data.append(item[n+1])
19-
figure_name = '%s/%s.png' % (self.graph_path,item[0])
20-
figure = bar_graph(item[0],self.attributes,data,figure_name)
21-
20+
figure_name = '%s/%s.png' % (self.graph_path, item[0])
21+
figure = bar_graph(item[0], self.attributes, data, figure_name)
22+
2223

23-
def bar_graph(title,x_value,y_value,path):
24+
def bar_graph(title, x_value, y_value, path):
2425
fig = plt.figure()
25-
ax = fig.add_subplot(1,1,1)
26+
ax = fig.add_subplot(1, 1, 1)
2627
x = range(len(y_value))
2728

28-
rects = ax.bar(x, y_value, facecolor='#777777', edgecolor='black',align='center',yerr=0.1,width=0.5)
29+
rects = ax.bar(x, y_value, facecolor='#777777', edgecolor='black',
30+
align='center', yerr=0.1, width=0.5)
2931
ax.set_title(title)
3032
ax.set_xticks(x)
3133
ax.set_xticklabels(x_value)
3234
for rect in rects:
3335
height = rect.get_height()
34-
plt.text(rect.get_x()+rect.get_width()/4, 1.01*height, '%s' % float(height))
36+
plt.text(rect.get_x()+rect.get_width()/4, 1.01*height, '%s' %
37+
float(height))
3538
#plt.show()
3639
fig.savefig(path)
37-
38-

0 commit comments

Comments
 (0)