#!/usr/bin/python import getopt, os, sys, base64 sys.path.append(".") sys.path.append("pydar") sys.path.append("/usr/share/pydar2/pydar") from xmlrpclib import Server from log4py import Logger from config import Config from pydarclient import PydarClient from optparse import OptionParser class RemoteClient: def __init__(self): self.__cat = Logger().get_instance(self) self.__config = Config.getInstance() self.__client = PydarClient(self.__config.getBuildMasterUrlClient()) def doBuildSpecByPath(self, userId,password, specRepoName, specFilePath, toEmail, distroArchTag, priority, target): self.__cat.debug("specFilePath=" + specFilePath + ",mailto=" + toEmail + ",distroArchTag=" + distroArchTag) self.__client.buildSpecByPath(userId, password, specRepoName, specFilePath, toEmail, distroArchTag, priority, target) def doTestBuildSpecByPath(self, userId,password,fileContents, toEmail, distroArchTag, priority): self.__cat.debug("userId=" + userId + ",mailto=" + toEmail + ",distroArchTag=" + distroArchTag) self.__client.testBuildSpecByPath(userId, password, fileContents, toEmail, distroArchTag, priority) def doUpdateSite(self,userId,password,specRepoName): self.__client.callUpdateSiteScript(userId,password,specRepoName) myUsage = "pydar-remote [options] " parser = OptionParser(usage=myUsage) parser.add_option("-c", "--clientconfig", default=None, dest="clientconfig", help="specify configuration file", metavar="FILE") (options, args) = parser.parse_args() Config.getInstance().specifyGetOptOptions(options) password = Config.getInstance().getClientPassword() myClient = RemoteClient() if len(args) < 2 or args[1] == "": print "known commands:" print " build " print " rebuild a specfile from a specrepository on the server and use the specified releasetag and machroot" print " testbuild " print " rebuild a spec file from your local disk on the server " print " site " print " call the script which builds the site" sys.exit(1) print "argv len: " + str(len(args)) if args[0] == "build" and len(args) == 8: myClient.doBuildSpecByPath(args[1],password,args[2], args[3], args[4], args[5], args[6], args[7]) if args[0] == "build" and len(args) != 8: print str(len(args)) + " args for 'build' but expected 8" if args[0] == "testbuild" and len(args) == 6: # get the file fileName = args[2] if os.path.exists(fileName): f = open(fileName) fileContents = f.read() f.close() fileContentsEncoded = base64.encodestring(fileContents) myClient.doTestBuildSpecByPath(args[1],password,fileContentsEncoded, args[3], args[4], args[5]) else: print fileName + " does not exist" if args[0] == "testbuild" and len(args) != 6: print str(len(args)) + " args for 'testbuild' but expected 6" if args[0] == "site": myClient.doUpdateSite(args[1],password,args[2])