def main(package, v, d, s, r, proxy, srpm, p, b, o, t, venv): """Convert PyPI package to RPM specfile or SRPM. \b \b\bArguments: PACKAGE Provide PyPI name of the package or path to compressed source file.""" register_file_log_handler('/tmp/pyp2rpm-{0}.log'.format(getpass.getuser())) if srpm or s: register_console_log_handler() distro = o if t in settings.KNOWN_DISTROS: distro = t logger = logging.getLogger(__name__) logger.info('Pyp2rpm initialized.') convertor = Convertor(package=package, version=v, save_dir=d, template=t or settings.DEFAULT_TEMPLATE, distro=distro, base_python_version=b, python_versions=p, rpm_name=r, proxy=proxy, venv=venv) logger.debug('Convertor: {0} created. Trying to convert.'.format(convertor)) converted = convertor.convert() logger.debug('Convertor: {0} succesfully converted.'.format(convertor)) if srpm or s: if r: spec_name = r + '.spec' else: spec_name = 'python-' + convertor.name + '.spec' logger.info('Using name: {0} for specfile.'.format(spec_name)) if d == settings.DEFAULT_PKG_SAVE_PATH: # default save_path is rpmbuild tree so we want to save spec # in rpmbuild/SPECS/ spec_path = d + '/SPECS/' + spec_name else: # if user provide save_path then save spec in provided path spec_path = d + '/' + spec_name spec_dir = os.path.dirname(spec_path) if not os.path.exists(spec_dir): os.makedirs(spec_dir) logger.debug('Opening specfile: {0}.'.format(spec_path)) if not utils.PY3: converted = converted.encode('utf-8') with open(spec_path, 'w') as f: f.write(converted) logger.info('Specfile saved at: {0}.'.format(spec_path)) if srpm: msg = utils.build_srpm(spec_path, d) if utils.PY3: logger.info(msg.decode('utf-8')) else: logger.info(msg) else: logger.debug('Printing specfile to stdout.') if utils.PY3: print(converted) else: print(converted.encode('utf-8')) logger.debug('Specfile printed.') logger.info("That's all folks!")
def main(package, v, d, s, r, proxy, srpm, p, b, o, t, venv, autonc, sclize, **scl_kwargs): """Convert PyPI package to RPM specfile or SRPM. \b \b\bArguments: PACKAGE Provide PyPI name of the package or path to compressed source file. """ register_file_log_handler('/tmp/pyp2rpm-{0}.log'.format(getpass.getuser())) if srpm or s: register_console_log_handler() distro = o if t and os.path.splitext(t)[0] in settings.KNOWN_DISTROS: distro = t if not distro and not (b or p): raise click.UsageError("Default python versions for template {0} are " "missing in settings, add them or use flags " "-b/-p to set python versions.".format(t)) logger = logging.getLogger(__name__) logger.info('Pyp2rpm initialized.') convertor = Convertor(package=package, version=v, save_dir=d, template=t or settings.DEFAULT_TEMPLATE, distro=distro, base_python_version=b, python_versions=p, rpm_name=r, proxy=proxy, venv=venv, autonc=autonc) logger.debug( 'Convertor: {0} created. Trying to convert.'.format(convertor)) converted = convertor.convert() logger.debug('Convertor: {0} succesfully converted.'.format(convertor)) if sclize: converted = convert_to_scl(converted, scl_kwargs) if srpm or s: if r: spec_name = r + '.spec' else: prefix = 'python-' if not convertor.name.startswith( 'python-') else '' spec_name = prefix + convertor.name + '.spec' logger.info('Using name: {0} for specfile.'.format(spec_name)) if d == settings.DEFAULT_PKG_SAVE_PATH: # default save_path is rpmbuild tree so we want to save spec # in rpmbuild/SPECS/ spec_path = d + '/SPECS/' + spec_name else: # if user provide save_path then save spec in provided path spec_path = d + '/' + spec_name spec_dir = os.path.dirname(spec_path) if not os.path.exists(spec_dir): os.makedirs(spec_dir) logger.debug('Opening specfile: {0}.'.format(spec_path)) if not utils.PY3: converted = converted.encode('utf-8') with open(spec_path, 'w') as f: f.write(converted) logger.info('Specfile saved at: {0}.'.format(spec_path)) if srpm: msg = utils.build_srpm(spec_path, d) logger.info(msg) else: logger.debug('Printing specfile to stdout.') if utils.PY3: print(converted) else: print(converted.encode('utf-8')) logger.debug('Specfile printed.') logger.info("That's all folks!")