Skip to content

Instantly share code, notes, and snippets.

@xtraclass
Created May 25, 2013 20:06
Show Gist options
  • Save xtraclass/5650587 to your computer and use it in GitHub Desktop.
Save xtraclass/5650587 to your computer and use it in GitHub Desktop.
Simple class for downloading artifacts from a private Nexus repository (usually a company makes its own private repository, in this case it is called aaa)
#!/usr/bin/python
import urllib2, sys
class NexusDownloader:
'''Simple class for downloading artifacts from a private Nexus repository.'''
nexus = 'http://nexus.aaa.com/nexus/service/local/artifact/maven/redirect?'
username = 'ci-deployment'
password = ''
@staticmethod
def download( group_id, artifact_id, version, repo, packaging, classifier ):
'''This methods downloads the artifact with the given IDs from the aaa Nexus repository.'''
url = '%sg=%s&a=%s&v=%s&r=%s&p=%s&c=%s' % ( NexusDownloader.nexus, group_id, artifact_id, version, repo, packaging, classifier )
if classifier is not None and len( classifier ) >= 1:
filename = '%s-%s-%s.%s' % ( artifact_id, version, classifier, packaging )
else:
filename = '%s-%s.%s' % ( artifact_id, version, packaging )
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password( None, 'http://nexus.aaa.com', NexusDownloader.username, NexusDownloader.password )
data = urllib2.build_opener( urllib2.HTTPBasicAuthHandler( password_mgr ) ).open( url ).read()
file = open( filename, 'wb' )
file.write( data )
file.close()
if __name__ == '__main__':
NexusDownloader.download( group_id = 'com.aaa.xxx', artifact_id = 'xxx-aaa-ear', version = '1.2.3.4', repo = 'public-releases', packaging = 'ear', classifier = '' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment