import time
import threading
import multiprocessing
+import socket
from multiprocessing import Process, cpu_count
from kafka import KafkaConsumer
from kafka import KafkaProducer
class GbsBuild(object):
errorRule = re.compile(r"some packages failed to be built")
+ ips = ['109.123.100.182','109.123.100.139','109.123.100.72']
+ cpus = [8,4,4]
def __init__(self,packageName, id):
super(GbsBuild, self).__init__()
self.sourcePath = "/home/scm/renjg/workspace"
self.gbsRoot = "/home/scm/GBS-ROOT"
self.packageName = packageName
self.threadId = id
+ self.result = "/home/scm/GBS-ROOT-%d/local/results" % id
+ self.localip = socket.gethostbyname(socket.gethostname())
def build(self):
os.system("cd %s" % (self.sourcePath))
os.system("mkdir -p %s" % self.logPath)
if GbsBuild.errorRule.findall(result):
print "%s build error \n log file is: %s/%s.log" % (self.packageName, self.logPath, self.packageName)
return "Fail"
- os.system("scp -r %s renjg@109.123.123.6:/home/renjg/GBS-ROOT/local/repos/unified_standard/" % (self.gbsRoot+"-"+str(self.threadId)+"/local/repos/unified_standard/armv7l/"))
- print "%s package in process %d ,build done, copy done" % (self.packageName, self.threadId)
+ #os.system("scp -r %s renjg@109.123.123.6:/home/renjg/GBS-ROOT/local/repos/unified_standard/" % (self.gbsRoot+"-"+str(self.threadId)+"/local/repos/unified_standard/armv7l/"))
+ print "%s package in process %d ,build done" % (self.packageName, self.threadId)
return "Success"
+ def syncResult(self):
+ buildFiles = []
+ with open(self.result, "r") as f:
+ buildFiles.append(f.readline)
+ os.system("rm -rf %s" % self.result)
+ if not buildFiles:
+ return
+ for ip, cpunumber in zip(GbsBuild.ips, GbsBuild.cpus):
+ if ip == self.localip:
+ for i in xrange(cpunumber):
+ if i == self.threadId:
+ continue
+ else:
+ print "copy to %s GBS-ROOT-%d" % (ip, i)
+ for file in buildFiles:
+ os.popen("cp %s /home/scm/GBS-ROOT-%d/local/repos/unified_standard/armv7l/RPMS/" % (file, i))
+ else:
+ for i in xrange(cpunumber):
+ print "copy to %s GBS-ROOT-%d" % (ip, i)
+ for file in buildFiles:
+ os.popen("scp %s samsung@%s:/home/scm/GBS-ROOT-%d/local/repos/unified_standard/armv7l/RPMS/" % (file, ip, i))
class Consumer(Process):
def __init__(self, threadId, partition = 0):
else:
print "send fail"
self.messageHandler.close()
+ gbsbuild.syncResult()
+ print "sync done"
class LargeConsumer(Process):
def __init__(self, threadId, partition = 0):
else:
print "send fail"
self.messageHandler.close()
+ gbsbuild.syncResult()
+ print "sync done"
class WorkerPool(object):
capcaticy = cpu_count()