def upload(cli, meta, owner, channels=['main'], config=None): """Upload a distribution, given the build metadata.""" if hasattr(conda_build, 'api'): fname = bldpkg_path(meta, config) else: fname = bldpkg_path(meta) package_type = detect_package_type(fname) package_attrs, release_attrs, file_attrs = get_attrs(package_type, fname) package_name = package_attrs['name'] version = release_attrs['version'] # Check the package exists, otherwise create one. try: cli.package(owner, package_name) except binstar_client.NotFound: print('Creating the {} package on {}'.format(package_name, owner)) summary = package_attrs['summary'] cli.add_package(owner, package_name, summary, package_attrs.get('license'), public=True) # Check the release exists, otherwise create one. try: cli.release(owner, package_name, version) except binstar_client.NotFound: # TODO: Add readme.md support for descriptions? cli.add_release(owner, package_name, version, requirements=[], announce=None, description='') try: cli.distribution(owner, package_name, version, file_attrs['basename']) except binstar_client.NotFound: # The file doesn't exist. pass else: print('Distribution %s already exists ... removing' % (file_attrs['basename'], )) cli.remove_dist(owner, package_name, version, file_attrs['basename']) with open(fname, 'rb') as fd: print('\nUploading file %s/%s/%s/%s to %s...' % (owner, package_name, version, file_attrs['basename'], channels)) upload_info = cli.upload(owner, package_name, version, file_attrs['basename'], fd, package_type, description='', dependencies=file_attrs.get('dependencies'), attrs=file_attrs['attrs'], channels=channels) return upload_info
def main(args): binstar = get_binstar(args) if args.user: username = args.user else: user = binstar.user() username = user['login'] if not exists(args.filename): raise BinstarError('file %s does not exist' % (args.filename)) log.info('detecting package type ...') sys.stdout.flush() package_type = detect_package_type(args.filename) if package_type is None: raise UserError('Could not detect package type of file %r' % args.filename) log.info(package_type) log.info('extracting package attributes ...') sys.stdout.flush() try: package_attrs = get_attrs(package_type, args.filename) except Exception: if args.show_traceback: raise raise BinstarError( 'Trouble reading metadata from %r. Please make sure this package is correct.' % (args.filename)) _, package_name, _, _, summary, _, license = package_attrs if args.summary: summary = args.summary if args.package: package_name = args.package try: binstar.package(username, package_name) except NotFound: binstar.add_package(username, package_name, summary, license, public=args.access != 'private', publish=args.access == 'publish') log.info('Created package %s/%s' % (username, package_name)) else: raise UserError('Package %s/%s already exists' % (username, package_name))
def main(args): binstar = get_binstar(args) if args.user: username = args.user else: user = binstar.user() username = user ['login'] if not exists(args.filename): raise BinstarError('file %s does not exist' % (args.filename)) log.info('detecting package type ...') sys.stdout.flush() package_type = detect_package_type(args.filename) if package_type is None: raise UserError('Could not detect package type of file %r' % args.filename) log.info(package_type) log.info('extracting package attributes ...') sys.stdout.flush() try: package_attrs = get_attrs(package_type, args.filename) except Exception: if args.show_traceback: raise raise BinstarError('Trouble reading metadata from %r. Please make sure this package is correct.' % (args.filename)) _, package_name, _, _, summary, _, license = package_attrs if args.summary: summary = args.summary if args.package: package_name = args.package try: binstar.package(username, package_name) except NotFound: binstar.add_package(username, package_name, summary, license, public=args.access != 'private', publish=args.access == 'publish') log.info('Created package %s/%s' % (username, package_name)) else: raise UserError('Package %s/%s already exists' % (username, package_name))
def upload(cli, meta, owner, channels=['main'], config=None): """Upload a distribution, given the build metadata.""" fname = get_output_file_path(meta) package_type = detect_package_type(fname) package_attrs, release_attrs, file_attrs = get_attrs(package_type, fname) package_name = package_attrs['name'] version = release_attrs['version'] # Check the package exists, otherwise create one. try: cli.package(owner, package_name) except binstar_client.NotFound: print('Creating the {} package on {}'.format(package_name, owner)) summary = package_attrs['summary'] cli.add_package(owner, package_name, summary, package_attrs.get('license'), public=True) # Check the release exists, otherwise create one. try: cli.release(owner, package_name, version) except binstar_client.NotFound: # TODO: Add readme.md support for descriptions? # The signature for add_release changed in anaconda-client 1.6.3. # First try the old signature, and if that fails, use the new. try: cli.add_release(owner, package_name, version, requirements=[], announce=None, description='') except TypeError: cli.add_release(owner, package_name, version, requirements=[], announce=None, release_attrs={'description': ''}) try: cli.distribution(owner, package_name, version, file_attrs['basename']) except binstar_client.NotFound: # The file doesn't exist. pass else: print('Distribution %s already exists ... removing' % (file_attrs['basename'],)) cli.remove_dist(owner, package_name, version, file_attrs['basename']) with open(fname, 'rb') as fd: print('\nUploading file %s/%s/%s/%s to %s...' % (owner, package_name, version, file_attrs['basename'], channels)) upload_info = cli.upload(owner, package_name, version, file_attrs['basename'], fd, package_type, description='', dependencies=file_attrs.get('dependencies'), attrs=file_attrs['attrs'], channels=channels) return upload_info
def determine_package_type(filename, args): """ return the file type from the inspected package or from the -t/--package-type argument """ if args.package_type: package_type = args.package_type else: log.info('detecting package type ...') sys.stdout.flush() package_type = detect_package_type(filename) if package_type is None: raise errors.BinstarError('Could not detect package type of file %r please specify package type with option --package-type' % filename) log.info(package_type) return package_type
def determine_package_type(filename, args): """ return the file type from the inspected package or from the -t/--package-type argument """ if args.package_type: package_type = args.package_type else: logger.info('Detecting file type...') package_type = detect_package_type(filename) if package_type is None: message = 'Could not detect package type of file %r please specify package type with option --package-type' % filename logger.error(message) raise errors.BinstarError(message) logger.info('File type is "%s"', package_type) return package_type
def main(args): for item in args.deprecated: log.warn('Argument %s has been deprecated and is no longer used. ' 'Please see the command "binstar register" for details' % item) binstar = get_binstar(args) if args.user: username = args.user else: user = binstar.user() username = user ['login'] uploaded_packages = [] for filename in args.files: if not exists(filename): raise BinstarError('file %s does not exist' % (filename)) if args.package_type: package_type = args.package_type else: log.info('detecting package type ...') sys.stdout.flush() package_type = detect_package_type(filename) if package_type is None: raise BinstarError('Could not detect package type of file %r please specify package type with option --package-type' % filename) log.info(package_type) if args.metadata: attrs = json.loads(args.metadata) package_name = args.package version = args.version description = '' basefilename = basename(filename) else: log.info('extracting package attributes for upload ...') sys.stdout.flush() try: package_attrs = get_attrs(package_type, filename) except Exception: if args.show_traceback: raise raise BinstarError('Trouble reading metadata from %r. Please make sure this package is correct or specify the --metadata, --package and --version arguments' % (filename)) basefilename, package_name, version, attrs, summary, description, license = package_attrs log.info('done') if args.package: package_name = args.package if args.version: version = args.version try: binstar.package(username, package_name) except NotFound: if args.no_register: raise UserError('Binstar package %s/%s does not exist. ' 'Please run "binstar register" to create this package namespace in the cloud.' % (username, package_name)) else: binstar.add_package(username, package_name, summary, license, public=True, publish=False) try: binstar.release(username, package_name, version) except NotFound: if args.mode == 'interactive': create_release_interactive(binstar, username, package_name, version) else: create_release(binstar, username, package_name, version, description) with open(filename, 'rb') as fd: log.info('\nUploading file %s/%s/%s/%s ... ' % (username, package_name, version, basefilename)) sys.stdout.flush() try: binstar.distribution(username, package_name, version, basefilename) except NotFound: pass else: if args.mode == 'force': log.warning('Distribution %s already exists ... removing' % (basefilename,)) binstar.remove_dist(username, package_name, version, basefilename) if args.mode == 'interactive': if bool_input('Distribution %s already exists. Would you like to replace it?' % (basefilename,)): binstar.remove_dist(username, package_name, version, basefilename) else: log.info('Not replacing distribution %s' % (basefilename,)) continue try: if args.build_id: attrs['binstar_build'] = args.build_id binstar.upload(username, package_name, version, basefilename, fd, package_type, args.description, attrs=attrs, channels=args.channels, callback=upload_print_callback(args)) except Conflict: full_name = '%s/%s/%s/%s' % (username, package_name, version, basefilename) log.info('Distribution already exists. Please use the -i/--interactive or --force options or `binstar remove %s`' % full_name) raise uploaded_packages.append(package_name) log.info("\n\nUpload(s) Complete\n") for package in uploaded_packages: log.info("Package located at:\nhttps://binstar.org/%s/%s\n" % (username, package))