1 | #!/usr/bin/env python |
---|
2 | #--------------------------------# |
---|
3 | # Author: V.garonne # |
---|
4 | # Mail: garonne@lal.in2p3.fr # |
---|
5 | # Description: script to create # |
---|
6 | # automaticaly a release # |
---|
7 | #--------------------------------# |
---|
8 | |
---|
9 | import pexpect |
---|
10 | import sys, os |
---|
11 | import string |
---|
12 | import commands |
---|
13 | import shutil |
---|
14 | import socket |
---|
15 | import tarfile, gzip |
---|
16 | import threading |
---|
17 | |
---|
18 | # my own stuffs |
---|
19 | from utils.ssh_session import * |
---|
20 | from p3 import decrypt |
---|
21 | |
---|
22 | #--------------------# For the Multi-threaded version #-------------------------# |
---|
23 | class constructor (threading.Thread): |
---|
24 | |
---|
25 | # static counter |
---|
26 | counter = 1 |
---|
27 | def __init__(self, host, user, pwd, version, machine): |
---|
28 | self.host = host |
---|
29 | self.user = user |
---|
30 | self.pwd = pwd |
---|
31 | self.version = version |
---|
32 | self.machine = machine |
---|
33 | print self.host, self.user, self.pwd |
---|
34 | self.number = constructor.counter |
---|
35 | constructor.counter = constructor.counter + 1 |
---|
36 | threading.Thread.__init__(self, target=self.run) |
---|
37 | |
---|
38 | def run (self): |
---|
39 | hostname = socket.gethostname() |
---|
40 | # first do a ssh connection |
---|
41 | preambule = 'create_bintar '+ str(constructor.counter) +' > ' |
---|
42 | if self.host != hostname: |
---|
43 | session = ssh_session (user=self.user, host=self.host, password=self.pwd, verbose=1) |
---|
44 | print session.ssh('hostname') |
---|
45 | # copy the source code on the build machine |
---|
46 | # in fact the input sandbox in grid terms |
---|
47 | if self.host != hostname: |
---|
48 | if os.path.exists ("CMT"+self.version+".tar.gz"): |
---|
49 | session.scp ("CMT"+self.version+".tar.gz",'.') |
---|
50 | else: |
---|
51 | print preambule + "CMT"+self.version+".tar.gz" + ' not found' |
---|
52 | sys.exit(-1) |
---|
53 | |
---|
54 | if os.path.exists ("tarfile.py"): |
---|
55 | session.scp ("tarfile.py",'.') |
---|
56 | |
---|
57 | if os.path.exists ("cmt_build_binaries"): |
---|
58 | session.scp ("cmt_build_binaries",'.') |
---|
59 | else: |
---|
60 | print preambule + "cmt_build_binaries" + ' not found' |
---|
61 | sys.exit(-1) |
---|
62 | |
---|
63 | cmd = "./cmt_build_binaries "+ self.version + " "+ self.machine |
---|
64 | print preambule + cmd |
---|
65 | if self.host != hostname: |
---|
66 | print session.ssh(cmd) |
---|
67 | else: |
---|
68 | status, output = commands.getstatusoutput (cmd) |
---|
69 | print output |
---|
70 | |
---|
71 | # get bin directory |
---|
72 | file = 'CMT'+self.version+self.machine+'.tar.gz' |
---|
73 | if self.host != hostname: |
---|
74 | file = 'CMT'+self.version+self.machine+'.tar.gz' |
---|
75 | #session.scpget (src='CMT/'+version+'/'+machine , dst='tmp/CMT/'+version+'/.', option='r') |
---|
76 | session.scpget (file, '.') |
---|
77 | # Clean up |
---|
78 | cmd = 'rm -rf '+ file + ' CMT ;' |
---|
79 | print preambule + cmd |
---|
80 | session.ssh (cmd) |
---|
81 | else: |
---|
82 | |
---|
83 | print preambule + 'build the pacman kit' |
---|
84 | cmd = 'cd CMT/'+self.version+'/mgr/;' |
---|
85 | if sys.platform == 'darwin': |
---|
86 | cmd = cmd + 'make' |
---|
87 | else: |
---|
88 | cmd = cmd + 'gmake' |
---|
89 | status, output = commands.getstatusoutput (cmd) |
---|
90 | file = 'CMT-'+self.version+'.pacman' |
---|
91 | #shutil.copy ('CMT/'+self.version+'/mgr/CMT.pacman', 'CMT/'+self.version+'/mgr/' + file) |
---|
92 | #shutil.copy ('CMT/'+self.version+'/mgr/' + file , file) |
---|
93 | print output |
---|
94 | #Clean up |
---|
95 | shutil.rmtree('CMT') |
---|
96 | |
---|
97 | #--------------------# MAIN #-------------------------# |
---|
98 | #if __name__ == '__main__': |
---|
99 | def cmt_create_bintar (version): |
---|
100 | path = 'tmp/CMT/' |
---|
101 | proxy = '.cmtproxy' |
---|
102 | preambule = 'build_release > ' |
---|
103 | here = os.getcwd() |
---|
104 | hostname = socket.gethostname() |
---|
105 | tarballs = list() |
---|
106 | srctar = "CMT"+version+".tar.gz" |
---|
107 | |
---|
108 | if not os.path.exists (srctar): |
---|
109 | print preambule + srctar + 'not exists' |
---|
110 | sys.exit(-1) |
---|
111 | |
---|
112 | if not os.path.exists (proxy): |
---|
113 | print preambule + 'First create the proxy' |
---|
114 | sys.exit(-1) |
---|
115 | pool = eval(decrypt('.cmtproxy')) |
---|
116 | |
---|
117 | # for machine in pool: |
---|
118 | # host = pool[machine]['machine'] |
---|
119 | # user = pool[machine]['user'] |
---|
120 | # pwd = pool[machine] ['pwd'] |
---|
121 | #print host, user, pwd, machine |
---|
122 | |
---|
123 | # build the binaries |
---|
124 | print preambule + 'build the binaries' |
---|
125 | threads = [] |
---|
126 | # pool = { |
---|
127 | # 'Linux-i686':pool['Linux-i686'], |
---|
128 | # 'VisualC':pool['VisualC'] |
---|
129 | # 'CYGWIN_NT-5.1-i686':pool['CYGWIN_NT-5.1-i686'] |
---|
130 | # } |
---|
131 | #pool = {'Linux-x86_64':pool['Linux-x86_64']} |
---|
132 | #pool = {'Darwin-PowerMacintosh':pool['Darwin-PowerMacintosh']} |
---|
133 | pool = { |
---|
134 | 'CYGWIN_NT-5.1-i686':pool['CYGWIN_NT-5.1-i686'] , |
---|
135 | 'VisualC':pool['VisualC'] |
---|
136 | } |
---|
137 | # 'OSF1-alpha': 'Linux-i686': 'Linux-x86_64': 'SunOS-sun4u': 'AIX-002064874C00': |
---|
138 | # 'Darwin-PowerMacintosh' 'CYGWIN_NT-5.1-i686' 'VisualC' |
---|
139 | |
---|
140 | for machine in pool: |
---|
141 | # print pool[machine]['machine'], pool[machine]['user'], pool[machine] ['pwd'] |
---|
142 | cmd = "./cmt_build_binaries "+ version + " "+ machine |
---|
143 | print cmd |
---|
144 | #sys.exit(-1) |
---|
145 | for machine in pool: |
---|
146 | host = pool[machine]['machine'] |
---|
147 | if host == '134.158.72.234' or host=='wl-72137.lal.in2p3.fr': |
---|
148 | host = '134.158.72.143' |
---|
149 | #host = '134.158.72.121' |
---|
150 | |
---|
151 | user = pool[machine]['user'] |
---|
152 | pwd = pool[machine] ['pwd'] |
---|
153 | print host, user, pwd, machine |
---|
154 | thread = constructor( host=host, user=user, pwd=pwd, version=version, machine=machine) |
---|
155 | threads.append (thread) |
---|
156 | thread.run() |
---|
157 | #thread.start() |
---|
158 | |
---|
159 | #for thread in threads: |
---|
160 | # thread.join () |
---|
161 | #----------------------- End Of File --------------------------# |
---|