def gbp_export(repo, args, config): """Export sources with GBP""" # Create output directories try: if not os.path.exists(args.outdir): os.makedirs(args.outdir) tmp_out = tempfile.mkdtemp(dir=args.outdir) except OSError as err: raise ExportError('Failed to create output directory: %s' % err, EXIT_ERR_SERVICE) # Determine UID/GID try: uid, gid = sanitize_uid_gid(config['gbp-user'], config['gbp-group']) except GbpServiceError as err: raise ExportError(err, EXIT_ERR_SERVICE) # Make temp outdir accessible to the GBP UID/GID os.chown(tmp_out, uid, gid) # Call GBP rpm_args, deb_args = construct_gbp_args(args, config, tmp_out) orig_dir = os.path.abspath(os.curdir) try: os.chdir(repo.repodir) specs_found = have_spec('.') if args.rpm == 'yes' or (args.rpm == 'auto' and specs_found): LOGGER.info('Exporting RPM packaging files with GBP') LOGGER.debug('git-buildpackage-rpm args: %s', ' '.join(rpm_args)) ret = fork_call(uid, gid, gbp_rpm)(rpm_args) if ret: raise ExportError('Git-buildpackage-rpm failed, unable to ' 'export RPM packaging files', EXIT_ERR_RPM_EXPORT) if args.deb == 'yes' or (args.deb== 'auto' and os.path.isdir('debian')): LOGGER.info('Exporting Debian source package with GBP') LOGGER.debug('git-buildpackage args: %s', ' '.join(deb_args)) ret = fork_call(uid, gid, gbp_deb)(deb_args) if ret: raise ExportError('Git-buildpackage failed, unable to export ' 'Debian sources package files', EXIT_ERR_DEB_EXPORT) move_dir_content(tmp_out, args.outdir) except GbpChildBTError as err: LOGGER.error('Unhandled exception in GBP:\n' '%s', err.prettyprint_tb()) raise ExportError('Failed to export packaging files', EXIT_ERR_GBP_CRASH) except GbpServiceError as err: LOGGER.error('Internal service error when trying to run GBP: %s', err) raise ExportError('This is most likely a configuration error (or a ' 'BUG)!', EXIT_ERR_SERVICE) finally: os.chdir(orig_dir) shutil.rmtree(tmp_out)
def gbs_export(repo, args, config): '''Export packaging files with GBS''' # Create temporary directory try: tmpdir = tempfile.mkdtemp(dir=args.outdir) except OSError as err: raise ServiceError('Failed to create tmpdir: %s' % err, EXIT_ERR_SERVICE) # Determine UID/GID and grant permissions to tmpdir try: uid, gid = sanitize_uid_gid(config['gbs-user'], config['gbs-group']) except GbpServiceError as err: raise ServiceError(err, EXIT_ERR_SERVICE) os.chown(tmpdir, uid, gid) # Do export try: gbs_args = construct_gbs_args(args, tmpdir, repo.repodir) LOGGER.info('Exporting packaging files with GBS') LOGGER.debug('gbs args: %s', gbs_args) try: fork_call(uid, gid, cmd_export)(gbs_args) except GbpServiceError as err: LOGGER.error( 'Internal service error when trying to run GBS: ' '%s', err) LOGGER.error('Most likely a configuration error (or a BUG)!') raise ServiceError('Failed to run GBS thread: %s' % err, EXIT_ERR_SERVICE) except GbpChildBTError as err: # CmdError and its sublasses are exptected errors if issubclass(err.typ, CmdError): raise ServiceError('GBS export failed: %s' % err.val, EXIT_ERR_GBS_EXPORT) else: LOGGER.error('Uncaught exception in GBS:\n' '%s', err.prettyprint_tb()) raise ServiceError('GBS crashed, export failed', EXIT_ERR_GBS_CRASH) # Move packaging files from tmpdir to actual outdir exportdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) for fname in os.listdir(exportdir): shutil.move(os.path.join(exportdir, fname), os.path.join(args.outdir, fname)) LOGGER.info('Packaging files successfully exported') finally: shutil.rmtree(tmpdir)
def gbs_export(repo, args, config): '''Export packaging files with GBS''' # Create temporary directory try: tmpdir = tempfile.mkdtemp(dir=args.outdir) except OSError as err: raise ServiceError('Failed to create tmpdir: %s' % err, EXIT_ERR_SERVICE) # Determine UID/GID and grant permissions to tmpdir try: uid, gid = sanitize_uid_gid(config['gbs-user'], config['gbs-group']) except GbpServiceError as err: raise ServiceError(err, EXIT_ERR_SERVICE) os.chown(tmpdir, uid, gid) # Do export try: gbs_args = construct_gbs_args(args, tmpdir, repo.repodir) LOGGER.info('Exporting packaging files with GBS') LOGGER.debug('gbs args: %s', gbs_args) try: fork_call(uid, gid, cmd_export)(gbs_args) except GbpServiceError as err: LOGGER.error('Internal service error when trying to run GBS: ' '%s', err) LOGGER.error('Most likely a configuration error (or a BUG)!') raise ServiceError('Failed to run GBS thread: %s' % err, EXIT_ERR_SERVICE) except GbpChildBTError as err: # CmdError and its sublasses are exptected errors if issubclass(err.typ, CmdError): raise ServiceError('GBS export failed: %s' % err.val, EXIT_ERR_GBS_EXPORT) else: LOGGER.error('Uncaught exception in GBS:\n' '%s', err.prettyprint_tb()) raise ServiceError('GBS crashed, export failed', EXIT_ERR_GBS_CRASH) # Move packaging files from tmpdir to actual outdir exportdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) for fname in os.listdir(exportdir): shutil.move(os.path.join(exportdir, fname), os.path.join(args.outdir, fname)) LOGGER.info('Packaging files successfully exported') finally: shutil.rmtree(tmpdir)