def _install(artifacts, exclusions=[], options={}): dryrun = options.get("dry-run", False) _exclusions = options.get('exclude', []) if _exclusions: _exclusions = map(lambda x: Artifact(*(x.split(":"))), _exclusions) exclusions.extend(_exclusions) download_list = _resolve_artifacts(artifacts, exclusions) if not dryrun: ## download to cache first for artifact in download_list: if artifact.repos != cache_manager.as_repos(): artifact.repos.download_jar( artifact, cache_manager.get_jar_path(artifact)) pool.join() for artifact in download_list: cache_manager.get_artifact_jar(artifact, get_lib_path()) index_manager.commit() logger.info("[Finished] dependencies resolved") else: logger.info("[Install] Artifacts to install:") for artifact in download_list: print artifact
def freeze(): """ Dump current configuration to a pom file """ dependencies = index_manager.to_pom() repositories = repos_manager.to_pom() template = Template(open(os.path.join(__path__[0], '../data/pom.tpl'), 'r').read()) logger.info( template.substitute({'dependencies': dependencies, 'repositories': repositories}))
def _install(artifacts, exclusions=[], options={}): dryrun = options.get("dry-run", False) _exclusions = options.get('exclude', []) if _exclusions: _exclusions = map(lambda x: Artifact(*(x.split(":"))), _exclusions) exclusions.extend(_exclusions) download_list = _resolve_artifacts(artifacts, exclusions) if not dryrun: ## download to cache first for artifact in download_list: if artifact.repos != cache_manager.as_repos(): artifact.repos.download_jar(artifact, cache_manager.get_jar_path(artifact)) pool.join() for artifact in download_list: cache_manager.get_artifact_jar(artifact, get_lib_path()) index_manager.commit() logger.info("[Finished] dependencies resolved") else: logger.info("[Install] Artifacts to install:") for artifact in download_list: print artifact
def download_jar(self, artifact, local_path): maven_path = self.get_artifact_uri(artifact, 'jar') logger.info('[Downloading] jar from %s' % maven_path) local_jip_path = local_path+"/"+artifact.to_jip_name() local_f = open(local_jip_path, 'w') ## download jar asyncly download(maven_path, local_f, True)
def clean(): """ Remove all downloaded packages """ logger.info("[Deleting] remove java libs in %s" % get_lib_path()) shutil.rmtree(get_lib_path()) index_manager.remove_all() index_manager.commit() logger.info("[Finished] all downloaded files erased")
def download_jar(self, artifact, local_path): maven_path = self.get_artifact_uri(artifact, 'jar') logger.info('[Downloading] jar from %s' % maven_path) local_jip_path = os.path.join(local_path, artifact.to_jip_name()) local_f = open(local_jip_path, 'wb') ## download jar asyncly download(maven_path, local_f, True)
def freeze(): """ Dump current configuration to a pom file """ dependencies = index_manager.to_pom() repositories = repos_manager.to_pom() template = Template(open(os.path.join(__path__[0], '../../../data/pom.tpl'), 'r').read()) logger.info( template.substitute({'dependencies': dependencies, 'repositories': repositories}))
def download_pom(self, artifact): if artifact in self.pom_not_found_cache: return None if artifact in self.pom_cache: return self.pom_cache[artifact] if artifact.is_snapshot(): snapshot_info = self.get_snapshot_info(artifact) if snapshot_info is not None: ts, bn = snapshot_info artifact.timestamp = ts artifact.build_number = bn maven_path = self.get_artifact_uri(artifact, 'pom') try: logger.info('[Checking] pom file %s'% maven_path) data = download_string(maven_path) ## cache self.pom_cache[artifact] = data return data except DownloadException: self.pom_not_found_cache.append(artifact) logger.info('[Skipped] Pom file not found at %s'% maven_path) return None
def download_pom(self, artifact): maven_file_path = self.get_artifact_uri(artifact, 'pom') logger.info('[Checking] pom file %s'% maven_file_path) if os.path.exists(maven_file_path): pom_file = open(maven_file_path, 'r') data = pom_file.read() pom_file.close() return data else: logger.info('[Skipped] pom file not found at %s' % maven_file_path) return None
def remove(artifact_id): """ Remove an artifact from library path """ logger.info('[Checking] %s in library index' % artifact_id) artifact = Artifact.from_id(artifact_id) artifact_path = os.path.join(get_lib_path(), artifact.to_jip_name()) if index_manager.is_installed(artifact) and os.path.exists(artifact_path): os.remove(artifact_path) index_manager.remove_artifact(artifact) index_manager.commit() logger.info('[Finished] %s removed from library path' % artifact_id) else: logger.error('[Error] %s not installed' % artifact_id) sys.exit(1)
def _retrieve_latest_version(group, artifact) -> str: import requests import re url = 'https://oss.sonatype.org/content/repositories/public/%s/%s' % ( group.replace('.', '/'), artifact) result = requests.get(url).text result = [ line.split('/')[-1] for line in re.findall('%s/(\d+\.\d+\.\d+)/' % url, result) ] version = max(result) logger.info('[INFO] Latest version of %s:%s (%s) will be used.', group, artifact, version) return version
def search(query="", options={}): """ Search maven central repository with keywords""" from .search import searcher if query is not None and len(query) > 0: logger.info('[Searching] "%s" in Maven central repository...' % query) results = searcher.search(query) else: g = options.get('group', '') a = options.get('artifact', '') logger.info('[Searching] "%s:%s" in Maven central repository...' % (g,a)) results = searcher.search_group_artifact(g, a) if len(results) > 0: for item in results: g,a,v,p = item logger.info("%s-%s (%s)\n\t%s:%s:%s" % (a,v,p,g,a,v)) else: logger.info('[Finished] nothing returned by criteria "%s"' % query)
def download(url, target, non_blocking=False, close_target=False, quiet=True, verify=True): import requests ### download file to target (target is a file-like object) if non_blocking: pool.submit(url, target, verify) else: try: t0 = time.time() source = requests.get(url, verify=verify, headers={'User-Agent': JIP_USER_AGENT}) source.raise_for_status() size = source.headers['Content-Length'] if not quiet: logger.info('[Downloading] %s %s bytes to download' % (url, size)) for buf in source.iter_content(BUF_SIZE): target.write(buf) source.close() if close_target: target.close() t1 = time.time() if not quiet: logger.info('[Downloading] Download %s completed in %f secs' % (url, (t1-t0))) except requests.exceptions.RequestException: _, e, _ = sys.exc_info() raise DownloadException(url, e)
def download_jar(self, artifact, local_path): maven_file_path = self.get_artifact_uri(artifact, 'jar') logger.info("[Checking] jar package from %s" % self.name) if os.path.exists(maven_file_path): local_jip_path = local_path+"/"+artifact.to_jip_name() logger.info("[Downloading] %s" % maven_file_path) shutil.copy(maven_file_path, local_jip_path) logger.info("[Finished] %s completed" % local_jip_path) else: logger.error("[Error] File not found %s" % maven_file_path) raise IOError('File not found:' + maven_file_path)
def download_jar(self, artifact, local_path): maven_file_path = self.get_artifact_uri(artifact, 'jar') logger.info("[Checking] jar package from %s" % self.name) if os.path.exists(maven_file_path): local_jip_path = os.path.join(local_path, artifact.to_jip_name()) logger.info("[Downloading] %s" % maven_file_path) shutil.copy(maven_file_path, local_jip_path) logger.info("[Finished] %s completed" % local_jip_path) else: logger.error("[Error] File not found %s" % maven_file_path) raise IOError('File not found:' + maven_file_path)
def list(): """ List current installed artifacts """ index_manager.keep_consistent() for a in index_manager.installed: logger.info("%s" % a)
def requires_java_install(): for repos in repositories: repos_manager.add_repos(repos[0], repos[1], 'remote') jip_install(dependencies, exclusions) pool.join() logger.info("[Finished] all dependencies resolved")
def run(self): _install.run(self) logger.info('running jip_resolve') self.run_command('resolve')
class DownloadException(Exception): pass def download(url, target, async=False, close_target=False, quiet=True): import requests ### download file to target (target is a file-like object) if async: pool.submit(url, target) else: try: t0 = time.time() source = requests.get(url, headers={'User-Agent': JIP_USER_AGENT}) size = source.headers['Content-Length'] if not quiet: logger.info('[Downloading] %s %s bytes to download' % (url, size)) for buf in source.iter_content(BUF_SIZE): target.write(buf) source.close() if close_target: target.close() t1 = time.time() if not quiet: logger.info('[Downloading] Download %s completed in %f secs' % (url, (t1 - t0))) except requests.exceptions.RequestException as e: raise DownloadException(url, e) def download_string(url): import requests
def version(): """ Display jip version """ logger.info('[Version] jip %s, jython %s' % (__version__, sys.version))
def version(): """ Display jip version """ logger.info('[Version] jip %s, jython %s' % (JIP_VERSION, sys.version))
class DownloadException(Exception): pass def download(url, target, async=False, close_target=False, quiet=True): ### download file to target (target is a file-like object) if async: pool.submit(url, target) else: request = urllib2.Request(url=url) request.add_header('User-Agent', JIP_USER_AGENT) try: t0 = time.time() source = urllib2.urlopen(request) size = source.headers.getheader('Content-Length') if not quiet: logger.info('[Downloading] %s %s bytes to download' % (url, size)) buf=source.read(BUF_SIZE) while len(buf) > 0: target.write(buf) buf = source.read(BUF_SIZE) source.close() if close_target: target.close() t1 = time.time() if not quiet: logger.info('[Downloading] Download %s completed in %f secs' % (url, (t1-t0))) except urllib2.HTTPError, e: raise DownloadException(url, e) except urllib2.URLError, e: raise DownloadException(url, e)