def main(args): if docker is None: raise errors.UserError( "binstar-build docker-worker requires docker and dockerpy to be installed\n" "Run:\n\tpip install dockerpy") bs = get_binstar(args, cls=BinstarBuildAPI) if args.queue.count('/') == 1: username, queue = args.queue.split('/', 1) args.username = username args.queue = queue elif args.queue.count('-') == 2: _, username, queue = args.queue.split('-', 2) args.username = username args.queue = queue else: raise errors.UserError( "Build queue must be of the form build-USERNAME-QUEUENAME or USERNAME/QUEUENAME" ) log.info('Starting worker:') log.info('User: %s' % args.username) log.info('Queue: %s' % args.queue) log.info('Platform: %s' % args.platform) woker = DockerWorker(bs, args) woker.work_forever()
def submit_git_build(binstar, args): log.info("Submitting the following repo for package creation: %s" % args.git_url) builds = get_gitrepo(urlparse(args.git_url)) if not args.package: user = binstar.user() user_name = user['login'] package_name = builds['repo'].split('/')[1] log.info("Using repo name '%s' as the pkg name." % package_name) args.package = PackageSpec(user_name, package_name) try: _ = binstar.package(args.package.user, args.package.name) except errors.NotFound: raise errors.UserError("Package %s does not exist" % (args.package,)) if not args.dry_run: log.info("Submitting the following repo for package creation: %s" % args.git_url) builds = get_gitrepo(urlparse(args.path)) build = binstar.submit_for_url_build(args.package.user, args.package.name, builds, channels=args.channels, queue=args.queue, sub_dir=args.sub_dir, test_only=args.test_only, callback=upload_print_callback(args), filter_platform=args.platform, ) print_build_results(args, build) else: log.info('Build not submitted (dry-run)')
def main(args): aserver_api = get_server_api(args.token, args.site, args.log_level) spec = args.spec channels = aserver_api.list_channels(spec.user) label_text = 'label' if (args.from_label and args.to_label) else 'channel' from_label = args.from_channel or args.from_label to_label = args.to_channel or args.to_label if from_label not in channels: raise errors.UserError( "{} {} does not exist\n\tplease choose from: {}".format( label_text.title(), from_label, ', '.join(channels) )) # TODO: add/replace from_channel => from_label and to_channel => to_label files = aserver_api.copy(spec.user, spec.package, spec.version, spec._basename, to_owner=args.to_owner, from_channel=from_label, to_channel=to_label) for binstar_file in files: print("Copied file: %(basename)s" % binstar_file) if files: log.info("Copied %i files" % len(files)) else: log.warning("Did not copy any files. Please check your inputs with\n\n\tanaconda show %s" % spec)
def add_package(aserver_api, args, username, package_name, package_attrs, package_type): try: return aserver_api.package(username, package_name) except errors.NotFound: if not args.auto_register: message = ( 'Anaconda repository package %s/%s does not exist. ' 'Please run "anaconda package --create" to create this package namespace in the cloud.' % (username, package_name) ) logger.error(message) raise errors.UserError(message) else: if args.summary: summary = args.summary else: if 'summary' not in package_attrs: message = "Could not detect package summary for package type %s, please use the --summary option" % (package_type,) logger.error(message) raise errors.BinstarError(message) summary = package_attrs['summary'] public = not args.private return aserver_api.add_package( username, package_name, summary, package_attrs.get('license'), public=public, attrs=package_attrs, license_url=package_attrs.get('license_url'), license_family=package_attrs.get('license_family'), package_type=package_type, )
def add_package(aserver_api, args, username, package_name, package_attrs, package_type): try: aserver_api.package(username, package_name) except errors.NotFound: if not args.auto_register: raise errors.UserError( 'Anaconda Cloud package %s/%s does not exist. ' 'Please run "anaconda package --create" to create this package namespace in the cloud.' % (username, package_name)) else: if args.summary: summary = args.summary else: if 'summary' not in package_attrs: raise errors.BinstarError( "Could not detect package summary for package type %s, please use the --summary option" % (package_type, )) summary = package_attrs['summary'] aserver_api.add_package(username, package_name, summary, package_attrs.get('license'), public=True, attrs=package_attrs)
def main(args): binstar = get_binstar(args, cls=BinstarBuildAPI) # Force user auth package_name = None url = urlparse(args.url) builds = get_gitrepo(url) ghowner, ghrepo = builds['repo'].split('/', 1) if not args.package: package_name = ghrepo log.info("Using repo name '%s' as the pkg name." % package_name) user = binstar.user() user_name = user['login'] args.package = PackageSpec(user_name, package_name) binstar = get_binstar(args, cls=BinstarBuildAPI) try: _ = binstar.package(args.package.user, args.package.name) except errors.NotFound: raise errors.UserError("Package %s does not exist" % (args.package,)) log.info("Submitting the following repo for package creation: %s" % args.url) # TODO: change channels= to labels= binstar.add_ci(args.package.user, args.package.name, ghowner=ghowner, ghrepo=ghrepo, channels=args.labels, queue=args.queue, sub_dir=args.sub_dir, email=args.email) log.info("CI Added to package %s", args.package)
def main(args): bs = get_binstar(args) spec = args.spec channels = bs.list_channels(spec.user) if args.from_channel not in channels: raise errors.UserError( "Channel %s does not exist\n\tplease choose from: %s" % (args.from_channel, ', '.join(channels))) files = bs.copy(spec.user, spec.package, spec.version, spec._basename, to_owner=args.to_owner, from_channel=args.from_channel, to_channel=args.to_channel) for binstar_file in files: print("Copied file: %(basename)s" % binstar_file) if files: log.info("Copied %i files" % len(files)) else: log.warning( "Did not copy any files. Please check your inputs with\n\n\tanaconda show %s" % spec)
def main(args): bs = get_binstar(args, cls=BinstarBuildAPI) if args.queue.count('/') == 1: username, queue = args.queue.split('/', 1) args.username = username args.queue = queue elif args.queue.count('-') == 2: _, username, queue = args.queue.split('-', 2) args.username = username args.queue = queue else: raise errors.UserError( "Build queue must be of the form build-USERNAME-QUEUENAME or USERNAME/QUEUENAME" ) backlog = bs.build_backlog(args.username, args.queue) print("Backlog for queue %s/%s" % (args.username, args.queue)) header = { 'name': 'Package', 'build_no': 'Build', 'tags': 'Platform', 'enqueued': 'Enqueued' } print('%(name)-30s | %(build_no)-10s | %(tags)-10s | %(enqueued)-30s' % header) print('-' * 89) for job in backlog: job['tags'] = ', '.join(job['tags']) print('%(name)-30s | %(build_no)10s | %(tags)10s | %(enqueued)30s' % job)
def main(args): aserver_api = get_server_api(args.token, args.site) spec = args.spec channels = aserver_api.list_channels(spec.user) label_text = 'label' if (args.from_label and args.to_label) else 'channel' from_label = args.from_label.lower() to_label = args.to_label.lower() if from_label not in channels: raise errors.UserError( "{} {} does not exist\n\tplease choose from: {}".format( label_text.title(), from_label, ', '.join(channels) )) if from_label == to_label: raise errors.UserError('--from-label and --to-label must be different') # Add files to to_label try: aserver_api.add_channel( to_label, spec.user, package=spec.package, version=spec._version, filename=spec._basename, ) except Exception: pass # Remove files from from_label try: aserver_api.remove_channel( from_label, spec.user, package=spec.package, version=spec._version, filename=spec._basename, ) except Exception: pass
def ensure_unique(binstar, username, package_name, version, basename, force): try: binstar.distribution(username, package_name, version, basename) full_name = '%s/%s/%s/%s' % (username, package_name, version, basename) raise errors.UserError( 'File already exists on server. Please use the --force options or `binstar remove %s`' % full_name) except errors.NotFound: return True
def main(args): bs = get_binstar(args, cls=BinstarBuildAPI) if args.queue is None: username = queue_name = None elif args.queue.count('/') == 1: username, queue_name = args.queue.split('/', 1) elif args.queue.count('/') == 2: _, username, queue_name = args.queue.split('/', 2) elif args.queue.count('-') == 2: _, username, queue_name = args.queue.split('-', 2) else: raise errors.UserError( "Build queue must be of the form build-USERNAME-QUEUENAME or USERNAME/QUEUENAME" ) if args.create: if queue_name is None: raise errors.BinstarError("Must specify a queue name to create") if not is_valid_name(queue_name): raise errors.BinstarError( 'Invalid name for ' 'queue: {}. Must start' ' with a letter and contain' ' only numbers, letters, -, and _'.format(queue_name)) bs.add_build_queue(username, queue_name) print("Created queue %s" % queue_name) return if queue_name: queue = bs.build_queue(username, queue_name) if args.remove: if queue.get('workers'): prompt = ('This build queue still has workers attached. ' 'Are you sure you want to remove it') if not bool_input(prompt, False): print("Not removing queue") return bs.remove_build_queue(username, queue_name) print("Removed queue %s" % queue_name) return if args.remove_worker: bs.remove_worker(username, queue_name, args.remove_worker) print("Removed worker %s from queue %s" % (args.remove_worker, queue_name)) return if queue_name: print() show_queue(queue) else: show_queues(bs, username)
def main(args): if docker is None: raise errors.UserError( "anaconda worker docker_run requires docker and docker-py to be installed\n" "Run:\n\tpip install docker-py") bs = get_binstar(args, cls=BinstarBuildAPI) worker_config = WorkerConfiguration.load(args.worker_id, bs) worker = DockerWorker(bs, worker_config, args) worker.work_forever()
def get_gitrepo(url): # split branch from repo if url.netloc != 'github.com': raise errors.UserError( "Currently only github.com urls are supported (got %s)" % url.netloc) pat = re.compile( '^/(?P<repo>[\w-]+/[\w-]+)(/tree/(?P<branch>[\w/]+))?(.git)?$') match = pat.match(url.path) if not match: raise errors.UserError("URL path '%s' is not a git repo" % url.path) groups = match.groupdict() repo = groups.get('repo') branch = groups.get('branch') or url.fragment or 'master' builds = {'repo': repo, 'branch': branch} return builds
def main(args): if docker is None: raise errors.UserError( "anaconda worker docker_run requires docker and docker-py to be installed\n" "Run:\n\tpip install docker-py") bs = get_binstar(args, cls=BinstarBuildAPI) worker_config = WorkerConfiguration.load(args.worker_id, bs, warn=True) WorkerConfiguration.validate_worker_name(bs, args.worker_id) if worker_config.hostname != WorkerConfiguration.HOSTNAME: log.warn( WRONG_HOSTNAME_MSG.format(worker_config.hostname, WorkerConfiguration.HOSTNAME)) worker = DockerWorker(bs, worker_config, args) worker.work_forever()
def split_queue_arg(queue): ''' Support old and new style queue ''' if queue.count('/') == 1: username, queue = queue.split('/', 1) elif queue.count('-') == 2: _, username, queue = queue.split('-', 2) elif queue.count('/') == 2: _, username, queue = queue.split('/', 2) else: raise errors.UserError( "Build queue must be of the form " "build-USERNAME-QUEUENAME or USERNAME/QUEUENAME") return username, queue
def main(args): if docker is None: raise errors.UserError( "anaconda worker docker_run requires docker and docker-py to be installed\n" "Run:\n\tpip install docker-py") bs = get_binstar(args, cls=BinstarBuildAPI) worker_config = WorkerConfiguration.load(args.worker_id, bs, warn=True) WorkerConfiguration.validate_worker_name(bs, args.worker_id) if worker_config.hostname != WorkerConfiguration.HOSTNAME: log.warn( WRONG_HOSTNAME_MSG.format(worker_config.hostname, WorkerConfiguration.HOSTNAME)) setup_logging(logging.getLogger('binstar_build_client'), args.log_level, args.color, show_tb=args.show_traceback) worker = DockerWorker(bs, worker_config, args) worker.write_stats() worker.work_forever()
def main(args): aserver_api = get_server_api(args.token, args.site) spec = args.spec channels = aserver_api.list_channels(spec.user) label_text = 'label' if (args.from_label and args.to_label) else 'channel' from_label = args.from_label to_label = args.to_label if from_label not in channels: raise errors.UserError( "{} {} does not exist\n\tplease choose from: {}".format( label_text.title(), from_label, ', '.join(channels))) files = aserver_api.copy(spec.user, spec.package, spec.version, spec._basename, to_owner=args.to_owner, from_label=from_label, to_label=to_label, replace=args.replace, update=args.update) for binstar_file in files: print("Copied file: %(basename)s" % binstar_file) update_msg = '\nNOTE: copy command with --update option doesn`t copy already existing files.' \ ' Try to use --replace to overwrite existing data' no_copied_files = "Did not copy any files. Please check your inputs with\n\n\tanaconda show {}".format( spec) logger.info("Copied {} files!{}".format(len(files), update_msg if args.update else '')) if not (files or args.update): logger.warning(no_copied_files)
def main(args): args.conda_build_dir = args.conda_build_dir.format(args=args) bs = get_binstar(args, cls=BinstarBuildAPI) if args.queue.count('/') == 1: username, queue = args.queue.split('/', 1) args.username = username args.queue = queue elif args.queue.count('-') == 2: _, username, queue = args.queue.split('-', 2) args.username = username args.queue = queue else: raise errors.UserError( "Build queue must be of the form build-USERNAME-QUEUENAME or USERNAME/QUEUENAME" ) log.info('Starting worker:') log.info('User: %s' % args.username) log.info('Queue: %s' % args.queue) log.info('Platform: %s' % args.platform) woker = Worker(bs, args) woker.work_forever()