def testExecute(self): arguments = ArgumentParser(['bmn.py','buildman','--file','bmtests/data/batch-buildman.xml']) bm = BuildMan(arguments) plugin = PlugInManager().getPlugInInstance("BuildManPlugIn") plugin._goalList = [] plugin.execute()
def execute(self): dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if dmplugin == None: self.reportError("DepMan PlugIn not found") return False if self._projectPath=="": self.reportError("Missing required project path option") return False self._projectPath = os.path.abspath(self._projectPath) if self._compiler=="": self._compiler = dmplugin.getOSCompiler() if self._projectName == "": self._projectName = os.path.basename(self._projectPath) if self._projectGenerationPath == "": self._projectGenerationPath = os.path.join(self._projectPath, "BMCMake") else: self._projectGenerationPath = os.path.abspath(self._projectGenerationPath) print "Executing Plugin:" + str(self.__class__) platform = dmplugin.getOSPlatform() if platform == "linux" or platform == "mac": self.__executeUnix() else: self.__executeVS() return True
def init(self): self.addGoal("create", "Create an artifact") self.addGoalOption("create","--path", "Specifies source directory") self.addGoalOption("create","--interactive", "ask for server or artifact deployment configuration") self.addPreGoal("create", "depman") self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") self._dmdeployplugin = PlugInManager().getPlugInInstance("DepManDeployPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return False if self._arguments.read("create"): self.setExecute(True) args=[""] if self._arguments.read("--path",args): self._path=args[0] if self._arguments.read("--interactive"): self._is_Interactive=True
def buildman(self): self.loadXMLFile(self._file) for goal in self._goalList: plugin = PlugInManager().getPlugInInstanceByGoal(goal.localName) plugin.initFromXML(goal) plugin.execute() if plugin.error(): for error in plugin.getErrorMessages(): self.reportError(error) return False return True
def testInitFromXML(self): arguments = ArgumentParser(['bmn.py','buildman','--file','bmtests/data/batch-buildman.xml']) bm = BuildMan(arguments) plugin = PlugInManager().getPlugInInstance("BuildManPlugIn") plugin._goalList = [] plugin.loadXMLFile(plugin.getFile()) goals = ['delete','svn','clean','update','create-solution','compile-solution','create'] i = 0 for goal in plugin.getGoalList(): self.assertEqual(goal.localName,goals[i]) i+=1
def getDependencies(self): self._dmget = PlugInManager().getPlugInInstance("DepManGetPlugIn") if self._dmget == None: self.reportError("PlugIn `depman get` not found") return unPackList = [] for dep in self._dependencyList: self._dmget.setDependency(dep) #prevents downloading of not matching platforms but overrided if not self._isInteractive: if self._isFromCache: self._dmget.setForceCache() else: self._dmget.setForceRemote() self._dmget.get(unPackList) return unPackList
def clean(self): self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") self.setExecute(False) return self._default_repository = self._dmplugin.getDepManPath() #the extra parameter "all" enables dmn to clear the cache directory print "* cleaning..." util = BMUtil() util.rmdir(self._default_repository+os.path.sep+"include") util.rmdir(self._default_repository+os.path.sep+"lib") util.rmdir(self._default_repository+os.path.sep+"bin") util.rmdir(self._default_repository+os.path.sep+"share") util.rmdir(self._default_repository+os.path.sep+"Frameworks") if self._delete_cache: util.rmdir(self._default_repository+os.path.sep+".cache") return True
def init(self): self.addGoal("deploy", "deploys an artifact") self.addGoalOption("deploy", "--interactive", "ask for server or artifact deployment configuration") self.addPreGoal("deploy", "create") self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") self._dmcreateplugin = PlugInManager().getPlugInInstance("DepManCreatePlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return False if self._arguments.read("deploy"): self.setExecute(True) if self._arguments.read("--interactive"): self._is_Interactive = True
def init(self): self.addGoal("buildman", "executes goals from a buildman file") self.addGoalOption("buildman","--file", "Sets the file to execute, otherwise search for buildman.xml") self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return isBuildMan = False while self._arguments.read("buildman"): self.setExecute(True) isBuildMan = True if not isBuildMan: return args=[""] while self._arguments.read("--file",args): self._file = args[0]
def update(self): if self._must_Clean: self._dmclean = PlugInManager().getPlugInInstance("DepManCleanPlugIn") if self._dmclean == None: self.reportError("PlugIn `depman clean` not found") return delete_cache = self._dmclean.getDeleteCache() self._dmclean.setDeleteCache(False) self._dmclean.clean() self._dmclean.setDeleteCache(delete_cache) if self._depmanNode == None: self.loadXMLFile(self._xmlfile) unPackList = self.getDependencies(self._depmanNode) #once the xml is parsed and files downloaded, lets unpack them self.unpack(unPackList)
def extract(self): self._dmupdate = PlugInManager().getPlugInInstance("DepManUpdatePlugIn") if self._dmupdate == None: self.reportError("PlugIn `depman update` not found") return if self._depmanNode == None: self.loadXMLFile(self._xmlFile) if not self._isInteractive: if self._isFromCache: self._dmupdate.setForceCache() else: self._dmupdate.setForceRemote() dependency_filenamepaths = self._dmupdate.getDependencies(self._depmanNode) package_namepath = self.parsePackage(self._depmanNode) print dependency_filenamepaths, self._destDir, self._filter bmutil = BMUtil() for file in dependency_filenamepaths: bmutil.untargzFiltered(file, self._destDir, self._filter)
def init(self): self.addGoal("update", "Update current project") self.addGoalOption("update","--cache", "Cache is preferred") self.addGoalOption("update","--remote", "Remote repository is preferred") self.addPreGoal("update","depman") self.addPreGoal("update","clean") if self._arguments.read("update"): self.setExecute(True) if self._arguments.read("--cache"): self._isInteractive=False self._isFromCache = True if self._arguments.read("--remote"): self._isInteractive=False self._isFromCache = False self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return
class DepManDeployPlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._is_Interactive = False self._dependency = None self._server = Server() self._servers = [] self._xmlConfigFile = "settings.xml" def setDependency(self, dependency): self._dependency = dependency def init(self): self.addGoal("deploy", "deploys an artifact") self.addGoalOption( "deploy", "--interactive", "ask for server or artifact deployment configuration") self.addPreGoal("deploy", "create") self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") self._dmcreateplugin = PlugInManager().getPlugInInstance( "DepManCreatePlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return False if self._arguments.read("deploy"): self.setExecute(True) if self._arguments.read("--interactive"): self._is_Interactive = True def initFromXML(self, node): distrNodes = node.getElementsByTagName("distributionManagement") if distrNodes != None: for n in distrNodes: if n.localName == "distributionManagement": for p in n.childNodes: if p.localName == "repository": repoName = None repoUrl = None for k in p.childNodes: if k.localName == "id": self.server._repository_id = k.childNodes[ 0].nodeValue if k.localName == "name": repoName = k.childNodes[0].nodeValue if k.localName == "url": repoUrl = urlparse( k.childNodes[0].nodeValue) self.server._repository_url = repo.netloc self.server._repository_path = repoUrl.path self.server._repository_proto = repoUrl.scheme print self.server._repository_proto + "://" + self.server._repository_url + "/" + self.server._repository_path settingsNodes = node.getElementsByTagName("servers") if settingsNodes != None: for n in settingsNodes: if n.localName == "servers": self._servers = [] for p in n.childNodes: if p.localName == "server": server = Server() for k in p.childNodes: if k.localName == "id": server._repository_id = k.childNodes[ 0].nodeValue if k.localName == "username": server._repository_login = k.childNodes[ 0].nodeValue if k.localName == "password": server._repository_passwd = k.childNodes[ 0].nodeValue self._servers.append(server) print self._servers def uploadFTPFile(self, url, user, pwd, destdir, path, orig_file, filename): #print url, user, pwd, destdir, path, orig_file, filename ftp = FTP_TLS(url) #ftp.set_debuglevel( 1 ) ftp.auth_tls() ftp.prot_p() ftp.login(user, pwd) ftp.set_pasv(1) #ftp.retrlines('LIST') ftp.cwd(destdir) dirs = string.split(path, os.path.sep) for dir in dirs: #print dir try: ftp.mkd(dir) except: pass try: ftp.cwd(dir) except: pass f = open(orig_file, "rb") ftp.storbinary("STOR " + filename, f) f.close() ftp.quit() def execute(self): self.initFromXML(self._dmplugin.getNode()) print self._dmplugin.getMavenPath() + os.path.sep + self._xmlConfigFile self.loadXMLFile(self._dmplugin.getMavenPath() + os.path.sep + self._xmlConfigFile) file_name = self._dependency.getDepManFileName() file_path = self._dependency.getDepManUrlPath() tarname = file_name + ".tar.gz" md5name = tarname + ".md5" dmfile = file_name + ".xml" dmutil = BMUtil() surl = self._server._repository_proto + "://" + self._server._repository_url + "/" + self._server._repository_path url = self._server._repository_url destdir = self._server._repository_path login = self._server._repository_login pwd = self._server._repository_passwd if self._is_Interactive: tmstr = "URL [*]:" surl = raw_input(string.replace(tmstr, "*", url)) if len(surl) == 0: surl = self._server._repository_url repoURL = urlparse(surl) self._server._repository_url = repo.netloc self._server._repository_path = repoUrl.path self._server._repository_proto = repoUrl.scheme url = self._server._repository_url tmstr = "Login [*]:" login = raw_input(string.replace(tmstr, "*", login)) if len(login) == 0: login = self._server._repository_login import getpass pwd = getpass.getpass() else: for s in self._servers: if s._repository_id == self._server._repository_id: login = self._server._repository_login = s._repository_login pwd = self._server._repository_passwd = s._repository_passwd #tmpdir = self._dmplugin.getDepManPath() + os.path.sep + ".cache" + os.path.sep + file_path tmpdir = self._dmplugin.getMavenPath( ) + os.path.sep + "repository" + os.path.sep + file_path if self._server._repository_proto == "ssh": dmutil.rmdir( ".dmn_tmp") # Prevent for uploading bad previous compilations! sshtmpdir = ".dmn_tmp" + os.path.sep + file_path dmutil.mkdir(sshtmpdir) shutil.copyfile(tmpdir + os.path.sep + tarname, sshtmpdir + os.path.sep + tarname) shutil.copyfile(tmpdir + os.path.sep + md5name, sshtmpdir + os.path.sep + md5name) if self._xmlfile != "": shutil.copyfile(tmpdir + os.path.sep + dmfile, sshtmpdir + os.path.sep + dmfile) #scp base_ssh = destdir url_ssh = url scpcommand = "scp" pscppath = "" if sys.platform == "win32": scpcommand = self._dmplugin.getDepManDataPath( ) + os.path.sep + "win32" + os.path.sep + "pscp.exe" scpcommand = '"' + os.path.normpath(scpcommand) + '"' cmdstr = scpcommand + " -r " + ".dmn_tmp" + os.path.sep + "*" + " " + login + "@" + url_ssh + ":" + base_ssh print cmdstr os.system(cmdstr) dmutil.rmdir(".dmn_tmp") elif self._server._repository_proto == "ftp": #ftp print "* Uploading ", tarname self.uploadFTPFile(url, login, pwd, destdir, os.path.sep + file_path, tmpdir + os.path.sep + tarname, tarname) print "* Uploading ", md5name self.uploadFTPFile(url, login, pwd, destdir, os.path.sep + file_path, tmpdir + os.path.sep + md5name, md5name) if not self._is_Interactive: print "* Uploading ", dmfile self.uploadFTPFile(url, login, pwd, destdir, os.path.sep + file_path, tmpdir + os.path.sep + dmfile, dmfile) return True
if sys.platform == "win32": scpcommand = self._dmplugin.getDepManDataPath( ) + os.path.sep + "win32" + os.path.sep + "pscp.exe" scpcommand = '"' + os.path.normpath(scpcommand) + '"' cmdstr = scpcommand + " -r " + ".dmn_tmp" + os.path.sep + "*" + " " + login + "@" + url_ssh + ":" + base_ssh print cmdstr os.system(cmdstr) dmutil.rmdir(".dmn_tmp") elif self._server._repository_proto == "ftp": #ftp print "* Uploading ", tarname self.uploadFTPFile(url, login, pwd, destdir, os.path.sep + file_path, tmpdir + os.path.sep + tarname, tarname) print "* Uploading ", md5name self.uploadFTPFile(url, login, pwd, destdir, os.path.sep + file_path, tmpdir + os.path.sep + md5name, md5name) if not self._is_Interactive: print "* Uploading ", dmfile self.uploadFTPFile(url, login, pwd, destdir, os.path.sep + file_path, tmpdir + os.path.sep + dmfile, dmfile) return True PlugInManager().registerPlugIn("DepManDeployPlugIn", DepManDeployPlugIn())
class DepManCreatePlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._path = "." self._group = "" self._artifact = "" self._version = "" self._platform = "default" self._arch = "default" self._compiler = "default" self._ltype = "" self._upload = False self._is_Interactive = True self._xmlfile = "" self._packageNode = None self._default_ssh = "murray.ai2.upv.es" self._default_login = "******" self._default_destdir = "/projects/AI2/www-aliases/depman/" def init(self): self.addGoal("create", "Create an artifact") self.addGoalOption("create", "--path", "Specifies source directory") self.addGoalOption("create", "--group", "Specifies artifact group name") self.addGoalOption("create", "--artifact", "Specifies artifact name") self.addGoalOption("create", "--version", "Specifies artifact version") self.addGoalOption("create", "--platform", "Specifies artifact OS platform") self.addGoalOption("create", "--arch", "Specifies artifact hardware architecture") self.addGoalOption("create", "--compiler", "Specifies artifact compiler version") self.addGoalOption("create", "--ltype", "Specifies library type if needed") self.addGoalOption("create", "--upload", "Whenever the artifact must be uploaded or not") self.addGoalOption( "create", "--from-xml", "Uses the given depman.xml file to create the package") isCreate = False if self._arguments.read("create"): self.setExecute(True) isCreate = True if not isCreate: return args = [""] use_xml = False if self._arguments.read("--from-xml", args): self._xmlfile = args[0] use_xml = True if use_xml: self.loadXMLFile(self._xmlfile) args = [""] if self._arguments.read("--path", args): self._path = args[0] args = [""] if self._arguments.read("--group", args): self._group = args[0] self._is_Interactive = False args = [""] if self._arguments.read("--artifact", args): self._artifact = args[0] self._is_Interactive = False args = [""] if self._arguments.read("--version", args): self._version = args[0] self._is_Interactive = False args = [""] if self._arguments.read("--platform", args): self._platform = args[0] self._is_Interactive = False args = [""] if self._arguments.read("--arch", args): self._arch = args[0] self._is_Interactive = False args = [""] if self._arguments.read("--compiler", args): self._compiler = args[0] self._is_Interactive = False args = [""] if self._arguments.read("--ltype", args): self._ltype = args[0] self._is_Interactive = False if self._arguments.read("--upload"): self._upload = True def initFromXML(self, node): if node.localName == "create": if node.hasAttributes(): if node.attributes.has_key("from-xml"): self._xmlfile = node.attributes.get("from-xml").value self.loadXMLFile(self._xmlfile) if node.attributes.has_key("path"): self._path = node.attributes.get("path").value if node.attributes.has_key("upload"): value = node.attributes.get("upload").value if value == "True" or value == "true": self._upload = True else: if node.localName == "depman": self._packageNode = node self._is_Interactive = False def execute(self): print "Executing Plugin:" + str(self.__class__) return self.create() def create(self): self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return False #user questions if self._is_Interactive: self._group = raw_input("Group: ") self._artifact = raw_input("Artifact: ") self._version = raw_input("Version: ") tmpstr = "" for p in self._dmplugin.getSupportedPlatforms(): tmpstr = tmpstr + p + " " print "( ", tmpstr, ")" tmstr = "Platform [*]:" self._platform = raw_input( string.replace(tmstr, "*", self._dmplugin.getOSPlatform())) if len(self._platform) == 0: self._platform = self._dmplugin.getOSPlatform() tmpstr = "" for p in self._dmplugin.getSupportedCompilers(): tmpstr = tmpstr + p + " " print "( ", tmpstr, ")" tmstr = "Compiler [*]:" self._compiler = raw_input( string.replace(tmstr, "*", self._dmplugin.getOSCompiler())) if len(self._compiler) == 0: self._compiler = self._dmplugin.getOSCompiler() tmpstr = "" for p in self._dmplugin.getSupportedArchs(): tmpstr = tmpstr + p + " " print "( ", tmpstr, ")" tmstr = "Architecture [*]:" self._arch = raw_input( string.replace(tmstr, "*", self._dmplugin.getOSArch())) if len(self._arch) == 0: self._arch = self._dmplugin.getOSArch() tmpstr = "" for p in self._dmplugin.getSupportedLibraryTypes(): tmpstr = tmpstr + p + " " print "( ", tmpstr, ")" self._ltype = raw_input("Library Type: ") upload_response = raw_input("Upload to server? (y/n): ") if upload_response == "y" or upload_response == "yes": self._upload = True if self._packageNode != None: for n in self._packageNode.childNodes: if n.localName == "package": processPackage = True if n.hasAttributes(): if n.attributes.has_key("platform"): values = n.attributes.get("platform").value.split( ",") if self._dmplugin.getOSPlatform() in values: processPackage = True else: processPackage = False if processPackage: print "Processing for platform..." for p in n.childNodes: if p.localName == "group": self._group = p.childNodes[0].nodeValue if p.localName == "artifact": self._artifact = p.childNodes[0].nodeValue if p.localName == "version": self._version = p.childNodes[0].nodeValue if p.localName == "platform": self._platform = p.childNodes[0].nodeValue if p.localName == "compiler": self._compiler = p.childNodes[0].nodeValue if p.localName == "arch": self._arch = p.childNodes[0].nodeValue if p.localName == "libraryType": self._ltype = p.childNodes[0].nodeValue if p.localName == "upload": #TODO: Maybe upload should be an external plugin for k in p.childNodes: if k.localName == "sshserver": self._default_ssh = k.childNodes[ 0].nodeValue if k.localName == "destdir": self._default_destdir = k.childNodes[ 0].nodeValue if k.localName == "username": self._default_login = k.childNodes[ 0].nodeValue if self._group == "": self.reportError("Group cannot be empty") return False if self._artifact == "": self.reportError("Artifact cannot be empty") return False if self._version == "": self.reportError("Version cannog be empty") return self._group = self._group.replace(".", "/") if self._platform == "default": self._platform = self._dmplugin.getOSPlatform() if self._compiler == "default": self._compiler = self._dmplugin.getOSCompiler() if self._arch == "default": self._arch = self._dmplugin.getOSArch() #let's check user input consistency if self._platform not in self._dmplugin.getSupportedPlatforms(): self.reportError("Platform not supported: " + self._platform + ". Supported platforms:" + str(self._dmplugin.getSupportedPlatforms())) return False if self._compiler not in self._dmplugin.getSupportedCompilers(): self.reportError("Compiler not supported: " + self._compiler + ". Supported compilers:" + str(self._dmplugin.getSupportedCompilers())) return False if self._arch not in self._dmplugin.getSupportedArchs(): self.reportError("Architecture not supported: " + self._arch + ". Supported archs:" + str(self._dmplugin.getSupportedArchs())) return False if self._ltype not in self._dmplugin.getSupportedLibraryTypes(): self.reportError("Library type not supported: " + self._ltype + ". Supported libraries:" + str(self._dmplugin.getSupportedLibraryTypes())) return False #artifact and md5 generation file_name = self._artifact + "-" + self._version + "-" + self._platform + "-" + self._compiler + "-" + self._arch + "-" + self._ltype tarname = file_name + ".tar.gz" md5name = tarname + ".md5" dmfile = file_name + ".xml" dmutil = BMUtil() tmpdir = self._dmplugin.getDepManPath( ) + os.path.sep + ".cache" + os.path.sep + self._group + os.path.sep + self._artifact + os.path.sep + self._version + os.path.sep + self._platform + os.path.sep + self._compiler + os.path.sep + self._arch + os.path.sep + self._ltype dmutil.mkdir(tmpdir) print tmpdir + os.path.sep + tarname, self._path dmutil.targz(os.path.join(tmpdir, tarname), self._path) #print "targz ",tmpdir+os.path.sep+tarname dmutil.createMD5(tmpdir + os.path.sep + tarname, tmpdir + os.path.sep + md5name) if self._xmlfile != "": shutil.copyfile(self._xmlfile, tmpdir + os.path.sep + dmfile) print "Artifact " + tarname + " created in:\n" + tmpdir if self._upload: dmutil.rmdir( ".dmn_tmp") # Prevent for uploading bad previous compilations! sshtmpdir = ".dmn_tmp" + os.path.sep + self._group + os.path.sep + self._artifact + os.path.sep + self._version + os.path.sep + self._platform + os.path.sep + self._compiler + os.path.sep + self._arch + os.path.sep + self._ltype dmutil.mkdir(sshtmpdir) shutil.copyfile(tmpdir + os.path.sep + tarname, sshtmpdir + os.path.sep + tarname) shutil.copyfile(tmpdir + os.path.sep + md5name, sshtmpdir + os.path.sep + md5name) if self._xmlfile != "": shutil.copyfile(tmpdir + os.path.sep + dmfile, sshtmpdir + os.path.sep + dmfile) url = self._default_ssh destdir = self._default_destdir login = self._default_login if self._is_Interactive: tmstr = "SSH Server [*]:" url = raw_input(string.replace(tmstr, "*", self._default_ssh)) if len(url) == 0: url = self._default_ssh tmstr = "Destination Directory [*]:" destdir = raw_input( string.replace(tmstr, "*", self._default_destdir)) if len(destdir) == 0: destdir = self._default_destdir tmstr = "Login [*]:" login = raw_input( string.replace(tmstr, "*", self._default_login)) if len(login) == 0: login = self._default_login download_dir = self._group + "/" + self._artifact + "/" + self._version + "/" + self._platform + "/" + self._compiler + "/" + self._arch + "/" + self._ltype print "* Uploading ", tarname print "* Uploading ", md5name #scp base_ssh = destdir url_ssh = url scpcommand = "scp" pscppath = "" if sys.platform == "win32": scpcommand = self._dmplugin.getDepManDataPath( ) + os.path.sep + "win32" + os.path.sep + "pscp.exe" scpcommand = '"' + os.path.normpath(scpcommand) + '"' cmdstr = scpcommand + " -r " + ".dmn_tmp" + os.path.sep + "*" + " " + login + "@" + url_ssh + ":" + base_ssh print cmdstr os.system(cmdstr) #scp dmutil.rmdir(".dmn_tmp")
class DepManGetPlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._default_repository = "" self._dependency = None self._forceCache = False self._isInteractive = True def setDependency(self, dependency): self._dependency = dependency def setURL(self, url): self._url = url def setForceCache(self): self._forceCache = True self._isInteractive = False def setForceRemote(self): self._forceCache = False self._isInteractive = False def init(self): self.addGoal("get", "downloads an artifact if not in cache.") self.addGoalOption("get", "--url", "URL base for the DepMan repository.") self.addGoalOption("get", "--group", "Group namespace of the artifact.") self.addGoalOption("get", "--artifact", "Name of the artifact to download.") self.addGoalOption("get", "--version", "Version of the artifact.") self.addGoalOption("get", "--platform", "Platform of the artifact.") self.addGoalOption("get", "--distribution", "Distribution of the artifact.") self.addGoalOption( "get", "--compiler", "Selects the compiler version that was used to compile the artifact." ) self.addGoalOption("get", "--arch", "Selects the architecture of the artifact.") self.addGoalOption("get", "--ltype", "Type of library of the artifact.") self.addGoalOption("get", "--cache", "Forces the use of cache files without asking.") self.addGoalOption( "get", "--remote", "Forces the download of remote without the use of the cache and without asking." ) self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return self._default_repository = self._dmplugin.getDepManPath() while self._arguments.read("get"): self._dependency = Dependency() self.setExecute(true) args = [""] if self._arguments.read("--url", args): self._dependency.url = args[0] args = [""] if self._arguments.read("--group", args): self._dependency.group = args[0] args = [""] if self._arguments.read("--artifact", args): self._dependency.artifact = args[0] args = [""] if self._arguments.read("--version", args): self._dependency.version = args[0] args = [""] if self._arguments.read("--platform", args): self._dependency.platform = args[0] args = [""] if self._arguments.read("--distribution", args): self._dependency.distribution = args[0] args = [""] if self._arguments.read("--compiler", args): self._dependency.compiler = args[0] args = [""] if self._arguments.read("--arch", args): self._dependency.arch = args[0] args = [""] if self._arguments.read("--ltype", args): self._dependency.libraryType = args[0] if self._arguments.read("--cache"): self._forceCache = True self._isInteractive = False if self._arguments.read("--remote"): self._forceCache = False self._isInteractive = False def initFromXML(self, node): pass #TODO: . . . def execute(self): if self._dependency == None: self.reportError("Missing dependency option") return False if self._url == "": self.reportError("Missing url option") return False if not self._dmplugin.validateDependency(self._dependency): return False return self.get() def get(self, unPackList=None): print "[", self._dependency.artifact, "]" file_name = self._dependency.getDepManFileName() tarname = file_name + ".tar.gz" md5name = tarname + ".md5" download_path = self._dependency.getDepManFilePath() download_dir = self._dependency.getDepManUrlPath() cache_path = self._default_repository + os.path.sep + ".cache" + os.path.sep + download_path is_snapshot = self._dependency.isSnapshot() dmutil = BMUtil() is_tar = True is_md5 = True if not dmutil.checkUrl(self._dependency.url + "/" + download_dir + "/" + md5name): #print "Error: File ",baseurl+"/"+download_dir+"/"+md5name, " not found in the repository" is_md5 = False if not dmutil.checkUrl(self._dependency.url + "/" + download_dir + "/" + tarname): #print "Error: File ",baseurl+"/"+download_dir+"/"+tarname, " not found in the repository" is_tar = False dmutil.mkdir(cache_path) if not os.path.isfile(cache_path + os.path.sep + md5name): is_cache = False else: is_cache = True #Once all variables have been collected, lets decide what to do with the artifact must_download = False if (not is_md5 or not is_tar) and not is_cache: print "Error: Artifact ", tarname, " not found" return False if not is_md5 and not is_tar and is_cache: print "* file not found in repository, using cache..." must_download = False if is_md5 and is_tar and not is_cache: print "* file is not in cache, downloading..." must_download = True if is_md5 and is_tar and is_cache: if is_snapshot: if self._isInteractive: repo = raw_input( "What snapshot do you want to use? (cache/remote): ") else: if self._forceCache: repo = "cache" else: repo = "remote" must_download = False #in case of misspeling, using cache by default if repo != "cache" and repo != "remote": repo = "cache" else: repo = "remote" if repo == "remote": print "* file cached, checking md5..." dmutil.download(self._url + "/" + download_dir + "/" + md5name, cache_path + os.path.sep + md5name + ".new") if dmutil.diff(cache_path + os.path.sep + md5name, cache_path + os.path.sep + md5name + ".new"): print "* no md5 matching, re-downloading..." must_download = True else: print "* md5 matching succesful" must_download = False os.remove(cache_path + os.path.sep + md5name + ".new") if must_download == True: print "URL :", self._dependency.url dmutil.download( self._dependency.url + "/" + download_dir + "/" + md5name, cache_path + os.path.sep + md5name) #print "* downloaded [",md5name,"]" dmutil.download( self._dependency.url + "/" + download_dir + "/" + tarname, cache_path + os.path.sep + tarname) #print "* downloaded[",tarname,"]" if unPackList != None: if (cache_path + os.path.sep + tarname) not in unPackList: unPackList.append(cache_path + os.path.sep + tarname) return True
class DepManExtractPlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._xmlFile = "depman.xml" self._destDir = "." self._filter = "*" self._isFromCache=False self._isInteractive=True self._depmanNode = None def init(self): self.addGoal("extract", "Extract the files of dependencies and package sections of a depman xml file.") self.addGoalOption("extract","--file", "Sets an alternate xml file. Default: depman.xml") self.addGoalOption("extract","--destdir", "Sets the destination directory of the extraction. Default: `.`") self.addGoalOption("extract","--filter", "Sets the the filter of the files to extract. Default: `*`") self.addGoalOption("extract","--cache", "Cache is preferred") self.addGoalOption("extract","--remote", "Remote repository is preferred") isExtract = False if self._arguments.read("extract"): self.setExecute(True) isExtract = True if not isExtract: return args = [""] if self._arguments.read("--file", args): self._xmlFile = args[0] args = [""] if self._arguments.read("--destdir", args): self._destDir = args[0] args = [""] if self._arguments.read("--filter", args): self._filter = args[0] if self._arguments.read("--cache"): self._isFromCache = True self._isInteractive = False if self._arguments.read("--remote"): self._isFromCache = False self._isInteractive = False def initFromXML(self,node): if node.localName=="extract": if node.hasAttributes(): if node.attributes.has_key("file"): elf._xmlFile = node.attributes.get("file").value if node.attributes.has_key("destdir"): elf._destDir = node.attributes.get("destdir").value if node.attributes.has_key("filter"): elf._filter = node.attributes.get("filter").value foundCache = False if node.attributes.has_key("cache"): value = node.attributes.get("cache").value if value == "True" or value == "true": self._isFromCache = True self._isInteractive = False if node.attributes.has_key("remote") and not foundCache: value = node.attributes.get("remote").value if value == "True" or value == "true": self._isFromCache = False self._isInteractive = False else: self._depmanNode = node def execute(self): print "Executing Plugin:" + str(self.__class__) return self.extract() def extract(self): self._dmupdate = PlugInManager().getPlugInInstance("DepManUpdatePlugIn") if self._dmupdate == None: self.reportError("PlugIn `depman update` not found") return if self._depmanNode == None: self.loadXMLFile(self._xmlFile) if not self._isInteractive: if self._isFromCache: self._dmupdate.setForceCache() else: self._dmupdate.setForceRemote() dependency_filenamepaths = self._dmupdate.getDependencies(self._depmanNode) package_namepath = self.parsePackage(self._depmanNode) print dependency_filenamepaths, self._destDir, self._filter bmutil = BMUtil() for file in dependency_filenamepaths: bmutil.untargzFiltered(file, self._destDir, self._filter) def parsePackage(self,node): return ""
def testArguments(self): arguments = ArgumentParser( ['bmn.py', 'buildman', '--file', 'bmtests/data/buildman.xml']) bm = BuildMan(arguments) plugin = PlugInManager().getPlugInInstance("BuildManPlugIn") self.assertEqual('bmtests/data/buildman.xml', plugin.getFile())
class DepManCreatePlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._path="." self._is_Interactive=False self._dependency = None self._default_ftp="downloads.gvsig.org" self._default_login="******" self._default_destdir = "/anon/pub/gvSIG-desktop/buildman-repository" def init(self): self.addGoal("create", "Create an artifact") self.addGoalOption("create","--path", "Specifies source directory") self.addGoalOption("create","--interactive", "ask for server or artifact deployment configuration") self.addPreGoal("create", "depman") self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") self._dmdeployplugin = PlugInManager().getPlugInInstance("DepManDeployPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return False if self._arguments.read("create"): self.setExecute(True) args=[""] if self._arguments.read("--path",args): self._path=args[0] if self._arguments.read("--interactive"): self._is_Interactive=True def initFromXML(self,node): packageNodes = node.getElementsByTagName("package") if packageNodes != None: for n in packageNodes: if n.localName=="package": processPackage = True if n.hasAttributes(): if n.attributes.has_key("platform"): values = n.attributes.get("platform").value.split(",") if self._dmplugin.getOSPlatform() in values: processPackage = True else: processPackage = False if processPackage: print "Processing for platform..." self._dependency = DepManDependency(self._dmplugin) for p in n.childNodes: if p.localName=="group": self._dependency.group=p.childNodes[0].nodeValue if p.localName=="artifact": self._dependency.artifact=p.childNodes[0].nodeValue if p.localName=="version": self._dependency.version=p.childNodes[0].nodeValue if p.localName=="platform": self._dependency.platform=p.childNodes[0].nodeValue if p.localName=="distribution": self._dependency.distribution=p.childNodes[0].nodeValue if p.localName=="compiler": self._dependency.compiler=p.childNodes[0].nodeValue if p.localName=="arch": self._dependency.arch=p.childNodes[0].nodeValue if p.localName=="libraryType": self._dependency.libraryType=p.childNodes[0].nodeValue print "Creating Artifact:" + str(self._dependency) def execute(self): return self.create() def create(self): self.initFromXML(self._dmplugin.getNode()) #user questions if self._dependency==None: self._dependency = DepManDependency(self._dmplugin) self._is_Interactive = True self._dependency.raw_input() upload_response = raw_input("Upload to server? (y/n): ") if upload_response == "y" or upload_response == "yes": self._upload=True if not self._dmplugin.validateDependency(self._dependency): return False #artifact and md5 generation file_name=self._dependency.getDepManFileName() file_path=self._dependency.getDepManFilePath() tarname=file_name+".tar.gz" md5name=tarname+".md5" dmfile=file_name+".xml" dmutil = BMUtil() tmpdir=self._dmplugin.getMavenPath()+os.path.sep+"repository"+os.path.sep+file_path dmutil.mkdir(tmpdir) print tmpdir+os.path.sep+tarname,self._path dmutil.targz(os.path.join(tmpdir,tarname),self._path) #print "targz ",tmpdir+os.path.sep+tarname dmutil.createMD5(tmpdir+os.path.sep+tarname,tmpdir+os.path.sep+md5name) if not self._is_Interactive: shutil.copyfile(self._dmplugin.getXMLFile(),tmpdir+os.path.sep+dmfile) self._dmdeployplugin.setDependency(self._dependency) print "Artifact " + tarname + " created in:\n" + tmpdir
class DepManUpdatePlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._must_Clean = True self._isFromCache = False self._isInteractive = True self._xmlfile = "depman.xml" self._depmanNode = None self._defurl = "http://murray.ai2.upv.es/depman" def init(self): self.addGoal("update", "Update current project") self.addGoalOption("update", "--no-clean", "Do not perform a repository clean before update") self.addGoalOption("update", "--cache", "Cache is preferred") self.addGoalOption("update", "--remote", "Remote repository is preferred") self.addGoalOption("update", "--file", "Specifies a dependency xml file") isUpdate = False if self._arguments.read("update"): self.setExecute(True) isUpdate = True if not isUpdate: return if self._arguments.read("--no-clean"): self._must_Clean = False if self._arguments.read("--cache"): self._isInteractive = False self._isFromCache = True if self._arguments.read("--remote"): self._isInteractive = False self._isFromCache = False args = [""] if self._arguments.read("--file", args): self._xmlfile = args[0] def initFromXML(self, node): if node.localName == "update": if node.hasAttributes(): if node.attributes.has_key("file"): self.loadXMLFile(node.attributes.get("file").value) if node.attributes.has_key("no-clean"): value = node.attributes.get("no-clean").value if value == "True" or value == "true": self._must_Clean = True foundCache = False if node.attributes.has_key("cache"): value = node.attributes.get("cache").value if value == "True" or value == "true": self._isFromCache = True if node.attributes.has_key("remote") and not foundCache: value = node.attributes.get("remote").value if value == "True" or value == "true": self._isFromCache = False self._isInteractive = False else: self._depmanNode = node def execute(self): print "Executing Plugin:" + str(self.__class__) return self.update() def update(self): if self._must_Clean: self._dmclean = PlugInManager().getPlugInInstance( "DepManCleanPlugIn") if self._dmclean == None: self.reportError("PlugIn `depman clean` not found") return delete_cache = self._dmclean.getDeleteCache() self._dmclean.setDeleteCache(False) self._dmclean.clean() self._dmclean.setDeleteCache(delete_cache) if self._depmanNode == None: self.loadXMLFile(self._xmlfile) unPackList = self.getDependencies(self._depmanNode) #once the xml is parsed and files downloaded, lets unpack them self.unpack(unPackList) def getDependencies(self, node): self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return self._dmget = PlugInManager().getPlugInInstance("DepManGetPlugIn") if self._dmget == None: self.reportError("PlugIn `depman get` not found") return group = "none" artifact = "none" version = "0" platform = "none" compiler = "none" arch = "none" ltype = "none" #os default values defplatform = self._dmplugin.getOSPlatform() defarch = self._dmplugin.getOSArch() defcompiler = self._dmplugin.getOSCompiler() #hardcoded default url #defurl=default_url defurl = self._defurl unPackList = [] if node.hasAttributes(): if node.attributes.has_key("url"): defurl = node.attributes.get("url").value for i in node.childNodes: if i.localName == "dependencies": url = defurl #os default values defplatform = self._dmplugin._osplatform defarch = self._dmplugin._osarch defcompiler = self._dmplugin._oscompiler if i.hasAttributes(): if i.attributes.has_key("platform"): defplatform = i.attributes.get("platform").value if i.attributes.has_key("architecture"): defarch = i.attributes.get("architecture").value if i.attributes.has_key("compiler"): defcompiler = i.attributes.get("compiler").value if i.attributes.has_key("url"): url = i.attributes.get("url").value list_of_platforms = defplatform.split(",") #depedencies platform checking #we just go on whenever host os or all matches if len(list_of_platforms) > 0 and self._dmplugin.getOSPlatform( ) not in list_of_platforms and "all" not in list_of_platforms: invalid_platform = True else: invalid_platform = False defplatform = self._dmplugin.getOSPlatform() del list_of_platforms[:] #print "Url: ",url if not invalid_platform: for j in i.childNodes: if j.localName == "dependency": #set default values platform = defplatform arch = defarch compiler = defcompiler group = "none" artifact = "none" version = "0" ltype = "none" durl = url if j.hasAttributes(): if j.attributes.has_key("url"): durl = j.attributes.get("url").value for h in j.childNodes: if h.localName == "group": group = h.childNodes[0].nodeValue if h.localName == "artifact": artifact = h.childNodes[0].nodeValue if h.localName == "version": version = h.childNodes[0].nodeValue if h.localName == "platform": platform = h.childNodes[0].nodeValue if h.localName == "compiler": compiler = h.childNodes[0].nodeValue if h.localName == "architecture": arch = h.childNodes[0].nodeValue if h.localName == "type": ltype = h.childNodes[0].nodeValue self._dmget.setURL(durl) self._dmget.setGroup(group) self._dmget.setArtifact(artifact) self._dmget.setVersion(version) self._dmget.setPlatform(platform) self._dmget.setCompiler(compiler) self._dmget.setArch(arch) self._dmget.setLibraryType(ltype) #prevents downloading of not matching platforms but overrided if not self._isInteractive: if self._isFromCache: self._dmget.setForceCache() else: self._dmget.setForceRemote() self._dmget.get(unPackList) return unPackList def unpack(self, unPackList): sep = os.path.sep dmutil = BMUtil() for file in unPackList: tmpstr = file[file.rfind(sep) + 1:] print "* unpacking ", tmpstr dmutil.untargz(file, self._dmplugin.getDepManPath()) def setForceCache(self): self._isFromCache = True self._isInteractive = False def setForceRemote(self): self._isFromCache = False self._isInteractive = False
self._dmget.setLibraryType(ltype) #prevents downloading of not matching platforms but overrided if not self._isInteractive: if self._isFromCache: self._dmget.setForceCache() else: self._dmget.setForceRemote() self._dmget.get(unPackList) return unPackList def unpack(self, unPackList): sep = os.path.sep dmutil = BMUtil() for file in unPackList: tmpstr = file[file.rfind(sep) + 1:] print "* unpacking ", tmpstr dmutil.untargz(file, self._dmplugin.getDepManPath()) def setForceCache(self): self._isFromCache = True self._isInteractive = False def setForceRemote(self): self._isFromCache = False self._isInteractive = False #after unpacking, the unpack list is freed PlugInManager().registerPlugIn("DepManUpdatePlugIn", DepManUpdatePlugIn())
class DepManUpdatePlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._must_Clean=True self._isFromCache=False self._isInteractive=True self._defurl="http://downloads.gvsig.org/pub/gvSIG-desktop/buildman-repository" self._dependencyList = [] def init(self): self.addGoal("update", "Update current project") self.addGoalOption("update","--cache", "Cache is preferred") self.addGoalOption("update","--remote", "Remote repository is preferred") self.addPreGoal("update","depman") self.addPreGoal("update","clean") if self._arguments.read("update"): self.setExecute(True) if self._arguments.read("--cache"): self._isInteractive=False self._isFromCache = True if self._arguments.read("--remote"): self._isInteractive=False self._isFromCache = False self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return def initFromXML(self,dom): defurl=self._defurl node = dom.getElementsByTagName("depman")[0] if node != None: if node.hasAttributes(): if node.attributes.has_key("url"): defurl=node.attributes.get("url").value for i in node.childNodes: if i.localName=="dependencies": url=defurl #os default values defplatform=self._dmplugin.getOSPlatform() defdistribution=self._dmplugin.getOSDistribution() defarch=self._dmplugin.getOSArch() defcompiler=self._dmplugin.getOSCompiler() if i.hasAttributes(): if i.attributes.has_key("platform"): defplatform=i.attributes.get("platform").value if i.attributes.has_key("distribution"): defdistribution=i.attributes.get("distribution").value if i.attributes.has_key("architecture"): defarch=i.attributes.get("architecture").value if i.attributes.has_key("compiler"): defcompiler=i.attributes.get("compiler").value if i.attributes.has_key("url"): url=i.attributes.get("url").value list_of_platforms=defplatform.split(",") #depedencies platform checking #we just go on whenever host os or all matches if len(list_of_platforms)>0 and self._dmplugin.getOSPlatform() not in list_of_platforms and "all" not in list_of_platforms: invalid_platform=True else: invalid_platform=False defplatform=self._dmplugin.getOSPlatform() del list_of_platforms[:] if not invalid_platform: for j in i.childNodes: if j.localName=="dependency": dependency = DepManDependency(self._dmplugin) #set default values dependency.platform=defplatform dependency.distribution=defdistribution dependency.arch=defarch dependency.compiler=defcompiler dependency.url = url if j.hasAttributes(): if j.attributes.has_key("url"): dependency.url=j.attributes.get("url").value for h in j.childNodes: if h.localName=="group": dependency.group=h.childNodes[0].nodeValue if h.localName=="artifact": dependency.artifact=h.childNodes[0].nodeValue if h.localName=="version": dependency.version=h.childNodes[0].nodeValue if h.localName=="platform": dependency.platform=h.childNodes[0].nodeValue if h.localName=="distribution": dependency.distribution=h.childNodes[0].nodeValue if h.localName=="compiler": dependency.compiler=h.childNodes[0].nodeValue if h.localName=="architecture": dependency.arch=h.childNodes[0].nodeValue if h.localName=="type": dependency.libraryType=h.childNodes[0].nodeValue self._dependencyList.append(dependency) def execute(self): return self.update() def update(self): self.initFromXML(self._dmplugin.getNode()) for i in self._dependencyList: print i unPackList = self.getDependencies() #once the xml is parsed and files downloaded, lets unpack them self.unpack(unPackList) def getDependencies(self): self._dmget = PlugInManager().getPlugInInstance("DepManGetPlugIn") if self._dmget == None: self.reportError("PlugIn `depman get` not found") return unPackList = [] for dep in self._dependencyList: self._dmget.setDependency(dep) #prevents downloading of not matching platforms but overrided if not self._isInteractive: if self._isFromCache: self._dmget.setForceCache() else: self._dmget.setForceRemote() self._dmget.get(unPackList) return unPackList def unpack(self,unPackList): sep=os.path.sep dmutil = BMUtil() for file in unPackList: tmpstr=file[file.rfind(sep)+1:] print "* unpacking ",tmpstr dmutil.untargz(file,self._dmplugin.getDepManPath()) def setForceCache(self): self._isFromCache = True self._isInteractive = False def setForceRemote(self): self._isFromCache = False self._isInteractive = False
def init(self): self.addGoal("get", "downloads an artifact if not in cache.") self.addGoalOption("get","--url", "URL base for the DepMan repository.") self.addGoalOption("get","--group", "Group namespace of the artifact.") self.addGoalOption("get","--artifact", "Name of the artifact to download.") self.addGoalOption("get","--version", "Version of the artifact.") self.addGoalOption("get","--platform", "Platform of the artifact.") self.addGoalOption("get","--compiler", "Selects the compiler version that was used to compile the artifact.") self.addGoalOption("get","--arch", "Selects the architecture of the artifact.") self.addGoalOption("get","--ltype", "Type of library of the artifact.") self.addGoalOption("get","--cache", "Forces the use of cache files without asking.") self.addGoalOption("get","--remote", "Forces the download of remote without the use of the cache and without asking.") self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return self._default_repository = self._dmplugin.getDepManPath() isGet = False while self._arguments.read("get"): isGet = True if not isGet: return args=[""] if self._arguments.read("--url",args): self._url = args[0] args=[""] if self._arguments.read("--group",args): self._group = args[0] args=[""] if self._arguments.read("--artifact",args): self._artifact = args[0] args=[""] if self._arguments.read("--version",args): self._version = args[0] args=[""] if self._arguments.read("--platform",args): self._platform = args[0] args=[""] if self._arguments.read("--compiler",args): self._compiler = args[0] args=[""] if self._arguments.read("--arch",args): self._arch = args[0] args=[""] if self._arguments.read("--ltype",args): self._ltype = args[0] if self._arguments.read("--cache"): self._forceCache = True self._isInteractive = False if self._arguments.read("--remote"): self._forceCache = False self._isInteractive = False self.setExecute(True)
dmutil.download(self._url + "/" + download_dir + "/" + md5name, cache_path + os.path.sep + md5name + ".new") if dmutil.diff(cache_path + os.path.sep + md5name, cache_path + os.path.sep + md5name + ".new"): print "* no md5 matching, re-downloading..." must_download = True else: print "* md5 matching succesful" must_download = False os.remove(cache_path + os.path.sep + md5name + ".new") if must_download == True: print "URL :", self._dependency.url dmutil.download( self._dependency.url + "/" + download_dir + "/" + md5name, cache_path + os.path.sep + md5name) #print "* downloaded [",md5name,"]" dmutil.download( self._dependency.url + "/" + download_dir + "/" + tarname, cache_path + os.path.sep + tarname) #print "* downloaded[",tarname,"]" if unPackList != None: if (cache_path + os.path.sep + tarname) not in unPackList: unPackList.append(cache_path + os.path.sep + tarname) return True PlugInManager().registerPlugIn("DepManGetPlugIn", DepManGetPlugIn())
class DepManDeployPlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._is_Interactive = False self._dependency = None self._server = Server() self._servers = [] self._xmlConfigFile = "settings.xml" def setDependency(self, dependency): self._dependency = dependency def init(self): self.addGoal("deploy", "deploys an artifact") self.addGoalOption("deploy", "--interactive", "ask for server or artifact deployment configuration") self.addPreGoal("deploy", "create") self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") self._dmcreateplugin = PlugInManager().getPlugInInstance("DepManCreatePlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return False if self._arguments.read("deploy"): self.setExecute(True) if self._arguments.read("--interactive"): self._is_Interactive = True def initFromXML(self, node): distrNodes = node.getElementsByTagName("distributionManagement") if distrNodes != None: for n in distrNodes: if n.localName == "distributionManagement": for p in n.childNodes: if p.localName == "repository": repoName = None repoUrl = None for k in p.childNodes: if k.localName == "id": self.server._repository_id = k.childNodes[0].nodeValue if k.localName == "name": repoName = k.childNodes[0].nodeValue if k.localName == "url": repoUrl = urlparse(k.childNodes[0].nodeValue) self.server._repository_url = repo.netloc self.server._repository_path = repoUrl.path self.server._repository_proto = repoUrl.scheme print self.server._repository_proto + "://" + self.server._repository_url + "/" + self.server._repository_path settingsNodes = node.getElementsByTagName("servers") if settingsNodes != None: for n in settingsNodes: if n.localName == "servers": self._servers = [] for p in n.childNodes: if p.localName == "server": server = Server() for k in p.childNodes: if k.localName == "id": server._repository_id = k.childNodes[0].nodeValue if k.localName == "username": server._repository_login = k.childNodes[0].nodeValue if k.localName == "password": server._repository_passwd = k.childNodes[0].nodeValue self._servers.append(server) print self._servers def uploadFTPFile(self, url, user, pwd, destdir, path, orig_file, filename): #print url, user, pwd, destdir, path, orig_file, filename ftp = FTP_TLS(url) #ftp.set_debuglevel( 1 ) ftp.auth_tls(); ftp.prot_p() ftp.login(user, pwd) ftp.set_pasv(1) #ftp.retrlines('LIST') ftp.cwd(destdir) dirs = string.split(path, os.path.sep) for dir in dirs: #print dir try: ftp.mkd(dir) except: pass try: ftp.cwd(dir) except: pass f = open(orig_file, "rb") ftp.storbinary("STOR " + filename, f) f.close() ftp.quit() def execute(self): self.initFromXML(self._dmplugin.getNode()) print self._dmplugin.getMavenPath() + os.path.sep + self._xmlConfigFile self.loadXMLFile(self._dmplugin.getMavenPath() + os.path.sep + self._xmlConfigFile) file_name = self._dependency.getDepManFileName() file_path = self._dependency.getDepManUrlPath() tarname = file_name + ".tar.gz" md5name = tarname + ".md5" dmfile = file_name + ".xml" dmutil = BMUtil() surl = self._server._repository_proto + "://" + self._server._repository_url + "/" + self._server._repository_path; url = self._server._repository_url destdir = self._server._repository_path login = self._server._repository_login pwd = self._server._repository_passwd if self._is_Interactive: tmstr = "URL [*]:" surl = raw_input(string.replace(tmstr, "*", url)) if len(surl) == 0: surl = self._server._repository_url repoURL = urlparse(surl) self._server._repository_url = repo.netloc self._server._repository_path = repoUrl.path self._server._repository_proto = repoUrl.scheme url = self._server._repository_url tmstr = "Login [*]:" login = raw_input(string.replace(tmstr, "*", login)) if len(login) == 0: login = self._server._repository_login import getpass pwd = getpass.getpass() else: for s in self._servers: if s._repository_id == self._server._repository_id: login = self._server._repository_login = s._repository_login pwd = self._server._repository_passwd = s._repository_passwd #tmpdir = self._dmplugin.getDepManPath() + os.path.sep + ".cache" + os.path.sep + file_path tmpdir = self._dmplugin.getMavenPath()+os.path.sep+"repository"+os.path.sep+file_path if self._server._repository_proto == "ssh": dmutil.rmdir(".dmn_tmp") # Prevent for uploading bad previous compilations! sshtmpdir = ".dmn_tmp" + os.path.sep + file_path dmutil.mkdir(sshtmpdir) shutil.copyfile(tmpdir + os.path.sep + tarname, sshtmpdir + os.path.sep + tarname) shutil.copyfile(tmpdir + os.path.sep + md5name, sshtmpdir + os.path.sep + md5name) if self._xmlfile != "": shutil.copyfile(tmpdir + os.path.sep + dmfile, sshtmpdir + os.path.sep + dmfile) #scp base_ssh = destdir url_ssh = url scpcommand = "scp" pscppath = "" if sys.platform == "win32": scpcommand = self._dmplugin.getDepManDataPath() + os.path.sep + "win32" + os.path.sep + "pscp.exe" scpcommand = '"' + os.path.normpath(scpcommand) + '"' cmdstr = scpcommand + " -r " + ".dmn_tmp" + os.path.sep + "*" + " " + login + "@" + url_ssh + ":" + base_ssh print cmdstr os.system(cmdstr) dmutil.rmdir(".dmn_tmp") elif self._server._repository_proto == "ftp": #ftp print "* Uploading ", tarname self.uploadFTPFile(url, login, pwd, destdir, os.path.sep + file_path, tmpdir + os.path.sep + tarname, tarname) print "* Uploading ", md5name self.uploadFTPFile(url, login, pwd, destdir, os.path.sep + file_path, tmpdir + os.path.sep + md5name, md5name) if not self._is_Interactive: print "* Uploading ", dmfile self.uploadFTPFile(url, login, pwd, destdir, os.path.sep + file_path, tmpdir + os.path.sep + dmfile, dmfile) return True
class DepManCreatePlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._path="." self._group="" self._artifact="" self._version="" self._platform="default" self._arch="default" self._compiler="default" self._ltype="" self._upload=False self._is_Interactive=True self._xmlfile = "" self._packageNode = None self._default_ssh="murray.ai2.upv.es" self._default_login="******" self._default_destdir = "/projects/AI2/www-aliases/depman/" def init(self): self.addGoal("create", "Create an artifact") self.addGoalOption("create","--path", "Specifies source directory") self.addGoalOption("create","--group", "Specifies artifact group name") self.addGoalOption("create","--artifact", "Specifies artifact name") self.addGoalOption("create","--version", "Specifies artifact version") self.addGoalOption("create","--platform", "Specifies artifact OS platform") self.addGoalOption("create","--arch", "Specifies artifact hardware architecture") self.addGoalOption("create","--compiler", "Specifies artifact compiler version") self.addGoalOption("create","--ltype", "Specifies library type if needed") self.addGoalOption("create","--upload", "Whenever the artifact must be uploaded or not") self.addGoalOption("create","--from-xml", "Uses the given depman.xml file to create the package") isCreate = False if self._arguments.read("create"): self.setExecute(True) isCreate = True if not isCreate: return args=[""] use_xml=False if self._arguments.read("--from-xml",args): self._xmlfile=args[0] use_xml=True if use_xml: self.loadXMLFile(self._xmlfile) args=[""] if self._arguments.read("--path",args): self._path=args[0] args=[""] if self._arguments.read("--group",args): self._group=args[0] self._is_Interactive=False args=[""] if self._arguments.read("--artifact",args): self._artifact=args[0] self._is_Interactive=False args=[""] if self._arguments.read("--version",args): self._version=args[0] self._is_Interactive=False args=[""] if self._arguments.read("--platform",args): self._platform=args[0] self._is_Interactive=False args=[""] if self._arguments.read("--arch",args): self._arch=args[0] self._is_Interactive=False args=[""] if self._arguments.read("--compiler",args): self._compiler=args[0] self._is_Interactive=False args=[""] if self._arguments.read("--ltype",args): self._ltype=args[0] self._is_Interactive=False if self._arguments.read("--upload"): self._upload=True def initFromXML(self,node): if node.localName == "create": if node.hasAttributes(): if node.attributes.has_key("from-xml"): self._xmlfile=node.attributes.get("from-xml").value self.loadXMLFile(self._xmlfile) if node.attributes.has_key("path"): self._path = node.attributes.get("path").value if node.attributes.has_key("upload"): value = node.attributes.get("upload").value if value =="True" or value =="true": self._upload = True else: if node.localName == "depman": self._packageNode = node self._is_Interactive=False def execute(self): print "Executing Plugin:" + str(self.__class__) return self.create() def create(self): self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return False #user questions if self._is_Interactive: self._group=raw_input("Group: ") self._artifact=raw_input("Artifact: ") self._version=raw_input("Version: ") tmpstr="" for p in self._dmplugin.getSupportedPlatforms(): tmpstr=tmpstr+p+" " print "( ",tmpstr,")" tmstr="Platform [*]:" self._platform=raw_input(string.replace(tmstr,"*",self._dmplugin.getOSPlatform())) if len(self._platform)==0: self._platform=self._dmplugin.getOSPlatform() tmpstr="" for p in self._dmplugin.getSupportedCompilers(): tmpstr=tmpstr+p+" " print "( ",tmpstr,")" tmstr="Compiler [*]:" self._compiler=raw_input(string.replace(tmstr,"*",self._dmplugin.getOSCompiler())) if len(self._compiler)==0: self._compiler=self._dmplugin.getOSCompiler() tmpstr="" for p in self._dmplugin.getSupportedArchs(): tmpstr=tmpstr+p+" " print "( ",tmpstr,")" tmstr="Architecture [*]:" self._arch=raw_input(string.replace(tmstr,"*",self._dmplugin.getOSArch())) if len(self._arch)==0: self._arch=self._dmplugin.getOSArch() tmpstr="" for p in self._dmplugin.getSupportedLibraryTypes(): tmpstr=tmpstr+p+" " print "( ",tmpstr,")" self._ltype=raw_input("Library Type: ") upload_response = raw_input("Upload to server? (y/n): ") if upload_response == "y" or upload_response == "yes": self._upload=True if self._packageNode != None: for n in self._packageNode.childNodes: if n.localName=="package": processPackage = True if n.hasAttributes(): if n.attributes.has_key("platform"): values = n.attributes.get("platform").value.split(",") if self._dmplugin.getOSPlatform() in values: processPackage = True else: processPackage = False if processPackage: print "Processing for platform..." for p in n.childNodes: if p.localName=="group": self._group=p.childNodes[0].nodeValue if p.localName=="artifact": self._artifact=p.childNodes[0].nodeValue if p.localName=="version": self._version=p.childNodes[0].nodeValue if p.localName=="platform": self._platform=p.childNodes[0].nodeValue if p.localName=="compiler": self._compiler=p.childNodes[0].nodeValue if p.localName=="arch": self._arch=p.childNodes[0].nodeValue if p.localName=="libraryType": self._ltype=p.childNodes[0].nodeValue if p.localName =="upload": #TODO: Maybe upload should be an external plugin for k in p.childNodes: if k.localName == "sshserver": self._default_ssh = k.childNodes[0].nodeValue if k.localName == "destdir": self._default_destdir = k.childNodes[0].nodeValue if k.localName == "username": self._default_login = k.childNodes[0].nodeValue if self._group == "": self.reportError("Group cannot be empty") return False if self._artifact == "": self.reportError("Artifact cannot be empty") return False if self._version == "": self.reportError("Version cannog be empty") return self._group=self._group.replace(".","/") if self._platform=="default": self._platform=self._dmplugin.getOSPlatform() if self._compiler=="default": self._compiler=self._dmplugin.getOSCompiler() if self._arch=="default": self._arch=self._dmplugin.getOSArch() #let's check user input consistency if self._platform not in self._dmplugin.getSupportedPlatforms(): self.reportError("Platform not supported: " + self._platform + ". Supported platforms:" + str(self._dmplugin.getSupportedPlatforms())) return False if self._compiler not in self._dmplugin.getSupportedCompilers(): self.reportError("Compiler not supported: " + self._compiler + ". Supported compilers:" +str(self._dmplugin.getSupportedCompilers())) return False if self._arch not in self._dmplugin.getSupportedArchs(): self.reportError("Architecture not supported: " + self._arch + ". Supported archs:" +str(self._dmplugin.getSupportedArchs())) return False if self._ltype not in self._dmplugin.getSupportedLibraryTypes(): self.reportError("Library type not supported: " + self._ltype + ". Supported libraries:" +str(self._dmplugin.getSupportedLibraryTypes())) return False #artifact and md5 generation file_name=self._artifact+"-"+self._version+"-"+self._platform+"-"+self._compiler+"-"+self._arch+"-"+self._ltype tarname=file_name+".tar.gz" md5name=tarname+".md5" dmfile=file_name+".xml" dmutil = BMUtil() tmpdir=self._dmplugin.getDepManPath()+os.path.sep+".cache"+os.path.sep+self._group+os.path.sep+self._artifact+os.path.sep+self._version+os.path.sep+self._platform+os.path.sep+self._compiler+os.path.sep+self._arch+os.path.sep+self._ltype dmutil.mkdir(tmpdir) print tmpdir+os.path.sep+tarname,self._path dmutil.targz(os.path.join(tmpdir,tarname),self._path) #print "targz ",tmpdir+os.path.sep+tarname dmutil.createMD5(tmpdir+os.path.sep+tarname,tmpdir+os.path.sep+md5name) if self._xmlfile != "": shutil.copyfile(self._xmlfile,tmpdir+os.path.sep+dmfile) print "Artifact " + tarname + " created in:\n" + tmpdir if self._upload: dmutil.rmdir(".dmn_tmp") # Prevent for uploading bad previous compilations! sshtmpdir=".dmn_tmp"+os.path.sep+self._group+os.path.sep+self._artifact+os.path.sep+self._version+os.path.sep+self._platform+os.path.sep+self._compiler+os.path.sep+self._arch+os.path.sep+self._ltype dmutil.mkdir(sshtmpdir) shutil.copyfile(tmpdir+os.path.sep+tarname,sshtmpdir+os.path.sep+tarname) shutil.copyfile(tmpdir+os.path.sep+md5name,sshtmpdir+os.path.sep+md5name) if self._xmlfile != "": shutil.copyfile(tmpdir+os.path.sep+dmfile,sshtmpdir+os.path.sep+dmfile) url = self._default_ssh; destdir = self._default_destdir login = self._default_login if self._is_Interactive: tmstr="SSH Server [*]:" url=raw_input(string.replace(tmstr,"*",self._default_ssh)) if len(url)==0: url=self._default_ssh tmstr="Destination Directory [*]:" destdir=raw_input(string.replace(tmstr,"*",self._default_destdir)) if len(destdir)==0: destdir=self._default_destdir tmstr="Login [*]:" login=raw_input(string.replace(tmstr,"*",self._default_login)) if len(login)==0: login=self._default_login download_dir = self._group+"/"+self._artifact+"/"+self._version+"/"+self._platform+"/"+self._compiler+"/"+self._arch+"/"+self._ltype print "* Uploading ",tarname print "* Uploading ",md5name #scp base_ssh=destdir url_ssh=url scpcommand = "scp" pscppath = "" if sys.platform == "win32": scpcommand=self._dmplugin.getDepManDataPath()+os.path.sep+"win32"+os.path.sep+"pscp.exe" scpcommand = '"'+os.path.normpath(scpcommand)+'"' cmdstr=scpcommand +" -r "+".dmn_tmp"+os.path.sep+"*"+" "+login+"@"+url_ssh+":"+base_ssh print cmdstr os.system(cmdstr) #scp dmutil.rmdir(".dmn_tmp")
class DepManCleanPlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._delete_cache = False self._default_repository = "" def init(self): self.addGoal("clean", "Cleans dependency files") self.addGoalOption("clean","--all", "Cleans also cache files") isClean = False if self._arguments.read("clean"): self.setExecute(True) isClean = True if not isClean: return if self._arguments.read("--all"): self._delete_cache = True def initFromXML(self,node): if node.localName=="clean": if node.hasAttributes(): if node.attributes.has_key("all"): value = node.attributes.get("all").value if value=="True" or value == "true": self._delete_cache = True def execute(self): print "Executing Plugin:" + str(self.__class__) return self.clean() def clean(self): self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") self.setExecute(False) return self._default_repository = self._dmplugin.getDepManPath() #the extra parameter "all" enables dmn to clear the cache directory print "* cleaning..." util = BMUtil() util.rmdir(self._default_repository+os.path.sep+"include") util.rmdir(self._default_repository+os.path.sep+"lib") util.rmdir(self._default_repository+os.path.sep+"bin") util.rmdir(self._default_repository+os.path.sep+"share") util.rmdir(self._default_repository+os.path.sep+"Frameworks") if self._delete_cache: util.rmdir(self._default_repository+os.path.sep+".cache") return True def setDeleteCache(self,value): self._delete_cache = value def getDeleteCache(self): return self._delete_cache def setDefaultRepository(self,defrepo): self._default_repository = defrepo def getDefaultRepository(self): return self._default_repository
def create(self): self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return False #user questions if self._is_Interactive: self._group=raw_input("Group: ") self._artifact=raw_input("Artifact: ") self._version=raw_input("Version: ") tmpstr="" for p in self._dmplugin.getSupportedPlatforms(): tmpstr=tmpstr+p+" " print "( ",tmpstr,")" tmstr="Platform [*]:" self._platform=raw_input(string.replace(tmstr,"*",self._dmplugin.getOSPlatform())) if len(self._platform)==0: self._platform=self._dmplugin.getOSPlatform() tmpstr="" for p in self._dmplugin.getSupportedCompilers(): tmpstr=tmpstr+p+" " print "( ",tmpstr,")" tmstr="Compiler [*]:" self._compiler=raw_input(string.replace(tmstr,"*",self._dmplugin.getOSCompiler())) if len(self._compiler)==0: self._compiler=self._dmplugin.getOSCompiler() tmpstr="" for p in self._dmplugin.getSupportedArchs(): tmpstr=tmpstr+p+" " print "( ",tmpstr,")" tmstr="Architecture [*]:" self._arch=raw_input(string.replace(tmstr,"*",self._dmplugin.getOSArch())) if len(self._arch)==0: self._arch=self._dmplugin.getOSArch() tmpstr="" for p in self._dmplugin.getSupportedLibraryTypes(): tmpstr=tmpstr+p+" " print "( ",tmpstr,")" self._ltype=raw_input("Library Type: ") upload_response = raw_input("Upload to server? (y/n): ") if upload_response == "y" or upload_response == "yes": self._upload=True if self._packageNode != None: for n in self._packageNode.childNodes: if n.localName=="package": processPackage = True if n.hasAttributes(): if n.attributes.has_key("platform"): values = n.attributes.get("platform").value.split(",") if self._dmplugin.getOSPlatform() in values: processPackage = True else: processPackage = False if processPackage: print "Processing for platform..." for p in n.childNodes: if p.localName=="group": self._group=p.childNodes[0].nodeValue if p.localName=="artifact": self._artifact=p.childNodes[0].nodeValue if p.localName=="version": self._version=p.childNodes[0].nodeValue if p.localName=="platform": self._platform=p.childNodes[0].nodeValue if p.localName=="compiler": self._compiler=p.childNodes[0].nodeValue if p.localName=="arch": self._arch=p.childNodes[0].nodeValue if p.localName=="libraryType": self._ltype=p.childNodes[0].nodeValue if p.localName =="upload": #TODO: Maybe upload should be an external plugin for k in p.childNodes: if k.localName == "sshserver": self._default_ssh = k.childNodes[0].nodeValue if k.localName == "destdir": self._default_destdir = k.childNodes[0].nodeValue if k.localName == "username": self._default_login = k.childNodes[0].nodeValue if self._group == "": self.reportError("Group cannot be empty") return False if self._artifact == "": self.reportError("Artifact cannot be empty") return False if self._version == "": self.reportError("Version cannog be empty") return self._group=self._group.replace(".","/") if self._platform=="default": self._platform=self._dmplugin.getOSPlatform() if self._compiler=="default": self._compiler=self._dmplugin.getOSCompiler() if self._arch=="default": self._arch=self._dmplugin.getOSArch() #let's check user input consistency if self._platform not in self._dmplugin.getSupportedPlatforms(): self.reportError("Platform not supported: " + self._platform + ". Supported platforms:" + str(self._dmplugin.getSupportedPlatforms())) return False if self._compiler not in self._dmplugin.getSupportedCompilers(): self.reportError("Compiler not supported: " + self._compiler + ". Supported compilers:" +str(self._dmplugin.getSupportedCompilers())) return False if self._arch not in self._dmplugin.getSupportedArchs(): self.reportError("Architecture not supported: " + self._arch + ". Supported archs:" +str(self._dmplugin.getSupportedArchs())) return False if self._ltype not in self._dmplugin.getSupportedLibraryTypes(): self.reportError("Library type not supported: " + self._ltype + ". Supported libraries:" +str(self._dmplugin.getSupportedLibraryTypes())) return False #artifact and md5 generation file_name=self._artifact+"-"+self._version+"-"+self._platform+"-"+self._compiler+"-"+self._arch+"-"+self._ltype tarname=file_name+".tar.gz" md5name=tarname+".md5" dmfile=file_name+".xml" dmutil = BMUtil() tmpdir=self._dmplugin.getDepManPath()+os.path.sep+".cache"+os.path.sep+self._group+os.path.sep+self._artifact+os.path.sep+self._version+os.path.sep+self._platform+os.path.sep+self._compiler+os.path.sep+self._arch+os.path.sep+self._ltype dmutil.mkdir(tmpdir) print tmpdir+os.path.sep+tarname,self._path dmutil.targz(os.path.join(tmpdir,tarname),self._path) #print "targz ",tmpdir+os.path.sep+tarname dmutil.createMD5(tmpdir+os.path.sep+tarname,tmpdir+os.path.sep+md5name) if self._xmlfile != "": shutil.copyfile(self._xmlfile,tmpdir+os.path.sep+dmfile) print "Artifact " + tarname + " created in:\n" + tmpdir if self._upload: dmutil.rmdir(".dmn_tmp") # Prevent for uploading bad previous compilations! sshtmpdir=".dmn_tmp"+os.path.sep+self._group+os.path.sep+self._artifact+os.path.sep+self._version+os.path.sep+self._platform+os.path.sep+self._compiler+os.path.sep+self._arch+os.path.sep+self._ltype dmutil.mkdir(sshtmpdir) shutil.copyfile(tmpdir+os.path.sep+tarname,sshtmpdir+os.path.sep+tarname) shutil.copyfile(tmpdir+os.path.sep+md5name,sshtmpdir+os.path.sep+md5name) if self._xmlfile != "": shutil.copyfile(tmpdir+os.path.sep+dmfile,sshtmpdir+os.path.sep+dmfile) url = self._default_ssh; destdir = self._default_destdir login = self._default_login if self._is_Interactive: tmstr="SSH Server [*]:" url=raw_input(string.replace(tmstr,"*",self._default_ssh)) if len(url)==0: url=self._default_ssh tmstr="Destination Directory [*]:" destdir=raw_input(string.replace(tmstr,"*",self._default_destdir)) if len(destdir)==0: destdir=self._default_destdir tmstr="Login [*]:" login=raw_input(string.replace(tmstr,"*",self._default_login)) if len(login)==0: login=self._default_login download_dir = self._group+"/"+self._artifact+"/"+self._version+"/"+self._platform+"/"+self._compiler+"/"+self._arch+"/"+self._ltype print "* Uploading ",tarname print "* Uploading ",md5name #scp base_ssh=destdir url_ssh=url scpcommand = "scp" pscppath = "" if sys.platform == "win32": scpcommand=self._dmplugin.getDepManDataPath()+os.path.sep+"win32"+os.path.sep+"pscp.exe" scpcommand = '"'+os.path.normpath(scpcommand)+'"' cmdstr=scpcommand +" -r "+".dmn_tmp"+os.path.sep+"*"+" "+login+"@"+url_ssh+":"+base_ssh print cmdstr os.system(cmdstr) #scp dmutil.rmdir(".dmn_tmp")
class BuildManPlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self.reset() def getFile(self): return self._file def getGoalList(self): return self._goalList def reset(self): self._goalList = [] self._file = "buildman.xml" def init(self): self.addGoal("buildman", "executes goals from a buildman file") self.addGoalOption("buildman","--file", "Sets the file to execute, otherwise search for buildman.xml") self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return isBuildMan = False while self._arguments.read("buildman"): self.setExecute(True) isBuildMan = True if not isBuildMan: return args=[""] while self._arguments.read("--file",args): self._file = args[0] def initFromXML(self,node): if node.localName=="buildman": for g in node.childNodes: if g.localName == "goals": addGoals = False if g.hasAttributes(): if g.attributes.has_key("platform"): value = g.attributes.get("platform").value platforms = value.split(",") for platform in platforms: if platform == self._dmplugin.getOSPlatform(): addGoals = True else: addGoals = True if addGoals: for goalNode in g.childNodes: #print goalNode.localName, " in ", PlugInManager().supportedGoals(), "?" if goalNode.localName=="buildman": if goalNode.hasAttributes(): if goalNode.attributes.has_key("file"): self.loadXMLFile(goalNode.attributes.get("file").value) else: if goalNode.localName in PlugInManager().supportedGoals(): self._goalList.append(goalNode) def execute(self): print "Executing Plugin:" + str(self.__class__) return self.buildman() def buildman(self): self.loadXMLFile(self._file) for goal in self._goalList: plugin = PlugInManager().getPlugInInstanceByGoal(goal.localName) plugin.initFromXML(goal) plugin.execute() if plugin.error(): for error in plugin.getErrorMessages(): self.reportError(error) return False return True
if self._projectPath=="": self.reportError("Missing required project path option") return False if self._cmakeGenerator!="" and self._projectPath!="": self._projectPath = os.path.abspath(self._projectPath) projectName = os.path.basename(self._projectPath) if self._projectGenerationPath=="": self._projectGenerationPath=os.path.abspath(os.path.join(self._projectPath,"BMCMake")) if self._installPath=="": self._installPath=os.path.abspath(self._projectPath+os.path.sep+".."+os.path.sep+projectName+"-install") if self._buildType=="": self._buildType="Release" bmutil = BMUtil() print " * Creating Project Generation Path: "+self._projectGenerationPath bmutil.mkdir(self._projectGenerationPath) olddir = os.getcwd() os.chdir(self._projectGenerationPath) if os.path.exists("CMakeCache.txt"): os.remove("CMakeCache.txt") cmakeCommand = "cmake "+self._cmakeOtherOptions+" -G\""+self._cmakeGenerator+"\" -DCMAKE_BUILD_TYPE="+self._buildType+" -DCMAKE_INSTALL_PREFIX="+self._installPath+" "+self._projectPath print " * Running CMAKE: " + cmakeCommand os.system(cmakeCommand) os.chdir(olddir) return True PlugInManager().registerPlugIn("CreateSolutionPlugIn",CreateSolutionPlugIn())
class DepManUpdatePlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._must_Clean = True self._isFromCache = False self._isInteractive = True self._defurl = "http://downloads.gvsig.org/pub/gvSIG-desktop/buildman-repository" self._dependencyList = [] def init(self): self.addGoal("update", "Update current project") self.addGoalOption("update", "--cache", "Cache is preferred") self.addGoalOption("update", "--remote", "Remote repository is preferred") self.addPreGoal("update", "depman") self.addPreGoal("update", "clean") if self._arguments.read("update"): self.setExecute(True) if self._arguments.read("--cache"): self._isInteractive = False self._isFromCache = True if self._arguments.read("--remote"): self._isInteractive = False self._isFromCache = False self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return def initFromXML(self, dom): defurl = self._defurl node = dom.getElementsByTagName("depman")[0] if node != None: if node.hasAttributes(): if node.attributes.has_key("url"): defurl = node.attributes.get("url").value for i in node.childNodes: if i.localName == "dependencies": url = defurl #os default values defplatform = self._dmplugin.getOSPlatform() defdistribution = self._dmplugin.getOSDistribution() defarch = self._dmplugin.getOSArch() defcompiler = self._dmplugin.getOSCompiler() if i.hasAttributes(): if i.attributes.has_key("platform"): defplatform = i.attributes.get("platform").value if i.attributes.has_key("distribution"): defdistribution = i.attributes.get( "distribution").value if i.attributes.has_key("architecture"): defarch = i.attributes.get("architecture").value if i.attributes.has_key("compiler"): defcompiler = i.attributes.get("compiler").value if i.attributes.has_key("url"): url = i.attributes.get("url").value list_of_platforms = defplatform.split(",") #depedencies platform checking #we just go on whenever host os or all matches if len( list_of_platforms ) > 0 and self._dmplugin.getOSPlatform( ) not in list_of_platforms and "all" not in list_of_platforms: invalid_platform = True else: invalid_platform = False defplatform = self._dmplugin.getOSPlatform() del list_of_platforms[:] if not invalid_platform: for j in i.childNodes: if j.localName == "dependency": dependency = DepManDependency(self._dmplugin) #set default values dependency.platform = defplatform dependency.distribution = defdistribution dependency.arch = defarch dependency.compiler = defcompiler dependency.url = url if j.hasAttributes(): if j.attributes.has_key("url"): dependency.url = j.attributes.get( "url").value for h in j.childNodes: if h.localName == "group": dependency.group = h.childNodes[ 0].nodeValue if h.localName == "artifact": dependency.artifact = h.childNodes[ 0].nodeValue if h.localName == "version": dependency.version = h.childNodes[ 0].nodeValue if h.localName == "platform": dependency.platform = h.childNodes[ 0].nodeValue if h.localName == "distribution": dependency.distribution = h.childNodes[ 0].nodeValue if h.localName == "compiler": dependency.compiler = h.childNodes[ 0].nodeValue if h.localName == "architecture": dependency.arch = h.childNodes[ 0].nodeValue if h.localName == "type": dependency.libraryType = h.childNodes[ 0].nodeValue self._dependencyList.append(dependency) def execute(self): return self.update() def update(self): self.initFromXML(self._dmplugin.getNode()) for i in self._dependencyList: print i unPackList = self.getDependencies() #once the xml is parsed and files downloaded, lets unpack them self.unpack(unPackList) def getDependencies(self): self._dmget = PlugInManager().getPlugInInstance("DepManGetPlugIn") if self._dmget == None: self.reportError("PlugIn `depman get` not found") return unPackList = [] for dep in self._dependencyList: self._dmget.setDependency(dep) #prevents downloading of not matching platforms but overrided if not self._isInteractive: if self._isFromCache: self._dmget.setForceCache() else: self._dmget.setForceRemote() self._dmget.get(unPackList) return unPackList def unpack(self, unPackList): sep = os.path.sep dmutil = BMUtil() for file in unPackList: tmpstr = file[file.rfind(sep) + 1:] print "* unpacking ", tmpstr dmutil.untargz(file, self._dmplugin.getDepManPath()) def setForceCache(self): self._isFromCache = True self._isInteractive = False def setForceRemote(self): self._isFromCache = False self._isInteractive = False
str(self._options)) return False if self._option not in self._options: self.reportError("not supported svn option, use one of " + str(self._options)) return False if self._projectPath == "": self.reportError("Missing required project path option") return False if self._option == "co" or self._option == "checkout": if self._svnUrl == "": self.reportError("Missing required svn url ption") return False self._projectPath = os.path.abspath(self._projectPath) projectName = os.path.basename(self._projectPath) print "Executing Plugin:" + str(self.__class__) bmutil = BMUtil() svnCommand = "svn " + self._option if self._option in ['co', 'checkout']: svnCommand += " " + self._svnUrl + " " + self._projectPath else: if self._option in ['up', 'update']: svnCommand += " " + self._projectPath os.system(svnCommand) return True PlugInManager().registerPlugIn("SVNPlugIn", SVNPlugIn())
addGoals = True if addGoals: for goalNode in g.childNodes: #print goalNode.localName, " in ", PlugInManager().supportedGoals(), "?" if goalNode.localName=="buildman": if goalNode.hasAttributes(): if goalNode.attributes.has_key("file"): self.loadXMLFile(goalNode.attributes.get("file").value) else: if goalNode.localName in PlugInManager().supportedGoals(): self._goalList.append(goalNode) def execute(self): print "Executing Plugin:" + str(self.__class__) return self.buildman() def buildman(self): self.loadXMLFile(self._file) for goal in self._goalList: plugin = PlugInManager().getPlugInInstanceByGoal(goal.localName) plugin.initFromXML(goal) plugin.execute() if plugin.error(): for error in plugin.getErrorMessages(): self.reportError(error) return False return True PlugInManager().registerPlugIn("BuildManPlugIn",BuildManPlugIn())
self.reportError("PlugIn `depman` not found") self.setExecute(False) return self._default_repository = self._dmplugin.getDepManPath() #the extra parameter "all" enables dmn to clear the cache directory print "* cleaning..." util = BMUtil() util.rmdir(self._default_repository + os.path.sep + "include") util.rmdir(self._default_repository + os.path.sep + "lib") util.rmdir(self._default_repository + os.path.sep + "bin") util.rmdir(self._default_repository + os.path.sep + "share") util.rmdir(self._default_repository + os.path.sep + "Frameworks") if self._delete_cache: util.rmdir(self._default_repository + os.path.sep + ".cache") return True def setDeleteCache(self, value): self._delete_cache = value def getDeleteCache(self): return self._delete_cache def setDefaultRepository(self, defrepo): self._default_repository = defrepo def getDefaultRepository(self): return self._default_repository PlugInManager().registerPlugIn("DepManCleanPlugIn", DepManCleanPlugIn())
def init(self): self.addGoal("get", "downloads an artifact if not in cache.") self.addGoalOption("get", "--url", "URL base for the DepMan repository.") self.addGoalOption("get", "--group", "Group namespace of the artifact.") self.addGoalOption("get", "--artifact", "Name of the artifact to download.") self.addGoalOption("get", "--version", "Version of the artifact.") self.addGoalOption("get", "--platform", "Platform of the artifact.") self.addGoalOption("get", "--distribution", "Distribution of the artifact.") self.addGoalOption( "get", "--compiler", "Selects the compiler version that was used to compile the artifact." ) self.addGoalOption("get", "--arch", "Selects the architecture of the artifact.") self.addGoalOption("get", "--ltype", "Type of library of the artifact.") self.addGoalOption("get", "--cache", "Forces the use of cache files without asking.") self.addGoalOption( "get", "--remote", "Forces the download of remote without the use of the cache and without asking." ) self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return self._default_repository = self._dmplugin.getDepManPath() while self._arguments.read("get"): self._dependency = Dependency() self.setExecute(true) args = [""] if self._arguments.read("--url", args): self._dependency.url = args[0] args = [""] if self._arguments.read("--group", args): self._dependency.group = args[0] args = [""] if self._arguments.read("--artifact", args): self._dependency.artifact = args[0] args = [""] if self._arguments.read("--version", args): self._dependency.version = args[0] args = [""] if self._arguments.read("--platform", args): self._dependency.platform = args[0] args = [""] if self._arguments.read("--distribution", args): self._dependency.distribution = args[0] args = [""] if self._arguments.read("--compiler", args): self._dependency.compiler = args[0] args = [""] if self._arguments.read("--arch", args): self._dependency.arch = args[0] args = [""] if self._arguments.read("--ltype", args): self._dependency.libraryType = args[0] if self._arguments.read("--cache"): self._forceCache = True self._isInteractive = False if self._arguments.read("--remote"): self._forceCache = False self._isInteractive = False
class BuildManPlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self.reset() def getFile(self): return self._file def getGoalList(self): return self._goalList def reset(self): self._goalList = [] self._file = "buildman.xml" def init(self): self.addGoal("buildman", "executes goals from a buildman file") self.addGoalOption("buildman","--file", "Sets the file to execute, otherwise search for buildman.xml") self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return isBuildMan = False while self._arguments.read("buildman"): self.setExecute(True) isBuildMan = True if not isBuildMan: return args=[""] while self._arguments.read("--file",args): self._file = args[0] def initFromXML(self,dom): node = dom.getElementsByTagName("buildman")[0] if node != None: if node.localName=="buildman": for g in node.childNodes: if g.localName == "goals": addGoals = False if g.hasAttributes(): if g.attributes.has_key("platform"): value = g.attributes.get("platform").value platforms = value.split(",") for platform in platforms: if platform == self._dmplugin.getOSPlatform(): addGoals = True else: addGoals = True if addGoals: for goalNode in g.childNodes: #print goalNode.localName, " in ", PlugInManager().supportedGoals(), "?" if goalNode.localName=="buildman": if goalNode.hasAttributes(): if goalNode.attributes.has_key("file"): self.loadXMLFile(goalNode.attributes.get("file").value) else: if goalNode.localName in PlugInManager().supportedGoals(): self._goalList.append(goalNode) def execute(self): return self.buildman() def buildman(self): self.loadXMLFile(self._file) for goal in self._goalList: plugin = PlugInManager().getPlugInInstanceByGoal(goal.localName) plugin.initFromXML(goal) plugin.execute() if plugin.error(): for error in plugin.getErrorMessages(): self.reportError(error) return False return True
class DepManCreatePlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._path = "." self._is_Interactive = False self._dependency = None self._default_ftp = "downloads.gvsig.org" self._default_login = "******" self._default_destdir = "/anon/pub/gvSIG-desktop/buildman-repository" def init(self): self.addGoal("create", "Create an artifact") self.addGoalOption("create", "--path", "Specifies source directory") self.addGoalOption( "create", "--interactive", "ask for server or artifact deployment configuration") self.addPreGoal("create", "depman") self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") self._dmdeployplugin = PlugInManager().getPlugInInstance( "DepManDeployPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return False if self._arguments.read("create"): self.setExecute(True) args = [""] if self._arguments.read("--path", args): self._path = args[0] if self._arguments.read("--interactive"): self._is_Interactive = True def initFromXML(self, node): packageNodes = node.getElementsByTagName("package") if packageNodes != None: for n in packageNodes: if n.localName == "package": processPackage = True if n.hasAttributes(): if n.attributes.has_key("platform"): values = n.attributes.get("platform").value.split( ",") if self._dmplugin.getOSPlatform() in values: processPackage = True else: processPackage = False if processPackage: print "Processing for platform..." self._dependency = DepManDependency(self._dmplugin) for p in n.childNodes: if p.localName == "group": self._dependency.group = p.childNodes[ 0].nodeValue if p.localName == "artifact": self._dependency.artifact = p.childNodes[ 0].nodeValue if p.localName == "version": self._dependency.version = p.childNodes[ 0].nodeValue if p.localName == "platform": self._dependency.platform = p.childNodes[ 0].nodeValue if p.localName == "distribution": self._dependency.distribution = p.childNodes[ 0].nodeValue if p.localName == "compiler": self._dependency.compiler = p.childNodes[ 0].nodeValue if p.localName == "arch": self._dependency.arch = p.childNodes[ 0].nodeValue if p.localName == "libraryType": self._dependency.libraryType = p.childNodes[ 0].nodeValue print "Creating Artifact:" + str(self._dependency) def execute(self): return self.create() def create(self): self.initFromXML(self._dmplugin.getNode()) #user questions if self._dependency == None: self._dependency = DepManDependency(self._dmplugin) self._is_Interactive = True self._dependency.raw_input() upload_response = raw_input("Upload to server? (y/n): ") if upload_response == "y" or upload_response == "yes": self._upload = True if not self._dmplugin.validateDependency(self._dependency): return False #artifact and md5 generation file_name = self._dependency.getDepManFileName() file_path = self._dependency.getDepManFilePath() tarname = file_name + ".tar.gz" md5name = tarname + ".md5" dmfile = file_name + ".xml" dmutil = BMUtil() tmpdir = self._dmplugin.getMavenPath( ) + os.path.sep + "repository" + os.path.sep + file_path dmutil.mkdir(tmpdir) print tmpdir + os.path.sep + tarname, self._path dmutil.targz(os.path.join(tmpdir, tarname), self._path) #print "targz ",tmpdir+os.path.sep+tarname dmutil.createMD5(tmpdir + os.path.sep + tarname, tmpdir + os.path.sep + md5name) if not self._is_Interactive: shutil.copyfile(self._dmplugin.getXMLFile(), tmpdir + os.path.sep + dmfile) self._dmdeployplugin.setDependency(self._dependency) print "Artifact " + tarname + " created in:\n" + tmpdir
def getDependencies(self, node): self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return self._dmget = PlugInManager().getPlugInInstance("DepManGetPlugIn") if self._dmget == None: self.reportError("PlugIn `depman get` not found") return group = "none" artifact = "none" version = "0" platform = "none" compiler = "none" arch = "none" ltype = "none" #os default values defplatform = self._dmplugin.getOSPlatform() defarch = self._dmplugin.getOSArch() defcompiler = self._dmplugin.getOSCompiler() #hardcoded default url #defurl=default_url defurl = self._defurl unPackList = [] if node.hasAttributes(): if node.attributes.has_key("url"): defurl = node.attributes.get("url").value for i in node.childNodes: if i.localName == "dependencies": url = defurl #os default values defplatform = self._dmplugin._osplatform defarch = self._dmplugin._osarch defcompiler = self._dmplugin._oscompiler if i.hasAttributes(): if i.attributes.has_key("platform"): defplatform = i.attributes.get("platform").value if i.attributes.has_key("architecture"): defarch = i.attributes.get("architecture").value if i.attributes.has_key("compiler"): defcompiler = i.attributes.get("compiler").value if i.attributes.has_key("url"): url = i.attributes.get("url").value list_of_platforms = defplatform.split(",") #depedencies platform checking #we just go on whenever host os or all matches if len(list_of_platforms) > 0 and self._dmplugin.getOSPlatform( ) not in list_of_platforms and "all" not in list_of_platforms: invalid_platform = True else: invalid_platform = False defplatform = self._dmplugin.getOSPlatform() del list_of_platforms[:] #print "Url: ",url if not invalid_platform: for j in i.childNodes: if j.localName == "dependency": #set default values platform = defplatform arch = defarch compiler = defcompiler group = "none" artifact = "none" version = "0" ltype = "none" durl = url if j.hasAttributes(): if j.attributes.has_key("url"): durl = j.attributes.get("url").value for h in j.childNodes: if h.localName == "group": group = h.childNodes[0].nodeValue if h.localName == "artifact": artifact = h.childNodes[0].nodeValue if h.localName == "version": version = h.childNodes[0].nodeValue if h.localName == "platform": platform = h.childNodes[0].nodeValue if h.localName == "compiler": compiler = h.childNodes[0].nodeValue if h.localName == "architecture": arch = h.childNodes[0].nodeValue if h.localName == "type": ltype = h.childNodes[0].nodeValue self._dmget.setURL(durl) self._dmget.setGroup(group) self._dmget.setArtifact(artifact) self._dmget.setVersion(version) self._dmget.setPlatform(platform) self._dmget.setCompiler(compiler) self._dmget.setArch(arch) self._dmget.setLibraryType(ltype) #prevents downloading of not matching platforms but overrided if not self._isInteractive: if self._isFromCache: self._dmget.setForceCache() else: self._dmget.setForceRemote() self._dmget.get(unPackList) return unPackList
class DepManGetPlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._default_repository = "" self._url = "" self._group = "" self._artifact = "" self._version = "" self._platform = "" self._artifact = "" self._compiler = "" self._arch = "" self._ltype = "" self._forceCache = False self._isInteractive = True def setURL(self,url): self._url = url def setGroup(self,group): self._group = group def setArtifact(self,artifact): self._artifact = artifact def setVersion(self,version): self._version = version def setPlatform(self,platform): self._platform = platform def setCompiler(self,compiler): self._compiler = compiler def setArch(self,arch): self._arch = arch def setLibraryType(self,ltype): self._ltype = ltype def setForceCache(self): self._forceCache = True self._isInteractive = False def setForceRemote(self): self._forceCache = False self._isInteractive = False def init(self): self.addGoal("get", "downloads an artifact if not in cache.") self.addGoalOption("get","--url", "URL base for the DepMan repository.") self.addGoalOption("get","--group", "Group namespace of the artifact.") self.addGoalOption("get","--artifact", "Name of the artifact to download.") self.addGoalOption("get","--version", "Version of the artifact.") self.addGoalOption("get","--platform", "Platform of the artifact.") self.addGoalOption("get","--compiler", "Selects the compiler version that was used to compile the artifact.") self.addGoalOption("get","--arch", "Selects the architecture of the artifact.") self.addGoalOption("get","--ltype", "Type of library of the artifact.") self.addGoalOption("get","--cache", "Forces the use of cache files without asking.") self.addGoalOption("get","--remote", "Forces the download of remote without the use of the cache and without asking.") self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return self._default_repository = self._dmplugin.getDepManPath() isGet = False while self._arguments.read("get"): isGet = True if not isGet: return args=[""] if self._arguments.read("--url",args): self._url = args[0] args=[""] if self._arguments.read("--group",args): self._group = args[0] args=[""] if self._arguments.read("--artifact",args): self._artifact = args[0] args=[""] if self._arguments.read("--version",args): self._version = args[0] args=[""] if self._arguments.read("--platform",args): self._platform = args[0] args=[""] if self._arguments.read("--compiler",args): self._compiler = args[0] args=[""] if self._arguments.read("--arch",args): self._arch = args[0] args=[""] if self._arguments.read("--ltype",args): self._ltype = args[0] if self._arguments.read("--cache"): self._forceCache = True self._isInteractive = False if self._arguments.read("--remote"): self._forceCache = False self._isInteractive = False self.setExecute(True) def initFromXML(self,node): pass #TODO: . . . def execute(self): print "Executing Plugin:" + str(self.__class__) if self._url == "": self.reportError("Missing url option") return if self._artifact == "": self.reportError("Missing artifact option") return if self._group == "": self.reportError("Missing group option") return if self._version == "": self.reportError("Missing version option") return if self._platform == "": self.reportError("Missing platform option") return if self._compiler == "": self.reportError("Missing compiler option") return if self._arch == "": self.reportError("Missing artifact option") return if self._ltype == "": self.reportError("Missing library type option") return if self._platform not in self._dmplugin.getSupportedPlatforms(): self.reportError("* Platform not supported: " + self._platform) return if self._compiler not in self._dmplugin.getSupportedCompilers(): self.reportError("* Compiler not supported: "+ self._compiler) return if self._arch not in self._dmplugin.getSupportedArchs(): self.reportError("* Architecture not supported: "+ self._arch) return if self._ltype not in self._dmplugin.getSupportedLibraryTypes(): self.reportError("* Library type not supported: " + self._ltype) return if self._platform!=self._dmplugin.getOSPlatform() and self._platform!="all": print "* Warning: Forced platform ",self._platform return self.get() def get(self, unPackList = None): #transform namespaces org.foo to org/foo group=self._group.replace(".","/") print "[",self._artifact,"]" file_name=self._artifact+"-"+self._version+"-"+self._platform+"-"+self._compiler+"-"+self._arch+"-"+self._ltype tarname=file_name+".tar.gz" md5name=tarname+".md5" download_path = group+os.path.sep+self._artifact+os.path.sep+self._version+os.path.sep+self._platform+os.path.sep+self._compiler+os.path.sep+self._arch+os.path.sep+self._ltype download_dir = group+"/"+self._artifact+"/"+self._version+"/"+self._platform+"/"+self._compiler+"/"+self._arch+"/"+self._ltype cache_path = self._default_repository+os.path.sep+".cache"+os.path.sep+download_path tstr=self._version.lower() if tstr.find("snapshot")!=-1: is_snapshot=True else: is_snapshot=False dmutil = BMUtil() is_tar=True is_md5=True if not dmutil.checkUrl(self._url+"/"+download_dir+"/"+md5name): #print "Error: File ",baseurl+"/"+download_dir+"/"+md5name, " not found in the repository" is_md5=False if not dmutil.checkUrl(self._url+"/"+download_dir+"/"+tarname): #print "Error: File ",baseurl+"/"+download_dir+"/"+tarname, " not found in the repository" is_tar=False dmutil.mkdir(cache_path) if not os.path.isfile(cache_path+os.path.sep+md5name): is_cache=False else: is_cache=True #Once all variables have been collected, lets decide what to do with the artifact must_download=False if (not is_md5 or not is_tar) and not is_cache: print "Error: Artifact ",tarname," not found" return False if not is_md5 and not is_tar and is_cache: print "* file not found in repository, using cache..." must_download=False if is_md5 and is_tar and not is_cache: print "* file is not in cache, downloading..." must_download=True if is_md5 and is_tar and is_cache: if is_snapshot: if self._isInteractive: repo=raw_input("What snapshot do you want to use? (cache/remote): ") else: if self._forceCache: repo="cache" else: repo="remote" must_download=False #in case of misspeling, using cache by default if repo!="cache" and repo!="remote": repo="cache" else: repo="remote" if repo=="remote": print "* file cached, checking md5..." dmutil.download(self._url+"/"+download_dir+"/"+md5name,cache_path+os.path.sep+md5name+".new") if dmutil.diff(cache_path+os.path.sep+md5name,cache_path+os.path.sep+md5name+".new"): print "* no md5 matching, re-downloading..." must_download=True else: print "* md5 matching succesful" must_download=False os.remove(cache_path+os.path.sep+md5name+".new") if must_download==True: print "URL :", self._url dmutil.download(self._url+"/"+download_dir+"/"+md5name,cache_path+os.path.sep+md5name) #print "* downloaded [",md5name,"]" dmutil.download(self._url+"/"+download_dir+"/"+tarname,cache_path+os.path.sep+tarname) #print "* downloaded[",tarname,"]" if unPackList != None: if (cache_path+os.path.sep+tarname) not in unPackList: unPackList.append(cache_path+os.path.sep+tarname) return True
self._path = args[0] self.setExecute(True) def initFromXML(self, dom): node = dom.getElementsByTagName("delete")[0] if node != None: if node.hasAttributes(): if node.attributes.has_key("path"): self._path = node.attributes.get("path").value def execute(self): if self._path == "": self.reportError("Missing required path option") self._path = os.path.abspath(self._path) util = BMUtil() if not os.path.exists(self._path): return True if os.path.isdir(self._path): print "* Removing directory " + self._path util.rmdir(self._path) else: print "* Removing file " + self._path os.remove(self._path) return True PlugInManager().registerPlugIn("DeleteFilePlugIn", DeleteFilePlugIn())
def getDependencies(self,node): self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return self._dmget = PlugInManager().getPlugInInstance("DepManGetPlugIn") if self._dmget == None: self.reportError("PlugIn `depman get` not found") return group="none" artifact="none" version="0" platform="none" compiler="none" arch="none" ltype="none" #os default values defplatform=self._dmplugin.getOSPlatform() defarch=self._dmplugin.getOSArch() defcompiler=self._dmplugin.getOSCompiler() #hardcoded default url #defurl=default_url defurl=self._defurl unPackList = [] if node.hasAttributes(): if node.attributes.has_key("url"): defurl=node.attributes.get("url").value for i in node.childNodes: if i.localName=="dependencies": url=defurl #os default values defplatform=self._dmplugin._osplatform defarch=self._dmplugin._osarch defcompiler=self._dmplugin._oscompiler if i.hasAttributes(): if i.attributes.has_key("platform"): defplatform=i.attributes.get("platform").value if i.attributes.has_key("architecture"): defarch=i.attributes.get("architecture").value if i.attributes.has_key("compiler"): defcompiler=i.attributes.get("compiler").value if i.attributes.has_key("url"): url=i.attributes.get("url").value list_of_platforms=defplatform.split(",") #depedencies platform checking #we just go on whenever host os or all matches if len(list_of_platforms)>0 and self._dmplugin.getOSPlatform() not in list_of_platforms and "all" not in list_of_platforms: invalid_platform=True else: invalid_platform=False defplatform=self._dmplugin.getOSPlatform() del list_of_platforms[:] #print "Url: ",url if not invalid_platform: for j in i.childNodes: if j.localName=="dependency": #set default values platform=defplatform arch=defarch compiler=defcompiler group="none" artifact="none" version="0" ltype="none" durl = url if j.hasAttributes(): if j.attributes.has_key("url"): durl=j.attributes.get("url").value for h in j.childNodes: if h.localName=="group": group=h.childNodes[0].nodeValue if h.localName=="artifact": artifact=h.childNodes[0].nodeValue if h.localName=="version": version=h.childNodes[0].nodeValue if h.localName=="platform": platform=h.childNodes[0].nodeValue if h.localName=="compiler": compiler=h.childNodes[0].nodeValue if h.localName=="architecture": arch=h.childNodes[0].nodeValue if h.localName=="type": ltype=h.childNodes[0].nodeValue self._dmget.setURL(durl) self._dmget.setGroup(group) self._dmget.setArtifact(artifact) self._dmget.setVersion(version) self._dmget.setPlatform(platform) self._dmget.setCompiler(compiler) self._dmget.setArch(arch) self._dmget.setLibraryType(ltype) #prevents downloading of not matching platforms but overrided if not self._isInteractive: if self._isFromCache: self._dmget.setForceCache() else: self._dmget.setForceRemote() self._dmget.get(unPackList) return unPackList
class DepManCleanPlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._delete_cache = False self._default_repository = "" def init(self): self.addGoal("clean", "Cleans the repository") self.addGoalOption("clean", "--all", "Cleans also cache files") isClean = False if self._arguments.read("clean"): self.setExecute(True) isClean = True if not isClean: return if self._arguments.read("--all"): self._delete_cache = True def initFromXML(self, dom): node = dom.getElementsByTagName("clean")[0] if node != None: if node.localName == "clean": if node.hasAttributes(): if node.attributes.has_key("all"): value = node.attributes.get("all").value if value == "True" or value == "true": self._delete_cache = True def execute(self): print "Executing Plugin:" + str(self.__class__) return self.clean() def clean(self): self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") self.setExecute(False) return self._default_repository = self._dmplugin.getDepManPath() #the extra parameter "all" enables dmn to clear the cache directory print "* cleaning..." util = BMUtil() util.rmdir(self._default_repository + os.path.sep + "include") util.rmdir(self._default_repository + os.path.sep + "lib") util.rmdir(self._default_repository + os.path.sep + "bin") util.rmdir(self._default_repository + os.path.sep + "share") util.rmdir(self._default_repository + os.path.sep + "Frameworks") if self._delete_cache: util.rmdir(self._default_repository + os.path.sep + ".cache") return True def setDeleteCache(self, value): self._delete_cache = value def getDeleteCache(self): return self._delete_cache def setDefaultRepository(self, defrepo): self._default_repository = defrepo def getDefaultRepository(self): return self._default_repository
class DepManExtractPlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._xmlFile = "depman.xml" self._destDir = "." self._filter = "*" self._isFromCache = False self._isInteractive = True self._depmanNode = None def init(self): self.addGoal( "extract", "Extract the files of dependencies and package sections of a depman xml file." ) self.addGoalOption("extract", "--file", "Sets an alternate xml file. Default: depman.xml") self.addGoalOption( "extract", "--destdir", "Sets the destination directory of the extraction. Default: `.`") self.addGoalOption( "extract", "--filter", "Sets the the filter of the files to extract. Default: `*`") self.addGoalOption("extract", "--cache", "Cache is preferred") self.addGoalOption("extract", "--remote", "Remote repository is preferred") isExtract = False if self._arguments.read("extract"): self.setExecute(True) isExtract = True if not isExtract: return args = [""] if self._arguments.read("--file", args): self._xmlFile = args[0] args = [""] if self._arguments.read("--destdir", args): self._destDir = args[0] args = [""] if self._arguments.read("--filter", args): self._filter = args[0] if self._arguments.read("--cache"): self._isFromCache = True self._isInteractive = False if self._arguments.read("--remote"): self._isFromCache = False self._isInteractive = False def initFromXML(self, node): if node.localName == "extract": if node.hasAttributes(): if node.attributes.has_key("file"): elf._xmlFile = node.attributes.get("file").value if node.attributes.has_key("destdir"): elf._destDir = node.attributes.get("destdir").value if node.attributes.has_key("filter"): elf._filter = node.attributes.get("filter").value foundCache = False if node.attributes.has_key("cache"): value = node.attributes.get("cache").value if value == "True" or value == "true": self._isFromCache = True self._isInteractive = False if node.attributes.has_key("remote") and not foundCache: value = node.attributes.get("remote").value if value == "True" or value == "true": self._isFromCache = False self._isInteractive = False else: self._depmanNode = node def execute(self): return self.extract() def extract(self): self._dmupdate = PlugInManager().getPlugInInstance( "DepManUpdatePlugIn") if self._dmupdate == None: self.reportError("PlugIn `depman update` not found") return if self._depmanNode == None: self.loadXMLFile(self._xmlFile) if not self._isInteractive: if self._isFromCache: self._dmupdate.setForceCache() else: self._dmupdate.setForceRemote() dependency_filenamepaths = self._dmupdate.getDependencies( self._depmanNode) package_namepath = self.parsePackage(self._depmanNode) print dependency_filenamepaths, self._destDir, self._filter bmutil = BMUtil() for file in dependency_filenamepaths: bmutil.untargzFiltered(file, self._destDir, self._filter) def parsePackage(self, node): return ""
class DepManUpdatePlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._must_Clean=True self._isFromCache=False self._isInteractive=True self._xmlfile="depman.xml" self._depmanNode = None self._defurl="http://murray.ai2.upv.es/depman" def init(self): self.addGoal("update", "Update current project") self.addGoalOption("update","--no-clean", "Do not perform a repository clean before update") self.addGoalOption("update","--cache", "Cache is preferred") self.addGoalOption("update","--remote", "Remote repository is preferred") self.addGoalOption("update","--file", "Specifies a dependency xml file") isUpdate = False if self._arguments.read("update"): self.setExecute(True) isUpdate = True if not isUpdate: return if self._arguments.read("--no-clean"): self._must_Clean = False if self._arguments.read("--cache"): self._isInteractive=False self._isFromCache = True if self._arguments.read("--remote"): self._isInteractive=False self._isFromCache = False args=[""] if self._arguments.read("--file",args): self._xmlfile=args[0] def initFromXML(self,node): if node.localName == "update": if node.hasAttributes(): if node.attributes.has_key("file"): self.loadXMLFile(node.attributes.get("file").value) if node.attributes.has_key("no-clean"): value = node.attributes.get("no-clean").value if value == "True" or value == "true": self._must_Clean = True foundCache = False if node.attributes.has_key("cache"): value = node.attributes.get("cache").value if value == "True" or value == "true": self._isFromCache = True if node.attributes.has_key("remote") and not foundCache: value = node.attributes.get("remote").value if value == "True" or value == "true": self._isFromCache = False self._isInteractive = False else: self._depmanNode = node def execute(self): print "Executing Plugin:" + str(self.__class__) return self.update() def update(self): if self._must_Clean: self._dmclean = PlugInManager().getPlugInInstance("DepManCleanPlugIn") if self._dmclean == None: self.reportError("PlugIn `depman clean` not found") return delete_cache = self._dmclean.getDeleteCache() self._dmclean.setDeleteCache(False) self._dmclean.clean() self._dmclean.setDeleteCache(delete_cache) if self._depmanNode == None: self.loadXMLFile(self._xmlfile) unPackList = self.getDependencies(self._depmanNode) #once the xml is parsed and files downloaded, lets unpack them self.unpack(unPackList) def getDependencies(self,node): self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return self._dmget = PlugInManager().getPlugInInstance("DepManGetPlugIn") if self._dmget == None: self.reportError("PlugIn `depman get` not found") return group="none" artifact="none" version="0" platform="none" compiler="none" arch="none" ltype="none" #os default values defplatform=self._dmplugin.getOSPlatform() defarch=self._dmplugin.getOSArch() defcompiler=self._dmplugin.getOSCompiler() #hardcoded default url #defurl=default_url defurl=self._defurl unPackList = [] if node.hasAttributes(): if node.attributes.has_key("url"): defurl=node.attributes.get("url").value for i in node.childNodes: if i.localName=="dependencies": url=defurl #os default values defplatform=self._dmplugin._osplatform defarch=self._dmplugin._osarch defcompiler=self._dmplugin._oscompiler if i.hasAttributes(): if i.attributes.has_key("platform"): defplatform=i.attributes.get("platform").value if i.attributes.has_key("architecture"): defarch=i.attributes.get("architecture").value if i.attributes.has_key("compiler"): defcompiler=i.attributes.get("compiler").value if i.attributes.has_key("url"): url=i.attributes.get("url").value list_of_platforms=defplatform.split(",") #depedencies platform checking #we just go on whenever host os or all matches if len(list_of_platforms)>0 and self._dmplugin.getOSPlatform() not in list_of_platforms and "all" not in list_of_platforms: invalid_platform=True else: invalid_platform=False defplatform=self._dmplugin.getOSPlatform() del list_of_platforms[:] #print "Url: ",url if not invalid_platform: for j in i.childNodes: if j.localName=="dependency": #set default values platform=defplatform arch=defarch compiler=defcompiler group="none" artifact="none" version="0" ltype="none" durl = url if j.hasAttributes(): if j.attributes.has_key("url"): durl=j.attributes.get("url").value for h in j.childNodes: if h.localName=="group": group=h.childNodes[0].nodeValue if h.localName=="artifact": artifact=h.childNodes[0].nodeValue if h.localName=="version": version=h.childNodes[0].nodeValue if h.localName=="platform": platform=h.childNodes[0].nodeValue if h.localName=="compiler": compiler=h.childNodes[0].nodeValue if h.localName=="architecture": arch=h.childNodes[0].nodeValue if h.localName=="type": ltype=h.childNodes[0].nodeValue self._dmget.setURL(durl) self._dmget.setGroup(group) self._dmget.setArtifact(artifact) self._dmget.setVersion(version) self._dmget.setPlatform(platform) self._dmget.setCompiler(compiler) self._dmget.setArch(arch) self._dmget.setLibraryType(ltype) #prevents downloading of not matching platforms but overrided if not self._isInteractive: if self._isFromCache: self._dmget.setForceCache() else: self._dmget.setForceRemote() self._dmget.get(unPackList) return unPackList def unpack(self,unPackList): sep=os.path.sep dmutil = BMUtil() for file in unPackList: tmpstr=file[file.rfind(sep)+1:] print "* unpacking ",tmpstr dmutil.untargz(file,self._dmplugin.getDepManPath()) def setForceCache(self): self._isFromCache = True self._isInteractive = False def setForceRemote(self): self._isFromCache = False self._isInteractive = False
def create(self): self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return False #user questions if self._is_Interactive: self._group = raw_input("Group: ") self._artifact = raw_input("Artifact: ") self._version = raw_input("Version: ") tmpstr = "" for p in self._dmplugin.getSupportedPlatforms(): tmpstr = tmpstr + p + " " print "( ", tmpstr, ")" tmstr = "Platform [*]:" self._platform = raw_input( string.replace(tmstr, "*", self._dmplugin.getOSPlatform())) if len(self._platform) == 0: self._platform = self._dmplugin.getOSPlatform() tmpstr = "" for p in self._dmplugin.getSupportedCompilers(): tmpstr = tmpstr + p + " " print "( ", tmpstr, ")" tmstr = "Compiler [*]:" self._compiler = raw_input( string.replace(tmstr, "*", self._dmplugin.getOSCompiler())) if len(self._compiler) == 0: self._compiler = self._dmplugin.getOSCompiler() tmpstr = "" for p in self._dmplugin.getSupportedArchs(): tmpstr = tmpstr + p + " " print "( ", tmpstr, ")" tmstr = "Architecture [*]:" self._arch = raw_input( string.replace(tmstr, "*", self._dmplugin.getOSArch())) if len(self._arch) == 0: self._arch = self._dmplugin.getOSArch() tmpstr = "" for p in self._dmplugin.getSupportedLibraryTypes(): tmpstr = tmpstr + p + " " print "( ", tmpstr, ")" self._ltype = raw_input("Library Type: ") upload_response = raw_input("Upload to server? (y/n): ") if upload_response == "y" or upload_response == "yes": self._upload = True if self._packageNode != None: for n in self._packageNode.childNodes: if n.localName == "package": processPackage = True if n.hasAttributes(): if n.attributes.has_key("platform"): values = n.attributes.get("platform").value.split( ",") if self._dmplugin.getOSPlatform() in values: processPackage = True else: processPackage = False if processPackage: print "Processing for platform..." for p in n.childNodes: if p.localName == "group": self._group = p.childNodes[0].nodeValue if p.localName == "artifact": self._artifact = p.childNodes[0].nodeValue if p.localName == "version": self._version = p.childNodes[0].nodeValue if p.localName == "platform": self._platform = p.childNodes[0].nodeValue if p.localName == "compiler": self._compiler = p.childNodes[0].nodeValue if p.localName == "arch": self._arch = p.childNodes[0].nodeValue if p.localName == "libraryType": self._ltype = p.childNodes[0].nodeValue if p.localName == "upload": #TODO: Maybe upload should be an external plugin for k in p.childNodes: if k.localName == "sshserver": self._default_ssh = k.childNodes[ 0].nodeValue if k.localName == "destdir": self._default_destdir = k.childNodes[ 0].nodeValue if k.localName == "username": self._default_login = k.childNodes[ 0].nodeValue if self._group == "": self.reportError("Group cannot be empty") return False if self._artifact == "": self.reportError("Artifact cannot be empty") return False if self._version == "": self.reportError("Version cannog be empty") return self._group = self._group.replace(".", "/") if self._platform == "default": self._platform = self._dmplugin.getOSPlatform() if self._compiler == "default": self._compiler = self._dmplugin.getOSCompiler() if self._arch == "default": self._arch = self._dmplugin.getOSArch() #let's check user input consistency if self._platform not in self._dmplugin.getSupportedPlatforms(): self.reportError("Platform not supported: " + self._platform + ". Supported platforms:" + str(self._dmplugin.getSupportedPlatforms())) return False if self._compiler not in self._dmplugin.getSupportedCompilers(): self.reportError("Compiler not supported: " + self._compiler + ". Supported compilers:" + str(self._dmplugin.getSupportedCompilers())) return False if self._arch not in self._dmplugin.getSupportedArchs(): self.reportError("Architecture not supported: " + self._arch + ". Supported archs:" + str(self._dmplugin.getSupportedArchs())) return False if self._ltype not in self._dmplugin.getSupportedLibraryTypes(): self.reportError("Library type not supported: " + self._ltype + ". Supported libraries:" + str(self._dmplugin.getSupportedLibraryTypes())) return False #artifact and md5 generation file_name = self._artifact + "-" + self._version + "-" + self._platform + "-" + self._compiler + "-" + self._arch + "-" + self._ltype tarname = file_name + ".tar.gz" md5name = tarname + ".md5" dmfile = file_name + ".xml" dmutil = BMUtil() tmpdir = self._dmplugin.getDepManPath( ) + os.path.sep + ".cache" + os.path.sep + self._group + os.path.sep + self._artifact + os.path.sep + self._version + os.path.sep + self._platform + os.path.sep + self._compiler + os.path.sep + self._arch + os.path.sep + self._ltype dmutil.mkdir(tmpdir) print tmpdir + os.path.sep + tarname, self._path dmutil.targz(os.path.join(tmpdir, tarname), self._path) #print "targz ",tmpdir+os.path.sep+tarname dmutil.createMD5(tmpdir + os.path.sep + tarname, tmpdir + os.path.sep + md5name) if self._xmlfile != "": shutil.copyfile(self._xmlfile, tmpdir + os.path.sep + dmfile) print "Artifact " + tarname + " created in:\n" + tmpdir if self._upload: dmutil.rmdir( ".dmn_tmp") # Prevent for uploading bad previous compilations! sshtmpdir = ".dmn_tmp" + os.path.sep + self._group + os.path.sep + self._artifact + os.path.sep + self._version + os.path.sep + self._platform + os.path.sep + self._compiler + os.path.sep + self._arch + os.path.sep + self._ltype dmutil.mkdir(sshtmpdir) shutil.copyfile(tmpdir + os.path.sep + tarname, sshtmpdir + os.path.sep + tarname) shutil.copyfile(tmpdir + os.path.sep + md5name, sshtmpdir + os.path.sep + md5name) if self._xmlfile != "": shutil.copyfile(tmpdir + os.path.sep + dmfile, sshtmpdir + os.path.sep + dmfile) url = self._default_ssh destdir = self._default_destdir login = self._default_login if self._is_Interactive: tmstr = "SSH Server [*]:" url = raw_input(string.replace(tmstr, "*", self._default_ssh)) if len(url) == 0: url = self._default_ssh tmstr = "Destination Directory [*]:" destdir = raw_input( string.replace(tmstr, "*", self._default_destdir)) if len(destdir) == 0: destdir = self._default_destdir tmstr = "Login [*]:" login = raw_input( string.replace(tmstr, "*", self._default_login)) if len(login) == 0: login = self._default_login download_dir = self._group + "/" + self._artifact + "/" + self._version + "/" + self._platform + "/" + self._compiler + "/" + self._arch + "/" + self._ltype print "* Uploading ", tarname print "* Uploading ", md5name #scp base_ssh = destdir url_ssh = url scpcommand = "scp" pscppath = "" if sys.platform == "win32": scpcommand = self._dmplugin.getDepManDataPath( ) + os.path.sep + "win32" + os.path.sep + "pscp.exe" scpcommand = '"' + os.path.normpath(scpcommand) + '"' cmdstr = scpcommand + " -r " + ".dmn_tmp" + os.path.sep + "*" + " " + login + "@" + url_ssh + ":" + base_ssh print cmdstr os.system(cmdstr) #scp dmutil.rmdir(".dmn_tmp")
def extract(self): self._dmupdate = PlugInManager().getPlugInInstance( "DepManUpdatePlugIn") if self._dmupdate == None: self.reportError("PlugIn `depman update` not found") return if self._depmanNode == None: self.loadXMLFile(self._xmlFile) if not self._isInteractive: if self._isFromCache: self._dmupdate.setForceCache() else: self._dmupdate.setForceRemote() dependency_filenamepaths = self._dmupdate.getDependencies( self._depmanNode) package_namepath = self.parsePackage(self._depmanNode) print dependency_filenamepaths, self._destDir, self._filter bmutil = BMUtil() for file in dependency_filenamepaths: bmutil.untargzFiltered(file, self._destDir, self._filter) def parsePackage(self, node): return "" PlugInManager().registerPlugIn("DepManExtractPlugIn", DepManExtractPlugIn())
def testArguments(self): arguments = ArgumentParser(['bmn.py','buildman','--file','bmtests/data/buildman.xml']) bm = BuildMan(arguments) plugin = PlugInManager().getPlugInInstance("BuildManPlugIn") self.assertEqual('bmtests/data/buildman.xml',plugin.getFile())
import shutil class PrepareSystemPlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) def init(self): self.addGoal( "init", "Prepares the system with the buildman user directory with an example plugin" ) while self._arguments.read("init"): self.setExecute(True) def execute(self): print "Executing Plugin:" + str(self.__class__) + "\n" util = BMUtil() bmpath = util.buildmanPlugInPath() try: util.mkdir(bmpath) #shutil.copy(sys.path[0]+os.path.sep+"bmplugins"+os.path.sep+"TestPlugIn.py_",util.buildmanPlugInPath()+os.path.sep+"TestPlugIn.py") except: self.reportError( "Error creating buildman directory or copying test plugin") return False return True PlugInManager().registerPlugIn("PrepareSystemPlugIn", PrepareSystemPlugIn())
class DepManGetPlugIn(IPlugIn): def __init__(self): IPlugIn.__init__(self) self._default_repository = "" self._dependency = None self._forceCache = False self._isInteractive = True def setDependency(self, dependency): self._dependency = dependency def setURL(self,url): self._url = url def setForceCache(self): self._forceCache = True self._isInteractive = False def setForceRemote(self): self._forceCache = False self._isInteractive = False def init(self): self.addGoal("get", "downloads an artifact if not in cache.") self.addGoalOption("get","--url", "URL base for the DepMan repository.") self.addGoalOption("get","--group", "Group namespace of the artifact.") self.addGoalOption("get","--artifact", "Name of the artifact to download.") self.addGoalOption("get","--version", "Version of the artifact.") self.addGoalOption("get","--platform", "Platform of the artifact.") self.addGoalOption("get","--distribution", "Distribution of the artifact.") self.addGoalOption("get","--compiler", "Selects the compiler version that was used to compile the artifact.") self.addGoalOption("get","--arch", "Selects the architecture of the artifact.") self.addGoalOption("get","--ltype", "Type of library of the artifact.") self.addGoalOption("get","--cache", "Forces the use of cache files without asking.") self.addGoalOption("get","--remote", "Forces the download of remote without the use of the cache and without asking.") self._dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn") if self._dmplugin == None: self.reportError("PlugIn `depman` not found") return self._default_repository = self._dmplugin.getDepManPath() while self._arguments.read("get"): self._dependency = Dependency() self.setExecute(true) args=[""] if self._arguments.read("--url",args): self._dependency.url = args[0] args=[""] if self._arguments.read("--group",args): self._dependency.group = args[0] args=[""] if self._arguments.read("--artifact",args): self._dependency.artifact = args[0] args=[""] if self._arguments.read("--version",args): self._dependency.version = args[0] args=[""] if self._arguments.read("--platform",args): self._dependency.platform = args[0] args=[""] if self._arguments.read("--distribution",args): self._dependency.distribution = args[0] args=[""] if self._arguments.read("--compiler",args): self._dependency.compiler = args[0] args=[""] if self._arguments.read("--arch",args): self._dependency.arch = args[0] args=[""] if self._arguments.read("--ltype",args): self._dependency.libraryType = args[0] if self._arguments.read("--cache"): self._forceCache = True self._isInteractive = False if self._arguments.read("--remote"): self._forceCache = False self._isInteractive = False def initFromXML(self,node): pass #TODO: . . . def execute(self): if self._dependency == None: self.reportError("Missing dependency option") return False if self._url == "": self.reportError("Missing url option") return False if not self._dmplugin.validateDependency(self._dependency): return False return self.get() def get(self, unPackList = None): print "[",self._dependency.artifact,"]" file_name = self._dependency.getDepManFileName() tarname=file_name+".tar.gz" md5name=tarname+".md5" download_path = self._dependency.getDepManFilePath() download_dir = self._dependency.getDepManUrlPath() cache_path = self._default_repository+os.path.sep+".cache"+os.path.sep+download_path is_snapshot = self._dependency.isSnapshot() dmutil = BMUtil() is_tar=True is_md5=True if not dmutil.checkUrl(self._dependency.url+"/"+download_dir+"/"+md5name): #print "Error: File ",baseurl+"/"+download_dir+"/"+md5name, " not found in the repository" is_md5=False if not dmutil.checkUrl(self._dependency.url+"/"+download_dir+"/"+tarname): #print "Error: File ",baseurl+"/"+download_dir+"/"+tarname, " not found in the repository" is_tar=False dmutil.mkdir(cache_path) if not os.path.isfile(cache_path+os.path.sep+md5name): is_cache=False else: is_cache=True #Once all variables have been collected, lets decide what to do with the artifact must_download=False if (not is_md5 or not is_tar) and not is_cache: print "Error: Artifact ",tarname," not found" return False if not is_md5 and not is_tar and is_cache: print "* file not found in repository, using cache..." must_download=False if is_md5 and is_tar and not is_cache: print "* file is not in cache, downloading..." must_download=True if is_md5 and is_tar and is_cache: if is_snapshot: if self._isInteractive: repo=raw_input("What snapshot do you want to use? (cache/remote): ") else: if self._forceCache: repo="cache" else: repo="remote" must_download=False #in case of misspeling, using cache by default if repo!="cache" and repo!="remote": repo="cache" else: repo="remote" if repo=="remote": print "* file cached, checking md5..." dmutil.download(self._url+"/"+download_dir+"/"+md5name,cache_path+os.path.sep+md5name+".new") if dmutil.diff(cache_path+os.path.sep+md5name,cache_path+os.path.sep+md5name+".new"): print "* no md5 matching, re-downloading..." must_download=True else: print "* md5 matching succesful" must_download=False os.remove(cache_path+os.path.sep+md5name+".new") if must_download==True: print "URL :", self._dependency.url dmutil.download(self._dependency.url+"/"+download_dir+"/"+md5name,cache_path+os.path.sep+md5name) #print "* downloaded [",md5name,"]" dmutil.download(self._dependency.url+"/"+download_dir+"/"+tarname,cache_path+os.path.sep+tarname) #print "* downloaded[",tarname,"]" if unPackList != None: if (cache_path+os.path.sep+tarname) not in unPackList: unPackList.append(cache_path+os.path.sep+tarname) return True