Пример #1
0
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
Пример #2
0
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
Пример #3
0
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
Пример #4
0
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
Пример #5
0
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
Пример #6
0
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