From 88213d8500b5771d6ba35d55f64cdae4b0662229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Sat, 6 Feb 2021 18:50:52 +0000 Subject: [PATCH] Split out vcs module. --- ognibuild/dist.py | 40 +---------------------------- ognibuild/vcs.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 39 deletions(-) create mode 100644 ognibuild/vcs.py diff --git a/ognibuild/dist.py b/ognibuild/dist.py index cf270b1..0000eee 100644 --- a/ognibuild/dist.py +++ b/ognibuild/dist.py @@ -26,8 +26,6 @@ from typing import Optional, List, Tuple, Callable, Type from debian.deb822 import Deb822 -from breezy.errors import NotBranchError -from breezy.export import export from breezy.tree import Tree from breezy.workingtree import WorkingTree @@ -44,6 +42,7 @@ from .buildsystem import detect_buildsystems, NoBuildToolsFound from .session import run_with_tee, Session from .session.schroot import SchrootSession from .debian.fix_build import DependencyContext +from .vcs import dupe_vcs_tree, export_vcs_tree class DistNoTarball(Exception): @@ -260,43 +259,6 @@ def run_dist(session): raise NoBuildToolsFound() -def export_vcs_tree(tree, directory): - try: - export(tree, directory, 'dir', None) - except OSError as e: - if e.errno == errno.ENOSPC: - raise DetailedFailure( - 1, ['export'], NoSpaceOnDevice()) - raise - - -def dupe_vcs_tree(tree, directory): - with tree.lock_read(): - if isinstance(tree, WorkingTree): - tree = tree.basis_tree() - try: - result = tree._repository.controldir.sprout( - directory, create_tree_if_local=True, - revision_id=tree.get_revision_id()) - except OSError as e: - if e.errno == errno.ENOSPC: - raise DetailedFailure( - 1, ['sprout'], NoSpaceOnDevice()) - raise - if not result.has_workingtree(): - raise AssertionError - # Copy parent location - some scripts need this - if isinstance(tree, WorkingTree): - parent = tree.branch.get_parent() - else: - try: - parent = tree._repository.controldir.open_branch().get_parent() - except NotBranchError: - parent = None - if parent: - result.open_branch().set_parent(parent) - - class DistCatcher(object): def __init__(self, directory): diff --git a/ognibuild/vcs.py b/ognibuild/vcs.py new file mode 100644 index 0000000..23994e5 --- /dev/null +++ b/ognibuild/vcs.py @@ -0,0 +1,65 @@ +#!/usr/bin/python3 +# Copyright (C) 2020 Jelmer Vernooij +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +import errno + +from breezy.errors import NotBranchError +from breezy.export import export +from breezy.workingtree import WorkingTree + +from buildlog_consultant.sbuild import ( + NoSpaceOnDevice, + ) + +from . import DetailedFailure + + +def export_vcs_tree(tree, directory): + try: + export(tree, directory, 'dir', None) + except OSError as e: + if e.errno == errno.ENOSPC: + raise DetailedFailure( + 1, ['export'], NoSpaceOnDevice()) + raise + + +def dupe_vcs_tree(tree, directory): + with tree.lock_read(): + if isinstance(tree, WorkingTree): + tree = tree.basis_tree() + try: + result = tree._repository.controldir.sprout( + directory, create_tree_if_local=True, + revision_id=tree.get_revision_id()) + except OSError as e: + if e.errno == errno.ENOSPC: + raise DetailedFailure( + 1, ['sprout'], NoSpaceOnDevice()) + raise + if not result.has_workingtree(): + raise AssertionError + # Copy parent location - some scripts need this + if isinstance(tree, WorkingTree): + parent = tree.branch.get_parent() + else: + try: + parent = tree._repository.controldir.open_branch().get_parent() + except NotBranchError: + parent = None + if parent: + result.open_branch().set_parent(parent)