Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Srpm exceptions #650

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions packit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
from packit.constants import SYNCING_NOTE
from packit.copr_helper import CoprHelper
from packit.distgit import DistGit
from packit.exceptions import PackitException
from packit.exceptions import (
PackitException,
PackitSRPMException,
PackitSRPMNotFoundException,
)
from packit.local_project import LocalProject
from packit.status import Status
from packit.sync import sync_files
Expand Down Expand Up @@ -452,15 +456,28 @@ def create_srpm(
"""
self.up.run_action(actions=ActionName.post_upstream_clone)

source_dir = self.up.prepare_upstream_for_srpm_creation(
upstream_ref=upstream_ref
)
try:
source_dir = self.up.prepare_upstream_for_srpm_creation(
upstream_ref=upstream_ref
)
except Exception as ex:
raise PackitSRPMException(
f"Preparing of the upstream to the SRPM build failed: {ex}"
) from ex

try:
srpm_path = self.up.create_srpm(
srpm_path=output_file, srpm_dir=srpm_dir, source_dir=source_dir
)
except PackitSRPMException:
raise
except Exception as ex:
raise PackitSRPMException(
f"An unexpected error occurred when creating the SRPM: {ex}"
) from ex

srpm_path = self.up.create_srpm(
srpm_path=output_file, srpm_dir=srpm_dir, source_dir=source_dir
)
if not srpm_path.exists():
raise PackitException(
raise PackitSRPMNotFoundException(
f"SRPM was created successfully, but can't be found at {srpm_path}"
)
return srpm_path
Expand Down
14 changes: 14 additions & 0 deletions packit/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from deprecated import deprecated


class PackitException(Exception):
Expand Down Expand Up @@ -50,5 +51,18 @@ class PackitInvalidConfigException(PackitConfigException):
""" provided configuration file is not valid """


@deprecated(reason="Use the PackitFailedToCreateSRPMException instead.")
class FailedCreateSRPM(PackitException):
""" Failed to create SRPM """


class PackitSRPMException(PackitException):
""" Problem with the SRPM """


class PackitSRPMNotFoundException(PackitSRPMException):
""" SRPM created but not found """


class PackitFailedToCreateSRPMException(PackitSRPMException):
""" Failed to create SRPM """
13 changes: 10 additions & 3 deletions packit/upstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
from packit.base_git import PackitRepositoryBase
from packit.config import Config, PackageConfig, SyncFilesConfig
from packit.constants import COMMON_ARCHIVE_EXTENSIONS
from packit.exceptions import PackitException, FailedCreateSRPM
from packit.exceptions import (
PackitException,
PackitSRPMNotFoundException,
PackitFailedToCreateSRPMException,
)
from packit.local_project import LocalProject
from packit.specfile import Specfile
from packit.utils import is_a_git_ref, run_command, git_remote_url_to_https_url
Expand Down Expand Up @@ -548,14 +552,17 @@ def create_srpm(
out = self.command_handler.run_command(cmd, return_output=True).strip()
except PackitException as ex:
logger.error(f"Failed to create SRPM: {ex!r}")
raise FailedCreateSRPM("Failed to create SRPM.")
raise PackitFailedToCreateSRPMException("Failed to create SRPM.")
logger.debug(f"{out}")
# not doing 'Wrote: (.+)' since people can have different locales; hi Franto!
reg = r": (.+\.src\.rpm)$"
try:
the_srpm = re.findall(reg, out)[0]
except IndexError:
raise PackitException("SRPM cannot be found, something is wrong.")
raise PackitSRPMNotFoundException(
"SRPM cannot be found, something is wrong."
)

logger.info("SRPM is %s", the_srpm)
if srpm_path:
shutil.move(the_srpm, srpm_path)
Expand Down