def main(args): binstar = get_binstar(args, cls=BinstarBuildAPI) package_name = None user_name = None if args.git_url: args.path = args.git_url if args.git_url or is_url(args.path): args.git_url = args.path args.git_url_path = get_urlpath(args.path) args.dont_git_ignore = True submit_git_build(binstar, args) # not a github repo (must check for valid .binstar.yml file else: binstar_yml = join(args.path, '.binstar.yml') if not isfile(binstar_yml): raise UserError("file %s does not exist\n perhaps you should run\n\n binstar-build init\n" % binstar_yml) package_name = None user_name = None with open(binstar_yml) as cfg: for build in yaml.load_all(cfg): if build.get('package'): package_name = build.get('package') if build.get('user'): user_name = build.get('user') # Force package to exist if args.package: if user_name and not args.package.user == user_name: log.warn('User name does not match the user specified in the .binstar.yml file (%s != %s)', args.package.user, user_name) user_name = args.package.user if package_name and not args.package.name == package_name: log.warn('Package name does not match the user specified in the .binstar.yml file (%s != %s)', args.package.name, package_name) package_name = args.package.name else: if user_name is None: user = binstar.user() user_name = user['login'] if not package_name: raise UserError("You must specify the package name in the .binstar.yml file or the command line") try: _ = binstar.package(user_name, package_name) except errors.NotFound: log.error("The package %s/%s does not exist." % (user_name, package_name)) log.error("Run: \n\n binstar package --create %s/%s\n\n to create this package" % (user_name, package_name)) raise errors.NotFound('Package %s/%s' % (user_name, package_name)) args.package = PackageSpec(user_name, package_name) submit_build(binstar, args)
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 read_package_file(fd): for lineno, line in enumerate(fd.readlines()): line = line.split('#', 1)[0] if not line.strip(): continue try: owner, package = line.strip().split('/', 1) except ValueError: msg = "Parse error from file: %s line: %i " % (fd.name, lineno + 1) raise UserError(msg) yield owner, package
def group_spec(spec): '''<organization>/<group_name>/<member>''' org = spec group = member = None if '/' in org: org, group = org.split('/', 1) if group and '/' in group: group, member = group.split('/', 1) if member and '/' in member: raise UserError( 'Invalid group specification "%s" (unexpected "/" in %s)' % member) return GroupSpec(org, group, member, spec)
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))
def basename(self): if self._basename is None: raise UserError( 'basename not given in spec (got %r expected <username>/<package>/<version>/<filename> )' % (self.spec_str, )) return self._basename
def version(self): if self._version is None: raise UserError( 'version not given in spec (got %r expected <username>/<package>/<version> )' % (self.spec_str, )) return self._version
def package(self): if self._package is None: raise UserError( 'package not given in spec (got %r expected <username>/<package> )' % (self.spec_str, )) return self._package
def user(self): if self._user is None: raise UserError('user not given (got %r expected <username> )' % (self.spec_str, )) return self._user
def member(self): if self._member is None: raise UserError( 'Member name not given (got %r expected <organization>/<group_name>/<member>)' % (self.spec_str, )) return self._member
def group_name(self): if self._group_name is None: raise UserError( 'Group name not given (got %r expected <organization>/<group_name>)' % (self.spec_str, )) return self._group_name
def org(self): if self._org is None: raise UserError( 'Organization not given (got %r expected <organization>)' % (self.spec_str, )) return self._org
def main(args): binstar = get_binstar() # Force user auth user = binstar.user() package_name = None user_name = None binstar_yml = join(args.path, '.binstar.yml') if not isfile(binstar_yml): raise UserError("file %s does not exist" % binstar_yml) with open(binstar_yml) as cfg: for build in yaml.load_all(cfg): package_name = build.get('package') user_name = build.get('user') # Force package to exist if args.package: if user_name and not args.package.user == user_name: log.warn( 'User name does not match the user specified in the .binstar.yml file (%s != %s)', args.package.user, user_name) user_name = args.package.user if package_name and not args.package.name == package_name: log.warn( 'Package name does not match the user specified in the .binstar.yml file (%s != %s)', args.package.name, package_name) package_name = args.package.name else: if user_name is None: user_name = user['login'] if not package_name: raise UserError( "You must specify the package name in the .binstar.yml file or the command line" ) try: _ = binstar.package(user_name, package_name) except errors.NotFound: log.error("The package %s/%s does not exist." % (user_name, package_name)) log.error( "Run: 'binstar package --create %s/%s' to create this package" % (user_name, package_name)) raise errors.NotFound('Package %s/%s' % (user_name, package_name)) args.package = PackageSpec(user_name, package_name) if args.resubmit: log.info("Re submit build %s", args.resubmit) return resubmit_build(binstar, args) if args.tail: return tail(binstar, args) if args.halt: return halt_build(binstar, args) if args.list: return list_builds(binstar, args)